building my first Hal component
07 Jan 2011 10:25 #6504
by andypugh
Replied by andypugh on topic Re:building my first Hal component
garymcrobertpdx wrote:
It's easy enough to find out, you can load and test components from the command line (And this is the simplest way to test your component too)
halrun
loadrt <insert module name>
show function
If you want to actually run the component:
loadrt threads
addf <module name> thread1
start
If you have a separate terminal window open you can keep typing dmesg to look for errors
Testing a component:
setp mycomponent.0.pin1 53
show pin
(etc)
Halrun/halcmd does tab completion, in fact the addf statement a bit earlier could really be addf <tab> <tab>
You can do most things, but the realtime function really needs to run through and exit very quickly. It should never wait, but rather set an internal "I am waiting" flag and check the condition next time it runs, for example.
Disk file access shouldn't be a problem, but should be in the EXTRA_SETUP code, I think.
Comp hides the fact that the code you write runs a number of parallel copies, but it is worth bearing in mind that any local variables you define within the code block will be shared between all instances of the function. You need to use the "variable" statement in the header section to create per-instance locals.
If you need to pass a filename to the component you are not limited to just using the "personality" and "count" modparams, you can actually use anything you like. This is a section of code from a .comp of mine which parses a "cfg=xx,yy,zz" string into an array for use by the components. (the three comma-separated parameters mean that three instances are created)
This is one of the macros described here:
www.linuxcnc.org/docview/html/man/man3/r...le_param.3rtapi.html
OK I have successfully got comp to convert a comp into a c program
not sure if I have seceded in creating a real time component yet.
I will test this soon.
It's easy enough to find out, you can load and test components from the command line (And this is the simplest way to test your component too)
halrun
loadrt <insert module name>
show function
If you want to actually run the component:
loadrt threads
addf <module name> thread1
start
If you have a separate terminal window open you can keep typing dmesg to look for errors
Testing a component:
setp mycomponent.0.pin1 53
show pin
(etc)
Halrun/halcmd does tab completion, in fact the addf statement a bit earlier could really be addf <tab> <tab>
A question since I am writing C code can I do any thing C or are
there significant restrictions. For example can I open a disk file
and read data into an array in my C code which this ultimately
happens in the hal component when it executes,.
You can do most things, but the realtime function really needs to run through and exit very quickly. It should never wait, but rather set an internal "I am waiting" flag and check the condition next time it runs, for example.
Disk file access shouldn't be a problem, but should be in the EXTRA_SETUP code, I think.
Comp hides the fact that the code you write runs a number of parallel copies, but it is worth bearing in mind that any local variables you define within the code block will be shared between all instances of the function. You need to use the "variable" statement in the header section to create per-instance locals.
If you need to pass a filename to the component you are not limited to just using the "personality" and "count" modparams, you can actually use anything you like. This is a section of code from a .comp of mine which parses a "cfg=xx,yy,zz" string into an array for use by the components. (the three comma-separated parameters mean that three instances are created)
;;
#include <rtapi_math.h>
#define MAX_CHAN 8
#define NUM_TAG 8
static char *cfg[NUM_TAG];
RTAPI_MP_ARRAY_STRING(cfg, NUM_TAG, "Description of each motor");
This is one of the macros described here:
www.linuxcnc.org/docview/html/man/man3/r...le_param.3rtapi.html
Please Log in or Create an account to join the conversation.
- garymcrobertpdx
- Offline
- Premium Member
Less
More
- Posts: 101
- Thank you received: 1
07 Jan 2011 19:59 #6522
by garymcrobertpdx
Replied by garymcrobertpdx on topic Re:building my first Hal component
Super! I look forward to exploring and creating useful hal components.
How ever I have hit yet another snag, most likely precipitated by my
lack of knowledge of the Linux OS. Once again I am using an existing
comp file as a learning tool. Here is the error message I received
me@CNC:~/emc2-dev/src/hal/components$ comp --install abs.comp
make -C /usr/src/linux-headers-2.6.24-16-rtai SUBDIRS=`pwd` CC=gcc V=0 -o /Module.symvers modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.24-16-rtai'
CC [M] /tmp/tmpLj9Hu8/abs.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "hal_ready" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "rtapi_print_msg" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_init" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_export_funct" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "rtapi_snprintf" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_pin_bit_newf" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_pin_float_newf" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_malloc" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_exit" [/tmp/tmpLj9Hu8/abs.ko] undefined!
CC /tmp/tmpLj9Hu8/abs.mod.o
LD [M] /tmp/tmpLj9Hu8/abs.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-16-rtai'
cp abs.ko /usr/realtime-2.6.24-16-rtai/modules/emc2/
cp: cannot create regular file `/usr/realtime-2.6.24-16-rtai/modules/emc2/abs.ko': Permission denied
make: *** [install] Error 1
me@CNC:~/emc2-dev/src/hal/components$
Did I fail to provide the OS with some type of file write Permission???
How ever I have hit yet another snag, most likely precipitated by my
lack of knowledge of the Linux OS. Once again I am using an existing
comp file as a learning tool. Here is the error message I received
me@CNC:~/emc2-dev/src/hal/components$ comp --install abs.comp
make -C /usr/src/linux-headers-2.6.24-16-rtai SUBDIRS=`pwd` CC=gcc V=0 -o /Module.symvers modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.24-16-rtai'
CC [M] /tmp/tmpLj9Hu8/abs.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "hal_ready" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "rtapi_print_msg" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_init" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_export_funct" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "rtapi_snprintf" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_pin_bit_newf" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_pin_float_newf" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_malloc" [/tmp/tmpLj9Hu8/abs.ko] undefined!
WARNING: "hal_exit" [/tmp/tmpLj9Hu8/abs.ko] undefined!
CC /tmp/tmpLj9Hu8/abs.mod.o
LD [M] /tmp/tmpLj9Hu8/abs.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-16-rtai'
cp abs.ko /usr/realtime-2.6.24-16-rtai/modules/emc2/
cp: cannot create regular file `/usr/realtime-2.6.24-16-rtai/modules/emc2/abs.ko': Permission denied
make: *** [install] Error 1
me@CNC:~/emc2-dev/src/hal/components$
Did I fail to provide the OS with some type of file write Permission???
Please Log in or Create an account to join the conversation.
07 Jan 2011 20:22 - 07 Jan 2011 20:24 #6523
by andypugh
Replied by andypugh on topic Re:building my first Hal component
I suspect I don't see that as I use a run-in-place dev version of emc2.
Try sudo comp --install <your file name>
xkcd.com/149/
Try sudo comp --install <your file name>
xkcd.com/149/
Last edit: 07 Jan 2011 20:24 by andypugh.
Please Log in or Create an account to join the conversation.
- garymcrobertpdx
- Offline
- Premium Member
Less
More
- Posts: 101
- Thank you received: 1
08 Jan 2011 19:29 #6551
by garymcrobertpdx
Replied by garymcrobertpdx on topic Re:building my first Hal component
At last! I am writing hal components that work! many many thanks to
Andy and John for their gracious assistance.
Now I am investigating the rs274ngc portion of EMC2
in particular interp_convert.cc Is advanced configurations
the appropriate forum location for this subject?
Andy and John for their gracious assistance.
Now I am investigating the rs274ngc portion of EMC2
in particular interp_convert.cc Is advanced configurations
the appropriate forum location for this subject?
Please Log in or Create an account to join the conversation.
08 Jan 2011 19:39 #6552
by andypugh
Replied by andypugh on topic Re:building my first Hal component
Maybe send that to the Developers mailing list.
Please Log in or Create an account to join the conversation.
Time to create page: 0.689 seconds