-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add headings and other geometric pins in motion using State_tags #3995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
5a8e0d9
cac77e5
52572e5
da9fa18
12d2cc2
d4f3a18
00450b3
1321309
7ae6979
8a869ec
2702760
7c6f016
8413344
245e91b
de27899
7021690
20992b0
5b2d61f
5461c2d
bafea85
b576a1f
ecb5799
d61aea7
34af536
37bd9ba
026421b
aa3f8e3
892b9a3
4fc14bc
8560dac
81e061d
d707137
2d9030a
cbc2c6d
9d7b041
b79afe5
90a6c94
87a2fb2
28395da
697ac51
44bf837
01dba4d
b700943
b59c583
d0d7143
43c1a2a
f030b39
0b572ff
043af1f
f9e9707
3e3ac4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,14 +26,15 @@ | |
| #include <posemath.h> | ||
| #include <kinematics.h> //for kinematicsSwitchable() | ||
| #include <motion_types.h> | ||
|
|
||
| #include "../tp/tp.h" | ||
| #include "simple_tp.h" | ||
| #include "motion.h" | ||
| #include "mot_priv.h" | ||
| #include "config.h" | ||
| #include "homing.h" | ||
| #include "axis.h" | ||
| #include "state_tag.h" | ||
|
|
||
|
|
||
| // Mark strings for translation, but defer translation to userspace | ||
| #define _(s) (s) | ||
|
|
@@ -1888,6 +1889,13 @@ static void output_to_hal(void) | |
| *(emcmot_hal_data->coord_error) = GET_MOTION_ERROR_FLAG(); | ||
| *(emcmot_hal_data->on_soft_limit) = emcmotStatus->on_soft_limit; | ||
|
|
||
| /* Performance Metadata */ | ||
| *(emcmot_hal_data->interp_feedrate) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_FEED]; | ||
|
|
||
| /* Line and Motion Type (Casting to int for s32 HAL pins) */ | ||
| *(emcmot_hal_data->interp_line_number) = (int)emcmotStatus->tag.fields[GM_FIELD_LINE_NUMBER]; | ||
| *(emcmot_hal_data->interp_motion_type) = (int)emcmotStatus->tag.fields[GM_FIELD_MOTION_MODE]; | ||
| *(emcmot_hal_data->iscircle) = (hal_bit_t)((emcmotStatus->tag.packed_flags & (1UL << GM_FLAG_IS_CIRCLE)) != 0); | ||
| switch (emcmotStatus->motionType) { | ||
| case EMC_MOTION_TYPE_FEED: //fall thru | ||
| case EMC_MOTION_TYPE_ARC: | ||
|
|
@@ -2033,10 +2041,9 @@ static void output_to_hal(void) | |
| /* point to joint struct */ | ||
| joint = &joints[joint_num]; | ||
| joint_data = &(emcmot_hal_data->joint[joint_num]); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On this line you (only) add trailing whitespace. I discovered that you have trailing whitespace on lines multiple places in your code. You should check for that and remove it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will review in a seperate commit from code fixes |
||
| /* apply backlash and motor offset to output */ | ||
| joint->motor_pos_cmd = | ||
| joint->pos_cmd + joint->backlash_filt + joint->motor_offset; | ||
| joint->motor_pos_cmd = joint->pos_cmd + joint->backlash_filt + joint->motor_offset; | ||
| /* point to HAL data */ | ||
| /* write to HAL pins */ | ||
| *(joint_data->motor_offset) = joint->motor_offset; | ||
|
|
@@ -2131,6 +2138,9 @@ static void update_status(void) | |
| // and the state machine is still active. The homing status deassertion | ||
| // must be delayed until the state machine is done. | ||
| joint_status->homing = get_homing(joint_num); | ||
| /* check to see if we should pause in order to implement | ||
| single emcmotStatus->stepping */ | ||
|
|
||
| } | ||
| joint_status->homed = get_homed(joint_num); | ||
| joint_status->pos_cmd = joint->pos_cmd; | ||
|
|
@@ -2211,6 +2221,90 @@ static void update_status(void) | |
| emcmotStatus->stepping = 0; | ||
| emcmotStatus->paused = 1; | ||
| } | ||
| // State Tags handling | ||
| // Get the current executing trajectory component (the "Source of Truth") | ||
| /* Update the HAL Output Pins from the active tag */ | ||
| if (emcmot_hal_data) { | ||
| // Line and Motion Type | ||
| if (emcmot_hal_data->interp_line_number) { | ||
| *(emcmot_hal_data->interp_line_number) = (int)emcmotStatus->tag.fields[GM_FIELD_LINE_NUMBER]; | ||
| } | ||
|
|
||
| // Performance Metadata | ||
| if (emcmot_hal_data->interp_feedrate) { | ||
| *(emcmot_hal_data->interp_feedrate) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_FEED]; | ||
| } | ||
|
|
||
| // Geometric Metadata | ||
|
|
||
| if (emcmot_hal_data->interp_arc_radius) { | ||
| *(emcmot_hal_data->interp_arc_radius) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_RADIUS]; | ||
| } | ||
| if (emcmot_hal_data->interp_arc_center_x) { | ||
| *(emcmot_hal_data->interp_arc_center_x) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_X]; | ||
| } | ||
| if (emcmot_hal_data->interp_arc_center_y) { | ||
| *(emcmot_hal_data->interp_arc_center_y) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_Y]; | ||
| } | ||
| if (emcmot_hal_data->interp_arc_center_z) { | ||
| *(emcmot_hal_data->interp_arc_center_z) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_Z]; | ||
| } | ||
| // Get the current motion type from the tag (1=G1, 2=G2, 3=G3) | ||
| int motion_type = (int)emcmotStatus->tag.fields[GM_FIELD_MOTION_MODE]; | ||
| if (motion_type == 10 || motion_type == 0) { | ||
| /* --- G1/G0 STATIC HEADING --- */ | ||
| // For linear moves, the heading doesn't change during the segment. | ||
| if (emcmot_hal_data->interp_straight_heading) { | ||
| *(emcmot_hal_data->interp_straight_heading) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_STRAIGHT_HEADING]; | ||
| } | ||
| } | ||
| else if (motion_type == 20 || motion_type == 30) { | ||
| /* --- G2/G3: DYNAMIC ARC HEADING --- */ | ||
|
|
||
| // 1. Get Static Center from Tag | ||
| double cx = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_X]; | ||
| double cy = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_Y]; | ||
| double cz = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_Z]; | ||
|
|
||
| // 2. Get Real-Time Feedback Deltas | ||
| double dx = emcmotStatus->carte_pos_fb.tran.x - cx; | ||
| double dy = emcmotStatus->carte_pos_fb.tran.y - cy; | ||
| double dz = emcmotStatus->carte_pos_fb.tran.z - cz; | ||
|
|
||
| // 3. Determine Plane and Radial Angle | ||
| int plane = emcmotStatus->tag.fields[GM_FIELD_PLANE]; | ||
| double angle_rad = 0.0; // Initialize to prevent "uninitialized" error | ||
|
|
||
| if (plane == 170) { // XY: X is Horizontal, Y is Vertical | ||
| angle_rad = atan2(dy, dx); | ||
| } | ||
| else if (plane == 180) { // XZ: Z is Horizontal, X is Vertical | ||
| angle_rad = atan2(dx, dz); | ||
| } | ||
| else if (plane == 190) { // YZ: Y is Horizontal, Z is Vertical | ||
| angle_rad = atan2(dz, dy); | ||
| } | ||
| // Optional: add an else here for a default plane if 170/180/190 aren't found | ||
|
|
||
| // 4. Calculate Normal Heading (Tool-to-Center) | ||
| double normal_deg = (angle_rad * (180.0 / M_PI)) + 180.0; | ||
| while (normal_deg < 0) normal_deg += 360.0; | ||
| while (normal_deg >= 360.0) normal_deg -= 360.0; | ||
| *(emcmot_hal_data->interp_normal_heading) = normal_deg; | ||
|
|
||
| // 5. Calculate Tangent Heading (Direction of Travel) | ||
| double tangent_rad = (motion_type == 30) ? (angle_rad + (M_PI / 2.0)) : (angle_rad - (M_PI / 2.0)); | ||
| double heading_deg = tangent_rad * (180.0 / M_PI); | ||
|
|
||
| // 6. Final Normalization and Assignment | ||
| while (heading_deg < 0) heading_deg += 360.0; | ||
| while (heading_deg >= 360.0) heading_deg -= 360.0; | ||
|
|
||
| if (emcmot_hal_data->interp_straight_heading) { | ||
| *(emcmot_hal_data->interp_straight_heading) = heading_deg; | ||
| } | ||
| } | ||
| } | ||
| #ifdef WATCH_FLAGS | ||
| /*! \todo FIXME - this is for debugging */ | ||
| if ( old_motion_flag != emcmotStatus->motionFlag ) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the z-value missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these lines are uperflous as they are all set (including z) further down at around line 2249.
Removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, its still here...