From a980740fd5244030016ed6382b19239b11580cca Mon Sep 17 00:00:00 2001 From: smathis Date: Thu, 24 Jul 2025 09:40:52 +0200 Subject: [PATCH] Test timing problem --- src/turboPmacAxis.cpp | 26 ++++++++++++++++++-------- src/turboPmacController.cpp | 16 ---------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/turboPmacAxis.cpp b/src/turboPmacAxis.cpp index 4dd1219..644e3ee 100644 --- a/src/turboPmacAxis.cpp +++ b/src/turboPmacAxis.cpp @@ -13,6 +13,15 @@ #include #include +#include + +long long timeInMilliseconds(void) { + struct timeval tv; + + gettimeofday(&tv, NULL); + return (((long long)tv.tv_sec) * 1000) + (tv.tv_usec / 1000); +} + struct turboPmacAxisImpl { bool waitForHandshake; time_t timeAtHandshake; @@ -739,6 +748,9 @@ asynStatus turboPmacAxis::doMove(double position, int relative, double minVelocity, double maxVelocity, double acceleration) { + asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR, + "Received move command at %lli\n", timeInMilliseconds()); + // Status of read-write-operations of ASCII commands to the controller asynStatus status = asynSuccess; @@ -886,14 +898,8 @@ asynStatus turboPmacAxis::doReset() { // if we're currently inside it. pTurboPmacA_->waitForHandshake = false; - // Disable the axis, if it is not in a moving state - int axStat = pTurboPmacA_->axisStatus; - if (axStat == 0 || axStat == -6) { - snprintf(command, sizeof(command), "M%2.2d14=0", axisNo_); - status = pC_->writeRead(axisNo_, command, response, 0); - } - - return status; + // Disable the axis + return enable(false); } /* @@ -1143,6 +1149,10 @@ asynStatus turboPmacAxis::enable(bool on) { bool moving = false; // Perform a poll to update the parameter library poll(&moving); + + asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR, + "Finished enable %i at %lli\n", on, timeInMilliseconds()); + return asynSuccess; } } diff --git a/src/turboPmacController.cpp b/src/turboPmacController.cpp index f4426b0..6256a1c 100644 --- a/src/turboPmacController.cpp +++ b/src/turboPmacController.cpp @@ -254,22 +254,6 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command, pasynOctetSyncIOipPort(), command, commandLength, response, MAXBUF_, pTurboPmacC_->comTimeout, &nbytesOut, &nbytesIn, &eomReason); - /* - If sth. is written to the controller, it needs some time to process the - command. However, the controller returns the acknowledgment via - pasynOctetSyncIO->writeRead immediately, signalling to the driver that it is - ready to receive the next command. In practice, this can result in commands - getting discarded on the driver side or in bringing the driver in undefined - states (e.g. stuck in status 1). - - To prevent this, we wait for 20 ms after a write command to give the - controller enough time to process everything. A write command can be - identified by looking for the equal sign. - */ - if (strchr(command, '=')) { - usleep(20000); - } - msgPrintControlKey comKey = msgPrintControlKey(portName, axisNo, __PRETTY_FUNCTION__, __LINE__);