Recompiling the motmod modules to expose pos-cmd pins
- hellvetica
- Offline
- Junior Member
-
Less
More
- Posts: 26
- Thank you received: 1
11 Sep 2025 11:16 #334815
by hellvetica
Recompiling the motmod modules to expose pos-cmd pins was created by hellvetica
Hi, I'd like to control my robot arm directly using linuxcnc.
So far I've been using MDI and external offset pins to move the robot but I've had some issues with latency (mdi) and absolute positioning (external offsets). (When the robot starts, the motor's target position is not set to 0 but some other value close to 0 like 18 or -23 for some reason)
I'd like to pretty much hack the motion module so I can expose the pos-cmd pins that the trajectory planner sets so i can just connect to hal and set my cartesian position as I wish and not go in all these roundabout ways to get the robot to move.
The mini PC running the robot has a debian image with linuxcnc preinstalled.
1. What would be the easiest way to modify the source to achieve this?
2. How would I build the module and use it in my existing linuxcnc installation?
I'm not at all wary of digging into the C code, but I've never build linuxcnc myself.
Thanks for any tips
So far I've been using MDI and external offset pins to move the robot but I've had some issues with latency (mdi) and absolute positioning (external offsets). (When the robot starts, the motor's target position is not set to 0 but some other value close to 0 like 18 or -23 for some reason)
I'd like to pretty much hack the motion module so I can expose the pos-cmd pins that the trajectory planner sets so i can just connect to hal and set my cartesian position as I wish and not go in all these roundabout ways to get the robot to move.
The mini PC running the robot has a debian image with linuxcnc preinstalled.
1. What would be the easiest way to modify the source to achieve this?
2. How would I build the module and use it in my existing linuxcnc installation?
I'm not at all wary of digging into the C code, but I've never build linuxcnc myself.
Thanks for any tips

Please Log in or Create an account to join the conversation.
- Aciera
-
- Offline
- Administrator
-
Less
More
- Posts: 4484
- Thank you received: 2005
11 Sep 2025 11:23 #334816
by Aciera
Replied by Aciera on topic Recompiling the motmod modules to expose pos-cmd pins
Please Log in or Create an account to join the conversation.
- hellvetica
- Offline
- Junior Member
-
Less
More
- Posts: 26
- Thank you received: 1
11 Sep 2025 12:40 #334823
by hellvetica
Replied by hellvetica on topic Recompiling the motmod modules to expose pos-cmd pins
Thank you for the quick reply!
It's good that I can build a separate version without interfering with my base installation.
I'm having a hard time following the path of the position command through the code because of all the shared memory.
Could you give me advice on which module would be the best candidate to inject the extra pins into? Ideally it would be whatever the trajectory planner outputs its cartesian coordinates to. So instead of taking values from the trajectory planner it would take values from HAL pins.
It's good that I can build a separate version without interfering with my base installation.
I'm having a hard time following the path of the position command through the code because of all the shared memory.
Could you give me advice on which module would be the best candidate to inject the extra pins into? Ideally it would be whatever the trajectory planner outputs its cartesian coordinates to. So instead of taking values from the trajectory planner it would take values from HAL pins.
Please Log in or Create an account to join the conversation.
- hellvetica
- Offline
- Junior Member
-
Less
More
- Posts: 26
- Thank you received: 1
12 Sep 2025 10:52 #334875
by hellvetica
Replied by hellvetica on topic Recompiling the motmod modules to expose pos-cmd pins
I figured it out.
I created 2 pins:
pos_cmd_override and pos_cmd_override_enable
to emc/motion/axis.c as well as add the variables in the emcmot_axis_t and axis_hal_t structs.
Created getter functions like in the axis.c and the corresponding declaration in axis.h
Then in axis_calc_motion in axis.c i added
```
if (axis_get_pos_cmd_override_enable(axis_num)) {
axis->teleop_tp.pos_cmd = axis_get_pos_cmd_override(axis_num);
axis->teleop_tp.enable = 1;
axis->teleop_tp.max_vel = axis->vel_limit;
axis->teleop_tp.max_acc = axis->acc_limit;
}
```
Now I can set the pins to the desired robot position and the trajectory planner will do the rest. I can also use useful feedback pins like in-position which i couldn't do when using external offsets.
I created 2 pins:
pos_cmd_override and pos_cmd_override_enable
to emc/motion/axis.c as well as add the variables in the emcmot_axis_t and axis_hal_t structs.
Created getter functions like in the axis.c and the corresponding declaration in axis.h
Then in axis_calc_motion in axis.c i added
```
if (axis_get_pos_cmd_override_enable(axis_num)) {
axis->teleop_tp.pos_cmd = axis_get_pos_cmd_override(axis_num);
axis->teleop_tp.enable = 1;
axis->teleop_tp.max_vel = axis->vel_limit;
axis->teleop_tp.max_acc = axis->acc_limit;
}
```
Now I can set the pins to the desired robot position and the trajectory planner will do the rest. I can also use useful feedback pins like in-position which i couldn't do when using external offsets.
Please Log in or Create an account to join the conversation.
- Aciera
-
- Offline
- Administrator
-
Less
More
- Posts: 4484
- Thank you received: 2005
12 Sep 2025 15:30 #334887
by Aciera
Replied by Aciera on topic Recompiling the motmod modules to expose pos-cmd pins
glad you got it working. If you feel like sharing you could go to your cloned folder and post the output of:
Might help somebody in the future.
git diff --minimal HEAD
Might help somebody in the future.
Please Log in or Create an account to join the conversation.
Time to create page: 0.059 seconds