Compare commits

..

1 Commits
0.4.3 ... 0.2.1

Author SHA1 Message Date
3b648c4f7b Improved the error message when the MCU response is printed and the IOC
shell constructor documentation.
2024-11-27 15:57:00 +01:00
7 changed files with 273 additions and 187 deletions

View File

@ -11,7 +11,7 @@ REQUIRED+=asynMotor
REQUIRED+=sinqMotor REQUIRED+=sinqMotor
# Specify the version of sinqMotor we want to build against # Specify the version of sinqMotor we want to build against
sinqMotor_VERSION=0.6.3 sinqMotor_VERSION=0.3.0
# These headers allow to depend on this library for derived drivers. # These headers allow to depend on this library for derived drivers.
HEADERS += src/pmacv3Axis.h HEADERS += src/pmacv3Axis.h

View File

@ -4,43 +4,50 @@
This is a driver for the pmacV3 motion controller with the SINQ communication protocol. It is based on the sinqMotor shared library (https://git.psi.ch/sinq-epics-modules/sinqmotor). The header files contain detailed documentation for all public functions. The headers themselves are exported when building the library to allow other drivers to depend on this one. This is a driver for the pmacV3 motion controller with the SINQ communication protocol. It is based on the sinqMotor shared library (https://git.psi.ch/sinq-epics-modules/sinqmotor). The header files contain detailed documentation for all public functions. The headers themselves are exported when building the library to allow other drivers to depend on this one.
## User guide ## Usage in IOC shell
This driver is a standard sinqMotor-derived driver and does not need any specific configuration. For the general configuration, please see https://git.psi.ch/sinq-epics-modules/sinqmotor/-/blob/main/README.md.
The folder "utils" contains utility scripts for working with pmac motor controllers:
- writeRead.py: Allows sending commands to and receiving commands from a pmac controller over an ethernet connection.
- analyzeTcpDump: This script takes a tcpdump as an input and
## Developer guide
### Usage in IOC shell
pmacv3 exposes the following IOC shell functions (all in pmacv3Controller.cpp): pmacv3 exposes the following IOC shell functions (all in pmacv3Controller.cpp):
- `pmacv3Controller`: Create a new controller object. - `pmacv3Controller`: Create a new controller object.
- `pmacv3Axis`: Create a new axis object. - `pmacv3Axis`: Create a new axis object.
These functions are parametrized as follows: The function arguments are documented directly within the source code or are available from the help function of the IOC shell.
## Database
The pmacV3 module provides additional PVs in the database template db/pmacv3.db. It can be parametrized with the `dbLoadTemplate` function from the IOC shell:
``` ```
pmacv3Controller( require sinqMotor, y.y.y # The sinqMotor module is needed for the pmacv3 module. The version y.y.y is defined in the Makefile (line sinqMotor_VERSION=x.x.x)
"$(NAME)", # Name of the MCU, e.g. mcu1. This parameter should be provided by an environment variable. require pmacv3, x.x.x # This is the three-digit version number of the pmacv3 module
"$(ASYN_PORT)", # IP-Port of the MCU. This parameter should be provided by an environment variable. dbLoadTemplate "motor.substitutions"
8, # Maximum number of axes
0.05, # Busy poll period in seconds
1, # Idle poll period in seconds
0.05 # Communication timeout in seconds
);
```
```
pmacv3Axis(
"$(NAME)", # Name of the associated MCU, e.g. mcu1. This parameter should be provided by an environment variable.
1 # Index of the axis.
);
``` ```
### Versioning The substitutions file can be concatenated with that of sinqMotor:
```
file "$(sinqMotor_DB)/sinqMotor.db"
{
pattern
...
}
file "$(pmacv3_DB)/pmacv3.db"
{
pattern
{ AXIS, M}
{ 1, "lin1"}
{ 2, "rot1"}
}
```
The sinqMotor pattern "..." is documented in https://git.psi.ch/sinq-epics-modules/sinqmotor/-/blob/main/README.md.
The other parameters have the following meaning:
- `AXIS`: Index of the axis, corresponds to the physical connection of the axis to the MCU
- `M`: Name of the motor as shown in EPICS
The axis name should correspond to that of the sinqMotor pattern with the same respective index.
## Versioning
Please see the documentation for the module sinqMotor: https://git.psi.ch/sinq-epics-modules/sinqmotor/-/blob/main/README.md. Please see the documentation for the module sinqMotor: https://git.psi.ch/sinq-epics-modules/sinqmotor/-/blob/main/README.md.
### How to build it ## How to build it
Please see the documentation for the module sinqMotor: https://git.psi.ch/sinq-epics-modules/sinqmotor/-/blob/main/README.md. Please see the documentation for the module sinqMotor: https://git.psi.ch/sinq-epics-modules/sinqmotor/-/blob/main/README.md.

View File

@ -1,19 +1,59 @@
# Trigger a rereading of the encoder. This action is sometimes necessary for # Encoder type
# absolute encoders after enabling them. For incremental encoders, this is a no-op. record(waveform, "$(P)$(M):Encoder_Type") {
# This record is coupled to the parameter library via rereadEncoderPosition_ -> REREAD_ENCODER_POSITION. field(DTYP, "asynOctetRead")
record(longout, "$(INSTR)$(M):RereadEncoder") { field(INP, "@asyn($(CONTROLLER),$(AXIS),1) ENCODER_TYPE")
field(FTVL, "CHAR")
field(NELM, "80")
field(SCAN, "I/O Intr")
}
# reread encoder
record(longout, "$(P)$(M):Reread_Encoder") {
field(DTYP, "asynInt32") field(DTYP, "asynInt32")
field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) REREAD_ENCODER_POSITION") field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) REREAD_ENCODER_POSITION")
field(PINI, "NO") field(PINI, "NO")
} }
# The pmacV3 driver reads certain configuration parameters (such as the velocity # reread encoder
# and the acceleration) directly from the MCU. This reading procedure is performed record(longout, "$(P)$(M):Read_Config") {
# once at IOC startup during atFirstPoll. However, it can be triggered manually
# by setting this record value to 1.
# This record is coupled to the parameter library via readConfig_ -> READ_CONFIG.
record(longout, "$(INSTR)$(M):ReadConfig") {
field(DTYP, "asynInt32") field(DTYP, "asynInt32")
field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) READ_CONFIG") field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) READ_CONFIG")
field(PINI, "NO") field(PINI, "NO")
} }
# ===================================================================
# The following records read acceleration and velocity from the driver and
# copy those values into the corresponding fields of the main motor record.
# This strategy is described here: https://epics.anl.gov/tech-talk/2022/msg00464.php
# Helper record for the high limit which is filled in by the driver
record(ai, "$(P)$(M):MOTOR_VELOCITY-RBV")
{
field(DTYP, "asynFloat64")
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_VELOCITY_FROM_DRIVER")
field(SCAN, "I/O Intr")
field(FLNK, "$(P)$(M):PUSH_VELO_TO_FIELD")
}
# Push the value into the field of the main motor record
record(ao, "$(P)$(M):PUSH_VELO_TO_FIELD") {
field(DOL, "$(P)$(M):MOTOR_VELOCITY-RBV CP")
field(OUT, "$(P)$(M).VELO")
field(OMSL, "closed_loop") # This configuration keeps the PV and the field in sync
}
# Helper record for the low limit which is filled in by the driver
record(ai, "$(P)$(M):MOTOR_ACCL-RBV")
{
field(DTYP, "asynFloat64")
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_ACCEL_FROM_DRIVER")
field(SCAN, "I/O Intr")
field(FLNK, "$(P)$(M):PUSH_ACCL_TO_FIELD")
}
# Push the value into the field of the main motor record
record(ao, "$(P)$(M):PUSH_ACCL_TO_FIELD") {
field(DOL, "$(P)$(M):MOTOR_ACCL-RBV CP")
field(OUT, "$(P)$(M).ACCL")
field(OMSL, "closed_loop") # This configuration keeps the PV and the field in sync
}

View File

@ -50,8 +50,7 @@ pmacv3Axis::pmacv3Axis(pmacv3Controller *pC, int axisNo)
exit(-1); exit(-1);
} }
// pmacv3 motors can always be disabled status = pC_->setDoubleParam(axisNo_, pC_->motorPosition_, 0.0);
status = pC_->setIntegerParam(axisNo_, pC_->motorCanDisable_, 1);
if (status != asynSuccess) { if (status != asynSuccess) {
asynPrint( asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR, pC_->pasynUserSelf, ASYN_TRACE_ERROR,
@ -74,7 +73,12 @@ pmacv3Axis::~pmacv3Axis(void) {
/** /**
Read the configuration at the first poll Read the configuration at the first poll
*/ */
asynStatus pmacv3Axis::atFirstPoll() { asynStatus pmacv3Axis::atFirstPoll() { return readConfig(); }
/*
Read the configuration from the motor control unit and the parameter library.
*/
asynStatus pmacv3Axis::readConfig() {
// Local variable declaration // Local variable declaration
asynStatus status = asynSuccess; asynStatus status = asynSuccess;
@ -83,7 +87,6 @@ asynStatus pmacv3Axis::atFirstPoll() {
double motorRecResolution = 0.0; double motorRecResolution = 0.0;
double motorPosition = 0.0; double motorPosition = 0.0;
double motorVelocity = 0.0; double motorVelocity = 0.0;
double motorVmax = 0.0;
double motorAccel = 0.0; double motorAccel = 0.0;
int acoDelay = 0.0; // Offset time for the movement watchdog caused by int acoDelay = 0.0; // Offset time for the movement watchdog caused by
// the air cushions in milliseconds. // the air cushions in milliseconds.
@ -98,19 +101,16 @@ asynStatus pmacv3Axis::atFirstPoll() {
__PRETTY_FUNCTION__, __LINE__); __PRETTY_FUNCTION__, __LINE__);
} }
/* // Software limits and current position
Read out the axis status, the current position, current and maximum speed,
acceleration and the air cushion delay.
*/
snprintf(command, sizeof(command), snprintf(command, sizeof(command),
"P%2.2d00 Q%2.2d10 Q%2.2d03 Q%2.2d04 Q%2.2d06 P%2.2d22", axisNo_, "P%2.2d00 Q%2.2d10 Q%2.2d04 Q%2.2d06 P%2.2d22", axisNo_, axisNo_,
axisNo_, axisNo_, axisNo_, axisNo_, axisNo_); axisNo_, axisNo_, axisNo_);
status = pC_->writeRead(axisNo_, command, response, 6); status = pC_->writeRead(axisNo_, command, response, 5);
if (status != asynSuccess) { if (status != asynSuccess) {
return status; return status;
} }
nvals = sscanf(response, "%d %lf %lf %lf %lf %d", &axStatus, &motorPosition, nvals = sscanf(response, "%d %lf %lf %lf %d", &axStatus, &motorPosition,
&motorVmax, &motorVelocity, &motorAccel, &acoDelay); &motorVelocity, &motorAccel, &acoDelay);
// The acoDelay is given in milliseconds -> Convert to seconds, rounded up // The acoDelay is given in milliseconds -> Convert to seconds, rounded up
offsetMovTimeout_ = std::ceil(acoDelay / 1000.0); offsetMovTimeout_ = std::ceil(acoDelay / 1000.0);
@ -120,7 +120,7 @@ asynStatus pmacv3Axis::atFirstPoll() {
// here to mm/s^2. // here to mm/s^2.
motorAccel = motorAccel * 1000; motorAccel = motorAccel * 1000;
if (nvals != 6) { if (nvals != 5) {
return pC_->errMsgCouldNotParseResponse(command, response, axisNo_, return pC_->errMsgCouldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__); __PRETTY_FUNCTION__, __LINE__);
} }
@ -135,14 +135,25 @@ asynStatus pmacv3Axis::atFirstPoll() {
__PRETTY_FUNCTION__, __LINE__); __PRETTY_FUNCTION__, __LINE__);
} }
// Write to the motor record fields status =
status = setVeloFields(motorVelocity, 0.0, motorVmax); pC_->setDoubleParam(axisNo_, pC_->motorVelocityRBV_, motorVelocity);
if (status != asynSuccess) { if (status != asynSuccess) {
return status; return pC_->paramLibAccessFailed(status, "motorVelocityRBV_",
__PRETTY_FUNCTION__, __LINE__);
} }
status = setAcclField(motorAccel);
status = pC_->setDoubleParam(axisNo_, pC_->motorAccelRBV_, motorAccel);
if (status != asynSuccess) { if (status != asynSuccess) {
return status; return pC_->paramLibAccessFailed(status, "motorAccelRBV_",
__PRETTY_FUNCTION__, __LINE__);
}
// Set the initial enable based on the motor status value
status =
setIntegerParam(pC_->enableMotor_, (axStatus != -3 && axStatus != -5));
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "enableMotor_",
__PRETTY_FUNCTION__, __LINE__);
} }
// Update the parameter library immediately // Update the parameter library immediately
@ -240,7 +251,7 @@ asynStatus pmacv3Axis::doPoll(bool *moving) {
} }
// Transform from EPICS to motor coordinates (see comment in // Transform from EPICS to motor coordinates (see comment in
// pmacv3Axis::atFirstPoll) // pmacv3Axis::readConfig())
previousPosition = previousPosition * motorRecResolution; previousPosition = previousPosition * motorRecResolution;
// Query the axis status // Query the axis status
@ -263,13 +274,13 @@ asynStatus pmacv3Axis::doPoll(bool *moving) {
The axis limits are set as: ({[]}) The axis limits are set as: ({[]})
where [] are the positive and negative limits set in EPICS/NICOS, {} are the where [] are the positive and negative limits set in EPICS/NICOS, {} are the
software limits set on the MCU and () are the hardware limit switches. In software limits set on the MCU and () are the hardware limit switches. In
other words, the EPICS/NICOS limits should be stricter than the software other words, the EPICS/NICOS limits must be stricter than the software
limits on the MCU which in turn should be stricter than the hardware limit limits on the MCU which in turn should be stricter than the hardware limit
switches. For example, if the hardware limit switches are at [-10, 10], the switches. For example, if the hardware limit switches are at [-10, 10], the
software limits could be at [-9, 9] and the EPICS / NICOS limits could be at software limits could be at [-9, 9] and the EPICS / NICOS limits could be at
[-8, 8]. Therefore, we cannot use the software limits read from the MCU [-8, 8]. Therefore, we cannot use the software limits read from the MCU
directly, but need to shrink them a bit. In this case, we're shrinking them directly, but need to shrink them a bit. In this case, we're shrinking them
by limitsOffset on both sides. by 0.1 mm or 0.1 degree (depending on the axis type) on both sides.
*/ */
pl_status = pl_status =
pC_->getDoubleParam(axisNo_, pC_->motorLimitsOffset_, &limitsOffset); pC_->getDoubleParam(axisNo_, pC_->motorLimitsOffset_, &limitsOffset);
@ -283,14 +294,6 @@ asynStatus pmacv3Axis::doPoll(bool *moving) {
// Store the axis status // Store the axis status
axisStatus_ = axStatus; axisStatus_ = axStatus;
// Update the enablement PV
pl_status = setIntegerParam(pC_->motorEnableRBV_,
(axStatus != -3 && axStatus != -5));
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorEnableRBV_",
__PRETTY_FUNCTION__, __LINE__);
}
// Intepret the status // Intepret the status
switch (axStatus) { switch (axStatus) {
case -6: case -6:
@ -521,7 +524,7 @@ asynStatus pmacv3Axis::doPoll(bool *moving) {
snprintf(command, sizeof(command), snprintf(command, sizeof(command),
"Maximum allowed following error exceeded (P%2.2d01 = %d). " "Maximum allowed following error exceeded (P%2.2d01 = %d). "
"Check if movement range is blocked. " "Check if movement range is blocked."
"Otherwise please call the support.", "Otherwise please call the support.",
axisNo_, error); axisNo_, error);
pl_status = setStringParam(pC_->motorMessageText_, command); pl_status = setStringParam(pC_->motorMessageText_, command);
@ -615,6 +618,13 @@ asynStatus pmacv3Axis::doPoll(bool *moving) {
} }
} }
pl_status = setIntegerParam(pC_->enableMotorRBV_,
(axStatus != -3 && axStatus != -5));
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "enableMotorRBV_",
__PRETTY_FUNCTION__, __LINE__);
}
pl_status = setIntegerParam(pC_->motorStatusMoving_, *moving); pl_status = setIntegerParam(pC_->motorStatusMoving_, *moving);
if (pl_status != asynSuccess) { if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusMoving_", return pC_->paramLibAccessFailed(pl_status, "motorStatusMoving_",
@ -648,7 +658,7 @@ asynStatus pmacv3Axis::doPoll(bool *moving) {
} }
// Transform from motor to EPICS coordinates (see comment in // Transform from motor to EPICS coordinates (see comment in
// pmacv3Axis::atFirstPoll()) // pmacv3Axis::readConfig())
currentPosition = currentPosition / motorRecResolution; currentPosition = currentPosition / motorRecResolution;
pl_status = setDoubleParam(pC_->motorPosition_, currentPosition); pl_status = setDoubleParam(pC_->motorPosition_, currentPosition);
@ -671,15 +681,12 @@ asynStatus pmacv3Axis::doMove(double position, int relative, double minVelocity,
char command[pC_->MAXBUF_], response[pC_->MAXBUF_]; char command[pC_->MAXBUF_], response[pC_->MAXBUF_];
double motorCoordinatesPosition = 0.0; double motorCoordinatesPosition = 0.0;
double motorRecResolution = 0.0;
double motorVelocity = 0.0;
int enabled = 0; int enabled = 0;
int motorCanSetSpeed = 0; double motorRecResolution = 0.0;
int writeOffset = 0;
// ========================================================================= // =========================================================================
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorEnableRBV_, &enabled); pl_status = pC_->getIntegerParam(axisNo_, pC_->enableMotorRBV_, &enabled);
if (pl_status != asynSuccess) { if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "enableMotorRBV_", return pC_->paramLibAccessFailed(pl_status, "enableMotorRBV_",
__PRETTY_FUNCTION__, __LINE__); __PRETTY_FUNCTION__, __LINE__);
@ -701,43 +708,18 @@ asynStatus pmacv3Axis::doMove(double position, int relative, double minVelocity,
// Convert from EPICS to user / motor units // Convert from EPICS to user / motor units
motorCoordinatesPosition = position * motorRecResolution; motorCoordinatesPosition = position * motorRecResolution;
motorVelocity = maxVelocity * motorRecResolution;
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW, asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
"%s => line %d:\nStart of axis %d to position %lf.\n", "%s => line %d:\nStart of axis %d to position %lf.\n",
__PRETTY_FUNCTION__, __LINE__, axisNo_, position); __PRETTY_FUNCTION__, __LINE__, axisNo_, position);
// Check if the speed is allowed to be changed // Perform handshake, Set target position and start the move command
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorCanSetSpeed_,
&motorCanSetSpeed);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorCanSetSpeed_",
__PRETTY_FUNCTION__, __LINE__);
}
// Prepend the new motor speed, if the user is allowed to set the speed.
// Mind the " " (space) before the closing "", as the command created here
// is prepended to the one down below.
if (motorCanSetSpeed != 0) {
snprintf(command, sizeof(command), "Q%2.2d04=%lf ", axisNo_,
motorVelocity);
writeOffset = strlen(command);
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
"%s => line %d:\nSetting speed of axis %d to %lf.\n",
__PRETTY_FUNCTION__, __LINE__, axisNo_, motorVelocity);
}
// Perform handshake, Set target position (and speed, if allowed) and start
// the move command
if (relative) { if (relative) {
snprintf(&command[writeOffset], sizeof(command) - writeOffset, snprintf(command, sizeof(command), "P%2.2d23=0 Q%2.2d02=%lf M%2.2d=2",
"P%2.2d23=0 Q%2.2d02=%lf M%2.2d=2", axisNo_, axisNo_, axisNo_, axisNo_, motorCoordinatesPosition, axisNo_);
motorCoordinatesPosition, axisNo_);
} else { } else {
snprintf(&command[writeOffset], sizeof(command) - writeOffset, snprintf(command, sizeof(command), "P%2.2d23=0 Q%2.2d01=%lf M%2.2d=1",
"P%2.2d23=0 Q%2.2d01=%lf M%2.2d=1", axisNo_, axisNo_, axisNo_, axisNo_, motorCoordinatesPosition, axisNo_);
motorCoordinatesPosition, axisNo_);
} }
// We don't expect an answer // We don't expect an answer
@ -950,18 +932,25 @@ asynStatus pmacv3Axis::rereadEncoder() {
} }
// Abort if the axis is incremental // Abort if the axis is incremental
if (strcmp(encoderType, IncrementalEncoder) == 0) { if (strcmp(encoderType, IncrementalEncoder) == 1) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW, asynPrint(pC_->pasynUserSelf, ASYN_TRACE_WARNING,
"%s => line %d:\nEncoder of axis %d is not reread because it " "%s => line %d:\nTrying to reread absolute encoder of "
"is incremental.\n", "axis %d on controller %s, but it is a relative encoder.\n",
__PRETTY_FUNCTION__, __LINE__, axisNo_); __PRETTY_FUNCTION__, __LINE__, axisNo_, pC_->portName);
return asynSuccess; pl_status = setStringParam(pC_->motorMessageText_,
"Cannot reread an incremental encoder.");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
__PRETTY_FUNCTION__, __LINE__);
}
return asynError;
} }
// Check if the axis is disabled. If not, inform the user that this // Check if the axis is disabled. If not, inform the user that this
// is necessary // is necessary
int enabled = 0; int enabled = 0;
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorEnableRBV_, &enabled); pl_status = pC_->getIntegerParam(axisNo_, pC_->enableMotorRBV_, &enabled);
if (pl_status != asynSuccess) { if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "enableMotorRBV_", return pC_->paramLibAccessFailed(pl_status, "enableMotorRBV_",
__PRETTY_FUNCTION__, __LINE__); __PRETTY_FUNCTION__, __LINE__);
@ -1042,6 +1031,13 @@ asynStatus pmacv3Axis::enable(bool on) {
__PRETTY_FUNCTION__, __LINE__); __PRETTY_FUNCTION__, __LINE__);
} }
// Reset the value in the param lib.
pl_status = setIntegerParam(pC_->enableMotor_, 1);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "enableMotor_",
__PRETTY_FUNCTION__, __LINE__);
}
return asynError; return asynError;
} }
@ -1055,14 +1051,6 @@ asynStatus pmacv3Axis::enable(bool on) {
return asynSuccess; return asynSuccess;
} }
// Reread the encoder, if the axis is going to be enabled
if (on != 0) {
rw_status = rereadEncoder();
if (rw_status != asynSuccess) {
return rw_status;
}
}
// Enable / disable the axis if it is not moving // Enable / disable the axis if it is not moving
snprintf(command, sizeof(command), "M%2.2d14=%d", axisNo_, on); snprintf(command, sizeof(command), "M%2.2d14=%d", axisNo_, on);
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW, asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
@ -1078,6 +1066,7 @@ asynStatus pmacv3Axis::enable(bool on) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_", return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
__PRETTY_FUNCTION__, __LINE__); __PRETTY_FUNCTION__, __LINE__);
} }
rw_status = pC_->writeRead(axisNo_, command, response, 0); rw_status = pC_->writeRead(axisNo_, command, response, 0);
if (rw_status != asynSuccess) { if (rw_status != asynSuccess) {
return rw_status; return rw_status;
@ -1127,3 +1116,8 @@ asynStatus pmacv3Axis::enable(bool on) {
} }
return asynError; return asynError;
} }
asynStatus pmacv3Axis::isEnabled(bool *on) {
*on = (axisStatus_ != -3 && axisStatus_ != -5);
return asynSuccess;
}

View File

@ -88,6 +88,15 @@ class pmacv3Axis : public sinqAxis {
*/ */
asynStatus enable(bool on); asynStatus enable(bool on);
/**
* @brief EThis function sets "on" to true, if the motor is enabled, and to
* false otherwise
*
* @param on
* @return asynStatus
*/
asynStatus isEnabled(bool *on);
/** /**
* @brief Read the encoder type (incremental or absolute) for this axis from * @brief Read the encoder type (incremental or absolute) for this axis from
* the MCU and store the information in the PV ENCODER_TYPE. * the MCU and store the information in the PV ENCODER_TYPE.
@ -106,6 +115,7 @@ class pmacv3Axis : public sinqAxis {
protected: protected:
pmacv3Controller *pC_; pmacv3Controller *pC_;
asynStatus readConfig();
bool initial_poll_; bool initial_poll_;
bool waitForHandshake_; bool waitForHandshake_;
time_t timeAtHandshake_; time_t timeAtHandshake_;

View File

@ -1,3 +1,6 @@
// Needed to use strcpy_s from string.h
#define __STDC_WANT_LIB_EXT1__ 1
#include "pmacv3Controller.h" #include "pmacv3Controller.h"
#include "asynMotorController.h" #include "asynMotorController.h"
#include "asynOctetSyncIO.h" #include "asynOctetSyncIO.h"
@ -11,21 +14,21 @@
#include <unistd.h> #include <unistd.h>
/** /**
* @brief Copy src into dst and replace all carriage returns with spaces. This * @brief Copy src into dst and replace all carriage returns with spaces
* allows to print *dst with asynPrint.
*
* *
* @param dst Buffer for the modified string * @param dst Buffer for the modified string
* @param src Original string * @param src Original string
*/ */
void adjustResponseForPrint(char *dst, const char *src, size_t buf_length) { void adjustResponseForPrint(char *dst, const char *src) {
for (size_t i = 0; i < buf_length; i++) { // Needed to use strcpy_s from string.h
if (src[i] == '\r') { #ifdef __STDC_LIB_EXT1__
dst[i] = ' '; strcpy_s(dst, src);
} else { for (size_t i = 0; i < strlen(dst); i++) {
dst[i] = src[i]; if (dst[i] == '\r') {
dst[i] = '_';
} }
} }
#endif
} }
/** /**
@ -48,10 +51,13 @@ pmacv3Controller::pmacv3Controller(const char *portName,
portName, ipPortConfigName, numAxes, movingPollPeriod, idlePollPeriod, portName, ipPortConfigName, numAxes, movingPollPeriod, idlePollPeriod,
/* /*
The following parameter library entries are added in this driver: The following parameter library entries are added in this driver:
- ENCODER_TYPE
- REREAD_ENCODER_POSITION - REREAD_ENCODER_POSITION
- READ_CONFIG - READ_CONFIG
- MOTOR_VELOCITY_FROM_DRIVER
- MOTOR_ACCEL_FROM_DRIVER
*/ */
NUM_PMACV3_DRIVER_PARAMS) 5)
{ {
@ -80,6 +86,15 @@ pmacv3Controller::pmacv3Controller(const char *portName,
// ========================================================================= // =========================================================================
// Create additional parameter library entries // Create additional parameter library entries
status = createParam("ENCODER_TYPE", asynParamOctet, &encoderType_);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"%s => line %d:\nFATAL ERROR (creating a parameter failed "
"with %s).\nTerminating IOC",
__PRETTY_FUNCTION__, __LINE__, stringifyAsynStatus(status));
exit(-1);
}
status = createParam("REREAD_ENCODER_POSITION", asynParamInt32, status = createParam("REREAD_ENCODER_POSITION", asynParamInt32,
&rereadEncoderPosition_); &rereadEncoderPosition_);
if (status != asynSuccess) { if (status != asynSuccess) {
@ -99,6 +114,26 @@ pmacv3Controller::pmacv3Controller(const char *portName,
exit(-1); exit(-1);
} }
status = createParam("MOTOR_VELOCITY_FROM_DRIVER", asynParamFloat64,
&motorVelocityRBV_);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"%s => line %d:\nFATAL ERROR (creating a parameter failed "
"with %s).\nTerminating IOC",
__PRETTY_FUNCTION__, __LINE__, stringifyAsynStatus(status));
exit(-1);
}
status = createParam("MOTOR_ACCEL_FROM_DRIVER", asynParamFloat64,
&motorAccelRBV_);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"%s => line %d:\nFATAL ERROR (creating a parameter failed "
"with %s).\nTerminating IOC",
__PRETTY_FUNCTION__, __LINE__, stringifyAsynStatus(status));
exit(-1);
}
/* /*
Define the end-of-string of a message coming from the device to EPICS. Define the end-of-string of a message coming from the device to EPICS.
It is not necessary to append a terminator to outgoing messages, since It is not necessary to append a terminator to outgoing messages, since
@ -293,14 +328,14 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
// Second check: If this fails, give up and propagate the error. // Second check: If this fails, give up and propagate the error.
if (numExpectedResponses != numReceivedResponses) { if (numExpectedResponses != numReceivedResponses) {
adjustResponseForPrint(modResponse, response, MAXBUF_); adjustResponseForPrint(modResponse, response);
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"%s => line %d:\nUnexpected response '%s' (carriage " "%s => line %d:\nUnexpected response %s (_ are "
"returns are replaced with spaces) for command %s\n", "carriage returns) for command %s\n",
__PRETTY_FUNCTION__, __LINE__, modResponse, command); __PRETTY_FUNCTION__, __LINE__, modResponse, command);
snprintf(drvMessageText, sizeof(drvMessageText), snprintf(drvMessageText, sizeof(drvMessageText),
"Received unexpected response '%s' (carriage returns " "Received unexpected response %s (_ are "
"are replaced with spaces) for command %s. " "carriage returns) for command %s. "
"Please call the support", "Please call the support",
modResponse, command); modResponse, command);
pl_status = setStringParam(motorMessageText_, drvMessageText); pl_status = setStringParam(motorMessageText_, drvMessageText);
@ -342,6 +377,29 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
} }
} }
if (status != asynSuccess) {
// Check if the axis already is in an error communication mode. If it is
// not, upstream the error. This is done to avoid "flooding" the user
// with different error messages if more than one error ocurred before
// an error-free communication
pl_status =
getIntegerParam(axisNo, motorStatusProblem_, &motorStatusProblem);
if (pl_status != asynSuccess) {
return paramLibAccessFailed(pl_status, "motorStatusProblem_",
__PRETTY_FUNCTION__, __LINE__);
}
if (motorStatusProblem == 0) {
pl_status =
axis->setStringParam(this->motorMessageText_, drvMessageText);
if (pl_status != asynSuccess) {
return paramLibAccessFailed(pl_status, "motorMessageText_",
__PRETTY_FUNCTION__, __LINE__);
}
}
}
// Log the overall status (communication successfull or not) // Log the overall status (communication successfull or not)
if (status == asynSuccess) { if (status == asynSuccess) {
@ -351,43 +409,21 @@ asynStatus pmacv3Controller::writeRead(int axisNo, const char *command,
__PRETTY_FUNCTION__, __LINE__, modResponse); __PRETTY_FUNCTION__, __LINE__, modResponse);
pl_status = axis->setIntegerParam(this->motorStatusCommsError_, 0); pl_status = axis->setIntegerParam(this->motorStatusCommsError_, 0);
} else { } else {
asynPrint(lowLevelPortUser_, ASYN_TRACE_ERROR, if (status == asynSuccess) {
"%s => line %d:\nCommunication failed for command %s (%s)\n", asynPrint(
__PRETTY_FUNCTION__, __LINE__, fullCommand, lowLevelPortUser_, ASYN_TRACE_ERROR,
stringifyAsynStatus(status)); "%s => line %d:\nCommunication failed for command %s (%s)\n",
__PRETTY_FUNCTION__, __LINE__, fullCommand,
stringifyAsynStatus(status));
pl_status = axis->setIntegerParam(this->motorStatusCommsError_, 1);
}
// Check if the axis already is in an error communication mode. If it is
// not, upstream the error. This is done to avoid "flooding" the user
// with different error messages if more than one error ocurred before
// an error-free communication
pl_status =
getIntegerParam(axisNo, motorStatusProblem_, &motorStatusProblem);
if (pl_status != asynSuccess) { if (pl_status != asynSuccess) {
return paramLibAccessFailed(pl_status, "motorStatusProblem_", return paramLibAccessFailed(pl_status, "motorStatusCommsError_",
__PRETTY_FUNCTION__, __LINE__); __PRETTY_FUNCTION__, __LINE__);
} }
if (motorStatusProblem == 0) {
pl_status = axis->setStringParam(motorMessageText_, drvMessageText);
if (pl_status != asynSuccess) {
return paramLibAccessFailed(pl_status, "motorMessageText_",
__PRETTY_FUNCTION__, __LINE__);
}
pl_status = axis->setIntegerParam(motorStatusProblem_, 1);
if (pl_status != asynSuccess) {
return paramLibAccessFailed(pl_status, "motorStatusProblem",
__PRETTY_FUNCTION__, __LINE__);
}
pl_status = axis->setIntegerParam(motorStatusProblem_, 1);
if (pl_status != asynSuccess) {
return paramLibAccessFailed(pl_status, "motorStatusCommsError_",
__PRETTY_FUNCTION__, __LINE__);
}
}
} }
return status; return asynSuccess;
} }
asynStatus pmacv3Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) { asynStatus pmacv3Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) {
@ -405,27 +441,17 @@ asynStatus pmacv3Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) {
if (function == rereadEncoderPosition_) { if (function == rereadEncoderPosition_) {
return axis->rereadEncoder(); return axis->rereadEncoder();
} else if (function == readConfig_) { } else if (function == readConfig_) {
return axis->atFirstPoll(); return axis->readConfig();
} else { } else {
return sinqController::writeInt32(pasynUser, value); return sinqController::writeInt32(pasynUser, value);
} }
} }
asynStatus sinqController::readInt32(asynUser *pasynUser, epicsInt32 *value) {
// PMACs can be disabled
if (pasynUser->reason == motorCanDisable_) {
*value = 1;
return asynSuccess;
} else {
return asynMotorController::readInt32(pasynUser, value);
}
}
asynStatus pmacv3Controller::errMsgCouldNotParseResponse( asynStatus pmacv3Controller::errMsgCouldNotParseResponse(
const char *command, const char *response, int axisNo, const char *command, const char *response, int axisNo,
const char *functionName, int lineNumber) { const char *functionName, int lineNumber) {
char modifiedResponse[MAXBUF_] = {0}; char modifiedResponse[MAXBUF_] = {0};
adjustResponseForPrint(modifiedResponse, response, MAXBUF_); adjustResponseForPrint(modifiedResponse, response);
return sinqController::errMsgCouldNotParseResponse( return sinqController::errMsgCouldNotParseResponse(
command, modifiedResponse, axisNo, functionName, lineNumber); command, modifiedResponse, axisNo, functionName, lineNumber);
} }
@ -441,7 +467,7 @@ C wrapper for the controller constructor. Please refer to the pmacv3Controller
constructor documentation. constructor documentation.
*/ */
asynStatus pmacv3CreateController(const char *portName, asynStatus pmacv3CreateController(const char *portName,
const char *ipPortConfigName, int numAxes, const char *lowLevelPortName, int numAxes,
double movingPollPeriod, double movingPollPeriod,
double idlePollPeriod, double comTimeout) { double idlePollPeriod, double comTimeout) {
/* /*
@ -456,7 +482,7 @@ asynStatus pmacv3CreateController(const char *portName,
#pragma GCC diagnostic ignored "-Wunused-but-set-variable" #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-variable"
pmacv3Controller *pController = pmacv3Controller *pController =
new pmacv3Controller(portName, ipPortConfigName, numAxes, new pmacv3Controller(portName, lowLevelPortName, numAxes,
movingPollPeriod, idlePollPeriod, comTimeout); movingPollPeriod, idlePollPeriod, comTimeout);
return asynSuccess; return asynSuccess;

View File

@ -12,6 +12,9 @@
#include "sinqAxis.h" #include "sinqAxis.h"
#include "sinqController.h" #include "sinqController.h"
#define IncrementalEncoder "Incremental encoder"
#define AbsoluteEncoder "Absolute encoder"
class pmacv3Controller : public sinqController { class pmacv3Controller : public sinqController {
public: public:
@ -48,9 +51,10 @@ class pmacv3Controller : public sinqController {
pmacv3Axis *getAxis(int axisNo); pmacv3Axis *getAxis(int axisNo);
/** /**
* @brief Overloaded function of sinqController * @brief Overloaded function of asynMotorController
* *
* The function is overloaded to allow rereading the encoder and config. * The function is overloaded to allow enabling / disabling the motor and
* rereading the encoder.
* *
* @param pasynUser Specify the axis via the asynUser * @param pasynUser Specify the axis via the asynUser
* @param value New value * @param value New value
@ -124,13 +128,18 @@ class pmacv3Controller : public sinqController {
double comTimeout_; double comTimeout_;
// Indices of additional PVs // Indices of additional PVs
#define FIRST_PMACV3_PARAM rereadEncoderPosition_
int rereadEncoderPosition_; int rereadEncoderPosition_;
int readConfig_; int readConfig_;
#define LAST_PMACV3_PARAM readConfig_ int encoderType_;
/*
Same strategy as with the limits in sinqController -> Use additional PVs to
write speed and acceleration from the driver to the record.
*/
int motorVelocityRBV_;
int motorAccelRBV_;
friend class pmacv3Axis; friend class pmacv3Axis;
}; };
#define NUM_PMACV3_DRIVER_PARAMS (&LAST_PMACV3_PARAM - &FIRST_PMACV3_PARAM + 1)
#endif /* pmacv3Controller_H */ #endif /* pmacv3Controller_H */