HAL COMPONENT FOR
- bedouno
- Offline
- New Member
-
Less
More
- Posts: 1
- Thank you received: 0
11 Apr 2026 23:31 #345428
by bedouno
HAL COMPONENT FOR 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: 11829
- Thank you received: 4009
12 Apr 2026 01:46 #345431
by rodw
Replied by rodw on topic HAL COMPONENT FOR
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: 11829
- Thank you received: 4009
12 Apr 2026 01:51 #345432
by rodw
Replied by rodw on topic HAL COMPONENT FOR
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.
Time to create page: 0.088 seconds