|
34 | 34 | #include "config.h" |
35 | 35 | #include "homing.h" |
36 | 36 | #include "axis.h" |
| 37 | +#include "state_tag.h" |
37 | 38 |
|
38 | 39 | // Mark strings for translation, but defer translation to userspace |
39 | 40 | #define _(s) (s) |
@@ -1888,6 +1889,13 @@ static void output_to_hal(void) |
1888 | 1889 | *(emcmot_hal_data->coord_error) = GET_MOTION_ERROR_FLAG(); |
1889 | 1890 | *(emcmot_hal_data->on_soft_limit) = emcmotStatus->on_soft_limit; |
1890 | 1891 |
|
| 1892 | + /* Performance Metadata */ |
| 1893 | + *(emcmot_hal_data->interp_feedrate) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_FEED]; |
| 1894 | + |
| 1895 | + /* Line and Motion Type (Casting to int for s32 HAL pins) */ |
| 1896 | + *(emcmot_hal_data->interp_line_number) = (int)emcmotStatus->tag.fields[GM_FIELD_LINE_NUMBER]; |
| 1897 | + *(emcmot_hal_data->interp_motion_type) = (int)emcmotStatus->tag.fields[GM_FIELD_MOTION_MODE]; |
| 1898 | + *(emcmot_hal_data->iscircle) = (hal_bit_t)((emcmotStatus->tag.packed_flags & (1UL << GM_FLAG_IS_CIRCLE)) != 0); |
1891 | 1899 | switch (emcmotStatus->motionType) { |
1892 | 1900 | case EMC_MOTION_TYPE_FEED: //fall thru |
1893 | 1901 | case EMC_MOTION_TYPE_ARC: |
@@ -2211,6 +2219,74 @@ static void update_status(void) |
2211 | 2219 | emcmotStatus->stepping = 0; |
2212 | 2220 | emcmotStatus->paused = 1; |
2213 | 2221 | } |
| 2222 | + // State Tags handling |
| 2223 | + // Get the current executing trajectory component (the "Source of Truth") |
| 2224 | + /* Update the HAL Output Pins from the active tag */ |
| 2225 | + // Line and Motion Type |
| 2226 | + *(emcmot_hal_data->interp_line_number) = (int)emcmotStatus->tag.fields[GM_FIELD_LINE_NUMBER]; |
| 2227 | + |
| 2228 | + // Performance Metadata |
| 2229 | + *(emcmot_hal_data->interp_feedrate) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_FEED]; |
| 2230 | + |
| 2231 | + // Geometric Metadata |
| 2232 | + *(emcmot_hal_data->interp_arc_radius) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_RADIUS]; |
| 2233 | + *(emcmot_hal_data->interp_arc_center_x) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_X]; |
| 2234 | + *(emcmot_hal_data->interp_arc_center_y) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_Y]; |
| 2235 | + *(emcmot_hal_data->interp_arc_center_z) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_Z]; |
| 2236 | + |
| 2237 | + // Get the current motion type from the tag (1=G1, 2=G2, 3=G3) |
| 2238 | + int motion_type = (int)emcmotStatus->tag.fields[GM_FIELD_MOTION_MODE]; |
| 2239 | + if (motion_type == 10 || motion_type == 0) { |
| 2240 | + /* --- G1/G0 STATIC HEADING --- */ |
| 2241 | + // For linear moves, the heading doesn't change during the segment. |
| 2242 | + *(emcmot_hal_data->interp_straight_heading) = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_STRAIGHT_HEADING]; |
| 2243 | + } |
| 2244 | + else if (motion_type == 20 || motion_type == 30) { |
| 2245 | + /* --- G2/G3: DYNAMIC ARC HEADING --- */ |
| 2246 | + |
| 2247 | + // 1. Get Static Center from Tag |
| 2248 | + double cx = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_X]; |
| 2249 | + double cy = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_Y]; |
| 2250 | + double cz = emcmotStatus->tag.fields_float[GM_FIELD_FLOAT_ARC_CENTER_Z]; |
| 2251 | + |
| 2252 | + // 2. Get Real-Time Feedback Deltas |
| 2253 | + double dx = emcmotStatus->carte_pos_fb.tran.x - cx; |
| 2254 | + double dy = emcmotStatus->carte_pos_fb.tran.y - cy; |
| 2255 | + double dz = emcmotStatus->carte_pos_fb.tran.z - cz; |
| 2256 | + |
| 2257 | + // 3. Determine Plane and Radial Angle |
| 2258 | + int plane = emcmotStatus->tag.fields[GM_FIELD_PLANE]; |
| 2259 | + double angle_rad = 0.0; // Initialize to prevent "uninitialized" error |
| 2260 | + |
| 2261 | + if (plane == 170) { // XY: X is Horizontal, Y is Verradiustical |
| 2262 | + angle_rad = atan2(dy, dx); |
| 2263 | + } |
| 2264 | + else if (plane == 180) { // XZ: Z is Horizontal, X is Vertical |
| 2265 | + angle_rad = atan2(dx, dz); |
| 2266 | + } |
| 2267 | + else if (plane == 190) { // YZ: Y is Horizontal, Z is Vertical |
| 2268 | + angle_rad = atan2(dz, dy); |
| 2269 | + } |
| 2270 | + // Optional: add an else here for a default plane if 170/180/190 aren't found |
| 2271 | + |
| 2272 | + // 4. Calculate Normal Heading (Tool-to-Center) |
| 2273 | + double normal_deg = (angle_rad * (180.0 / M_PI)) + 180.0; |
| 2274 | + while (normal_deg < 0) normal_deg += 360.0; |
| 2275 | + while (normal_deg >= 360.0) normal_deg -= 360.0; |
| 2276 | + *(emcmot_hal_data->interp_normal_heading) = normal_deg; |
| 2277 | + |
| 2278 | + // 5. Calculate Tangent Heading (Direction of Travel) |
| 2279 | + double tangent_rad = (motion_type == 30) ? (angle_rad + (M_PI / 2.0)) : (angle_rad - (M_PI / 2.0)); |
| 2280 | + double heading_deg = tangent_rad * (180.0 / M_PI); |
| 2281 | + |
| 2282 | + // 6. Final Normalization and Assignment |
| 2283 | + while (heading_deg < 0) heading_deg += 360.0; |
| 2284 | + while (heading_deg >= 360.0) heading_deg -= 360.0; |
| 2285 | + |
| 2286 | + if (emcmot_hal_data->interp_straight_heading) { |
| 2287 | + *(emcmot_hal_data->interp_straight_heading) = heading_deg; |
| 2288 | + } |
| 2289 | + } |
2214 | 2290 | #ifdef WATCH_FLAGS |
2215 | 2291 | /*! \todo FIXME - this is for debugging */ |
2216 | 2292 | if ( old_motion_flag != emcmotStatus->motionFlag ) { |
|
0 commit comments