Skip to content

Commit

Permalink
merge features of MCS driver that were lost from version 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Zamofing committed Sep 11, 2023
1 parent 86c607f commit b185945
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 271 deletions.
37 changes: 23 additions & 14 deletions smarActApp/src/smarActMCS2MotorDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Jan 19, 2019
#include <epicsExport.h>
#include "smarActMCS2MotorDriver.h"

#ifdef DEBUG
#define DBG_PRINTF(...) printf(__VA_ARGS__)
#else
#define DBG_PRINTF(...)
#endif

static const char *driverName = "SmarActMCS2MotorDriver";

/** Creates a new MCS2Controller object.
Expand All @@ -46,13 +52,12 @@ MCS2Controller::MCS2Controller(const char *portName, const char *MCS2PortName, i
asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER, "MCS2Controller::MCS2Controller: Creating controller\n");

// Create controller-specific parameters
createParam(MCS2MclfString, asynParamInt32, &this->mclf_);
createParam(MCS2PtypString, asynParamInt32, &this->ptyp_);
createParam(MCS2PtypRbString, asynParamInt32, &this->ptyprb_);
createParam(MCS2PstatString, asynParamInt32, &this->pstatrb_); // whole positioner status word
createParam(MCS2CalString, asynParamInt32, &this->cal_);
createParam(MCS2MclfString, asynParamInt32, &this->mclf_);
createParam(MCS2HoldString, asynParamInt32, &this->hold_);

createParam(MCS2CalString, asynParamInt32, &this->cal_);

// Connect to MCS2 controller
status = pasynOctetSyncIO->connect(MCS2PortName, 0, &pasynUserController_, NULL);
Expand Down Expand Up @@ -215,16 +220,16 @@ asynStatus MCS2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value)
* status at the end, but that's OK */
status = setIntegerParam(pAxis->axisNo_, function, value);

if (function == mclf_) {
// set piezo MaxClockFreq
sprintf(pAxis->pC_->outString_, ":CHAN%d:MCLF:CURR %d", pAxis->axisNo_, value);
status = pAxis->pC_->writeController();
}
else if (function == ptyp_) {
if (function == ptyp_) {
// set positioner type
sprintf(pAxis->pC_->outString_, ":CHAN%d:PTYP %d", pAxis->axisNo_, value);
status = pAxis->pC_->writeController();
}
else if (function == mclf_) {
// set piezo MaxClockFreq
sprintf(pAxis->pC_->outString_, ":CHAN%d:MCLF:CURR %d", pAxis->axisNo_, value);
status = pAxis->pC_->writeController();
}
else if (function == cal_) {
// send calibration command
sprintf(pAxis->pC_->outString_, ":CAL%d", pAxis->axisNo_);
Expand Down Expand Up @@ -356,7 +361,9 @@ asynStatus MCS2Axis::move(double position, int relative, double minVelocity, dou

if(hasEnc)
{
printf("MCS2Axis::move closeloop: position: %g rel: %d\n",position,relative);
printf("MCS2Axis::move: closeloop: position: %g rel: %d\n",position,relative);

DBG_PRINTF("MCS2Axis::move: closeloop: position: %g rel: %d\n",position,relative);
sprintf(pC_->outString_, ":CHAN%d:MMOD %d", channel_, relative > 0 ? 1 : 0);
status = pC_->writeController();
// Set acceleration
Expand All @@ -377,16 +384,18 @@ asynStatus MCS2Axis::move(double position, int relative, double minVelocity, dou
if(!relative)
position=position-curPos;
curPos+=position;
printf("MCS2Axis::move openloop: new_pos: %g rel_move: %g\n",curPos,position);
DBG_PRINTF("MCS2Axis::move: openloop: new_pos: %g rel_move: %g\n",curPos,position);
//:STEP:FREQuency 1..20000, default:1000 Hz.
//:STEP:AMPLitude 1..65535, default:65535 (100 V).
setDoubleParam(pC_->motorEncoderPosition_, curPos);
setDoubleParam(pC_->motorPosition_, curPos);

sprintf(pC_->outString_, ":CHAN%d:MMOD %d", channel_, 4);
status = pC_->writeController();
sprintf(pC_->outString_, ":MOVE%d %f", channel_, position * PULSES_PER_STEP);
DBG_PRINTF("MCS2Axis::move: %s ->status:%d\n",pC_->outString_,status);
sprintf(pC_->outString_, ":MOVE%d %f", channel_, position);
status = pC_->writeController();
DBG_PRINTF("MCS2Axis::move: %s ->status:%d\n",pC_->outString_,status);
}
return status;
}
Expand All @@ -403,7 +412,7 @@ asynStatus MCS2Axis::home(double minVelocity, double maxVelocity, double acceler

// Set default reference options - direction and autozero
sprintf(pC_->outString_, ":CHAN%d:REF:OPT %d", channel_, refOpt);
printf("MCS2Axis::home: %s",pC_->outString_);
DBG_PRINTF("MCS2Axis::home: %s",pC_->outString_);

status = pC_->writeController();
pC_->clearErrors();
Expand Down Expand Up @@ -438,7 +447,7 @@ asynStatus MCS2Axis::setPosition(double position)
asynStatus status = asynSuccess;

sprintf(pC_->outString_, ":CHAN%d:POS %f", channel_, position * PULSES_PER_STEP);
printf("MCS2Axis::setPosition: %s",pC_->outString_);
DBG_PRINTF("MCS2Axis::setPosition: %s",pC_->outString_);
status = pC_->writeController();
return status;
}
Expand Down
10 changes: 5 additions & 5 deletions smarActApp/src/smarActMCS2MotorDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ const unsigned short STOP_ON_REF_FOUND = 0x0020;
#define HOLD_FOREVER 0xffffffff

/** drvInfo strings for extra parameters that the MCS2 controller supports */
#define MCS2MclfString "MCLF"
#define MCS2PtypString "PTYP"
#define MCS2PtypRbString "PTYP_RB"
#define MCS2PstatString "PSTAT"
#define MCS2CalString "CAL"
#define MCS2MclfString "MCLF"
#define MCS2HoldString "HOLD"
#define MCS2CalString "CAL"

class epicsShareClass MCS2Axis : public asynMotorAxis
{
Expand Down Expand Up @@ -109,13 +109,13 @@ class epicsShareClass MCS2Controller : public asynMotorController
MCS2Axis *getAxis(int axisNo);

protected:
int mclf_; /**< MCL frequency */
#define FIRST_MCS2_PARAM mclf_
int ptyp_; /**< positioner type */
#define FIRST_MCS2_PARAM ptyp_
int ptyprb_; /**< positioner type readback */
int pstatrb_; /**< positoner status word readback */
int cal_; /**< calibration command */
int mclf_; /**< MCL frequency */
int hold_; /**< hold time */
int cal_; /**< calibration command */
#define LAST_MCS2_PARAM cal_
#define NUM_MCS2_PARAMS (&LAST_MCS2_PARAM - &FIRST_MCS2_PARAM + 1)

Expand Down
Loading

0 comments on commit b185945

Please sign in to comment.