Added doReset wrapper around reset and added two functions to set and

retrieve the motor position which handle the conversion via
motorRecResolution.
This commit is contained in:
2025-03-28 14:51:09 +01:00
parent 828e9bc59c
commit 7729eceb28
6 changed files with 198 additions and 94 deletions

View File

@@ -14,8 +14,10 @@
class msgPrintControlKey {
public:
std::string controller_;
// -1 is a non-axis specific message
// -1 indicates a non-axis specific message
int axisNo_;
const char *functionName_;
int line_;
@@ -32,7 +34,7 @@ class msgPrintControlKey {
};
/**
* @brief Implementation of the hash functionality for msgPrintControlKey
* @brief Implementation of the hash functionality for `msgPrintControlKey`
*
*/
namespace std {
@@ -57,7 +59,7 @@ template <> struct hash<msgPrintControlKey> {
* axis fails, a corresponding error message is created in each poll. This
* could "flood" the IOC shell with noise. To prevent this, this class keeps
* track of the number of subsequent error message repetition. Each message is
* uniquely identified by "msgPrintControlKey". The function shouldBePrinted
* uniquely identified by `msgPrintControlKey`. The function `shouldBePrinted`
* can be used in order to see if a message should be printed or not:
*
* ```
@@ -67,7 +69,6 @@ template <> struct hash<msgPrintControlKey> {
* if (msgPrintControl.shouldBePrinted(controller, axisNo, __PRETTY_FUNCTION__,
* __LINE__, wantToPrint)) { asynPrint(...)
* }
*
* ```
*/
class msgPrintControl {
@@ -76,17 +77,17 @@ class msgPrintControl {
/**
* @brief Checks if the error message associated with "key" has been printed
* more than "maxRepetitions_" times in a row. If yes, returns false,
* otherwise true. Counter is reset if wantToPrint is false.
* more than `this->maxRepetitions_` times in a row. If yes, returns false,
* otherwise true. Counter is reset if `wantToPrint` is false.
*
* If the conditions for printing a message are met, "wantToPrint" must be
* set to true. The function then checks if "maxRepetitions_" has been
* If the conditions for printing a message are met, `wantToPrint` must be
* set to true. The function then checks if `maxRepetitions_` has been
* exceeded. If yes, the function returns no, indicating that the message
* should not be printed. If no, the number of repetitions stored in the map
* is incremented and the function returns true, indicating that the message
* should be printed.
*
* If the conditions for printing a message are not met, "wantToPrint" must
* If the conditions for printing a message are not met, `wantToPrint` must
* be set to false. This resets the map entry.
*
* @param key Key associated with the message, used to
@@ -117,13 +118,13 @@ class msgPrintControl {
int line, bool wantToPrint, asynUser *pasynUser);
/**
* @brief Reset the error message count incremented in shouldBePrinted for
* @brief Reset the error message count incremented in `shouldBePrinted` for
* the given key
*
* @param key Key associated with the message, used to
* identify individual messages
* @param pasynUser If the problem has been resolved (wantToPrint =
* false), a corresponding status message is printed using the given
* @param pasynUser If the problem has been resolved (`wantToPrint =
* false`), a corresponding status message is printed using the given
* asynUser. If this pointer is a nullptr, no message is printed.
*/
void resetCount(msgPrintControlKey &key, asynUser *pasynUser);

View File

@@ -283,6 +283,7 @@ asynStatus sinqAxis::home(double minVelocity, double maxVelocity,
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
// Set field ATHM to zero
status = setIntegerParam(pC_->motorStatusHomed(), 0);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorStatusHomed_",
@@ -322,10 +323,73 @@ asynStatus sinqAxis::doHome(double minVelocity, double maxVelocity,
return asynSuccess;
}
asynStatus sinqAxis::reset() { return asynSuccess; }
asynStatus sinqAxis::reset() {
asynStatus status = doReset();
if (status == asynSuccess) {
// Perform some fast polls
pC_->lock();
bool moving = false;
for (int i = 0; i < 5; i++) {
epicsThreadSleep(pC_->movingPollPeriod());
if (poll(&moving) == asynSuccess) {
break;
}
}
pC_->unlock();
}
return status;
}
asynStatus sinqAxis::doReset() { return asynError; }
asynStatus sinqAxis::enable(bool on) { return asynSuccess; }
asynStatus sinqAxis::motorPosition(double *motorPosition) {
asynStatus status = asynSuccess;
double motorRecResolution = 0.0;
status = pC_->getDoubleParam(axisNo(), pC_->motorRecResolution(),
&motorRecResolution);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorRecResolution_",
axisNo(), __PRETTY_FUNCTION__,
__LINE__);
}
status = pC_->getDoubleParam(axisNo(), pC_->motorPosition(), motorPosition);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorPosition_", axisNo(),
__PRETTY_FUNCTION__,
__LINE__);
}
*motorPosition = *motorPosition * motorRecResolution;
return status;
}
asynStatus sinqAxis::setMotorPosition(double motorPosition) {
asynStatus status = asynSuccess;
double motorRecResolution = 0.0;
status = pC_->getDoubleParam(axisNo(), pC_->motorRecResolution(),
&motorRecResolution);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorRecResolution_",
axisNo(), __PRETTY_FUNCTION__,
__LINE__);
}
status = setDoubleParam(pC_->motorPosition(),
motorPosition / motorRecResolution);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorPosition_", axisNo(),
__PRETTY_FUNCTION__,
__LINE__);
}
return status;
}
asynStatus sinqAxis::setVeloFields(double velo, double vbas, double vmax) {
asynStatus status = asynSuccess;
int variableSpeed = 0;
@@ -455,8 +519,7 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
if (enableMovWatchdog == 1) {
// These parameters are only needed in this branch
double motorPosition = 0.0;
double motorPositionRec = 0.0;
double motorPos = 0.0;
double motorVelocity = 0.0;
double motorVelocityRec = 0.0;
double motorAccel = 0.0;
@@ -473,24 +536,11 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
to save the read result to the member variable earlier), since the
parameter library is updated at a later stage!
*/
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(),
&motorRecResolution);
pl_status = motorPosition(&motorPos);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorRecResolution_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
return pl_status;
}
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorPosition(),
&motorPositionRec);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorPosition",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
motorPosition = motorPositionRec * motorRecResolution;
/*
We use motorVelocity, which corresponds to the record field VELO.
From https://epics.anl.gov/docs/APS2015/14-Motor-Record.pdf:
@@ -503,6 +553,13 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
= VELO / MRES motorAccel = (motorVelocity - motorVelBase) / ACCL
Therefore, we need to correct the values from the parameter library.
*/
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(),
&motorRecResolution);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorRecResolution_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
// Read the velocity
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorVelocity(),
@@ -516,7 +573,7 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
if (pl_status == asynSuccess) {
timeContSpeed = std::ceil(
std::fabs(targetPosition_ - motorPosition) / motorVelocity);
std::fabs(targetPosition_ - motorPos) / motorVelocity);
}
}

View File

@@ -19,15 +19,12 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
sinqAxis(class sinqController *pC_, int axisNo);
/**
* @brief Perform some standardized operation before and after the concrete
* @brief Perform some standardized operations before and after the concrete
`doPoll` implementation.
*
* Wrapper around doPoll which performs the following operations:
Before calling doPoll:
* Wrapper around `doPoll` which performs the following operations:
- Try to execute atFirstPoll once (and retry, if that failed)
After calling doPoll:
- Call the `doPoll` method
- Reset motorStatusProblem_, motorStatusCommsError_ and motorMessageText_ if
doPoll returned asynSuccess
@@ -45,8 +42,8 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
*
* @param moving Forwarded to `doPoll`.
* @return asynStatus Forward the status of `doPoll`, unless one of
the parameter library operation fails (in that case, returns the failed
operation status).
the parameter library operation fails (in that case, returns the status of
the failed operation.
*/
asynStatus poll(bool *moving);
@@ -61,11 +58,12 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
virtual asynStatus doPoll(bool *moving);
/**
* @brief Perform some standardized operation before and after the concrete
* @brief Perform some standardized operations before and after the concrete
`doMove` implementation.
* Wrapper around `doMove` which calculates the (absolute) target position
and stores it in the parameter library. After that, it calls and returns
and stores it in the member variable `targetPosition_`. This member variable
is e.g. used for the movement watchdog. Afterwards, it calls and returns
`doMove`.
*
* @param position Forwarded to `doMove`.
@@ -162,20 +160,30 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
/**
* @brief This function is called when the PV "$(INSTR)$(M):Reset" is set to
* any value. This method should be implemented by a child class of
* sinqAxis.
* any value. It calls `doReset` (which ought to be implemented by a child
* class) and then performs da defined number of consecutive fast polls. If
* one of the polls returns asynSuccess, it returns immediately.
*
* @return asynStatus
*/
virtual asynStatus reset();
asynStatus reset();
/**
* @brief Implementation of the "proper", device-specific `reset` method.
This method should be implemented by a child class of sinqAxis. If the
motor cannot be reset, this function should return asynError.
*
* @return asynStatus
*/
virtual asynStatus doReset();
/**
* @brief This function enables / disables an axis. It should be implemented
* by a child class of sinqAxis.
*
* The concrete implementation should (but doesn't need to) follow the
* convetion that a value of 0 disables the axis and any other value enables
* it.
* convention that a value of 0 disables the axis and any other value
* enables it.
*
* @param on
* @return asynStatus
@@ -188,7 +196,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
* Populates the speed fields of the motor record. If the param lib
* entry motorCanSetSpeed_ (connected to the PV x:VariableSpeed) is set to
* 1, VBAS and VMAX are set to min and max respectively. Otherwise, they are
* set to val. Additionally, the speed itself is set to velo.
* set to val. Additionally, the speed itself is set to VELO.
*
* The units of the inputs are engineering units (EGU) per second (e.g. mm/s
* if the EGU is mm).
@@ -243,15 +251,15 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
with
timeContSpeed = abs(motorTargetPosition - motorPosition) / motorVelBase
timeContSpeed = abs(targetPosition - motorPosition) / motorVelBase
timeAcc = motorVelBase / motorAccel
The values motorTargetPosition, motorVelBase, motorAccel and
positionAtMovementStart are taken from the parameter library. Therefore it
is necessary to populate them before using this function. If they are not
given, both speed and velocity are assumed to be infinite. This means that
timeContSpeed and/or timeAcc are set to zero. motorTargetPosition is
populated automatically when using the doMove function.
The values motorVelBase, motorAccel and positionAtMovementStart are taken
from the parameter library. Therefore it is necessary to populate them
before using this function. If they are not given, both speed and velocity
are assumed to be infinite. This means that timeContSpeed and/or timeAcc are
set to zero. targetPosition is populated automatically when using the doMove
function.
The values offsetMovTimeout_ and scaleMovTimeout_ can be set directly from
the IOC shell with the functions setScaleMovTimeout and setOffsetMovTimeout,
@@ -280,7 +288,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
* @brief Set the offsetMovTimeout. Also available in the IOC shell
* (see "extern C" section in sinqController.cpp).
*
See documentation of `checkMovTimeoutWatchdog` for details.
* See documentation of `checkMovTimeoutWatchdog` for details.
*
* @param offsetMovTimeout Offset (in seconds)
* @return asynStatus
@@ -311,6 +319,34 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
*/
int axisNo() { return axisNo_; }
/**
* @brief Read the motor position from the paramLib, adjusted for the
* motorRecResolution
*
* The motorPosition value in the paramLib is the encoder position
* divided by the motorRecResolution (see README.md). This function
* fetches the paramLib value and multiplies it with motorRecResolution
* (also fetched from the paramLib).
*
* @param motorPositon
* @return asynStatus
*/
asynStatus motorPosition(double *motorPositon);
/**
* @brief Write the motor position in the paramLib, adjusted for the
* motorRecResolution
*
* The motorPosition value in the paramLib is the encoder position
* divided by the motorRecResolution (see README.md). This function takes
* the input value and divides it with motorRecResolution (fetched from
* the paramLib).
*
* @param motorPosition
* @return asynStatus
*/
asynStatus setMotorPosition(double motorPosition);
protected:
// Internal variables used in the movement timeout watchdog
time_t expectedArrivalTime_;

View File

@@ -55,8 +55,13 @@ sinqController::sinqController(const char *portName,
// Initial values for the average timeout mechanism, can be overwritten
// later by a FFI function
comTimeoutWindow_ = 3600;
comTimeoutWindow_ = 3600; // seconds
// Number of timeouts which may occur before an error is forwarded to the
// user
maxNumberTimeouts_ = 60;
// Queue holding the timeout event timestamps
timeoutEvents_ = {};
// Inform the user after 10 timeouts in a row (default value)
@@ -341,11 +346,11 @@ asynStatus sinqController::readInt32(asynUser *pasynUser, epicsInt32 *value) {
}
}
asynStatus sinqController::errMsgCouldNotParseResponse(const char *command,
const char *response,
int axisNo,
const char *functionName,
int line) {
asynStatus sinqController::couldNotParseResponse(const char *command,
const char *response,
int axisNo,
const char *functionName,
int line) {
asynStatus pl_status = asynSuccess;
asynPrint(ipPortUser_, ASYN_TRACE_ERROR,
@@ -591,8 +596,8 @@ extern "C" {
* implementation)
*
* @param comTimeoutWindow Size of the time window used to calculate
* the moving average of timeout events. Set this value to 0 to deactivate
* the watchdog.
* the moving average of timeout events in seconds. Set this value to 0 to
* deactivate the watchdog.
* @param maxNumberTimeouts Maximum number of timeouts which may occur
* within the time window before the watchdog is triggered.
* @return asynStatus

View File

@@ -32,9 +32,9 @@ class epicsShareClass sinqController : public asynMotorController {
pAxes_ which has the length specified here. When getting an axis, the
`getAxis` function indexes into this array. A length of 8 would therefore
mean that the axis slots 0 to 7 are available. However, in order to keep the
axis enumeration in sync with the electronics counting logic, we start
counting the axes with 1 and end at 8. Therefore, an offset of 1 is added
when forwarding this number to asynMotorController.
axis enumeration identical to that of the hardware, we start counting the
axes with 1 and end at 8. Therefore, an offset of 1 is added when forwarding
this number to asynMotorController.
* @param movingPollPeriod Time between polls when moving (in seconds)
* @param idlePollPeriod Time between polls when not moving (in
seconds)
@@ -82,7 +82,7 @@ class epicsShareClass sinqController : public asynMotorController {
*
* If accessing the parameter library failed (return status !=
asynSuccess), calling this function writes a standardized message to both
the IOC shell and the motor message text PV. It then returns the input
the IOC shell and the motorMessageText PV. It then returns the input
status.
*
* @param status Status of the failed parameter library access
@@ -90,7 +90,7 @@ class epicsShareClass sinqController : public asynMotorController {
error messages.
* @param functionName Name of the caller function. It is recommended
to use a macro, e.g. __func__ or __PRETTY_FUNCTION__.
* @param line Source code line where this function is
* @param line Source code line where this function is
called. It is recommended to use a macro, e.g. __LINE__.
* @return asynStatus Returns input status.
*/
@@ -115,7 +115,7 @@ class epicsShareClass sinqController : public asynMotorController {
called. It is recommended to use a macro, e.g. __LINE__.
* @return asynStatus Returns asynError.
*/
asynStatus errMsgCouldNotParseResponse(const char *command,
asynStatus couldNotParseResponse(const char *command,
const char *response, int axisNo,
const char *functionName, int line);
@@ -131,7 +131,7 @@ class epicsShareClass sinqController : public asynMotorController {
* @brief This function should be called when a communication timeout
occured. It calculates the frequency of communication timeout events and
creates an error message, if an threshold has been exceeded.
*
Occasionally, communication timeouts between the IOC and the motor
controller may happen, usually because the controller takes too long to
respond. If this happens infrequently, this is not a problem. However, if it
@@ -181,7 +181,7 @@ class epicsShareClass sinqController : public asynMotorController {
/**
* @brief Inform the user, if the number of timeouts exceeds the threshold
* specified with setMaxSubsequentTimeouts
* specified with `setMaxSubsequentTimeouts`.
*
* @param timeoutNo Number of subsequent timeouts which already
* happened.
@@ -192,10 +192,10 @@ class epicsShareClass sinqController : public asynMotorController {
class sinqAxis *axis);
/**
* @brief See documentation of checkMaxSubsequentTimeouts(sinqAxis * axis)
* @brief See documentation of `checkMaxSubsequentTimeouts(sinqAxis * axis)`
*
* @param userMessage Buffer for the user message
* @param userMessageSize Buffer size in chars
* @param userMessage Buffer for the user message
* @param userMessageSize Buffer size in chars
* @return asynStatus
*/
virtual asynStatus checkMaxSubsequentTimeouts(int timeoutNo, int axisNo,
@@ -216,8 +216,8 @@ class epicsShareClass sinqController : public asynMotorController {
/**
* @brief Get a reference to the map used to control the maximum number of
* message repetitions. See the documentation of printRepetitionWatchdog in
* msgPrintControl.h for details.
* message repetitions. See the documentation of `printRepetitionWatchdog`
* in msgPrintControl.h for details.
*/
msgPrintControl &getMsgPrintControl();
@@ -253,7 +253,7 @@ class epicsShareClass sinqController : public asynMotorController {
int motorStatus() { return motorStatus_; }
int motorUpdateStatus() { return motorUpdateStatus_; }
// Accessors for sztatus bits (integers)
// Accessors for status bits (integers)
int motorStatusDirection() { return motorStatusDirection_; }
int motorStatusDone() { return motorStatusDone_; }
int motorStatusHighLimit() { return motorStatusHighLimit_; }
@@ -295,6 +295,8 @@ class epicsShareClass sinqController : public asynMotorController {
// Additional members
int numAxes() { return numAxes_; }
double idlePollPeriod() { return idlePollPeriod_; }
double movingPollPeriod() { return movingPollPeriod_; }
asynUser *asynUserSelf() { return pasynUserSelf; }
asynUser *ipPortUser() { return ipPortUser_; }
@@ -302,7 +304,7 @@ class epicsShareClass sinqController : public asynMotorController {
protected:
// Pointer to the port user which is specified by the char array
// ipPortConfigName in the constructor
// `ipPortConfigName` in the constructor
asynUser *ipPortUser_;
double movingPollPeriod_;
double idlePollPeriod_;