How to link .a lib in my hal comp ?

More
06 Nov 2014 13:03 #52865 by blightxdm1
OK.This is what i'm trying to do .
I have a MEI card ( from kollmorgen ),it'a a motion controller and i want to integrate it into linuxcnc . i have the driver , lib file and header files of the card. so i need to write a rt hal module .As the title show , i got the problem : how to link a lib file to compile a rt hal component c file .

Attached the lib file ,header files and mei.c-- my test module.
Attachments:

Please Log in or Create an account to join the conversation.

More
06 Nov 2014 18:09 - 07 Nov 2014 00:40 #52871 by ArcEye
Hi

I don't know what editor you use, but mei.c had no line endings whatsoever in it and lots of spurious // C++ comments
Took me 3/4 hr just to put the line endings back in so I could read it

I will look at a permanent patch for comp / halcompile to allow extra libs, but assuming you don't want to wait for all the testing etc that trying to work in python will entail,
in the interim here is a simple alternative

I have hacked comp to include the -n switch to make in the module building sections.
This will output to stdout the commands that would be executed

You can just cut and paste them and create your own script which includes the extra libs and / or flags you want to add.

Now that I know it is a rt module, you will see the process is different to userspace
// RT

# comp-output --compile oilactivate.comp 
echo Compiling realtime oilactivate.c
gcc -o oilactivate.o -I. -pthread -DTHREAD_FLAVOR_ID=1 -DRTAPI -D_GNU_SOURCE -D_FORTIFY_SOURCE=0 -D__MODULE__ -mieee-fp  -I/usr/src/machinekit/include -fPIC -g -I/usr/src/machinekit -I/usr/src/machinekit  { extra libs here } -c oilactivate.c
echo Linking oilactivate.so
ld -d -r -o oilactivate.tmp oilactivate.o
if ! test `uname -m` = ppc -o `uname -m` = ppc64; then objcopy -j .rtapi_export -O binary oilactivate.tmp oilactivate.exp; fi
if ! test `uname -m` = ppc -o `uname -m` = ppc64; then objcopy -G __x86.get_pc_thunk.bx -G __i686.get_pc_thunk.bx `xargs -r0n1 echo -G < oilactivate.exp | grep -ve '^-G $' | sort -u` oilactivate.tmp; fi
gcc -shared -Bsymbolic  -o oilactivate.so oilactivate.tmp -lm
Unable to copy module from temporary directory

// Userspace
# comp-output --compile threadkill.comp 
gcc -I. -pthread -DTHREAD_FLAVOR_ID=1 -DRTAPI -D_GNU_SOURCE -D_FORTIFY_SOURCE=0 -D__MODULE__ -mieee-fp  -I/usr/src/machinekit/include -fPIC -g -URTAPI -U__MODULE__ -DULAPI /
	 -Os  -o threadkill /tmp/tmp77CbZ3/threadkill.c -Wl,-rpath,/usr/src/machinekit/lib -L/usr/src/machinekit/lib -llinuxcnchal

Ignore the errors that accompany, they are just because the build was not done for real
Also note this was demo was done on a rt-preempt kernel build, hence the .so extention.

Hopefully this will get you going and I will look at the full mod in due course

The version of comp below that I modified is from the 10.04 2.5.4 linuxcnc-dev package, but should work on any version

regards
Attachments:
Last edit: 07 Nov 2014 00:40 by ArcEye.

Please Log in or Create an account to join the conversation.

More
06 Nov 2014 18:29 #52872 by andypugh

I have a MEI card ( from kollmorgen ),it'a a motion controller and i want to integrate it into linuxcnc


That might actually be difficult, as LinuxCNC is a motion controller too.
The data available to a HAL driver is not "move this axis and this axis to these end points" but "this millisecond I want this motor here, and that motor there"
At a higher level there is a G-code interpreter that sends messages like STRAIGHT_TRAVERSE(100,100,20,0,0,0,0) to the motion queue where it is handled by the motion module.
It might be that your card wants to be at the level where "motion" sits, not in the HAL layer below motion.

Attached the lib file ,header files and mei.c-- my test module.

There seem to be no line-breaks at all in your mei.c file, which is not something I have seen before.

Do you have good documentation for the card? You might want to be working at a lower level with register writes to the card. (this is more typical of how HAL drivers work)

Please Log in or Create an account to join the conversation.

More
06 Nov 2014 21:19 #52876 by blightxdm1

I have a MEI card ( from kollmorgen ),it'a a motion controller and i want to integrate it into linuxcnc


That might actually be difficult, as LinuxCNC is a motion controller too.
The data available to a HAL driver is not "move this axis and this axis to these end points" but "this millisecond I want this motor here, and that motor there"
At a higher level there is a G-code interpreter that sends messages like STRAIGHT_TRAVERSE(100,100,20,0,0,0,0) to the motion queue where it is handled by the motion module.
It might be that your card wants to be at the level where "motion" sits, not in the HAL layer below motion.

Attached the lib file ,header files and mei.c-- my test module.

There seem to be no line-breaks at all in your mei.c file, which is not something I have seen before.

Do you have good documentation for the card? You might want to be working at a lower level with register writes to the card. (this is more typical of how HAL drivers work)


Yes , as you said mei is another motion controller as the motmotion in linuxcnc .my first step is to make it work together . if possible ,in the second step ,i'll do something about this issue. Maybe replace the motion controller with mei .Thank you very much .

Please Log in or Create an account to join the conversation.

More
06 Nov 2014 21:42 #52877 by andypugh

Yes , as you said mei is another motion controller as the motmotion in linuxcnc .my first step is to make it work together . if possible ,in the second step ,i'll do something about this issue. Maybe replace the motion controller with mei .Thank you very much .


I can't help feeling that that would be a very large amount of work for very little benefit.

Maybe a better solution (especially if this is a one-off and you are not in the situation of having a warehouse full of MEI cards and a large order for LinuxCNC machines) would be to see if you can configure the MEI card to behave like a set of velocity-mode servo drives. This would be an easier fit into the LinuxCNC structure. If you can send velocity commands to the controller and receive position data back then your MEU driver can link to motion through a PID module, and everything should work fairly smoothly. (This is largely the structure used for the supported interfaces with onboard encoder counting, such as Motenc, Mesa, Pico, General Mechatronics and so on)

Please Log in or Create an account to join the conversation.

More
06 Nov 2014 22:14 #52878 by mariusl

I have a MEI card ( from kollmorgen ),it'a a motion controller and i want to integrate it into linuxcnc


The data available to a HAL driver is not "move this axis and this axis to these end points" but "this millisecond I want this motor here, and that motor there"


Andy, thanks for raising this interesting subject. Where can we read up on how the motion interface would work. The timing information and motor position information etc.

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
06 Nov 2014 22:28 #52879 by andypugh

Andy, thanks for raising this interesting subject. Where can we read up on how the motion interface would work. The timing information and motor position information etc.


Possibly here:
www.linuxcnc.org/docs/html/code/Code_Notes.html

Though it is incomplete and not 100% up to date. (some things have moved to different files since that was written, and the first bloc diagram is pre-HAL (the second includes it)

Please Log in or Create an account to join the conversation.

More
07 Nov 2014 01:18 #52883 by ArcEye
Hi

A testing version of modified comp is attached

I can't see much use for it in rt modules, but it will make adding external libraries to a userspace component easier

Takes a link argument in the .comp file eg.
component threadkill                  "This component waits for machine.in-position and kills a pre-defined thread process";

pin in bit commandfinished = 1        "signal last command completed - connect to motion.in-position";
pin in bit homed = 0                  "signal that machine is homed and ready for commands - connect to last axis to home - halui.joint.2.is-homed";
pin in bit machineon = 0              "signal to ensure machine is on - connect to halui.machine.is-on"; 
option singleton yes;               
option userspace yes;

link "-L/usr/local/lib -lEMC_Access";

author "ArcEye <arceyeATmgwareDOTcoDOTuk>";
license "GPL";
;;

which produces the gcc command when building a userspace example of
gcc -I. -pthread -DTHREAD_FLAVOR_ID=1 -DRTAPI -D_GNU_SOURCE -D_FORTIFY_SOURCE=0 -D__MODULE__ -mieee-fp  -I/usr/src/machinekit/include -fPIC -g -URTAPI -U__MODULE__ -DULAPI /
	-Os  -o threadkill /tmp/tmppD12Ij/threadkill.c -Wl,-rpath,/usr/src/machinekit/lib -L/usr/src/machinekit/lib -llinuxcnchal  -L/usr/local/lib -lEMC_Access

with a corresponding entry in the gcc line for building the initial object file for a rt module

Give it a try and see how it works for you

regards
Attachments:

Please Log in or Create an account to join the conversation.

More
16 Nov 2014 18:08 #53135 by ArcEye
Just an update to the thread for any future views

In consultation with Jeff Epler, halcompile (comp) has been amended to include a field to accept extra lib and lib path specifications.

The field is 'extra_link_args', the changes have been pushed and will filter into the next release / update in due course, along with amended docs regards its usage.

regards

Please Log in or Create an account to join the conversation.

Time to create page: 0.248 seconds
Powered by Kunena Forum