HAL component for tangential knife
- bedouno
- Offline
- New Member
-
Less
More
- Posts: 3
- Thank you received: 0
11 Apr 2026 23:31 #345428
by bedouno
HAL component for tangential knife was created by bedouno
dear friends , i am new imegrant from MACH3 to LINUXCNC, and hope to get engaged to the Real-Time environomrnt and its cabapilties to lead a tangential knife to my application. that MACH3 has this feature with suffecient performance,
i am intending to develop same logic HALComponent to direct A-AXIS and now i am doing the math and trying to apply it to real-time C languge progrmming , i hope if there any help to guide and cooperate to accomplish it
here is the first approach
component tangent_knife;
// inputs
pin in float vel_x;
pin in float vel_y;
pin in float acc_x ;
pin in float acc_y ;
pin in float current_angle;
pin in float threshold;
pin in float lookahead_time ;
// outputs
pin out float command_angle ;
pin out bit intervention_required;
function _;
license "GPL";
;;
#include <rtapi_math.h>
FUNCTION(_) {
double target_angle;
double future_vel_x, future_vel_y;
double angle_diff;
// 1.Simple Lookahead
// V_future = V_current + (Acceleration * Time)
future_vel_x = vel_x + (acc_x * lookahead_time);
future_vel_y = vel_y + (acc_y * lookahead_time);
// 2. alculate ange
if (fabs(future_vel_x) > 1e-6 || fabs(future_vel_y) > 1e-6) {
target_angle = atan2(future_vel_y, future_vel_x);
} else {
target_angle = current_angle;
}
// calculating (Shortest Path)
angle_diff = target_angle - current_angle;
// normalization -PI و PI
while (angle_diff > PM_PI) angle_diff -= 2.0 * PM_PI;
while (angle_diff < -PM_PI) angle_diff += 2.0 * PM_PI;
if (fabs(angle_diff) > threshold) {
intervention_required = 1;
} else {
intervention_required = 0;
}
command_angle = target_angle;
}
i am intending to develop same logic HALComponent to direct A-AXIS and now i am doing the math and trying to apply it to real-time C languge progrmming , i hope if there any help to guide and cooperate to accomplish it
here is the first approach
component tangent_knife;
// inputs
pin in float vel_x;
pin in float vel_y;
pin in float acc_x ;
pin in float acc_y ;
pin in float current_angle;
pin in float threshold;
pin in float lookahead_time ;
// outputs
pin out float command_angle ;
pin out bit intervention_required;
function _;
license "GPL";
;;
#include <rtapi_math.h>
FUNCTION(_) {
double target_angle;
double future_vel_x, future_vel_y;
double angle_diff;
// 1.Simple Lookahead
// V_future = V_current + (Acceleration * Time)
future_vel_x = vel_x + (acc_x * lookahead_time);
future_vel_y = vel_y + (acc_y * lookahead_time);
// 2. alculate ange
if (fabs(future_vel_x) > 1e-6 || fabs(future_vel_y) > 1e-6) {
target_angle = atan2(future_vel_y, future_vel_x);
} else {
target_angle = current_angle;
}
// calculating (Shortest Path)
angle_diff = target_angle - current_angle;
// normalization -PI و PI
while (angle_diff > PM_PI) angle_diff -= 2.0 * PM_PI;
while (angle_diff < -PM_PI) angle_diff += 2.0 * PM_PI;
if (fabs(angle_diff) > threshold) {
intervention_required = 1;
} else {
intervention_required = 0;
}
command_angle = target_angle;
}
Please Log in or Create an account to join the conversation.
- rodw
-
- Offline
- Platinum Member
-
Less
More
- Posts: 11831
- Thank you received: 4010
12 Apr 2026 01:46 #345431
by rodw
Replied by rodw on topic HAL component for tangential knife
This is something that is missing in Linuxcnc. This is actually quite complex. I had a go at it some years ago but my use case faded away.
The pull request still persists. github.com/LinuxCNC/linuxcnc/pull/900
I got it working but it needed a bit of cleanup once the devs reviewed. It really needs to be completed.
This gets pretty deep into the Linuxcnc internals. The interpreter and motion are totally seperate entities in Linuxcnc. The interpreter tokenises the gcode so motion only sees the waypoints.
The interpreter knows or can calculate the centre of the G2/G3 arc and its radius. Motion does not. The change which enabled this was the release of state tags. State Tags passes the interpreter state to motion in real time.
github.com/LinuxCNC/linuxcnc/blob/master...c/motion/state_tag.h
I extended the tags to include
GM_FIELD_FLOAT_ARC_RADIUS,
GM_FIELD_FLOAT_ARC_CENTER_X,
GM_FIELD_FLOAT_ARC_CENTER_Y,
GM_FIELD_FLOAT_STRAIGHT_HEADING,
The last field is the heading you need for your knife.
I published all of these state tags as interp.* pins including the heading so interp.heading is exactly what you need!
I was thinking recently now I am retired I should revisit this project. Maybe you can help and come along for the ride.
The pull request still persists. github.com/LinuxCNC/linuxcnc/pull/900
I got it working but it needed a bit of cleanup once the devs reviewed. It really needs to be completed.
This gets pretty deep into the Linuxcnc internals. The interpreter and motion are totally seperate entities in Linuxcnc. The interpreter tokenises the gcode so motion only sees the waypoints.
The interpreter knows or can calculate the centre of the G2/G3 arc and its radius. Motion does not. The change which enabled this was the release of state tags. State Tags passes the interpreter state to motion in real time.
github.com/LinuxCNC/linuxcnc/blob/master...c/motion/state_tag.h
I extended the tags to include
GM_FIELD_FLOAT_ARC_RADIUS,
GM_FIELD_FLOAT_ARC_CENTER_X,
GM_FIELD_FLOAT_ARC_CENTER_Y,
GM_FIELD_FLOAT_STRAIGHT_HEADING,
The last field is the heading you need for your knife.
I published all of these state tags as interp.* pins including the heading so interp.heading is exactly what you need!
I was thinking recently now I am retired I should revisit this project. Maybe you can help and come along for the ride.
Please Log in or Create an account to join the conversation.
- rodw
-
- Offline
- Platinum Member
-
Less
More
- Posts: 11831
- Thank you received: 4010
12 Apr 2026 01:51 #345432
by rodw
Replied by rodw on topic HAL component for tangential knife
Before this, I tried a component and attempted to read the current X & Y position and the prior x,y position. This allowed me to calculate the radius which I wanted but it never worked accurately. So I went to the state tags approach and Andy one of the devs convinced me to add the heading while I was at it.
Please Log in or Create an account to join the conversation.
- bedouno
- Offline
- New Member
-
Less
More
- Posts: 3
- Thank you received: 0
12 Apr 2026 16:21 #345458
by bedouno
Replied by bedouno on topic HAL component for tangential knife
thanks for your great contribut and i will study it, i have searched for a while and i got this :' the trajectory planner process the G-code and pass the move sequence to a queue to be managed by the motion planner , so what if we can modify the sequence process the queue by our component our module to calculate the angle and specify the cretical angle points then inject this to the motion planner , we can use the lookahead trajectory planner strategy ' .
how you see that
how you see that
Please Log in or Create an account to join the conversation.
- tommylight
-
- Away
- Moderator
-
Less
More
- Posts: 21486
- Thank you received: 7325
12 Apr 2026 18:46 #345464
by tommylight
Replied by tommylight on topic HAL component for tangential knife
What should the tittle of this topic be?
As is seems left in half.
As is seems left in half.
Please Log in or Create an account to join the conversation.
- rodw
-
- Offline
- Platinum Member
-
Less
More
- Posts: 11831
- Thank you received: 4010
12 Apr 2026 21:36 #345468
by rodw
Replied by rodw on topic HAL component for tangential knife
@Tommy, add FOR TANGENTAL KNIFE to the title
@bedouno, Linuxcnc's architecture is complex and described in the docs here
linuxcnc.org/docs/devel/html/code/code-notes.html
The problem to set the tangential heading is that the geometry is known by the gcode but once the gcode is tokenised into a buffer, the gcode (and geometry) is thrown away so motion is just left with way points and segments. Furthermore, this gcode tokenisation is buffered so the interpreter can be many segments ahead of the motion parameters at run time.The intent of state tags was to "tag" each of these motion segments with the interpreter state so certain information was known by motion but it is not exposed in a useful way. (It was originally for GUI's).
The purpose of my code was to extend the state tags mechanism to include the radius and tangential heading and publish the available tags to a set of pins so the data can be used by anyone.
You can do some stuff in a hal component by saving the lastX and lastY positions (axis.L.pos-cmd) and the current axis.x.pos-cmd and axis.y.pos-cmd. motion.motion-type tells you if you are on an arc or a linear segment. Now you can do some trig calculations. If its linear you just need to calculate the slope of the line (angle) and you have the heading. If its an arc, you can calculate the radius, arc and then the tangent which is your heading. I tried this and never got reliable results.
Ref: linuxcnc.org/docs/devel/html/man/man9/motion.9.html
Regardless of what AI thinks, there isn't a method to inject into the motion planner. Perhaps you can develop a kinematic model of the tangential knife. linuxcnc.org/docs/devel/html/motion/kinematics.html
But I think the correct method which AI won't know anything about is to work with state tags.
My thought was that there would be a component that took the heading and set the A axis angle with it.
Yesterday, I made a start on merging the current 2.10 master branch into my 6 year old arc-radius branch but I have not committed it back to GitHub. github.com/rodw-au/linuxcnc/tree/arc-radius
There are 7 files that need manual intervention because of changes to the code base. I'm on my second attempt.....
@bedouno, Linuxcnc's architecture is complex and described in the docs here
linuxcnc.org/docs/devel/html/code/code-notes.html
The problem to set the tangential heading is that the geometry is known by the gcode but once the gcode is tokenised into a buffer, the gcode (and geometry) is thrown away so motion is just left with way points and segments. Furthermore, this gcode tokenisation is buffered so the interpreter can be many segments ahead of the motion parameters at run time.The intent of state tags was to "tag" each of these motion segments with the interpreter state so certain information was known by motion but it is not exposed in a useful way. (It was originally for GUI's).
The purpose of my code was to extend the state tags mechanism to include the radius and tangential heading and publish the available tags to a set of pins so the data can be used by anyone.
You can do some stuff in a hal component by saving the lastX and lastY positions (axis.L.pos-cmd) and the current axis.x.pos-cmd and axis.y.pos-cmd. motion.motion-type tells you if you are on an arc or a linear segment. Now you can do some trig calculations. If its linear you just need to calculate the slope of the line (angle) and you have the heading. If its an arc, you can calculate the radius, arc and then the tangent which is your heading. I tried this and never got reliable results.
Ref: linuxcnc.org/docs/devel/html/man/man9/motion.9.html
Regardless of what AI thinks, there isn't a method to inject into the motion planner. Perhaps you can develop a kinematic model of the tangential knife. linuxcnc.org/docs/devel/html/motion/kinematics.html
But I think the correct method which AI won't know anything about is to work with state tags.
My thought was that there would be a component that took the heading and set the A axis angle with it.
Yesterday, I made a start on merging the current 2.10 master branch into my 6 year old arc-radius branch but I have not committed it back to GitHub. github.com/rodw-au/linuxcnc/tree/arc-radius
There are 7 files that need manual intervention because of changes to the code base. I'm on my second attempt.....
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
- tommylight
-
- Away
- Moderator
-
Less
More
- Posts: 21486
- Thank you received: 7325
12 Apr 2026 22:16 #345469
by tommylight
Replied by tommylight on topic HAL component for tangential knife
Done, thank you.@Tommy, add FOR TANGENTAL KNIFE to the title
Please Log in or Create an account to join the conversation.
- bedouno
- Offline
- New Member
-
Less
More
- Posts: 3
- Thank you received: 0
13 Apr 2026 01:03 #345471
by bedouno
Replied by bedouno on topic HAL component for tangential knife
DEAR Sir, it is great work and i hope to learn alot of you , that was very deep in the CNC FOUNDATION, I am now in need to use my machine and the level of mach3 is very suffecient to me , so what do you recommend to achieve this level now and i hope to join your effort of your project that i hope to learn much of you , thank you sir
Please Log in or Create an account to join the conversation.
Time to create page: 0.090 seconds