How to make HAL pins from .c kinematics file?
20 Aug 2024 01:52 #308182
by winyk
How to make HAL pins from .c kinematics file? was created by winyk
Hello. I am a newbie. Please note that not only I am new to LinuxCNC, but I am also new to CNC as well. However, the reason I am learning LinuxCNC is because my boss want someone to help with one of the mills that we have in our office. The mill is very similar to that of 5axiskins config (located at configs/sim/axis/vismach/5axis/bridgemill) that provided with LinuxCNC by default. Since it is too dangerous to experiment on the actual machine, I am testing things out on a virtual machine (LinuxCNC on Debian inside VirtualBox). I have installed LinuxCNC using run-in-place method.
What I am trying to achieve for now is to make some extra HAL pins from 5axiskins.c . My boss suggest that I can create additional HAL pins by simply adding additional members to the haldata structure in 5axiskins.c . Actually, he had done this before. He managed to create two HAL pins named x-offset and y-offset by modifying the haldata struct to be as followed:
Then he added these lines to the [HAL] part in the 5axis.ini to create two signals
However, after I tried to follow his steps, I cannot reproduce his result. AXIS is no longer able to start the config, and it gives me an error saying that pin 5axiskins.x-offset does not exist.
This error was generated from the lines I added in 5axis.ini. Commenting out the four lines I just added in 5axis.ini allowed me to get into AXIS, but I couldn't find the pins I just added inside Halshow (note that pivot-length pin comes with 5axiskins.c by default). So the cause of the error is clear: the pins didn't get created at all.
After consulting with my boss, he is not sure why it doesn't work this time either. So, I am asking for help on this post. Is it possible to create HAL pins by simply modifying haldata struct in .c kinematics file? If so, what did I do wrong?
What I am trying to achieve for now is to make some extra HAL pins from 5axiskins.c . My boss suggest that I can create additional HAL pins by simply adding additional members to the haldata structure in 5axiskins.c . Actually, he had done this before. He managed to create two HAL pins named x-offset and y-offset by modifying the haldata struct to be as followed:
struct haldata {
hal_float_t *pivot_length;
hal_float_t *x_offset;
hal_float_t *y_offset;
} *haldata;
Then he added these lines to the [HAL] part in the 5axis.ini to create two signals
HALCMD = net :x-offset 5axiskins.x-offset
HALCMD = net :y-offset 5axiskins.y-offset
HALCMD = net: sets x-offset -0.25
HALCMD = net: sets y-offset -37.975
However, after I tried to follow his steps, I cannot reproduce his result. AXIS is no longer able to start the config, and it gives me an error saying that pin 5axiskins.x-offset does not exist.
This error was generated from the lines I added in 5axis.ini. Commenting out the four lines I just added in 5axis.ini allowed me to get into AXIS, but I couldn't find the pins I just added inside Halshow (note that pivot-length pin comes with 5axiskins.c by default). So the cause of the error is clear: the pins didn't get created at all.
After consulting with my boss, he is not sure why it doesn't work this time either. So, I am asking for help on this post. Is it possible to create HAL pins by simply modifying haldata struct in .c kinematics file? If so, what did I do wrong?
Attachments:
Please Log in or Create an account to join the conversation.
20 Aug 2024 05:56 #308191
by Aciera
Replied by Aciera on topic How to make HAL pins from .c kinematics file?
you also need to call the 'hal_pin_float_newf()' to create the pins:
So after this:
add this
So after this:
result = hal_pin_float_newf(HAL_IN,&(haldata->pivot_length),comp_id,
"%s.pivot-length",kp->halprefix);
add this
result = hal_pin_float_newf(HAL_IN,&(haldata->x_offset),comp_id,"%s.x-offset",kp->halprefix);
if(result < 0) goto error;
result = hal_pin_float_newf(HAL_IN,&(haldata->y_offset),comp_id,"%s.y-offset",kp->halprefix);
if(result < 0) goto error;
The following user(s) said Thank You: winyk
Please Log in or Create an account to join the conversation.
20 Aug 2024 07:17 #308194
by Özkarhan
Replied by Özkarhan on topic How to make HAL pins from .c kinematics file?
in the lines below, you are actually creating a variable to hold your data in program memory.
struct haldata {
hal_float_t *pivot_length;
hal_float_t *x_offset;
hal_float_t *y_offset;
} *haldata;
You need to expose that addresses named x_offset, y_offset, pivot_length to hal layer, this means exporting pin. As aciera said, you can use hal_pin_float_newf function to export it. You can also use other functions to export it, they are declared at src/hal/lib/hal.h file.
This exporting process works like this:
1- You have a struct in your program memory and it is only for your program, not for other programs.
2- With this exporting functions, you are sharing your program's memory with other programs. You can consider it like giving a permission to hal layer to access your program's memory. You are registering your program's memory to public area.
3- Afte exporting your pins, you are giving ability to use that pin names in hal layer appropriately. for example, if you use this code block,
result = hal_pin_float_newf(HAL_IN,&(haldata->pivot_length),comp_id,
"%s.pivot-length", "component-name");
it means you are exporting haldata->pivot_length memory area to hal layer with name component-name.pivot-length. After that, you can use it in your hal file with this name.
I recommend to read about Inter Process Communication mechanisms in Linux, especially shared memory. LinuxCNC uses shared memory to register hal pins.
struct haldata {
hal_float_t *pivot_length;
hal_float_t *x_offset;
hal_float_t *y_offset;
} *haldata;
You need to expose that addresses named x_offset, y_offset, pivot_length to hal layer, this means exporting pin. As aciera said, you can use hal_pin_float_newf function to export it. You can also use other functions to export it, they are declared at src/hal/lib/hal.h file.
This exporting process works like this:
1- You have a struct in your program memory and it is only for your program, not for other programs.
2- With this exporting functions, you are sharing your program's memory with other programs. You can consider it like giving a permission to hal layer to access your program's memory. You are registering your program's memory to public area.
3- Afte exporting your pins, you are giving ability to use that pin names in hal layer appropriately. for example, if you use this code block,
result = hal_pin_float_newf(HAL_IN,&(haldata->pivot_length),comp_id,
"%s.pivot-length", "component-name");
it means you are exporting haldata->pivot_length memory area to hal layer with name component-name.pivot-length. After that, you can use it in your hal file with this name.
I recommend to read about Inter Process Communication mechanisms in Linux, especially shared memory. LinuxCNC uses shared memory to register hal pins.
Please Log in or Create an account to join the conversation.
Time to create page: 0.189 seconds