Run XYZAC through upstream LinuxCNC TP

This commit is contained in:
2026-09-01 11:44:05 +08:00
parent bbdfad8364
commit d18141ec81
23 changed files with 1550 additions and 139 deletions

View File

@@ -1,7 +1,39 @@
diff --git a/src/emc/nml_intf/emc.cc b/src/emc/nml_intf/emc.cc
index 59fdabe..cdba7ed 100644
--- a/src/emc/nml_intf/emc.cc
+++ b/src/emc/nml_intf/emc.cc
@@ -1838,6 +1838,7 @@ void EMC_TRAJ_STAT::update(CMS * cms)
cms->update(probeval);
cms->update(kinematics_type);
cms->update(motion_type);
+ cms->update(motion_heartbeat);
}
@@ -2261,4 +2262,4 @@ void EMC_MOTION_ADAPTIVE::update(CMS * cms)
void EMC_MOTION_CMD_MSG::update(CMS * cms)
{
-}
\ No newline at end of file
+}
diff --git a/src/emc/nml_intf/emc_nml.hh b/src/emc/nml_intf/emc_nml.hh
index 2d5e61e..8c713b7 100644
--- a/src/emc/nml_intf/emc_nml.hh
+++ b/src/emc/nml_intf/emc_nml.hh
@@ -834,6 +834,7 @@ class EMC_TRAJ_STAT:public EMC_TRAJ_STAT_MSG {
//bool spindle_override_enabled; moved to SPINDLE_STAT
bool adaptive_feed_enabled;
bool feed_hold_enabled;
+ uint32_t motion_heartbeat; // native motion-controller servo-cycle counter
StateTag tag;
};
diff --git a/src/emc/task/emctaskmain.cc b/src/emc/task/emctaskmain.cc
index 6d5ebd5..d215e2e 100644
--- a/src/emc/task/emctaskmain.cc
+++ b/src/emc/task/emctaskmain.cc
@@ -3490,4 +3490,9 @@ int main(int argc, char *argv[])
@@ -3490,6 +3490,11 @@ int main(int argc, char *argv[])
// since emcStatus was passed to the WM init functions, it
// will be updated in the _update() functions above. There's
// no need to call the individual functions on all WM items.
@@ -11,16 +43,40 @@ diff --git a/src/emc/task/emctaskmain.cc b/src/emc/task/emctaskmain.cc
+ // wall-clock sampling.
+ emcStatus->task.heartbeat++;
emcStatusBuffer->write(emcStatus);
// wait on timer cycle, if specified, or calculate actual
diff --git a/src/emc/task/taskintf.cc b/src/emc/task/taskintf.cc
index 36fbd97..b3ae2aa 100644
--- a/src/emc/task/taskintf.cc
+++ b/src/emc/task/taskintf.cc
@@ -1612,6 +1612,7 @@ int emcTrajUpdate(EMC_TRAJ_STAT * stat)
stat->feed_override_enabled = enables & FS_ENABLED;
stat->adaptive_feed_enabled = enables & AF_ENABLED;
stat->feed_hold_enabled = enables & FH_ENABLED;
+ stat->motion_heartbeat = emcmotStatus.heartbeat;
if (new_config) {
stat->cycleTime = emcmotConfig.trajCycleTime;
diff --git a/src/emc/usr_intf/axis/extensions/emcmodule.cc b/src/emc/usr_intf/axis/extensions/emcmodule.cc
index b43f041..96f12a2 100644
--- a/src/emc/usr_intf/axis/extensions/emcmodule.cc
+++ b/src/emc/usr_intf/axis/extensions/emcmodule.cc
@@ -409,4 +409,7 @@ static PyMemberDef Stat_members[] = {
@@ -409,6 +409,9 @@ static PyMemberDef Stat_members[] = {
{(char*)"echo_serial_number", T_INT, O(echo_serial_number), READONLY},
{(char*)"echo_serial_number", T_INT, O(echo_serial_number), READONLY},
{(char*)"state", T_INT, O(status), READONLY},
+ {(char*)"task_heartbeat", T_UINT, O(task.heartbeat), READONLY,
+ "Native EMC task-loop heartbeat. This counter is incremented by the "
+ "LinuxCNC task thread and is suitable for identifying native status ticks."},
// task
{(char*)"task_mode", T_INT, O(task.mode), READONLY},
@@ -473,6 +476,8 @@ static PyMemberDef Stat_members[] = {
{(char*)"feed_override_enabled", T_BOOL, O(motion.traj.feed_override_enabled), READONLY},
{(char*)"adaptive_feed_enabled", T_BOOL, O(motion.traj.adaptive_feed_enabled), READONLY},
{(char*)"feed_hold_enabled", T_BOOL, O(motion.traj.feed_hold_enabled), READONLY},
+ {(char*)"motion_heartbeat", T_UINT, O(motion.traj.motion_heartbeat), READONLY,
+ "Native motion-controller servo-cycle counter."},
{(char*)"num_extrajoints", T_INT, O(motion.numExtraJoints), READONLY},

View File

@@ -0,0 +1,69 @@
diff --git a/src/emc/motion/control.c b/src/emc/motion/control.c
index 8c9ce66..0ab0f5f 100644
--- a/src/emc/motion/control.c
+++ b/src/emc/motion/control.c
@@ -19,6 +19,9 @@
#ifdef SWITCHKINS_DEBUG
#include <stdio.h> // rtpreempt only, consolidate to stderr
#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
#include "posemath.h"
#include "rtapi.h"
@@ -67,6 +70,46 @@ extern struct emcmot_status_t *emcmotStatus;
// etc.
static double *pcmd_p[EMCMOT_MAX_AXIS];
+/* Optional simulation-only servo oracle. It is disabled unless the caller
+ * provides a file path, so normal LinuxCNC motion timing is unchanged. */
+static FILE *xyzac_trace_stream;
+static void xyzac_trace_tick(void) {
+ const char *path;
+ int joint;
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (xyzac_trace_stream == NULL) {
+ path = getenv("LINUXCNC_XYZAC_TRACE_FILE");
+ if (path == NULL || path[0] == '\0') return;
+ xyzac_trace_stream = fopen(path, "w");
+ if (xyzac_trace_stream == NULL) return;
+ setvbuf(xyzac_trace_stream, NULL, _IOLBF, 0);
+ }
+ fprintf(xyzac_trace_stream,
+ "{\"wall_ns\":%llu,\"motion_heartbeat\":%u,\"position\":[%.17g,%.17g,%.17g,%.17g,%.17g,%.17g,%.17g,%.17g,%.17g],\"actual_position\":[%.17g,%.17g,%.17g,%.17g,%.17g,%.17g,%.17g,%.17g,%.17g],\"velocity\":%.17g,\"acceleration\":%.17g,\"queue_depth\":%d,\"active_depth\":%d,\"motion_id\":%d,\"motion_type\":%d,\"paused\":%d,\"queue_full\":%d,\"joints\":[",
+ (unsigned long long)now.tv_sec * 1000000000ull + (unsigned long long)now.tv_nsec,
+ emcmotStatus->heartbeat,
+ emcmotStatus->carte_pos_cmd.tran.x, emcmotStatus->carte_pos_cmd.tran.y, emcmotStatus->carte_pos_cmd.tran.z,
+ emcmotStatus->carte_pos_cmd.a, emcmotStatus->carte_pos_cmd.b, emcmotStatus->carte_pos_cmd.c,
+ emcmotStatus->carte_pos_cmd.u, emcmotStatus->carte_pos_cmd.v, emcmotStatus->carte_pos_cmd.w,
+ emcmotStatus->carte_pos_fb.tran.x, emcmotStatus->carte_pos_fb.tran.y, emcmotStatus->carte_pos_fb.tran.z,
+ emcmotStatus->carte_pos_fb.a, emcmotStatus->carte_pos_fb.b, emcmotStatus->carte_pos_fb.c,
+ emcmotStatus->carte_pos_fb.u, emcmotStatus->carte_pos_fb.v, emcmotStatus->carte_pos_fb.w,
+ emcmotStatus->current_vel, emcmotStatus->acc, emcmotStatus->depth,
+ emcmotStatus->activeDepth, emcmotStatus->id, emcmotStatus->motionType,
+ emcmotStatus->paused, emcmotStatus->queueFull);
+ for (joint = 0; joint < EMCMOT_MAX_JOINTS; ++joint) {
+ if (joint != 0) fputc(',', xyzac_trace_stream);
+ fprintf(xyzac_trace_stream, "{\"cmd\":%.17g,\"fb\":%.17g,\"vel\":%.17g,\"acc\":%.17g,\"homed\":%d}",
+ emcmotStatus->joint_status[joint].pos_cmd,
+ emcmotStatus->joint_status[joint].pos_fb,
+ emcmotStatus->joint_status[joint].vel_cmd,
+ emcmotStatus->joint_status[joint].acc_cmd,
+ emcmotStatus->joint_status[joint].homed);
+ }
+ fputs("]}\n", xyzac_trace_stream);
+}
+
/***********************************************************************
* LOCAL FUNCTION PROTOTYPES *
************************************************************************/
@@ -271,6 +314,7 @@ void emcmotController(void *arg, long period)
update_status();
/* here ends the core of the controller */
emcmotStatus->heartbeat++;
+ xyzac_trace_tick();
/* set tail to head, to indicate work complete */
emcmotStatus->tail = emcmotStatus->head;
/* end of controller function */