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

@ -8,7 +8,7 @@ This library offers base classes for EPICS motor drivers (`sinqAxis` and `sinqCo
### Architecture of EPICS motor drivers at SINQ ### Architecture of EPICS motor drivers at SINQ
The asyn-framework offers two base classes `asynMotorAxis` and `asynMotorController`. At SINQ, we extend those classes by two children `sinqAxis` and `sinqController` which are not complete drivers on their own, but serve as an additional framework for writing drivers. The concrete drivers are then created as separated libraries, an example is the TurboPMAC-driver: https://git.psi.ch/sinq-epics-modules/turboPmac. The asyn-framework offers two base classes `asynMotorAxis` and `asynMotorController`. At SINQ, we extend those classes by two children `sinqAxis` and `sinqController` which are not complete drivers on their own, but serve as a framework extension for writing drivers. The concrete drivers are then created as separated libraries, an example is the TurboPMAC-driver: https://git.psi.ch/sinq-epics-modules/turboPmac.
The full inheritance chain for two different motor drivers "a" and "b" looks like this: The full inheritance chain for two different motor drivers "a" and "b" looks like this:
`asynController -> sinqController -> aController` `asynController -> sinqController -> aController`
@ -36,17 +36,17 @@ epicsEnvSet("TOP","/ioc/sinq-ioc/sinqtest-ioc/")
epicsEnvSet("INSTR","SQ:SINQTEST:") epicsEnvSet("INSTR","SQ:SINQTEST:")
# Include other scripts for the controllers 1 and 2 # Include other scripts for the controllers 1 and 2
< mcu1.cmd < turboPmac1.cmd
< mcu2.cmd < turboPmac2.cmd
iocInit() iocInit()
``` ```
The first line is a so-called shebang which instructs Linux to execute the file with the executable located at the given path - the IOC shell in this case. The controller script "mcu1.cmd" looks like this: The first line is a so-called shebang which instructs Linux to execute the file with the executable located at the given path - the IOC shell in this case. The controller script "mcu1.cmd" looks like this:
The script for controller 1 ("mcu1.cmd") for a Turbo PMAC (see https://git.psi.ch/sinq-epics-modules/turboPmac) has the following structure. The scripts for other controller types can be found in the README.md of their respective repositories. The script for controller 1 ("turboPmac1.cmd") for a Turbo PMAC (see https://git.psi.ch/sinq-epics-modules/turboPmac) has the following structure. The scripts for other controller types can be found in the README.md of their respective repositories.
``` ```
# Define the name of the controller and the corresponding port # Define the name of the controller and the corresponding port
epicsEnvSet("NAME","mcu1") epicsEnvSet("NAME","turboPmac1")
epicsEnvSet("ASYN_PORT","p$(NAME)") epicsEnvSet("ASYN_PORT","p$(NAME)")
# Create the TCP/IP socket used to talk with the controller. The socket can be adressed from within the IOC shell via the port name # Create the TCP/IP socket used to talk with the controller. The socket can be adressed from within the IOC shell via the port name
@ -60,7 +60,7 @@ drvAsynIPPortConfigure("$(ASYN_PORT)","172.28.101.24:1025")
# 1: Socket communication timeout in seconds # 1: Socket communication timeout in seconds
turboPmacController("$(NAME)", "$(ASYN_PORT)", 8, 0.05, 1, 1); turboPmacController("$(NAME)", "$(ASYN_PORT)", 8, 0.05, 1, 1);
# Define some axes for the specified MCU at the given slot (1, 2 and 5). No slot may be used twice! # Define some axes for the specified motor controller at the given slot (1, 2 and 5). No slot may be used twice!
turboPmacAxis("$(NAME)",1); turboPmacAxis("$(NAME)",1);
turboPmacAxis("$(NAME)",2); turboPmacAxis("$(NAME)",2);
turboPmacAxis("$(NAME)",5); turboPmacAxis("$(NAME)",5);
@ -68,10 +68,10 @@ turboPmacAxis("$(NAME)",5);
# Set the number of subsequent timeouts # Set the number of subsequent timeouts
setMaxSubsequentTimeouts("$(NAME)", 20); setMaxSubsequentTimeouts("$(NAME)", 20);
# Configure the timeout frequency watchdog: # Configure the timeout frequency watchdog: A maximum of 10 timeouts are allowed in 300 seconds before an alarm message is sent.
setThresholdComTimeout("$(NAME)", 100, 1); setThresholdComTimeout("$(NAME)", 300, 10);
# Parametrize the EPICS record database with the substitution file named after the MCU. # Parametrize the EPICS record database with the substitution file named after the motor controller.
epicsEnvSet("SINQDBPATH","$(sinqMotor_DB)/sinqMotor.db") epicsEnvSet("SINQDBPATH","$(sinqMotor_DB)/sinqMotor.db")
dbLoadTemplate("$(TOP)/$(NAME).substitutions", "INSTR=$(INSTR)$(NAME):,CONTROLLER=$(NAME)") dbLoadTemplate("$(TOP)/$(NAME).substitutions", "INSTR=$(INSTR)$(NAME):,CONTROLLER=$(NAME)")
epicsEnvSet("SINQDBPATH","$(turboPmac_DB)/turboPmac.db") epicsEnvSet("SINQDBPATH","$(turboPmac_DB)/turboPmac.db")
@ -106,14 +106,14 @@ The variable `SINQDBPATH` has been set in "mcu1.cmd" before calling `dbLoadTempl
#### Optional parameters #### Optional parameters
The default values for those parameters are given for the individual records in db/sinqMotor.db The default values for those parameters are given for the individual records in db/sinqMotor.db
- `DESC`: Description of the motor. This field is just for documentation and is not needed for operating a motor. - `DESC`: Description of the motor. This field is just for documentation and is not needed for operating a motor. Defaults to the motor name.
- `MSGTEXTSIZE`: Buffer size for the motor message record in characters - `MSGTEXTSIZE`: Buffer size for the motor message record in characters. Defaults to 200 characters
- `ENABLEMOVWATCHDOG`: Sets `setWatchdogEnabled` during IOC startup to the given value. - `ENABLEMOVWATCHDOG`: Sets `setWatchdogEnabled` during IOC startup to the given value. Defaults to 0.
- `LIMITSOFFSET`: If the motor limits are read out from the controller, they can - `LIMITSOFFSET`: If the motor limits are read out from the controller, they can
be further reduced by this offset in order to avoid errors due to slight overshoot be further reduced by this offset in order to avoid errors due to slight overshoot
on the motor controller. For example, if this value is 1.0 and the read-out limits on the motor controller. For example, if this value is 1.0 and the read-out limits
are [-10.0 10.0], the EPICS limits are set to [-9.0 9.0]. This parameter uses engineering units (EGU). are [-10.0 10.0], the EPICS limits are set to [-9.0 9.0]. This parameter uses engineering units (EGU). Defaults to 0.0.
- `CANSETSPEED`: If set to 1, the motor speed can be modified by the user. - `CANSETSPEED`: If set to 1, the motor speed can be modified by the user. Defaults to 0.
### Motor record resolution MRES ### Motor record resolution MRES
@ -162,7 +162,7 @@ transferred to (motor_record_pv_name).MRES or to
sinqMotor offers a variety of additional methods for children classes to standardize certain patterns (e.g. writing messages to the IOC shell and the motor message PV). For a detailed description, please see the respective function documentation in the .h-files. All of these functions can be overwritten manually if e.g. a completely different implementation of `poll` is required. Some functions are marked as virtual, because they are called from other functions of sinqMotor and therefore need runtime polymorphism. Functions without that marker are not called anywhere in sinqMotor. sinqMotor offers a variety of additional methods for children classes to standardize certain patterns (e.g. writing messages to the IOC shell and the motor message PV). For a detailed description, please see the respective function documentation in the .h-files. All of these functions can be overwritten manually if e.g. a completely different implementation of `poll` is required. Some functions are marked as virtual, because they are called from other functions of sinqMotor and therefore need runtime polymorphism. Functions without that marker are not called anywhere in sinqMotor.
#### sinqController.h #### sinqController.h
- `errMsgCouldNotParseResponse`: Write a standardized message if parsing a device response failed. - `couldNotParseResponse`: Write a standardized message if parsing a device response failed.
- `paramLibAccessFailed`: Write a standardized message if accessing the parameter library failed. - `paramLibAccessFailed`: Write a standardized message if accessing the parameter library failed.
- `stringifyAsynStatus`: Convert the enum `asynStatus` into a human-readable string. - `stringifyAsynStatus`: Convert the enum `asynStatus` into a human-readable string.
- `checkComTimeoutWatchdog`: Calculates the timeout frequency (number of timeouts in a given time) and informs the user if a specified limit has been exceeded. - `checkComTimeoutWatchdog`: Calculates the timeout frequency (number of timeouts in a given time) and informs the user if a specified limit has been exceeded.
@ -174,7 +174,8 @@ sinqMotor offers a variety of additional methods for children classes to standar
- `enable`: This function is called if the `$(INSTR)$(M):Enable` PV from db/sinqMotor.db is set. - `enable`: This function is called if the `$(INSTR)$(M):Enable` PV from db/sinqMotor.db is set.
This is an empty function which should be overwritten by concrete driver implementations. This is an empty function which should be overwritten by concrete driver implementations.
- `reset`: This function is called when the `$(INSTR)$(M):Reset` PV from db/sinqMotor.db is set. - `reset`: This function is called when the `$(INSTR)$(M):Reset` PV from db/sinqMotor.db is set.
This is an empty function which should be overwritten by concrete driver implementations. It calls `doReset` and performs some fast polls after `doReset` returns.
- `doReset`: This is an empty function which should be overwritten by concrete driver implementations.
- `move`: This function sets the absolute target position in the parameter library and then calls `doMove`. - `move`: This function sets the absolute target position in the parameter library and then calls `doMove`.
- `doMove`: This is an empty function which should be overwritten by concrete driver implementations. - `doMove`: This is an empty function which should be overwritten by concrete driver implementations.
- `home`: This function sets the internal status flags for the homing process and then calls doHome. - `home`: This function sets the internal status flags for the homing process and then calls doHome.
@ -190,6 +191,8 @@ This is an empty function which should be overwritten by concrete driver impleme
- Reset `motorStatusProblem_`, `motorStatusCommsError_` and `motorMessageText_` if `doPoll` returned `asynSuccess` - Reset `motorStatusProblem_`, `motorStatusCommsError_` and `motorMessageText_` if `doPoll` returned `asynSuccess`
- Run `callParamCallbacks` - Run `callParamCallbacks`
- Return the status of `doPoll` - Return the status of `doPoll`
- `motorPosition`: Returns the parameter library value of the motor position, accounted for the motor record resolution (see section "Motor record resolution MRES")
- `setMotorPosition`: Writes the given value into the parameter library, accounted for the motor record resolution (see section "Motor record resolution MRES")
- `setVeloFields`: Populates the motor record fields VELO (actual velocity), VBAS (minimum allowed velocity) and VMAX (maximum allowed velocity) from the driver. - `setVeloFields`: Populates the motor record fields VELO (actual velocity), VBAS (minimum allowed velocity) and VMAX (maximum allowed velocity) from the driver.
- `setAcclField`: Populates the motor record field ACCL from the driver. - `setAcclField`: Populates the motor record field ACCL from the driver.
- `startMovTimeoutWatchdog`: Starts a watchdog for the movement time. This watchdog compares the actual time spent in a movement operation with an expected time, which is calculated based on the distance of the current and the target position. - `startMovTimeoutWatchdog`: Starts a watchdog for the movement time. This watchdog compares the actual time spent in a movement operation with an expected time, which is calculated based on the distance of the current and the target position.

View File

@ -14,8 +14,10 @@
class msgPrintControlKey { class msgPrintControlKey {
public: public:
std::string controller_; std::string controller_;
// -1 is a non-axis specific message
// -1 indicates a non-axis specific message
int axisNo_; int axisNo_;
const char *functionName_; const char *functionName_;
int line_; 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 { namespace std {
@ -57,7 +59,7 @@ template <> struct hash<msgPrintControlKey> {
* axis fails, a corresponding error message is created in each poll. This * 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 * 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 * 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: * 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__, * if (msgPrintControl.shouldBePrinted(controller, axisNo, __PRETTY_FUNCTION__,
* __LINE__, wantToPrint)) { asynPrint(...) * __LINE__, wantToPrint)) { asynPrint(...)
* } * }
*
* ``` * ```
*/ */
class msgPrintControl { class msgPrintControl {
@ -76,17 +77,17 @@ class msgPrintControl {
/** /**
* @brief Checks if the error message associated with "key" has been printed * @brief Checks if the error message associated with "key" has been printed
* more than "maxRepetitions_" times in a row. If yes, returns false, * more than `this->maxRepetitions_` times in a row. If yes, returns false,
* otherwise true. Counter is reset if wantToPrint is false. * otherwise true. Counter is reset if `wantToPrint` is false.
* *
* If the conditions for printing a message are met, "wantToPrint" must be * If the conditions for printing a message are met, `wantToPrint` must be
* set to true. The function then checks if "maxRepetitions_" has been * set to true. The function then checks if `maxRepetitions_` has been
* exceeded. If yes, the function returns no, indicating that the message * 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 * 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 * is incremented and the function returns true, indicating that the message
* should be printed. * 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. * be set to false. This resets the map entry.
* *
* @param key Key associated with the message, used to * @param key Key associated with the message, used to
@ -117,13 +118,13 @@ class msgPrintControl {
int line, bool wantToPrint, asynUser *pasynUser); 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 * the given key
* *
* @param key Key associated with the message, used to * @param key Key associated with the message, used to
* identify individual messages * identify individual messages
* @param pasynUser If the problem has been resolved (wantToPrint = * @param pasynUser If the problem has been resolved (`wantToPrint =
* false), a corresponding status message is printed using the given * false`), a corresponding status message is printed using the given
* asynUser. If this pointer is a nullptr, no message is printed. * asynUser. If this pointer is a nullptr, no message is printed.
*/ */
void resetCount(msgPrintControlKey &key, asynUser *pasynUser); void resetCount(msgPrintControlKey &key, asynUser *pasynUser);

View File

@ -283,6 +283,7 @@ asynStatus sinqAxis::home(double minVelocity, double maxVelocity,
axisNo_, __PRETTY_FUNCTION__, axisNo_, __PRETTY_FUNCTION__,
__LINE__); __LINE__);
} }
// Set field ATHM to zero
status = setIntegerParam(pC_->motorStatusHomed(), 0); status = setIntegerParam(pC_->motorStatusHomed(), 0);
if (status != asynSuccess) { if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorStatusHomed_", return pC_->paramLibAccessFailed(status, "motorStatusHomed_",
@ -322,10 +323,73 @@ asynStatus sinqAxis::doHome(double minVelocity, double maxVelocity,
return asynSuccess; 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::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 sinqAxis::setVeloFields(double velo, double vbas, double vmax) {
asynStatus status = asynSuccess; asynStatus status = asynSuccess;
int variableSpeed = 0; int variableSpeed = 0;
@ -455,8 +519,7 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
if (enableMovWatchdog == 1) { if (enableMovWatchdog == 1) {
// These parameters are only needed in this branch // These parameters are only needed in this branch
double motorPosition = 0.0; double motorPos = 0.0;
double motorPositionRec = 0.0;
double motorVelocity = 0.0; double motorVelocity = 0.0;
double motorVelocityRec = 0.0; double motorVelocityRec = 0.0;
double motorAccel = 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 to save the read result to the member variable earlier), since the
parameter library is updated at a later stage! parameter library is updated at a later stage!
*/ */
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(), pl_status = motorPosition(&motorPos);
&motorRecResolution);
if (pl_status != asynSuccess) { if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorRecResolution_", return pl_status;
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
} }
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. We use motorVelocity, which corresponds to the record field VELO.
From https://epics.anl.gov/docs/APS2015/14-Motor-Record.pdf: From https://epics.anl.gov/docs/APS2015/14-Motor-Record.pdf:
@ -503,6 +553,13 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
= VELO / MRES motorAccel = (motorVelocity - motorVelBase) / ACCL = VELO / MRES motorAccel = (motorVelocity - motorVelBase) / ACCL
Therefore, we need to correct the values from the parameter library. 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 // Read the velocity
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorVelocity(), pl_status = pC_->getDoubleParam(axisNo_, pC_->motorVelocity(),
@ -516,7 +573,7 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
if (pl_status == asynSuccess) { if (pl_status == asynSuccess) {
timeContSpeed = std::ceil( 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); 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. `doPoll` implementation.
* *
* Wrapper around doPoll which performs the following operations: * Wrapper around `doPoll` which performs the following operations:
Before calling doPoll:
- Try to execute atFirstPoll once (and retry, if that failed) - Call the `doPoll` method
After calling doPoll:
- Reset motorStatusProblem_, motorStatusCommsError_ and motorMessageText_ if - Reset motorStatusProblem_, motorStatusCommsError_ and motorMessageText_ if
doPoll returned asynSuccess doPoll returned asynSuccess
@ -45,8 +42,8 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
* *
* @param moving Forwarded to `doPoll`. * @param moving Forwarded to `doPoll`.
* @return asynStatus Forward the status of `doPoll`, unless one of * @return asynStatus Forward the status of `doPoll`, unless one of
the parameter library operation fails (in that case, returns the failed the parameter library operation fails (in that case, returns the status of
operation status). the failed operation.
*/ */
asynStatus poll(bool *moving); asynStatus poll(bool *moving);
@ -61,11 +58,12 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
virtual asynStatus doPoll(bool *moving); 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. `doMove` implementation.
* Wrapper around `doMove` which calculates the (absolute) target position * 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`. `doMove`.
* *
* @param position Forwarded to `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 * @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 * any value. It calls `doReset` (which ought to be implemented by a child
* sinqAxis. * class) and then performs da defined number of consecutive fast polls. If
* one of the polls returns asynSuccess, it returns immediately.
* *
* @return asynStatus * @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 * @brief This function enables / disables an axis. It should be implemented
* by a child class of sinqAxis. * by a child class of sinqAxis.
* *
* The concrete implementation should (but doesn't need to) follow the * 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 * convention that a value of 0 disables the axis and any other value
* it. * enables it.
* *
* @param on * @param on
* @return asynStatus * @return asynStatus
@ -188,7 +196,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
* Populates the speed fields of the motor record. If the param lib * Populates the speed fields of the motor record. If the param lib
* entry motorCanSetSpeed_ (connected to the PV x:VariableSpeed) is set to * 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 * 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 * The units of the inputs are engineering units (EGU) per second (e.g. mm/s
* if the EGU is mm). * if the EGU is mm).
@ -243,15 +251,15 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
with with
timeContSpeed = abs(motorTargetPosition - motorPosition) / motorVelBase timeContSpeed = abs(targetPosition - motorPosition) / motorVelBase
timeAcc = motorVelBase / motorAccel timeAcc = motorVelBase / motorAccel
The values motorTargetPosition, motorVelBase, motorAccel and The values motorVelBase, motorAccel and positionAtMovementStart are taken
positionAtMovementStart are taken from the parameter library. Therefore it from the parameter library. Therefore it is necessary to populate them
is necessary to populate them before using this function. If they are not before using this function. If they are not given, both speed and velocity
given, both speed and velocity are assumed to be infinite. This means that are assumed to be infinite. This means that timeContSpeed and/or timeAcc are
timeContSpeed and/or timeAcc are set to zero. motorTargetPosition is set to zero. targetPosition is populated automatically when using the doMove
populated automatically when using the doMove function. function.
The values offsetMovTimeout_ and scaleMovTimeout_ can be set directly from The values offsetMovTimeout_ and scaleMovTimeout_ can be set directly from
the IOC shell with the functions setScaleMovTimeout and setOffsetMovTimeout, 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 * @brief Set the offsetMovTimeout. Also available in the IOC shell
* (see "extern C" section in sinqController.cpp). * (see "extern C" section in sinqController.cpp).
* *
See documentation of `checkMovTimeoutWatchdog` for details. * See documentation of `checkMovTimeoutWatchdog` for details.
* *
* @param offsetMovTimeout Offset (in seconds) * @param offsetMovTimeout Offset (in seconds)
* @return asynStatus * @return asynStatus
@ -311,6 +319,34 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
*/ */
int axisNo() { return axisNo_; } 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: protected:
// Internal variables used in the movement timeout watchdog // Internal variables used in the movement timeout watchdog
time_t expectedArrivalTime_; time_t expectedArrivalTime_;

View File

@ -55,8 +55,13 @@ sinqController::sinqController(const char *portName,
// Initial values for the average timeout mechanism, can be overwritten // Initial values for the average timeout mechanism, can be overwritten
// later by a FFI function // 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; maxNumberTimeouts_ = 60;
// Queue holding the timeout event timestamps
timeoutEvents_ = {}; timeoutEvents_ = {};
// Inform the user after 10 timeouts in a row (default value) // Inform the user after 10 timeouts in a row (default value)
@ -341,7 +346,7 @@ asynStatus sinqController::readInt32(asynUser *pasynUser, epicsInt32 *value) {
} }
} }
asynStatus sinqController::errMsgCouldNotParseResponse(const char *command, asynStatus sinqController::couldNotParseResponse(const char *command,
const char *response, const char *response,
int axisNo, int axisNo,
const char *functionName, const char *functionName,
@ -591,8 +596,8 @@ extern "C" {
* implementation) * implementation)
* *
* @param comTimeoutWindow Size of the time window used to calculate * @param comTimeoutWindow Size of the time window used to calculate
* the moving average of timeout events. Set this value to 0 to deactivate * the moving average of timeout events in seconds. Set this value to 0 to
* the watchdog. * deactivate the watchdog.
* @param maxNumberTimeouts Maximum number of timeouts which may occur * @param maxNumberTimeouts Maximum number of timeouts which may occur
* within the time window before the watchdog is triggered. * within the time window before the watchdog is triggered.
* @return asynStatus * @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 pAxes_ which has the length specified here. When getting an axis, the
`getAxis` function indexes into this array. A length of 8 would therefore `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 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 axis enumeration identical to that of the hardware, we start counting the
counting the axes with 1 and end at 8. Therefore, an offset of 1 is added axes with 1 and end at 8. Therefore, an offset of 1 is added when forwarding
when forwarding this number to asynMotorController. this number to asynMotorController.
* @param movingPollPeriod Time between polls when moving (in seconds) * @param movingPollPeriod Time between polls when moving (in seconds)
* @param idlePollPeriod Time between polls when not moving (in * @param idlePollPeriod Time between polls when not moving (in
seconds) seconds)
@ -82,7 +82,7 @@ class epicsShareClass sinqController : public asynMotorController {
* *
* If accessing the parameter library failed (return status != * If accessing the parameter library failed (return status !=
asynSuccess), calling this function writes a standardized message to both 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. status.
* *
* @param status Status of the failed parameter library access * @param status Status of the failed parameter library access
@ -115,7 +115,7 @@ class epicsShareClass sinqController : public asynMotorController {
called. It is recommended to use a macro, e.g. __LINE__. called. It is recommended to use a macro, e.g. __LINE__.
* @return asynStatus Returns asynError. * @return asynStatus Returns asynError.
*/ */
asynStatus errMsgCouldNotParseResponse(const char *command, asynStatus couldNotParseResponse(const char *command,
const char *response, int axisNo, const char *response, int axisNo,
const char *functionName, int line); const char *functionName, int line);
@ -131,7 +131,7 @@ class epicsShareClass sinqController : public asynMotorController {
* @brief This function should be called when a communication timeout * @brief This function should be called when a communication timeout
occured. It calculates the frequency of communication timeout events and occured. It calculates the frequency of communication timeout events and
creates an error message, if an threshold has been exceeded. creates an error message, if an threshold has been exceeded.
*
Occasionally, communication timeouts between the IOC and the motor Occasionally, communication timeouts between the IOC and the motor
controller may happen, usually because the controller takes too long to controller may happen, usually because the controller takes too long to
respond. If this happens infrequently, this is not a problem. However, if it 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 * @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 * @param timeoutNo Number of subsequent timeouts which already
* happened. * happened.
@ -192,7 +192,7 @@ class epicsShareClass sinqController : public asynMotorController {
class sinqAxis *axis); 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 userMessage Buffer for the user message
* @param userMessageSize Buffer size in chars * @param userMessageSize Buffer size in chars
@ -216,8 +216,8 @@ class epicsShareClass sinqController : public asynMotorController {
/** /**
* @brief Get a reference to the map used to control the maximum number of * @brief Get a reference to the map used to control the maximum number of
* message repetitions. See the documentation of printRepetitionWatchdog in * message repetitions. See the documentation of `printRepetitionWatchdog`
* msgPrintControl.h for details. * in msgPrintControl.h for details.
*/ */
msgPrintControl &getMsgPrintControl(); msgPrintControl &getMsgPrintControl();
@ -253,7 +253,7 @@ class epicsShareClass sinqController : public asynMotorController {
int motorStatus() { return motorStatus_; } int motorStatus() { return motorStatus_; }
int motorUpdateStatus() { return motorUpdateStatus_; } int motorUpdateStatus() { return motorUpdateStatus_; }
// Accessors for sztatus bits (integers) // Accessors for status bits (integers)
int motorStatusDirection() { return motorStatusDirection_; } int motorStatusDirection() { return motorStatusDirection_; }
int motorStatusDone() { return motorStatusDone_; } int motorStatusDone() { return motorStatusDone_; }
int motorStatusHighLimit() { return motorStatusHighLimit_; } int motorStatusHighLimit() { return motorStatusHighLimit_; }
@ -295,6 +295,8 @@ class epicsShareClass sinqController : public asynMotorController {
// Additional members // Additional members
int numAxes() { return numAxes_; } int numAxes() { return numAxes_; }
double idlePollPeriod() { return idlePollPeriod_; }
double movingPollPeriod() { return movingPollPeriod_; }
asynUser *asynUserSelf() { return pasynUserSelf; } asynUser *asynUserSelf() { return pasynUserSelf; }
asynUser *ipPortUser() { return ipPortUser_; } asynUser *ipPortUser() { return ipPortUser_; }
@ -302,7 +304,7 @@ class epicsShareClass sinqController : public asynMotorController {
protected: protected:
// Pointer to the port user which is specified by the char array // Pointer to the port user which is specified by the char array
// ipPortConfigName in the constructor // `ipPortConfigName` in the constructor
asynUser *ipPortUser_; asynUser *ipPortUser_;
double movingPollPeriod_; double movingPollPeriod_;
double idlePollPeriod_; double idlePollPeriod_;