diff --git a/Makefile b/Makefile index 0d28cbd..e7a06ef 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ REQUIRED+=asynMotor REQUIRED+=sinqMotor # Specify the version of sinqMotor we want to build against -sinqMotor_VERSION=0.4.0 +sinqMotor_VERSION=0.5.0 # These headers allow to depend on this library for derived drivers. HEADERS += src/pmacv3Axis.h diff --git a/db/pmacv3.db b/db/pmacv3.db index 81d3d39..23fd65d 100644 --- a/db/pmacv3.db +++ b/db/pmacv3.db @@ -1,18 +1,7 @@ -# Read out the encoder type in human-readable form. The output numbers can be -# interpreted as ASCII. -# This record is coupled to the parameter library via encoderType -> ENCODER_TYPE. -record(waveform, "$(INSTR)$(M):Encoder_Type") { - field(DTYP, "asynOctetRead") - field(INP, "@asyn($(CONTROLLER),$(AXIS),1) ENCODER_TYPE") - field(FTVL, "CHAR") - field(NELM, "80") - field(SCAN, "I/O Intr") -} - # Trigger a rereading of the encoder. This action is sometimes necessary for # absolute encoders after enabling them. For incremental encoders, this is a no-op. # This record is coupled to the parameter library via rereadEncoderPosition_ -> REREAD_ENCODER_POSITION. -record(longout, "$(INSTR)$(M):Reread_Encoder") { +record(longout, "$(INSTR)$(M):RereadEncoder") { field(DTYP, "asynInt32") field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) REREAD_ENCODER_POSITION") field(PINI, "NO") @@ -23,7 +12,7 @@ record(longout, "$(INSTR)$(M):Reread_Encoder") { # 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):Read_Config") { +record(longout, "$(INSTR)$(M):ReadConfig") { field(DTYP, "asynInt32") field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) READ_CONFIG") field(PINI, "NO") diff --git a/src/pmacv3Axis.cpp b/src/pmacv3Axis.cpp index 639d1ef..293bb52 100644 --- a/src/pmacv3Axis.cpp +++ b/src/pmacv3Axis.cpp @@ -50,6 +50,16 @@ pmacv3Axis::pmacv3Axis(pmacv3Controller *pC, int axisNo) exit(-1); } + status = pC_->setIntegerParam(axisNo_, pC_->motorEnableRBV_, 0); + if (status != asynSuccess) { + asynPrint( + pC_->pasynUserSelf, ASYN_TRACE_ERROR, + "%s => line %d:\nFATAL ERROR (setting a parameter value failed " + "with %s)\n. Terminating IOC", + __PRETTY_FUNCTION__, __LINE__, pC_->stringifyAsynStatus(status)); + exit(-1); + } + status = pC_->setDoubleParam(axisNo_, pC_->motorPosition_, 0.0); if (status != asynSuccess) { asynPrint( @@ -73,7 +83,17 @@ pmacv3Axis::~pmacv3Axis(void) { /** Read the configuration at the first poll */ -asynStatus pmacv3Axis::atFirstPoll() { return readConfig(); } +asynStatus pmacv3Axis::atFirstPoll() { + asynStatus status = asynSuccess; + + // pmacv3 motors can always be disabled + status = pC_->setIntegerParam(axisNo_, pC_->motorCanDisable_, 1); + if (status != asynSuccess) { + return pC_->paramLibAccessFailed(status, "motorCanDisable_", + __PRETTY_FUNCTION__, __LINE__); + } + return readConfig(); +} /* Read the configuration from the motor control unit and the parameter library. @@ -284,6 +304,14 @@ asynStatus pmacv3Axis::doPoll(bool *moving) { // Store the axis status 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 switch (axStatus) { case -6: @@ -608,13 +636,6 @@ asynStatus pmacv3Axis::doPoll(bool *moving) { } } - pl_status = setIntegerParam(pC_->motorEnableRBV_, - (axStatus != -3 && axStatus != -5)); - if (pl_status != asynSuccess) { - return pC_->paramLibAccessFailed(pl_status, "motorEnableRBV_", - __PRETTY_FUNCTION__, __LINE__); - } - pl_status = setIntegerParam(pC_->motorStatusMoving_, *moving); if (pl_status != asynSuccess) { return pC_->paramLibAccessFailed(pl_status, "motorStatusMoving_", @@ -950,7 +971,11 @@ asynStatus pmacv3Axis::rereadEncoder() { } // Abort if the axis is incremental - if (strcmp(encoderType, IncrementalEncoder) == 1) { + if (strcmp(encoderType, IncrementalEncoder) == 0) { + asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW, + "%s => line %d:\nEncoder of axis %d is not reread because it " + "is incremental.\n", + __PRETTY_FUNCTION__, __LINE__, axisNo_); return asynSuccess; } @@ -1123,8 +1148,3 @@ asynStatus pmacv3Axis::enable(bool on) { } return asynError; } - -asynStatus pmacv3Axis::isEnabled(bool *on) { - *on = (axisStatus_ != -3 && axisStatus_ != -5); - return asynSuccess; -} diff --git a/src/pmacv3Axis.h b/src/pmacv3Axis.h index a587810..0a8ed51 100644 --- a/src/pmacv3Axis.h +++ b/src/pmacv3Axis.h @@ -88,15 +88,6 @@ class pmacv3Axis : public sinqAxis { */ 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 * the MCU and store the information in the PV ENCODER_TYPE. diff --git a/src/pmacv3Controller.cpp b/src/pmacv3Controller.cpp index 58bbd97..5ae9ba3 100644 --- a/src/pmacv3Controller.cpp +++ b/src/pmacv3Controller.cpp @@ -51,12 +51,10 @@ pmacv3Controller::pmacv3Controller(const char *portName, portName, ipPortConfigName, numAxes, movingPollPeriod, idlePollPeriod, /* The following parameter library entries are added in this driver: - - ENCODER_TYPE - REREAD_ENCODER_POSITION - READ_CONFIG - - ACCEL_FROM_DRIVER */ - 4) + NUM_PMACV3_DRIVER_PARAMS) { @@ -85,15 +83,6 @@ pmacv3Controller::pmacv3Controller(const char *portName, // ========================================================================= // 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, &rereadEncoderPosition_); if (status != asynSuccess) { @@ -426,6 +415,16 @@ asynStatus pmacv3Controller::writeInt32(asynUser *pasynUser, epicsInt32 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( const char *command, const char *response, int axisNo, const char *functionName, int lineNumber) { diff --git a/src/pmacv3Controller.h b/src/pmacv3Controller.h index c4a474f..613a76c 100644 --- a/src/pmacv3Controller.h +++ b/src/pmacv3Controller.h @@ -12,9 +12,6 @@ #include "sinqAxis.h" #include "sinqController.h" -#define IncrementalEncoder "Incremental encoder" -#define AbsoluteEncoder "Absolute encoder" - class pmacv3Controller : public sinqController { public: @@ -127,11 +124,13 @@ class pmacv3Controller : public sinqController { double comTimeout_; // Indices of additional PVs +#define FIRST_PMACV3_PARAM rereadEncoderPosition_ int rereadEncoderPosition_; int readConfig_; - int encoderType_; +#define LAST_PMACV3_PARAM readConfig_ friend class pmacv3Axis; }; +#define NUM_PMACV3_DRIVER_PARAMS (&LAST_PMACV3_PARAM - &FIRST_PMACV3_PARAM + 1) #endif /* pmacv3Controller_H */