From 646b5fb87d3c12a30bec3b8c34c514faccaa02a0 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 8 Mar 2018 11:41:19 -0600 Subject: [PATCH 01/65] Added support for the ANF2. Code compiles without error but hasn't been tested yet. --- motorApp/AMCISrc/AMCISupport.dbd | 2 + motorApp/AMCISrc/ANF2Driver.cpp | 690 +++++++++++++++++++++++++++++++ motorApp/AMCISrc/ANF2Driver.h | 116 ++++++ motorApp/AMCISrc/ANF2Support.dbd | 2 + motorApp/AMCISrc/Makefile | 3 + 5 files changed, 813 insertions(+) create mode 100644 motorApp/AMCISrc/AMCISupport.dbd create mode 100644 motorApp/AMCISrc/ANF2Driver.cpp create mode 100644 motorApp/AMCISrc/ANF2Driver.h create mode 100644 motorApp/AMCISrc/ANF2Support.dbd diff --git a/motorApp/AMCISrc/AMCISupport.dbd b/motorApp/AMCISrc/AMCISupport.dbd new file mode 100644 index 00000000..48132bba --- /dev/null +++ b/motorApp/AMCISrc/AMCISupport.dbd @@ -0,0 +1,2 @@ +include "ANG1Support.dbd" +include "ANF2Support.dbd" diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp new file mode 100644 index 00000000..3deea3de --- /dev/null +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -0,0 +1,690 @@ +/* +FILENAME... ANF2Driver.cpp +USAGE... Motor record driver support for the AMCI ANF2 stepper motor controller over Modbus/TCP. + +Kevin Peterson + +Based on the AMCI ANG1 Model 3 device driver written by Kurt Goetze + +*/ + + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "ANF2Driver.h" +#include + +#define NINT(f) (int)((f)>0 ? (f)+0.5 : (f)-0.5) + +static const char *driverName = "ANF2MotorDriver"; + +/** Constructor, Creates a new ANF2Controller object. + * \param[in] portName The name of the asyn port that will be created for this driver + * \param[in] ANF2InPortName The name of the drvAsynSerialPort that was created previously to connect to the ANF2 controller + * \param[in] ANF2OutPortName The name of the drvAsynSerialPort that was created previously to connect to the ANF2 controller + * \param[in] numAxes The number of axes that this controller supports + * \param[in] movingPollPeriod The time between polls when any axis is moving + * \param[in] idlePollPeriod The time between polls when no axis is moving + */ +ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, + double movingPollPeriod, double idlePollPeriod) + : asynMotorController(portName, numAxes, NUM_ANF2_PARAMS, + 0, // No additional interfaces beyond those in base class + 0, // No additional callback interfaces beyond those in base class + ASYN_CANBLOCK | ASYN_MULTIDEVICE, + 1, // autoconnect + 0, 0) // Default priority and stack size +{ + int i, j; + asynStatus status = asynSuccess; + static const char *functionName = "ANF2Controller::ANF2Controller"; + + inputDriver_ = epicsStrDup(ANF2InPortName); // Set this before calls to create Axis objects + + // Create controller-specific parameters + createParam(ANF2JerkString, asynParamInt32, &ANF2Jerk_); + + if (numAxes > MAX_AXES) { + numAxes = MAX_AXES; + } + + for (j=0; jconnect(ANF2InPortName, i, &pasynUserInReg_[j][i], NULL); + } + for (i=0; iconnect(ANF2OutPortName, i, &pasynUserOutReg_[j][i], NULL); + } + } + if (status) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, + "%s: cannot connect to ANF2 controller\n", + functionName); + } + + /* Create the poller thread for this controller (do 2 forced-fast polls) + * NOTE: at this point the axis objects don't yet exist, but the poller tolerates this <- KMP: how does it tolerate this? */ + startPoller(movingPollPeriod, idlePollPeriod, 2); +} + + +/** Creates a new ANF2Controller object. + * Configuration command, called directly or from iocsh + * \param[in] portName The name of the asyn port that will be created for this driver + * \param[in] ANF2InPortName The name of the drvAsynIPPPort that was created previously to connect to the ANF2 controller + * \param[in] ANF2OutPortName The name of the drvAsynIPPPort that was created previously to connect to the ANF2 controller + * \param[in] numAxes The number of axes that this controller supports + * \param[in] movingPollPeriod The time in ms between polls when any axis is moving + * \param[in] idlePollPeriod The time in ms between polls when no axis is moving + */ +extern "C" int ANF2CreateController(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, + int movingPollPeriod, int idlePollPeriod) +{ + /* + ANF2Controller *pANF2Controller + = new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numAxes, movingPollPeriod/1000., idlePollPeriod/1000.); + pANF2Controller = NULL; + */ + new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numAxes, movingPollPeriod/1000., idlePollPeriod/1000.); + return(asynSuccess); +} + +/** Reports on status of the driver + * \param[in] fp The file pointer on which report information will be written + * \param[in] level The level of report detail desired + * + * If details > 0 then information is printed about each axis. + * After printing controller-specific information it calls asynMotorController::report() + */ +void ANF2Controller::report(FILE *fp, int level) +{ + fprintf(fp, "ANF2 motor driver %s, numAxes=%d, moving poll period=%f, idle poll period=%f\n", + this->portName, numAxes_, movingPollPeriod_, idlePollPeriod_); + + // Call the base class method + asynMotorController::report(fp, level); +} + +/** Returns a pointer to an ANF2Axis object. + * Returns NULL if the axis number encoded in pasynUser is invalid. + * \param[in] pasynUser asynUser structure that encodes the axis index number. */ +ANF2Axis* ANF2Controller::getAxis(asynUser *pasynUser) +{ +// ? return static_cast(asynMotorController::getAxis(pANF2Axis methodsasynUser)); + return static_cast(asynMotorController::getAxis(pasynUser)); +} + +/** Returns a pointer to an ANF2Axis object. + * Returns NULL if the axis number encoded in pasynUser is invalid. + * \param[in] No Axis index number. */ +ANF2Axis* ANF2Controller::getAxis(int axisNo) +{ + return static_cast(asynMotorController::getAxis(axisNo)); +} + +/** Called when asyn clients call pasynInt32->write(). + * Extracts the function and axis number from pasynUser. + * Sets the value in the parameter library (?) + * + * If the function is ANF2Jerk_ it sets the jerk value in the controller. + * Calls any registered callbacks for this pasynUser->reason and address. + * + * For all other functions it calls asynMotorController::writeInt32. + * \param[in] pasynUser asynUser structure that encodes the reason and address. + * \param[in] value Value to write. */ +asynStatus ANF2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) +{ + int function = pasynUser->reason; + asynStatus status = asynSuccess; + ANF2Axis *pAxis = getAxis(pasynUser); + static const char *functionName = "writeInt32"; + + /* Set the parameter and readback in the parameter library. */ + status = setIntegerParam(pAxis->axisNo_, function, value); + + // The ANF controller doesn't have a jerk variable + // Could probably just not overload writeInt32 at all + /* + if (function == ANF2Jerk_) + { + // Jerk in units steps/sec/sec/sec (0 - 5000) + printf("Jerk = %d\n", value); + status = writeReg16(JERK, value, DEFAULT_CONTROLLER_TIMEOUT); + +// sprintf(outString_, "%s JOG JRK %f", pAxis->axisName_, value); +// status = writeController(); + + } else { + // Call base class method + status = asynMotorController::writeInt32(pasynUser, value); + } + */ + // Call base class method + status = asynMotorController::writeInt32(pasynUser, value); + + /* Do callbacks so higher layers see any changes */ + pAxis->callParamCallbacks(); + if (status) + asynPrint(pasynUser, ASYN_TRACE_ERROR, + "%s:%s: error, status=%d function=%d, value=%d\n", + driverName, functionName, status, function, value); + else + asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, + "%s:%s: function=%d, value=%d\n", + driverName, functionName, function, value); + return status; +} + +asynStatus ANF2Controller::writeReg16(int axisNo, int axisReg, int output, double timeout) +{ + asynStatus status; + + //printf("writeReg16: writing %d to register %d\n", output, axisReg); + asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"writeReg16: writing %d to register %d\n", output, axisReg); + status = pasynInt32SyncIO->write(pasynUserOutReg_[axisNo][axisReg], output, timeout); + epicsThreadSleep(0.01); + + return status ; +} + +asynStatus ANF2Controller::writeReg32(int axisNo, int axisReg, int output, double timeout) +{ +//.. break 32-bit integer into 2 pieces +//.. write the pieces into ANF2 registers + + asynStatus status; + float fnum; + int lower,upper; + + fnum = (output / 1000.0); + upper = (int)fnum; + fnum = fnum - upper; + fnum = NINT(fnum * 1000); + lower = (int)fnum; + + // writeReg16(piece1 ie MSW ... + status = writeReg16(axisNo, axisReg, upper, DEFAULT_CONTROLLER_TIMEOUT); + + // writeReg16(piece2 ie LSW ... + axisReg++; + status = writeReg16(axisNo, axisReg, lower, DEFAULT_CONTROLLER_TIMEOUT); + + return status ; +} + +asynStatus ANF2Controller::readReg16(int axisNo, int axisReg, epicsInt32 *input, double timeout) +{ + asynStatus status; + + //printf("axisReg = %d\n", axisReg); + asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"readReg16 reg = %d\n", axisReg); + status = pasynInt32SyncIO->read(pasynUserInReg_[axisNo][axisReg], input, timeout); + + return status ; +} + +asynStatus ANF2Controller::readReg32(int axisNo, int axisReg, epicsInt32 *combo, double timeout) +{ +//.. read 2 16-bit words from ANF2 registers +//.. assemble 2 16-bit pieces into 1 32-bit integer + + asynStatus status; +// float fnum; + epicsInt32 lowerWord32, upperWord32; // only have pasynInt32SyncIO, not pasynInt16SyncIO , + epicsInt16 lowerWord16, upperWord16; // so we need to get 32-bits and cast to 16-bit integer + + //printf("calling readReg16\n"); + status = readReg16(axisNo, axisReg, &upperWord32, timeout); //get Upper Word + upperWord16 = (epicsInt16)upperWord32; + //printf("upperWord16: %d\n", upperWord16); + asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"readReg32 upperWord16: %d\n", upperWord16); + + // if status != 1 : + axisReg++; + status = readReg16(axisNo, axisReg, &lowerWord32, timeout); //get Lower Word + lowerWord16 = (epicsInt16)lowerWord32; + //printf("lowerWord16: %d\n", lowerWord16); + asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"readReg32 lowerWord16: %d\n", lowerWord16); + + *combo = NINT((upperWord16 * 1000) + lowerWord16); + + return status ; +} + + +// ANF2Axis methods Here +// These are the ANF2Axis methods + +/** Creates a new ANF2Axis object. + * \param[in] pC Pointer to the ANF2Controller to which this axis belongs. + * \param[in] axisNo Index number of this axis, range 0 to pC->numAxes_-1. + * + * Initializes register numbers, etc. + */ +ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) + : asynMotorAxis(pC, axisNo), + pC_(pC) +{ + int status; + axisNo_ = axisNo; + + //status = pasynInt32SyncIO->connect(myModbusInputDriver, 0, &pasynUserForceRead_, "MODBUS_READ"); + status = pasynInt32SyncIO->connect(pC_->inputDriver_, 0, &pasynUserForceRead_, "MODBUS_READ"); + if (status) { + //printf("%s:%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver %s\n", pC_->inputDriver_, pC_->functionName, myModbusInputDriver); + printf("%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver\n", pC_->inputDriver_); + } + printf("ANF2Axis::ANF2Axis : pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); + + // Send the configuration + status = pC_->writeReg32(axisNo_, CONFIG_MSW, config, DEFAULT_CONTROLLER_TIMEOUT); + + // set position to 0 + setPosition(0); +} + +/* + Configuration Bits: + 0x1 - Caputure Input (0 = Disabled, 1 = Enabled) + 0x2 - External Input (0 = Disabled, 1 = Enabled) + 0x4 - Home Input (0 = Disabled, 1 = Enabled) + 0x8 - + + + + + + + + */ + +extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which controller by port name */ + int axis, /* axis number 0-1 */ + const char *hexConfig) /* desired configuration in hex */ +{ + ANF2Controller *pC; + epicsInt32 config; + static const char *functionName = "ANF2CreateAxis"; + + pC = (ANF2Controller*) findAsynPortDriver(ANF2Name); + if (!pC) { + printf("%s:%s: Error port %s not found\n", + driverName, functionName, ANF2Name); + return asynError; + } + + errno = 0; + config = strtoul(hexConfig, NULL, 16); + if (errno != 0) { + printf("%s:%s: Error invalid config=%s\n", + driverName, functionName, hexConfig); + return asynError; + } else { + printf("%s:%s: Config=>%s=%x\n", + driverName, functionName, hexConfig, config); + } + + pC->lock(); + new ANF2Axis(pC, axis, config); + pC->unlock(); + return asynSuccess; +} + + +/** Reports on status of the axis + * \param[in] fp The file pointer on which report information will be written + * \param[in] level The level of report detail desired + * + * After printing device-specific information calls asynMotorAxis::report() + */ +void ANF2Axis::report(FILE *fp, int level) +{ + if (level > 0) { + fprintf(fp, " axis %d\n", + axisNo_); + } + + // Call the base class method + asynMotorAxis::report(fp, level); +} + +// SET VEL & ACCEL +asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) +{ + asynStatus status; + // static const char *functionName = "ANF2::sendAccelAndVelocity"; + + // Send the velocity + status = pC_->writeReg32(axisNo_, SPD_UPR, NINT(velocity), DEFAULT_CONTROLLER_TIMEOUT); + + // Send the acceleration + // ANF2 acceleration range 1 to 5000 steps/ms/sec + // Therefore need to limit range received by motor record from 1000 to 5e6 steps/sec/sec + if (acceleration < 1000) { + // print message noting that accel has been capped low + acceleration = 1000; + } + if (acceleration > 5000000) { + // print message noting that accel has been capped high + acceleration = 5000000; + } + // ANF2 acceleration units are steps/millisecond/second, so we divide by 1000 here + status = pC_->writeReg16(axisNo_, ACCEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg16(axisNo_, DECEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); + return status; +} + +// MOVE +asynStatus ANF2Axis::move(double position, int relative, double minVelocity, double maxVelocity, double acceleration) +{ + asynStatus status; + int distance, move_bit; + + printf(" ** ANF2Axis::move called, relative = %d\n", relative); + + status = sendAccelAndVelocity(acceleration, maxVelocity); + + if (relative) { + printf(" ** relative move called\n"); + //status = pC_->writeReg32(axisNo_, SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); + //distance = position * SOM_OTHER_SCALE_FACTOR; + distance = NINT(position); + status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x2; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + } else { + // absolute + printf(" ** absolute move called\n"); + //status = pC_->writeReg32(axisNo_, SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); + //distance = position * SOM_OTHER_SCALE_FACTOR; + distance = NINT(position); + printf(" ** distance = %d\n", distance); + status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x1; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + } + // Delay the first status read, give the controller some time to return moving status + epicsThreadSleep(0.05); + return status; +} + +// HOME (needs work) +asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceleration, int forwards) +{ + asynStatus status; + int home_bit; + // static const char *functionName = "ANF2Axis::home"; + + //status = sendAccelAndVelocity(acceleration, maxVelocity); + + if (forwards) { + printf(" ** HOMING FORWARDS **\n"); + home_bit = 0x20; + status = pC_->writeReg16(axisNo_, CMD_MSW, home_bit, DEFAULT_CONTROLLER_TIMEOUT); + } else { + home_bit = 0x40; + status = pC_->writeReg16(axisNo_, CMD_MSW, home_bit, DEFAULT_CONTROLLER_TIMEOUT); + } + return status; +} + +// JOG +asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double acceleration) +{ + asynStatus status; + int velo, distance, move_bit; + static const char *functionName = "ANF2Axis::moveVelocity"; + + asynPrint(pasynUser_, ASYN_TRACE_FLOW, + "%s: minVelocity=%f, maxVelocity=%f, acceleration=%f\n", + functionName, minVelocity, maxVelocity, acceleration); + + velo = NINT(fabs(maxVelocity)); + + status = sendAccelAndVelocity(acceleration, velo); + + /* ANF2 does not have jog command. Move 1 million steps */ + if (maxVelocity > 0.) { + /* This is a positive move in ANF2 coordinates */ + //printf(" ** relative move (JOG pos) called\n"); + distance = 1000000; + status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x2; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + } else { + /* This is a negative move in ANF2 coordinates */ + //printf(" ** relative move (JOG neg) called\n"); + distance = -1000000; + status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x2; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + } + // Delay the first status read, give the controller some time to return moving status + epicsThreadSleep(0.05); + return status; +} + + +// STOP +asynStatus ANF2Axis::stop(double acceleration) +{ + asynStatus status; + int stop_bit; + //static const char *functionName = "ANF2Axis::stop"; + + printf("\n STOP \n\n"); + + stop_bit = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, stop_bit, DEFAULT_CONTROLLER_TIMEOUT); + +// stop_bit = 0x10; Immediate stop + stop_bit = 0x4; // Hold move + status = pC_->writeReg16(axisNo_, CMD_MSW, stop_bit, DEFAULT_CONTROLLER_TIMEOUT); + + return status; +} + +// SET +asynStatus ANF2Axis::setPosition(double position) +{ + asynStatus status; + int set_position, set_bit; + //static const char *functionName = "ANF2Axis::setPosition"; + + //status = writeReg32(SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); + //distance = position * SOM_OTHER_SCALE_FACTOR; + set_position = NINT(position); + + status = pC_->writeReg32(axisNo_, POS_WR_UPR, set_position, DEFAULT_CONTROLLER_TIMEOUT); + + set_bit = 0x200; + status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); + + set_bit = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); + + return status; +} + +// ENABLE TORQUE +asynStatus ANF2Axis::setClosedLoop(bool closedLoop) +{ + asynStatus status; + int enable = 0x8000; + int disable = 0x0000; + int cmd; + + printf(" ** setClosedLoop called \n"); + if (closedLoop) { + printf("setting enable %X\n", enable); + // Let's reset errors first + cmd = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, cmd, DEFAULT_CONTROLLER_TIMEOUT); + + cmd = 0x400; + status = pC_->writeReg16(axisNo_, CMD_MSW, cmd, DEFAULT_CONTROLLER_TIMEOUT); + + cmd = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, cmd, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg16(axisNo_, CMD_LSW, enable, DEFAULT_CONTROLLER_TIMEOUT); + setIntegerParam(pC_->motorStatusPowerOn_, 1); + + } else { + printf("setting disable %X\n", disable); + status = pC_->writeReg16(axisNo_, CMD_LSW, disable, DEFAULT_CONTROLLER_TIMEOUT); + setIntegerParam(pC_->motorStatusPowerOn_, 0); + } + + return status; +} + +// POLL +/** Polls the axis. + * This function reads motor position, limit status, home status, and moving status + * It calls setIntegerParam() and setDoubleParam() for each item that it polls, + * and then calls callParamCallbacks() at the end. + * \param[out] moving A flag that is set indicating that the axis is moving (true) or done (false). */ +asynStatus ANF2Axis::poll(bool *moving) +{ + int done; + int limit; + int enabled; + double position; + asynStatus status; + epicsInt32 read_val; // don't use a pointer here. The _address_ of read_val should be passed to the read function. + + // Force a read operation + //printf(" . . . . . Calling pasynInt32SyncIO->write\n"); + //printf("Calling pasynInt32SyncIO->write(pasynUserForceRead_, 1, TIMEOUT), pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); + status = pasynInt32SyncIO->write(pasynUserForceRead_, 1, DEFAULT_CONTROLLER_TIMEOUT); + //printf(" . . . . . status = %d\n", status); + // if status goto end + + // Read the current motor position + // + //readReg32(int reg, epicsInt32 *combo, double timeout) + status = pC_->readReg32(axisNo_, POS_RD_UPR, &read_val, DEFAULT_CONTROLLER_TIMEOUT); + printf("ANF2Axis::poll: Motor position raw: %d\n", read_val); + position = (double) read_val; + setDoubleParam(pC_->motorPosition_, position); + printf("ANF2Axis::poll: Motor position: %f\n", position); + + // Read the moving status of this motor + // + status = pC_->readReg16(axisNo_, STATUS_1, &read_val, DEFAULT_CONTROLLER_TIMEOUT); + //printf("status 1 is 0x%X\n", read_val); + + // Done logic + done = ((read_val & 0x8) >> 3); // status word 1 bit 3 set to 1 when the motor is not in motion. + setIntegerParam(pC_->motorStatusDone_, done); + *moving = done ? false:true; + printf("done is %d\n", done); + + // Read the limit status + // + status = pC_->readReg16(axisNo_, STATUS_2, &read_val, DEFAULT_CONTROLLER_TIMEOUT); + printf("status 2 is 0x%X\n", read_val); + + limit = (read_val & 0x1); // a cw limit has been reached + setIntegerParam(pC_->motorStatusHighLimit_, limit); + //printf("+limit %d\n", limit); + if (limit) { // reset error and set position so we can move off of the limit + // Reset error + setClosedLoop(1); + // Reset position + //printf(" Reset Position\n"); + setPosition(position); + } + + limit = (read_val & 0x2); // a ccw limit has been reached + setIntegerParam(pC_->motorStatusLowLimit_, limit); + //printf("-limit %d\n", limit); + if (limit) { // reset error and set position so we can move off of the limit + // Reset error + setClosedLoop(1); + // Reset position + setPosition(position); + } + + // test for home + + // Should be in init routine? Allows CNEN to be used. + setIntegerParam(pC_->motorStatusGainSupport_, 1); + + // Check for the torque status and set accordingly. + enabled = (read_val & 0x8000); + if (enabled) + setIntegerParam(pC_->motorStatusPowerOn_, 1); + else + setIntegerParam(pC_->motorStatusPowerOn_, 0); + + // Notify asynMotorController polling routine that we're ready + callParamCallbacks(); + + return status; +} + +/** Code for iocsh registration */ + +/* ANF2CreateController */ +static const iocshArg ANF2CreateControllerArg0 = {"Port name", iocshArgString}; +static const iocshArg ANF2CreateControllerArg1 = {"ANF2 In port name", iocshArgString}; +static const iocshArg ANF2CreateControllerArg2 = {"ANF2 Out port name", iocshArgString}; +static const iocshArg ANF2CreateControllerArg3 = {"Number of axes", iocshArgInt}; +static const iocshArg ANF2CreateControllerArg4 = {"Moving poll period (ms)", iocshArgInt}; +static const iocshArg ANF2CreateControllerArg5 = {"Idle poll period (ms)", iocshArgInt}; +static const iocshArg * const ANF2CreateControllerArgs[] = {&ANF2CreateControllerArg0, + &ANF2CreateControllerArg1, + &ANF2CreateControllerArg2, + &ANF2CreateControllerArg3, + &ANF2CreateControllerArg4, + &ANF2CreateControllerArg5,}; +static const iocshFuncDef ANF2CreateControllerDef = {"ANF2CreateController", 6, ANF2CreateControllerArgs}; +static void ANF2CreateControllerCallFunc(const iocshArgBuf *args) +{ + ANF2CreateController(args[0].sval, args[1].sval, args[2].sval, args[3].ival, args[4].ival, args[5].ival); +} + + +/* ANF2CreateAxis */ +static const iocshArg ANF2CreateAxisArg0 = {"Port name", iocshArgString}; +static const iocshArg ANF2CreateAxisArg1 = {"Axis number", iocshArgInt}; +static const iocshArg ANF2CreateAxisArg2 = {"Hex config", iocshArgString}; +static const iocshArg * const ANF2CreateAxisArgs[] = {&ANF2CreateAxisArg0, + &ANF2CreateAxisArg1, + &ANF2CreateAxisArg2}; +static const iocshFuncDef ANF2CreateAxisDef = {"ANF2CreateAxis", 3, ANF2CreateAxisArgs}; +static void ANF2CreateAxisCallFunc(const iocshArgBuf *args) +{ + ANF2CreateAxis(args[0].sval, args[1].ival, args[2].sval); +} + + +static void ANF2Register(void) +{ + iocshRegister(&ANF2CreateControllerDef, ANF2CreateControllerCallFunc); + iocshRegister(&ANF2CreateAxisDef, ANF2CreateAxisCallFunc); +} + +extern "C" { +epicsExportRegistrar(ANF2Register); +} diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h new file mode 100644 index 00000000..1dfb5db4 --- /dev/null +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -0,0 +1,116 @@ +/* +FILENAME... ANF2Driver.h +USAGE... Motor driver support for the AMCI ANF2 controller. + +Based on MCB-4B driver written by +Mark Rivers +March 1, 2012 + +K. Goetze 2014-03-24 + +*/ + +#include "asynMotorController.h" +#include "asynMotorAxis.h" + +#define MAX_AXES 2 + +#define MAX_INPUT_REGS 10 +#define MAX_OUTPUT_REGS 10 + +#define AXIS_REG_OFFSET 10 + +/*** Input CMD Registers ***/ +#define STATUS_1 0 +#define STATUS_2 1 +#define POS_RD_UPR 2 +#define POS_RD_LWR 3 +#define EN_POS_UPR 4 +#define EN_POS_LWR 5 +#define EN_CAP_UPR 6 +#define EN_CAP_LWR 7 +// Not used must equal zero #define RESERVED 8 +#define NET_CONN 9 + +/*** Output CMD Registers ***/ +#define CMD_MSW 0 // module 0 starts at register address 1024. This is set in drvModbusAsynConfigure. +#define CMD_LSW 1 +#define POS_WR_UPR 2 +#define POS_WR_LWR 3 +#define SPD_UPR 4 +#define SPD_LWR 5 +#define ACCEL 6 +#define DECEL 7 +// Not used must equal zero #define RESERVED 8 +// Not used must equal zero #define RESERVED 9 + +/*** Output Configuration Registers ***/ +#define CONFIG_MSW 0 +#define CONFIG_LSW 1 +#define BASE_SPD_MSW 2 +#define BASE_SPD_LSW 3 +#define HOME_TIMEOUT 4 + + +// No. of controller-specific parameters +#define NUM_ANF2_PARAMS 1 + +/** drvInfo strings for extra parameters that the ACR controller supports */ +#define ANF2JerkString "ANF2_JERK" + +class ANF2Axis : public asynMotorAxis +{ +public: + /* These are the methods we override from the base class */ + ANF2Axis(class ANF2Controller *pC, int axisNo, epicsInt32 config); + void report(FILE *fp, int level); + asynStatus move(double position, int relative, double min_velocity, double max_velocity, double acceleration); + asynStatus moveVelocity(double min_velocity, double max_velocity, double acceleration); + asynStatus home(double min_velocity, double max_velocity, double acceleration, int forwards); + asynStatus stop(double acceleration); + asynStatus poll(bool *moving); + asynStatus setPosition(double position); + asynStatus setClosedLoop(bool closedLoop); + +private: + ANF2Controller *pC_; /**< Pointer to the asynMotorController to which this axis belongs. + * Abbreviated because it is used very frequently */ + asynStatus sendAccelAndVelocity(double accel, double velocity); + asynUser *pasynUserForceRead_; + +friend class ANF2Controller; +}; + +class ANF2Controller : public asynMotorController { +public: + ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, double movingPollPeriod, double idlePollPeriod); + + void report(FILE *fp, int level); + ANF2Axis* getAxis(asynUser *pasynUser); + ANF2Axis* getAxis(int axisNo); + asynUser *pasynUserInReg_[MAX_AXES][MAX_INPUT_REGS]; + asynUser *pasynUserOutReg_[MAX_AXES][MAX_OUTPUT_REGS]; +// asynUser *pasynUserForceRead_; + + + /* These are the methods that we override from asynMotorDriver */ + asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); + //asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value); + //void report(FILE *fp, int level); + + /* These are the methods that are new to this class */ + +protected: + int ANF2Jerk_; /**< Jerk time parameter index */ + + +private: + asynStatus writeReg16(int, int, int, double); + asynStatus writeReg32(int, int, int, double); + asynStatus readReg16(int, int, epicsInt32*, double); + asynStatus readReg32(int, int, epicsInt32*, double); + char *inputDriver_; + int axisNo_; + +friend class ANF2Axis; +}; diff --git a/motorApp/AMCISrc/ANF2Support.dbd b/motorApp/AMCISrc/ANF2Support.dbd new file mode 100644 index 00000000..73678200 --- /dev/null +++ b/motorApp/AMCISrc/ANF2Support.dbd @@ -0,0 +1,2 @@ +#registrar(ANF2MotorRegister) +registrar(ANF2Register) diff --git a/motorApp/AMCISrc/Makefile b/motorApp/AMCISrc/Makefile index 9f1782e7..ac94d326 100644 --- a/motorApp/AMCISrc/Makefile +++ b/motorApp/AMCISrc/Makefile @@ -12,10 +12,13 @@ LIBRARY_IOC += AMCI # motorRecord.h will be created from motorRecord.dbd # install devMotorSoft.dbd into /dbd +DBD += AMCISupport.dbd DBD += ANG1Support.dbd +DBD += ANF2Support.dbd # The following are compiled and added to the Support library AMCI_SRCS += ANG1Driver.cpp +AMCI_SRCS += ANF2Driver.cpp AMCI_LIBS += motor AMCI_LIBS += asyn From 751905b275f636afe39700321a80b76703c57954 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 8 Mar 2018 15:55:46 -0600 Subject: [PATCH 02/65] Removed some print statements. Added more report info. --- motorApp/AMCISrc/ANF2Driver.cpp | 18 +++++++++++------- motorApp/AMCISrc/ANF2Driver.h | 3 ++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 3deea3de..ab48333c 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -277,7 +277,9 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) pC_(pC) { int status; + axisNo_ = axisNo; + //this->axisNo_ = axisNo; //status = pasynInt32SyncIO->connect(myModbusInputDriver, 0, &pasynUserForceRead_, "MODBUS_READ"); status = pasynInt32SyncIO->connect(pC_->inputDriver_, 0, &pasynUserForceRead_, "MODBUS_READ"); @@ -351,8 +353,10 @@ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which con void ANF2Axis::report(FILE *fp, int level) { if (level > 0) { - fprintf(fp, " axis %d\n", - axisNo_); + fprintf(fp, " axis %d\n", axisNo_); + fprintf(fp, " this->axisNo_ %i\n", this->axisNo_); + fprintf(fp, " this->config_ %x\n", this->config_); + fprintf(fp, " config_ %x\n", config_); } // Call the base class method @@ -391,7 +395,7 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou asynStatus status; int distance, move_bit; - printf(" ** ANF2Axis::move called, relative = %d\n", relative); + printf(" ** ANF2Axis::move called, relative = %d, axisNo_ = %i\n", relative, this->axisNo_); status = sendAccelAndVelocity(acceleration, maxVelocity); @@ -583,10 +587,10 @@ asynStatus ANF2Axis::poll(bool *moving) // //readReg32(int reg, epicsInt32 *combo, double timeout) status = pC_->readReg32(axisNo_, POS_RD_UPR, &read_val, DEFAULT_CONTROLLER_TIMEOUT); - printf("ANF2Axis::poll: Motor position raw: %d\n", read_val); + //printf("ANF2Axis::poll: Motor position raw: %d\n", read_val); position = (double) read_val; setDoubleParam(pC_->motorPosition_, position); - printf("ANF2Axis::poll: Motor position: %f\n", position); + //printf("ANF2Axis::poll: Motor position: %f\n", position); // Read the moving status of this motor // @@ -597,12 +601,12 @@ asynStatus ANF2Axis::poll(bool *moving) done = ((read_val & 0x8) >> 3); // status word 1 bit 3 set to 1 when the motor is not in motion. setIntegerParam(pC_->motorStatusDone_, done); *moving = done ? false:true; - printf("done is %d\n", done); + //printf("done is %d\n", done); // Read the limit status // status = pC_->readReg16(axisNo_, STATUS_2, &read_val, DEFAULT_CONTROLLER_TIMEOUT); - printf("status 2 is 0x%X\n", read_val); + //printf("status 2 is 0x%X\n", read_val); limit = (read_val & 0x1); // a cw limit has been reached setIntegerParam(pC_->motorStatusHighLimit_, limit); diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 1dfb5db4..c21df2b2 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -77,6 +77,8 @@ private: * Abbreviated because it is used very frequently */ asynStatus sendAccelAndVelocity(double accel, double velocity); asynUser *pasynUserForceRead_; + int axisNo_; + epicsInt32 config_; friend class ANF2Controller; }; @@ -110,7 +112,6 @@ private: asynStatus readReg16(int, int, epicsInt32*, double); asynStatus readReg32(int, int, epicsInt32*, double); char *inputDriver_; - int axisNo_; friend class ANF2Axis; }; From 5651f7071e832457e314105691ae17302700fdc0 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 9 Mar 2018 14:37:00 -0600 Subject: [PATCH 03/65] Added some variables and methods to troubleshoot init problems. Unsuccessful so far. --- motorApp/AMCISrc/ANF2Driver.cpp | 73 ++++++++++++++++++++++++++++++--- motorApp/AMCISrc/ANF2Driver.h | 2 + 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index ab48333c..42714232 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -49,6 +49,9 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, asynStatus status = asynSuccess; static const char *functionName = "ANF2Controller::ANF2Controller"; + // Keep track of the number of axes created, so the poller can wait for all the axes to be created before starting + axesCreated_ = 0; + inputDriver_ = epicsStrDup(ANF2InPortName); // Set this before calls to create Axis objects // Create controller-specific parameters @@ -74,7 +77,7 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, } /* Create the poller thread for this controller (do 2 forced-fast polls) - * NOTE: at this point the axis objects don't yet exist, but the poller tolerates this <- KMP: how does it tolerate this? */ + * NOTE: at this point the axis objects don't yet exist, but the poller tolerates this */ startPoller(movingPollPeriod, idlePollPeriod, 2); } @@ -111,6 +114,7 @@ void ANF2Controller::report(FILE *fp, int level) { fprintf(fp, "ANF2 motor driver %s, numAxes=%d, moving poll period=%f, idle poll period=%f\n", this->portName, numAxes_, movingPollPeriod_, idlePollPeriod_); + fprintf(fp, " axesCreated=%i\n", axesCreated_); // Call the base class method asynMotorController::report(fp, level); @@ -204,14 +208,21 @@ asynStatus ANF2Controller::writeReg32(int axisNo, int axisReg, int output, doubl //.. write the pieces into ANF2 registers asynStatus status; - float fnum; + int lower,upper; + /*float fnum; fnum = (output / 1000.0); upper = (int)fnum; fnum = fnum - upper; fnum = NINT(fnum * 1000); - lower = (int)fnum; + lower = (int)fnum;*/ + + upper = (output >> 16) & 0x0000FFFF; + lower = output & 0x0000FFFF; + + printf("upper = 0x%x\t= %i\n", upper, upper); + printf("lower = 0x%x\t= %i\n", lower, lower); // writeReg16(piece1 ie MSW ... status = writeReg16(axisNo, axisReg, upper, DEFAULT_CONTROLLER_TIMEOUT); @@ -289,11 +300,35 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) } printf("ANF2Axis::ANF2Axis : pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); + epicsThreadSleep(3.0); + + // Read data that is likely to be stale + //getInfo(); + // Send the configuration - status = pC_->writeReg32(axisNo_, CONFIG_MSW, config, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg32(axisNo_, CONFIG_MSW, config, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg16(axisNo_, CONFIG_MSW, 0x8600, DEFAULT_CONTROLLER_TIMEOUT); + + // Delay + epicsThreadSleep(1.0); + + // Read the configuration? Or maybe the command registers? + getInfo(); + + //IAMHERE // set position to 0 setPosition(0); + //setPosition(1337); + + // Delay + epicsThreadSleep(1.0); + + // Read the command registers + getInfo(); + + // Tell the driver the axis has been created + pC_->axesCreated_ += 1; } /* @@ -343,6 +378,24 @@ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which con return asynSuccess; } +void ANF2Axis::getInfo() +{ + asynStatus status; + int i; + epicsInt32 read_val; + + // For a read (not sure why this is necessary) + status = pasynInt32SyncIO->write(pasynUserForceRead_, 1, DEFAULT_CONTROLLER_TIMEOUT); + + printf("Info for axis %i\n", axisNo_); + + for( i=0; ireadReg16(axisNo_, i, &read_val, DEFAULT_CONTROLLER_TIMEOUT); + printf(" status=%d, register=%i, val=0x%x\n", status, i, read_val); + } +} + /** Reports on status of the axis * \param[in] fp The file pointer on which report information will be written @@ -549,8 +602,10 @@ asynStatus ANF2Axis::setClosedLoop(bool closedLoop) cmd = 0x0; status = pC_->writeReg16(axisNo_, CMD_MSW, cmd, DEFAULT_CONTROLLER_TIMEOUT); + /* status = pC_->writeReg16(axisNo_, CMD_LSW, enable, DEFAULT_CONTROLLER_TIMEOUT); setIntegerParam(pC_->motorStatusPowerOn_, 1); + */ } else { printf("setting disable %X\n", disable); @@ -576,6 +631,12 @@ asynStatus ANF2Axis::poll(bool *moving) asynStatus status; epicsInt32 read_val; // don't use a pointer here. The _address_ of read_val should be passed to the read function. + // Don't do any polling until ALL the axes have been created; this ensures that we don't interpret the configuration values as command values + if (pC_->axesCreated_ != pC_->numAxes_) { + *moving = false; + return asynSuccess; + } + // Force a read operation //printf(" . . . . . Calling pasynInt32SyncIO->write\n"); //printf("Calling pasynInt32SyncIO->write(pasynUserForceRead_, 1, TIMEOUT), pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); @@ -635,7 +696,9 @@ asynStatus ANF2Axis::poll(bool *moving) setIntegerParam(pC_->motorStatusGainSupport_, 1); // Check for the torque status and set accordingly. - enabled = (read_val & 0x8000); + // The ANG1 driver does the wrong thing for torque enable/disable + //enabled = (read_val & 0x8000); + enabled = 1; if (enabled) setIntegerParam(pC_->motorStatusPowerOn_, 1); else diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index c21df2b2..44a75fea 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -76,6 +76,7 @@ private: ANF2Controller *pC_; /**< Pointer to the asynMotorController to which this axis belongs. * Abbreviated because it is used very frequently */ asynStatus sendAccelAndVelocity(double accel, double velocity); + void getInfo(); asynUser *pasynUserForceRead_; int axisNo_; epicsInt32 config_; @@ -112,6 +113,7 @@ private: asynStatus readReg16(int, int, epicsInt32*, double); asynStatus readReg32(int, int, epicsInt32*, double); char *inputDriver_; + int axesCreated_; friend class ANF2Axis; }; From 43c8eee384551369b594ad1f802d65377b527bf2 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 9 Mar 2018 15:54:00 -0600 Subject: [PATCH 04/65] Added a port to enable atomic writes of the config data --- motorApp/AMCISrc/ANF2Driver.cpp | 29 ++++++++++++++++++++--------- motorApp/AMCISrc/ANF2Driver.h | 3 ++- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 42714232..c4c3630f 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -283,7 +283,7 @@ asynStatus ANF2Controller::readReg32(int axisNo, int axisReg, epicsInt32 *combo, * * Initializes register numbers, etc. */ -ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) +ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epicsInt32 config) : asynMotorAxis(pC, axisNo), pC_(pC) { @@ -300,14 +300,22 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) } printf("ANF2Axis::ANF2Axis : pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); + status = pasynInt32SyncIO->connect(ANF2ConfName, 0, &pasynUserConfWrite_, NULL); + if (status) { + printf("%s: Error, unable to connect pasynUserConfWrite_ to Modbus input driver\n", ANF2ConfName); + } + printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_->reason=%d\n", pasynUserConfWrite_->reason); + epicsThreadSleep(3.0); // Read data that is likely to be stale - //getInfo(); + getInfo(); // Send the configuration //status = pC_->writeReg32(axisNo_, CONFIG_MSW, config, DEFAULT_CONTROLLER_TIMEOUT); - status = pC_->writeReg16(axisNo_, CONFIG_MSW, 0x8600, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg16(axisNo_, CONFIG_MSW, 0x8600, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32SyncIO->write(pasynUserConfWrite_, config, DEFAULT_CONTROLLER_TIMEOUT); + epicsThreadSleep(0.01); // Delay epicsThreadSleep(1.0); @@ -347,6 +355,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) */ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which controller by port name */ + const char *ANF2ConfName, /* specify which config port name */ int axis, /* axis number 0-1 */ const char *hexConfig) /* desired configuration in hex */ { @@ -373,7 +382,7 @@ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which con } pC->lock(); - new ANF2Axis(pC, axis, config); + new ANF2Axis(pC, ANF2ConfName, axis, config); pC->unlock(); return asynSuccess; } @@ -734,15 +743,17 @@ static void ANF2CreateControllerCallFunc(const iocshArgBuf *args) /* ANF2CreateAxis */ static const iocshArg ANF2CreateAxisArg0 = {"Port name", iocshArgString}; -static const iocshArg ANF2CreateAxisArg1 = {"Axis number", iocshArgInt}; -static const iocshArg ANF2CreateAxisArg2 = {"Hex config", iocshArgString}; +static const iocshArg ANF2CreateAxisArg1 = {"Config port name", iocshArgString}; +static const iocshArg ANF2CreateAxisArg2 = {"Axis number", iocshArgInt}; +static const iocshArg ANF2CreateAxisArg3 = {"Hex config", iocshArgString}; static const iocshArg * const ANF2CreateAxisArgs[] = {&ANF2CreateAxisArg0, &ANF2CreateAxisArg1, - &ANF2CreateAxisArg2}; -static const iocshFuncDef ANF2CreateAxisDef = {"ANF2CreateAxis", 3, ANF2CreateAxisArgs}; + &ANF2CreateAxisArg2, + &ANF2CreateAxisArg3}; +static const iocshFuncDef ANF2CreateAxisDef = {"ANF2CreateAxis", 4, ANF2CreateAxisArgs}; static void ANF2CreateAxisCallFunc(const iocshArgBuf *args) { - ANF2CreateAxis(args[0].sval, args[1].ival, args[2].sval); + ANF2CreateAxis(args[0].sval, args[1].sval, args[2].ival, args[3].sval); } diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 44a75fea..fa2c6d27 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -62,7 +62,7 @@ class ANF2Axis : public asynMotorAxis { public: /* These are the methods we override from the base class */ - ANF2Axis(class ANF2Controller *pC, int axisNo, epicsInt32 config); + ANF2Axis(class ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epicsInt32 config); void report(FILE *fp, int level); asynStatus move(double position, int relative, double min_velocity, double max_velocity, double acceleration); asynStatus moveVelocity(double min_velocity, double max_velocity, double acceleration); @@ -78,6 +78,7 @@ private: asynStatus sendAccelAndVelocity(double accel, double velocity); void getInfo(); asynUser *pasynUserForceRead_; + asynUser *pasynUserConfWrite_; int axisNo_; epicsInt32 config_; From faba02a442f9a6c6913dd3d19ac1b22bc47412ee Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 14 Mar 2018 10:28:05 -0500 Subject: [PATCH 05/65] Set the configuration bits with array writes --- motorApp/AMCISrc/ANF2Driver.cpp | 52 ++++++++++++++++++++++++++++----- motorApp/AMCISrc/ANF2Driver.h | 6 ++-- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index c4c3630f..eb67b6ad 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -39,8 +39,8 @@ static const char *driverName = "ANF2MotorDriver"; ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, double movingPollPeriod, double idlePollPeriod) : asynMotorController(portName, numAxes, NUM_ANF2_PARAMS, - 0, // No additional interfaces beyond those in base class - 0, // No additional callback interfaces beyond those in base class + asynInt32ArrayMask, // One additional interface beyond those in base class + asynInt32ArrayMask, // One additional callback interface beyond those in base class ASYN_CANBLOCK | ASYN_MULTIDEVICE, 1, // autoconnect 0, 0) // Default priority and stack size @@ -68,6 +68,7 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, } for (i=0; iconnect(ANF2OutPortName, i, &pasynUserOutReg_[j][i], NULL); + //status = pasynInt32ArraySyncIO->connect(ANF2OutPortName, i, &pasynUserOutArrayReg_[j][i], NULL); } } if (status) { @@ -197,11 +198,22 @@ asynStatus ANF2Controller::writeReg16(int axisNo, int axisReg, int output, doubl //printf("writeReg16: writing %d to register %d\n", output, axisReg); asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"writeReg16: writing %d to register %d\n", output, axisReg); status = pasynInt32SyncIO->write(pasynUserOutReg_[axisNo][axisReg], output, timeout); + //status = pasynInt32ArraySyncIO->write(pasynUserOutArrayReg_[axisNo][axisReg], &output, 1, timeout); epicsThreadSleep(0.01); return status ; } +/*asynStatus ANF2Controller::writeReg32Array(int axisNo, int axisReg, epicsInt32* output, int nElements, double timeout) +{ + asynStatus status; + + asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"writeReg32Array: writing %d elements starting at register %d\n", nElements, axisReg); + status = pasynInt32ArraySyncIO->write(pasynUserOutArrayReg_[axisNo][axisReg], output, nElements, timeout); + + return status ; +}*/ + asynStatus ANF2Controller::writeReg32(int axisNo, int axisReg, int output, double timeout) { //.. break 32-bit integer into 2 pieces @@ -231,6 +243,9 @@ asynStatus ANF2Controller::writeReg32(int axisNo, int axisReg, int output, doubl axisReg++; status = writeReg16(axisNo, axisReg, lower, DEFAULT_CONTROLLER_TIMEOUT); + // No breaking up the output value required when writing an array + //status = pasynInt32ArraySyncIO->write(pasynUserOutArrayReg_[axisNo][axisReg], &output, 2, timeout); + return status ; } @@ -288,6 +303,9 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi pC_(pC) { int status; + long long bigConfig; + long long configAndSpeed; + epicsInt32 configBits[2]; axisNo_ = axisNo; //this->axisNo_ = axisNo; @@ -300,7 +318,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi } printf("ANF2Axis::ANF2Axis : pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); - status = pasynInt32SyncIO->connect(ANF2ConfName, 0, &pasynUserConfWrite_, NULL); + status = pasynInt32ArraySyncIO->connect(ANF2ConfName, 0, &pasynUserConfWrite_, NULL); if (status) { printf("%s: Error, unable to connect pasynUserConfWrite_ to Modbus input driver\n", ANF2ConfName); } @@ -314,11 +332,29 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // Send the configuration //status = pC_->writeReg32(axisNo_, CONFIG_MSW, config, DEFAULT_CONTROLLER_TIMEOUT); //status = pC_->writeReg16(axisNo_, CONFIG_MSW, 0x8600, DEFAULT_CONTROLLER_TIMEOUT); - status = pasynInt32SyncIO->write(pasynUserConfWrite_, config, DEFAULT_CONTROLLER_TIMEOUT); - epicsThreadSleep(0.01); + // Send the configuration bits + //status = pasynInt32SyncIO->write(pasynUserConfWrite_, config, DEFAULT_CONTROLLER_TIMEOUT); + // Set the start speed to a non-zero value (100) + //status = pC_->writeReg16(axisNo_, POS_WR_LWR, 0x0064, DEFAULT_CONTROLLER_TIMEOUT); + //epicsThreadSleep(0.01); + + /*bigConfig = (long long) config & 0xFFFFFFFF; + configAndSpeed = (bigConfig << 32) | 0x00000064; + printf("bigConfig = %lx, configAndSpeed = %lx\n", bigConfig, configAndSpeed); + status = pasynInt32SyncIO->write(pasynUserConfWrite_, configAndSpeed, DEFAULT_CONTROLLER_TIMEOUT);*/ + + configBits[0] = config; + configBits[1] = 0x00000064; + /*status = pasynInt32SyncIO->write(pasynUserConfWrite_, *configBits, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32SyncIO->write(pasynUserConfWrite_, *(configBits+1), DEFAULT_CONTROLLER_TIMEOUT);*/ + + // Does the number of elements refer to the number of 16-bit elements? + //status = this->pC_->writeReg32Array(axisNo, CONFIG_MSW, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); + // + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); // Delay - epicsThreadSleep(1.0); + epicsThreadSleep(10.0); // Read the configuration? Or maybe the command registers? getInfo(); @@ -326,8 +362,8 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi //IAMHERE // set position to 0 - setPosition(0); - //setPosition(1337); + //setPosition(0); + setPosition(1337); // Delay epicsThreadSleep(1.0); diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index fa2c6d27..c1d604a0 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -12,6 +12,8 @@ K. Goetze 2014-03-24 #include "asynMotorController.h" #include "asynMotorAxis.h" +//#include +#include #define MAX_AXES 2 @@ -94,8 +96,7 @@ public: ANF2Axis* getAxis(int axisNo); asynUser *pasynUserInReg_[MAX_AXES][MAX_INPUT_REGS]; asynUser *pasynUserOutReg_[MAX_AXES][MAX_OUTPUT_REGS]; -// asynUser *pasynUserForceRead_; - + //asynUser *pasynUserOutArrayReg_[MAX_AXES][MAX_OUTPUT_REGS]; /* These are the methods that we override from asynMotorDriver */ asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); @@ -111,6 +112,7 @@ protected: private: asynStatus writeReg16(int, int, int, double); asynStatus writeReg32(int, int, int, double); + //asynStatus writeReg32Array(int, int, epicsInt32*, int, double); asynStatus readReg16(int, int, epicsInt32*, double); asynStatus readReg32(int, int, epicsInt32*, double); char *inputDriver_; From a05f47f96cf39bf2286157e9ed65c8bc0ec372e0 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 14 Mar 2018 11:18:25 -0500 Subject: [PATCH 06/65] Cleaned up code. Reduced delays added for testing. --- motorApp/AMCISrc/ANF2Driver.cpp | 43 ++++++++++----------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index eb67b6ad..6552cea5 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -68,6 +68,7 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, } for (i=0; iconnect(ANF2OutPortName, i, &pasynUserOutReg_[j][i], NULL); + // Maybe send the outputs with Array calls in the future //status = pasynInt32ArraySyncIO->connect(ANF2OutPortName, i, &pasynUserOutArrayReg_[j][i], NULL); } } @@ -204,6 +205,7 @@ asynStatus ANF2Controller::writeReg16(int axisNo, int axisReg, int output, doubl return status ; } +// This could be useful in the future, but it isn't needed yet /*asynStatus ANF2Controller::writeReg32Array(int axisNo, int axisReg, epicsInt32* output, int nElements, double timeout) { asynStatus status; @@ -222,6 +224,8 @@ asynStatus ANF2Controller::writeReg32(int axisNo, int axisReg, int output, doubl asynStatus status; int lower,upper; + + // This is the way the ANG1 driver does it, and the code doesn't appear to work /*float fnum; fnum = (output / 1000.0); @@ -243,7 +247,7 @@ asynStatus ANF2Controller::writeReg32(int axisNo, int axisReg, int output, doubl axisReg++; status = writeReg16(axisNo, axisReg, lower, DEFAULT_CONTROLLER_TIMEOUT); - // No breaking up the output value required when writing an array + // No breaking up the output value required when writing an array - maybe do this in the future //status = pasynInt32ArraySyncIO->write(pasynUserOutArrayReg_[axisNo][axisReg], &output, 2, timeout); return status ; @@ -303,14 +307,11 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi pC_(pC) { int status; - long long bigConfig; - long long configAndSpeed; epicsInt32 configBits[2]; axisNo_ = axisNo; //this->axisNo_ = axisNo; - //status = pasynInt32SyncIO->connect(myModbusInputDriver, 0, &pasynUserForceRead_, "MODBUS_READ"); status = pasynInt32SyncIO->connect(pC_->inputDriver_, 0, &pasynUserForceRead_, "MODBUS_READ"); if (status) { //printf("%s:%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver %s\n", pC_->inputDriver_, pC_->functionName, myModbusInputDriver); @@ -324,46 +325,34 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi } printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_->reason=%d\n", pasynUserConfWrite_->reason); - epicsThreadSleep(3.0); + epicsThreadSleep(1.0); // Read data that is likely to be stale getInfo(); // Send the configuration //status = pC_->writeReg32(axisNo_, CONFIG_MSW, config, DEFAULT_CONTROLLER_TIMEOUT); - //status = pC_->writeReg16(axisNo_, CONFIG_MSW, 0x8600, DEFAULT_CONTROLLER_TIMEOUT); - // Send the configuration bits - //status = pasynInt32SyncIO->write(pasynUserConfWrite_, config, DEFAULT_CONTROLLER_TIMEOUT); - // Set the start speed to a non-zero value (100) - //status = pC_->writeReg16(axisNo_, POS_WR_LWR, 0x0064, DEFAULT_CONTROLLER_TIMEOUT); - //epicsThreadSleep(0.01); - - /*bigConfig = (long long) config & 0xFFFFFFFF; - configAndSpeed = (bigConfig << 32) | 0x00000064; - printf("bigConfig = %lx, configAndSpeed = %lx\n", bigConfig, configAndSpeed); - status = pasynInt32SyncIO->write(pasynUserConfWrite_, configAndSpeed, DEFAULT_CONTROLLER_TIMEOUT);*/ - + + // Send the configuration (array) + // assemble the configuration bits; set the start speed to a non-zero value (100), which is required for the configuration to be accepted configBits[0] = config; configBits[1] = 0x00000064; - /*status = pasynInt32SyncIO->write(pasynUserConfWrite_, *configBits, DEFAULT_CONTROLLER_TIMEOUT); - status = pasynInt32SyncIO->write(pasynUserConfWrite_, *(configBits+1), DEFAULT_CONTROLLER_TIMEOUT);*/ // Does the number of elements refer to the number of 16-bit elements? - //status = this->pC_->writeReg32Array(axisNo, CONFIG_MSW, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); - // status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); + // Mabye do it this way in the future + //status = this->pC_->writeReg32Array(axisNo, CONFIG_MSW, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); // Delay - epicsThreadSleep(10.0); + epicsThreadSleep(1.0); // Read the configuration? Or maybe the command registers? getInfo(); - //IAMHERE - // set position to 0 //setPosition(0); setPosition(1337); + //setPosition(3141); // Delay epicsThreadSleep(1.0); @@ -382,12 +371,6 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi 0x4 - Home Input (0 = Disabled, 1 = Enabled) 0x8 - - - - - - - */ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which controller by port name */ From 65dea5b7d2849f388026a260d9ca7b6e3b3dcc1a Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 16 Mar 2018 13:02:41 -0500 Subject: [PATCH 07/65] Added a GetInfo that results in the getInfo() axis method being called. --- motorApp/AMCISrc/ANF2Driver.cpp | 54 ++++++++++++++++++--------------- motorApp/AMCISrc/ANF2Driver.h | 4 +-- motorApp/Db/ANF2Aux.template | 9 ++++++ 3 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 motorApp/Db/ANF2Aux.template diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 6552cea5..74566314 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -55,7 +55,7 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, inputDriver_ = epicsStrDup(ANF2InPortName); // Set this before calls to create Axis objects // Create controller-specific parameters - createParam(ANF2JerkString, asynParamInt32, &ANF2Jerk_); + createParam(ANF2GetInfoString, asynParamInt32, &ANF2GetInfo_); if (numAxes > MAX_AXES) { numAxes = MAX_AXES; @@ -159,23 +159,19 @@ asynStatus ANF2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) /* Set the parameter and readback in the parameter library. */ status = setIntegerParam(pAxis->axisNo_, function, value); - // The ANF controller doesn't have a jerk variable - // Could probably just not overload writeInt32 at all - /* - if (function == ANF2Jerk_) + if (function == ANF2GetInfo_) { - // Jerk in units steps/sec/sec/sec (0 - 5000) - printf("Jerk = %d\n", value); - status = writeReg16(JERK, value, DEFAULT_CONTROLLER_TIMEOUT); + // Only get info when value is 1 + if (value == 1) { + printf("ANF2Controller:writeInt32: Getting info for axis = %d\n", pAxis->axisNo_); + pAxis->getInfo(); -// sprintf(outString_, "%s JOG JRK %f", pAxis->axisName_, value); -// status = writeController(); - + } } else { // Call base class method status = asynMotorController::writeInt32(pasynUser, value); } - */ + // Call base class method status = asynMotorController::writeInt32(pasynUser, value); @@ -483,24 +479,28 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou if (relative) { printf(" ** relative move called\n"); //status = pC_->writeReg32(axisNo_, SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); - //distance = position * SOM_OTHER_SCALE_FACTOR; - distance = NINT(position); + //distance = position * SOM_OTHER_SCALE_FACTOR; + distance = NINT(position); status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x2; + + //move_bit = 0x0; + //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + + move_bit = 0x2; status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); } else { // absolute printf(" ** absolute move called\n"); //status = pC_->writeReg32(axisNo_, SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); - //distance = position * SOM_OTHER_SCALE_FACTOR; - distance = NINT(position); - printf(" ** distance = %d\n", distance); + //distance = position * SOM_OTHER_SCALE_FACTOR; + distance = NINT(position); + printf(" ** distance = %d\n", distance); status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x1; + + //move_bit = 0x0; + //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + + move_bit = 0x1; status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); } // Delay the first status read, give the controller some time to return moving status @@ -665,6 +665,8 @@ asynStatus ANF2Axis::poll(bool *moving) return asynSuccess; } + //getInfo(); + // Force a read operation //printf(" . . . . . Calling pasynInt32SyncIO->write\n"); //printf("Calling pasynInt32SyncIO->write(pasynUserForceRead_, 1, TIMEOUT), pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); @@ -672,6 +674,8 @@ asynStatus ANF2Axis::poll(bool *moving) //printf(" . . . . . status = %d\n", status); // if status goto end + //getInfo(); + // Read the current motor position // //readReg32(int reg, epicsInt32 *combo, double timeout) @@ -697,7 +701,7 @@ asynStatus ANF2Axis::poll(bool *moving) status = pC_->readReg16(axisNo_, STATUS_2, &read_val, DEFAULT_CONTROLLER_TIMEOUT); //printf("status 2 is 0x%X\n", read_val); - limit = (read_val & 0x1); // a cw limit has been reached + limit = (read_val & 0x8); // a cw limit has been reached setIntegerParam(pC_->motorStatusHighLimit_, limit); //printf("+limit %d\n", limit); if (limit) { // reset error and set position so we can move off of the limit @@ -708,7 +712,7 @@ asynStatus ANF2Axis::poll(bool *moving) setPosition(position); } - limit = (read_val & 0x2); // a ccw limit has been reached + limit = (read_val & 0x10); // a ccw limit has been reached setIntegerParam(pC_->motorStatusLowLimit_, limit); //printf("-limit %d\n", limit); if (limit) { // reset error and set position so we can move off of the limit diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index c1d604a0..9062f5a6 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -58,7 +58,7 @@ K. Goetze 2014-03-24 #define NUM_ANF2_PARAMS 1 /** drvInfo strings for extra parameters that the ACR controller supports */ -#define ANF2JerkString "ANF2_JERK" +#define ANF2GetInfoString "ANF2_GET_INFO" class ANF2Axis : public asynMotorAxis { @@ -106,7 +106,7 @@ public: /* These are the methods that are new to this class */ protected: - int ANF2Jerk_; /**< Jerk time parameter index */ + int ANF2GetInfo_; /**< Jerk time parameter index */ private: diff --git a/motorApp/Db/ANF2Aux.template b/motorApp/Db/ANF2Aux.template new file mode 100644 index 00000000..0cf8bb4f --- /dev/null +++ b/motorApp/Db/ANF2Aux.template @@ -0,0 +1,9 @@ +# Database for extra PVs for AMCI ANG1 controllers + +record(bo,"$(P)$(R)GetInfo") { + field(DESC,"Get Info") + field(PINI, "0") + field(VAL,"0") + field(DTYP, "asynInt32") + field(OUT,"@asyn($(PORT),$(ADDR))ANF2_GET_INFO") +} From aaae2e642a08c2dfcadd0051a749fd50601bd379 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 16 Mar 2018 13:50:41 -0500 Subject: [PATCH 08/65] Zeroing the CMD_MSW doesn't fix the unable-to-move problem --- motorApp/AMCISrc/ANF2Driver.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 74566314..009bf48f 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -454,10 +454,12 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) // Therefore need to limit range received by motor record from 1000 to 5e6 steps/sec/sec if (acceleration < 1000) { // print message noting that accel has been capped low + //printf("Acceleration is < 1000: %lf\n", acceleration); acceleration = 1000; } if (acceleration > 5000000) { // print message noting that accel has been capped high + //printf("Acceleration is > 5000: %lf\n", acceleration); acceleration = 5000000; } // ANF2 acceleration units are steps/millisecond/second, so we divide by 1000 here @@ -483,8 +485,8 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou distance = NINT(position); status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - //move_bit = 0x0; - //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x2; status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); @@ -497,8 +499,8 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou printf(" ** distance = %d\n", distance); status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - //move_bit = 0x0; - //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + move_bit = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x1; status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); From d792f9afe715c76173e9ba28ffb1705bdbbbb08a Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 16 Mar 2018 15:16:03 -0500 Subject: [PATCH 09/65] Send all the registers when setting the configuration (fixes failure-to-configure problem after an error occurs). Also try to send move data with all 10 registers (fails in the same way as setting the registers independently) --- motorApp/AMCISrc/ANF2Driver.cpp | 56 ++++++++++++++++++++++++++------- motorApp/AMCISrc/ANF2Driver.h | 1 + 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 009bf48f..3ac7cd12 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -308,6 +308,12 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi axisNo_ = axisNo; //this->axisNo_ = axisNo; + registers_[0] = 0x0; + registers_[1] = 0x0; + registers_[2] = 0x0; + registers_[3] = 0x0; + registers_[4] = 0x0; + status = pasynInt32SyncIO->connect(pC_->inputDriver_, 0, &pasynUserForceRead_, "MODBUS_READ"); if (status) { //printf("%s:%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver %s\n", pC_->inputDriver_, pC_->functionName, myModbusInputDriver); @@ -334,10 +340,15 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi configBits[0] = config; configBits[1] = 0x00000064; + registers_[0] = config; + registers_[1] = 0x00000064; + // Does the number of elements refer to the number of 16-bit elements? status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); // Mabye do it this way in the future //status = this->pC_->writeReg32Array(axisNo, CONFIG_MSW, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); + // Write all the registers + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 10, DEFAULT_CONTROLLER_TIMEOUT); // Delay epicsThreadSleep(1.0); @@ -447,7 +458,10 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) // static const char *functionName = "ANF2::sendAccelAndVelocity"; // Send the velocity - status = pC_->writeReg32(axisNo_, SPD_UPR, NINT(velocity), DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg32(axisNo_, SPD_UPR, NINT(velocity), DEFAULT_CONTROLLER_TIMEOUT); + + // Set the velocity register + registers_[2] = NINT(velocity); // Send the acceleration // ANF2 acceleration range 1 to 5000 steps/ms/sec @@ -463,8 +477,12 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) acceleration = 5000000; } // ANF2 acceleration units are steps/millisecond/second, so we divide by 1000 here - status = pC_->writeReg16(axisNo_, ACCEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); - status = pC_->writeReg16(axisNo_, DECEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg16(axisNo_, ACCEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg16(axisNo_, DECEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); + + // Set the accel/decel register + registers_[3] = (NINT(acceleration/1000.0) << 16) | (NINT(acceleration/1000.0)); + return status; } @@ -481,30 +499,46 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou if (relative) { printf(" ** relative move called\n"); //status = pC_->writeReg32(axisNo_, SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); - //distance = position * SOM_OTHER_SCALE_FACTOR; distance = NINT(position); - status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x2; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + + // Set position and cmd registers + registers_[1] = NINT(position); + registers_[0] = 0x2 << 16; + } else { // absolute printf(" ** absolute move called\n"); //status = pC_->writeReg32(axisNo_, SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); - //distance = position * SOM_OTHER_SCALE_FACTOR; distance = NINT(position); printf(" ** distance = %d\n", distance); - status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x1; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + + // Set position and cmd registers + registers_[1] = NINT(position); + registers_[0] = 0x1 << 16; + } + + // The final registers are zero for absolute and relative moves + registers_[4] = 0x0; + + // Write all the registers atomically IAMHERE + // Does the number of elements refer to the number of 16-bit elements? + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 10, DEFAULT_CONTROLLER_TIMEOUT); + // Delay the first status read, give the controller some time to return moving status epicsThreadSleep(0.05); return status; diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 9062f5a6..1e504e3e 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -83,6 +83,7 @@ private: asynUser *pasynUserConfWrite_; int axisNo_; epicsInt32 config_; + epicsInt32 registers_[5]; friend class ANF2Controller; }; From 13ee3d23e4e2fd4198b868cb323f4a2833e888c3 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 16 Mar 2018 15:37:30 -0500 Subject: [PATCH 10/65] Only configure the axis once --- motorApp/AMCISrc/ANF2Driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 3ac7cd12..04064919 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -344,7 +344,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi registers_[1] = 0x00000064; // Does the number of elements refer to the number of 16-bit elements? - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); + //status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); // Mabye do it this way in the future //status = this->pC_->writeReg32Array(axisNo, CONFIG_MSW, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); // Write all the registers From 2c269bb69fd8ce41c47997b315b8cff028176f30 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 16 Mar 2018 16:30:06 -0500 Subject: [PATCH 11/65] Also set all the registers when setting the position. Allows a single move to succeed after each setPosition call. --- motorApp/AMCISrc/ANF2Driver.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 04064919..70fc1bfd 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -628,20 +628,29 @@ asynStatus ANF2Axis::stop(double acceleration) asynStatus ANF2Axis::setPosition(double position) { asynStatus status; - int set_position, set_bit; + int set_bit; + epicsInt32 set_position; //static const char *functionName = "ANF2Axis::setPosition"; //status = writeReg32(SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); - //distance = position * SOM_OTHER_SCALE_FACTOR; set_position = NINT(position); - status = pC_->writeReg32(axisNo_, POS_WR_UPR, set_position, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg32(axisNo_, POS_WR_UPR, set_position, DEFAULT_CONTROLLER_TIMEOUT); set_bit = 0x200; - status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); set_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); + + registers_[0] = 0x200 << 16; + registers_[1] = set_position; + registers_[2] = 0x0; + registers_[3] = 0x0; + registers_[4] = 0x0; + + // Write all the registers atomically + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 10, DEFAULT_CONTROLLER_TIMEOUT); return status; } From fae911bc3576310283300e861b7585d4fd34d46c Mon Sep 17 00:00:00 2001 From: kpetersn Date: Mon, 19 Mar 2018 15:33:32 -0500 Subject: [PATCH 12/65] Uncommented lines that zeroed the command register before a move (required for every move after the first after power-on to succeed) --- motorApp/AMCISrc/ANF2Driver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 70fc1bfd..44c1bff1 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -503,7 +503,7 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou //status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x0; - //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x2; //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); @@ -521,7 +521,7 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou //status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x0; - //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x1; //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); From 758f6fcc8bed29d07a03bf828d407b35324d13ca Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 20 Mar 2018 13:47:56 -0500 Subject: [PATCH 13/65] Print more info. Try to write/read registers for axis 2 (currently doesn't work properly). --- motorApp/AMCISrc/ANF2Driver.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 44c1bff1..6bc7558a 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -64,10 +64,10 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, for (j=0; jconnect(ANF2InPortName, i, &pasynUserInReg_[j][i], NULL); + status = pasynInt32SyncIO->connect(ANF2InPortName, i+j*AXIS_REG_OFFSET, &pasynUserInReg_[j][i], NULL); } for (i=0; iconnect(ANF2OutPortName, i, &pasynUserOutReg_[j][i], NULL); + status = pasynInt32SyncIO->connect(ANF2OutPortName, i+j*AXIS_REG_OFFSET, &pasynUserOutReg_[j][i], NULL); // Maybe send the outputs with Array calls in the future //status = pasynInt32ArraySyncIO->connect(ANF2OutPortName, i, &pasynUserOutArrayReg_[j][i], NULL); } @@ -114,10 +114,18 @@ extern "C" int ANF2CreateController(const char *portName, const char *ANF2InPort */ void ANF2Controller::report(FILE *fp, int level) { + int i, j; + fprintf(fp, "ANF2 motor driver %s, numAxes=%d, moving poll period=%f, idle poll period=%f\n", this->portName, numAxes_, movingPollPeriod_, idlePollPeriod_); fprintf(fp, " axesCreated=%i\n", axesCreated_); - + + for (j=0; jreason=%d\n", pasynUserForceRead_->reason); - status = pasynInt32ArraySyncIO->connect(ANF2ConfName, 0, &pasynUserConfWrite_, NULL); + status = pasynInt32ArraySyncIO->connect(ANF2ConfName, axisNo_*AXIS_REG_OFFSET, &pasynUserConfWrite_, NULL); if (status) { printf("%s: Error, unable to connect pasynUserConfWrite_ to Modbus input driver\n", ANF2ConfName); } printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_->reason=%d\n", pasynUserConfWrite_->reason); + printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_ offset=%d\n", axisNo_*AXIS_REG_OFFSET); epicsThreadSleep(1.0); @@ -632,6 +641,9 @@ asynStatus ANF2Axis::setPosition(double position) epicsInt32 set_position; //static const char *functionName = "ANF2Axis::setPosition"; + set_bit = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); + //status = writeReg32(SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); set_position = NINT(position); @@ -728,7 +740,7 @@ asynStatus ANF2Axis::poll(bool *moving) //printf("ANF2Axis::poll: Motor position raw: %d\n", read_val); position = (double) read_val; setDoubleParam(pC_->motorPosition_, position); - //printf("ANF2Axis::poll: Motor position: %f\n", position); + //printf("ANF2Axis::poll: Motor #%i position: %f\n", axisNo_, position); // Read the moving status of this motor // From 5eef01248cb8c1baee3b651d17847e7c28e74955 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 20 Mar 2018 14:57:17 -0500 Subject: [PATCH 14/65] Removed configBits --- motorApp/AMCISrc/ANF2Driver.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 6bc7558a..b8e21f5e 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -311,8 +311,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi pC_(pC) { int status; - epicsInt32 configBits[2]; - + axisNo_ = axisNo; //this->axisNo_ = axisNo; @@ -346,16 +345,10 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // Send the configuration (array) // assemble the configuration bits; set the start speed to a non-zero value (100), which is required for the configuration to be accepted - configBits[0] = config; - configBits[1] = 0x00000064; - registers_[0] = config; registers_[1] = 0x00000064; // Does the number of elements refer to the number of 16-bit elements? - //status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); - // Mabye do it this way in the future - //status = this->pC_->writeReg32Array(axisNo, CONFIG_MSW, configBits, 4, DEFAULT_CONTROLLER_TIMEOUT); // Write all the registers status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 10, DEFAULT_CONTROLLER_TIMEOUT); From 1f8e9d8a23474c45003f67f687443cd7e96b5e69 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 21 Mar 2018 14:58:37 -0500 Subject: [PATCH 15/65] Added a reconfig routine. Corrected nElements after switching to modbus master branch on github. --- motorApp/AMCISrc/ANF2Driver.cpp | 52 ++++++++++++++++++++++++++++----- motorApp/AMCISrc/ANF2Driver.h | 5 +++- motorApp/Db/ANF2Aux.template | 8 +++++ 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index b8e21f5e..da546309 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -56,7 +56,8 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, // Create controller-specific parameters createParam(ANF2GetInfoString, asynParamInt32, &ANF2GetInfo_); - + createParam(ANF2ReconfigString, asynParamInt32, &ANF2Reconfig_); + if (numAxes > MAX_AXES) { numAxes = MAX_AXES; } @@ -175,6 +176,10 @@ asynStatus ANF2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) pAxis->getInfo(); } + } else if (function == ANF2Reconfig_) + { + // reconfig regardless of the value + pAxis->reconfig(); } else { // Call base class method status = asynMotorController::writeInt32(pasynUser, value); @@ -321,7 +326,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi registers_[3] = 0x0; registers_[4] = 0x0; - status = pasynInt32SyncIO->connect(pC_->inputDriver_, 0, &pasynUserForceRead_, "MODBUS_READ"); + status = pasynInt32SyncIO->connect(pC_->inputDriver_, axisNo_*AXIS_REG_OFFSET, &pasynUserForceRead_, "MODBUS_READ"); if (status) { //printf("%s:%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver %s\n", pC_->inputDriver_, pC_->functionName, myModbusInputDriver); printf("%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver\n", pC_->inputDriver_); @@ -348,9 +353,8 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi registers_[0] = config; registers_[1] = 0x00000064; - // Does the number of elements refer to the number of 16-bit elements? // Write all the registers - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 10, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Delay epicsThreadSleep(1.0); @@ -433,6 +437,38 @@ void ANF2Axis::getInfo() } } +void ANF2Axis::reconfig() +{ + asynStatus status; + int reg; + + printf("Reconfiguring axis %i\n", axisNo_); + + // The command/cfg register must first be zeroed + reg = 0x0; + status = pC_->writeReg16(axisNo_, CMD_MSW, reg, DEFAULT_CONTROLLER_TIMEOUT); + + // Construct the new config + registers_[0] = 0x86000000; + registers_[1] = 0x00000064; + registers_[2] = 0x0; + registers_[3] = 0x0; + registers_[4] = 0x0; + + epicsThreadSleep(2.0); + getInfo(); + + // Send the new config + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 5, DEFAULT_CONTROLLER_TIMEOUT); + + epicsThreadSleep(2.0); + getInfo(); + + // Set the position to clear the invalid position error + setPosition(2048); + getInfo(); +} + /** Reports on status of the axis * \param[in] fp The file pointer on which report information will be written @@ -537,9 +573,9 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou // The final registers are zero for absolute and relative moves registers_[4] = 0x0; - // Write all the registers atomically IAMHERE - // Does the number of elements refer to the number of 16-bit elements? - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 10, DEFAULT_CONTROLLER_TIMEOUT); + // Write all the registers atomically + // The number of elements refers to the number of epicsInt32s registers_ + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Delay the first status read, give the controller some time to return moving status epicsThreadSleep(0.05); @@ -655,7 +691,7 @@ asynStatus ANF2Axis::setPosition(double position) registers_[4] = 0x0; // Write all the registers atomically - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 10, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 5, DEFAULT_CONTROLLER_TIMEOUT); return status; } diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 1e504e3e..3637b7a1 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -55,10 +55,11 @@ K. Goetze 2014-03-24 // No. of controller-specific parameters -#define NUM_ANF2_PARAMS 1 +#define NUM_ANF2_PARAMS 2 /** drvInfo strings for extra parameters that the ACR controller supports */ #define ANF2GetInfoString "ANF2_GET_INFO" +#define ANF2ReconfigString "ANF2_RECONFIG" class ANF2Axis : public asynMotorAxis { @@ -79,6 +80,7 @@ private: * Abbreviated because it is used very frequently */ asynStatus sendAccelAndVelocity(double accel, double velocity); void getInfo(); + void reconfig(); asynUser *pasynUserForceRead_; asynUser *pasynUserConfWrite_; int axisNo_; @@ -108,6 +110,7 @@ public: protected: int ANF2GetInfo_; /**< Jerk time parameter index */ + int ANF2Reconfig_; /**< Jerk time parameter index */ private: diff --git a/motorApp/Db/ANF2Aux.template b/motorApp/Db/ANF2Aux.template index 0cf8bb4f..93a7b6c8 100644 --- a/motorApp/Db/ANF2Aux.template +++ b/motorApp/Db/ANF2Aux.template @@ -7,3 +7,11 @@ record(bo,"$(P)$(R)GetInfo") { field(DTYP, "asynInt32") field(OUT,"@asyn($(PORT),$(ADDR))ANF2_GET_INFO") } + +record(bo,"$(P)$(R)Reconfig") { + field(DESC,"Reconfig") + field(PINI, "0") + field(VAL,"0") + field(DTYP, "asynInt32") + field(OUT,"@asyn($(PORT),$(ADDR))ANF2_RECONFIG") +} From 1a4d1756b9f07e97e71c5fd8d687044acd082271 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 21 Mar 2018 15:07:55 -0500 Subject: [PATCH 16/65] Corrected the max acceleration/deceleration --- motorApp/AMCISrc/ANF2Driver.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index da546309..3176bb3c 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -502,17 +502,17 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) registers_[2] = NINT(velocity); // Send the acceleration - // ANF2 acceleration range 1 to 5000 steps/ms/sec + // ANF2 acceleration range 1 to 2000 steps/ms/sec // Therefore need to limit range received by motor record from 1000 to 5e6 steps/sec/sec if (acceleration < 1000) { // print message noting that accel has been capped low //printf("Acceleration is < 1000: %lf\n", acceleration); acceleration = 1000; } - if (acceleration > 5000000) { + if (acceleration > 2000000) { // print message noting that accel has been capped high - //printf("Acceleration is > 5000: %lf\n", acceleration); - acceleration = 5000000; + //printf("Acceleration is > 2000: %lf\n", acceleration); + acceleration = 2000000; } // ANF2 acceleration units are steps/millisecond/second, so we divide by 1000 here //status = pC_->writeReg16(axisNo_, ACCEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); From 1fc33f95f951161026bc8c284e3d9a93a468239a Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 22 Mar 2018 11:33:05 -0500 Subject: [PATCH 17/65] Fixed the readReg32 calculation. Don't use registers_ for everything. Added zeroRegisters method. --- motorApp/AMCISrc/ANF2Driver.cpp | 117 ++++++++++++++++++-------------- motorApp/AMCISrc/ANF2Driver.h | 4 +- 2 files changed, 68 insertions(+), 53 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 3176bb3c..0a0ce133 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -275,28 +275,16 @@ asynStatus ANF2Controller::readReg16(int axisNo, int axisReg, epicsInt32 *input, asynStatus ANF2Controller::readReg32(int axisNo, int axisReg, epicsInt32 *combo, double timeout) { -//.. read 2 16-bit words from ANF2 registers -//.. assemble 2 16-bit pieces into 1 32-bit integer - asynStatus status; -// float fnum; epicsInt32 lowerWord32, upperWord32; // only have pasynInt32SyncIO, not pasynInt16SyncIO , - epicsInt16 lowerWord16, upperWord16; // so we need to get 32-bits and cast to 16-bit integer //printf("calling readReg16\n"); status = readReg16(axisNo, axisReg, &upperWord32, timeout); //get Upper Word - upperWord16 = (epicsInt16)upperWord32; - //printf("upperWord16: %d\n", upperWord16); - asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"readReg32 upperWord16: %d\n", upperWord16); - // if status != 1 : axisReg++; status = readReg16(axisNo, axisReg, &lowerWord32, timeout); //get Lower Word - lowerWord16 = (epicsInt16)lowerWord32; - //printf("lowerWord16: %d\n", lowerWord16); - asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"readReg32 lowerWord16: %d\n", lowerWord16); - - *combo = NINT((upperWord16 * 1000) + lowerWord16); + + *combo = NINT((upperWord32 << 16) | lowerWord32); return status ; } @@ -320,11 +308,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi axisNo_ = axisNo; //this->axisNo_ = axisNo; - registers_[0] = 0x0; - registers_[1] = 0x0; - registers_[2] = 0x0; - registers_[3] = 0x0; - registers_[4] = 0x0; + zeroRegisters(confReg_); status = pasynInt32SyncIO->connect(pC_->inputDriver_, axisNo_*AXIS_REG_OFFSET, &pasynUserForceRead_, "MODBUS_READ"); if (status) { @@ -350,11 +334,11 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // Send the configuration (array) // assemble the configuration bits; set the start speed to a non-zero value (100), which is required for the configuration to be accepted - registers_[0] = config; - registers_[1] = 0x00000064; + confReg_[0] = config; + confReg_[1] = 0x00000064; // Write all the registers - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Delay epicsThreadSleep(1.0); @@ -419,6 +403,16 @@ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which con return asynSuccess; } +void ANF2Axis::zeroRegisters(epicsInt32 *reg) +{ + int i; + + for(i=0; i<5; i++) + { + reg[i] = 0x0; + } +} + void ANF2Axis::getInfo() { asynStatus status; @@ -440,26 +434,30 @@ void ANF2Axis::getInfo() void ANF2Axis::reconfig() { asynStatus status; - int reg; + epicsInt32 confReg[5]; printf("Reconfiguring axis %i\n", axisNo_); // The command/cfg register must first be zeroed - reg = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, reg, DEFAULT_CONTROLLER_TIMEOUT); + //reg = 0x0; + //status = pC_->writeReg16(axisNo_, CMD_MSW, reg, DEFAULT_CONTROLLER_TIMEOUT); + + zeroRegisters(confReg); + // Clear the command/configuration register + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg, 5, DEFAULT_CONTROLLER_TIMEOUT); // Construct the new config - registers_[0] = 0x86000000; - registers_[1] = 0x00000064; - registers_[2] = 0x0; - registers_[3] = 0x0; - registers_[4] = 0x0; + confReg[0] = 0x86000000; + confReg[1] = 0x00000064; + //confReg[2] = 0x0; + //confReg[3] = 0x0; + //confReg[4] = 0x0; epicsThreadSleep(2.0); getInfo(); // Send the new config - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(2.0); getInfo(); @@ -499,7 +497,7 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) //status = pC_->writeReg32(axisNo_, SPD_UPR, NINT(velocity), DEFAULT_CONTROLLER_TIMEOUT); // Set the velocity register - registers_[2] = NINT(velocity); + motionReg_[2] = NINT(velocity); // Send the acceleration // ANF2 acceleration range 1 to 2000 steps/ms/sec @@ -519,7 +517,7 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) //status = pC_->writeReg16(axisNo_, DECEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); // Set the accel/decel register - registers_[3] = (NINT(acceleration/1000.0) << 16) | (NINT(acceleration/1000.0)); + motionReg_[3] = (NINT(acceleration/1000.0) << 16) | (NINT(acceleration/1000.0)); return status; } @@ -532,6 +530,13 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou printf(" ** ANF2Axis::move called, relative = %d, axisNo_ = %i\n", relative, this->axisNo_); + zeroRegisters(motionReg_); + // Clear the command/configuration register + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + + epicsThreadSleep(0.05); + + // This sets indices 2 & 3 of motionReg_ status = sendAccelAndVelocity(acceleration, maxVelocity); if (relative) { @@ -540,15 +545,15 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou distance = NINT(position); //status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + //move_bit = 0x0; + //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x2; //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); // Set position and cmd registers - registers_[1] = NINT(position); - registers_[0] = 0x2 << 16; + motionReg_[1] = NINT(position); + motionReg_[0] = 0x2 << 16; } else { // absolute @@ -558,24 +563,24 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou printf(" ** distance = %d\n", distance); //status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + //move_bit = 0x0; + //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); move_bit = 0x1; //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); // Set position and cmd registers - registers_[1] = NINT(position); - registers_[0] = 0x1 << 16; + motionReg_[1] = NINT(position); + motionReg_[0] = 0x1 << 16; } // The final registers are zero for absolute and relative moves - registers_[4] = 0x0; + motionReg_[4] = 0x0; // Write all the registers atomically // The number of elements refers to the number of epicsInt32s registers_ - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Delay the first status read, give the controller some time to return moving status epicsThreadSleep(0.05); @@ -652,6 +657,9 @@ asynStatus ANF2Axis::stop(double acceleration) printf("\n STOP \n\n"); + // do nothing (for testing) + //return asynSuccess; + stop_bit = 0x0; status = pC_->writeReg16(axisNo_, CMD_MSW, stop_bit, DEFAULT_CONTROLLER_TIMEOUT); @@ -668,10 +676,15 @@ asynStatus ANF2Axis::setPosition(double position) asynStatus status; int set_bit; epicsInt32 set_position; + epicsInt32 posReg[5]; //static const char *functionName = "ANF2Axis::setPosition"; + + //set_bit = 0x0; + //status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); - set_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); + zeroRegisters(posReg); + // Clear the command/configuration register + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); //status = writeReg32(SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); set_position = NINT(position); @@ -681,17 +694,17 @@ asynStatus ANF2Axis::setPosition(double position) set_bit = 0x200; //status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); - set_bit = 0x0; + //set_bit = 0x0; //status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); - registers_[0] = 0x200 << 16; - registers_[1] = set_position; - registers_[2] = 0x0; - registers_[3] = 0x0; - registers_[4] = 0x0; + posReg[0] = 0x200 << 16; + posReg[1] = set_position; + //posReg[2] = 0x0; + //posReg[3] = 0x0; + //posReg[4] = 0x0; // Write all the registers atomically - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, registers_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); return status; } diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 3637b7a1..d742533e 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -81,11 +81,13 @@ private: asynStatus sendAccelAndVelocity(double accel, double velocity); void getInfo(); void reconfig(); + void zeroRegisters(epicsInt32 *reg); asynUser *pasynUserForceRead_; asynUser *pasynUserConfWrite_; int axisNo_; epicsInt32 config_; - epicsInt32 registers_[5]; + epicsInt32 motionReg_[5]; + epicsInt32 confReg_[5]; friend class ANF2Controller; }; From 89cf615600326c8cc77fc1ef6bd65a2e8204567d Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 22 Mar 2018 11:49:41 -0500 Subject: [PATCH 18/65] Cleaned up some of the code. --- motorApp/AMCISrc/ANF2Driver.cpp | 35 +++++---------------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 0a0ce133..6d9bc213 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -490,43 +490,33 @@ void ANF2Axis::report(FILE *fp, int level) // SET VEL & ACCEL asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) { - asynStatus status; // static const char *functionName = "ANF2::sendAccelAndVelocity"; - // Send the velocity - //status = pC_->writeReg32(axisNo_, SPD_UPR, NINT(velocity), DEFAULT_CONTROLLER_TIMEOUT); - // Set the velocity register motionReg_[2] = NINT(velocity); - // Send the acceleration // ANF2 acceleration range 1 to 2000 steps/ms/sec - // Therefore need to limit range received by motor record from 1000 to 5e6 steps/sec/sec + // Therefore need to limit range received by motor record from 1000 to 2e6 steps/sec/sec if (acceleration < 1000) { - // print message noting that accel has been capped low //printf("Acceleration is < 1000: %lf\n", acceleration); acceleration = 1000; } if (acceleration > 2000000) { - // print message noting that accel has been capped high //printf("Acceleration is > 2000: %lf\n", acceleration); acceleration = 2000000; } - // ANF2 acceleration units are steps/millisecond/second, so we divide by 1000 here - //status = pC_->writeReg16(axisNo_, ACCEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); - //status = pC_->writeReg16(axisNo_, DECEL, NINT(acceleration/1000.0), DEFAULT_CONTROLLER_TIMEOUT); // Set the accel/decel register motionReg_[3] = (NINT(acceleration/1000.0) << 16) | (NINT(acceleration/1000.0)); - return status; + return asynSuccess; } // MOVE asynStatus ANF2Axis::move(double position, int relative, double minVelocity, double maxVelocity, double acceleration) { asynStatus status; - int distance, move_bit; + epicsInt32 distance; printf(" ** ANF2Axis::move called, relative = %d, axisNo_ = %i\n", relative, this->axisNo_); @@ -541,15 +531,8 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou if (relative) { printf(" ** relative move called\n"); - //status = pC_->writeReg32(axisNo_, SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); + distance = NINT(position); - //status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - - //move_bit = 0x0; - //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); - - move_bit = 0x2; - //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); // Set position and cmd registers motionReg_[1] = NINT(position); @@ -558,21 +541,13 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou } else { // absolute printf(" ** absolute move called\n"); - //status = pC_->writeReg32(axisNo_, SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); + distance = NINT(position); printf(" ** distance = %d\n", distance); - //status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - - //move_bit = 0x0; - //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); - - move_bit = 0x1; - //status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); // Set position and cmd registers motionReg_[1] = NINT(position); motionReg_[0] = 0x1 << 16; - } // The final registers are zero for absolute and relative moves From ff2ac7196fbecd2cb8c442021c3da686e29d5bf7 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 22 Mar 2018 14:45:02 -0500 Subject: [PATCH 19/65] Added macros for 32-bit registers --- motorApp/AMCISrc/ANF2Driver.cpp | 17 +++++++---------- motorApp/AMCISrc/ANF2Driver.h | 13 ++++++------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 6d9bc213..3bc30475 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -329,13 +329,10 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // Read data that is likely to be stale getInfo(); - // Send the configuration - //status = pC_->writeReg32(axisNo_, CONFIG_MSW, config, DEFAULT_CONTROLLER_TIMEOUT); - // Send the configuration (array) // assemble the configuration bits; set the start speed to a non-zero value (100), which is required for the configuration to be accepted - confReg_[0] = config; - confReg_[1] = 0x00000064; + confReg_[CONFIGURATION] = config; + confReg_[BASE_SPEED] = 0x00000064; // Write all the registers status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); @@ -447,11 +444,11 @@ void ANF2Axis::reconfig() status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg, 5, DEFAULT_CONTROLLER_TIMEOUT); // Construct the new config - confReg[0] = 0x86000000; - confReg[1] = 0x00000064; - //confReg[2] = 0x0; - //confReg[3] = 0x0; - //confReg[4] = 0x0; + confReg[CONFIGURATION] = 0x86000000; + confReg[BASE_SPEED] = 0x00000064; + //confReg[HOME_TIMEOUT] = 0x0; + //confReg[CONFIG_REG_3] = 0x0; + //confReg[CONFIG_REG_4] = 0x0; epicsThreadSleep(2.0); getInfo(); diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index d742533e..444a3cde 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -46,13 +46,12 @@ K. Goetze 2014-03-24 // Not used must equal zero #define RESERVED 8 // Not used must equal zero #define RESERVED 9 -/*** Output Configuration Registers ***/ -#define CONFIG_MSW 0 -#define CONFIG_LSW 1 -#define BASE_SPD_MSW 2 -#define BASE_SPD_LSW 3 -#define HOME_TIMEOUT 4 - +/*** Output Configuration Registers (32-bit) ***/ +#define CONFIGURATION 0 +#define BASE_SPEED 1 +#define HOME_TIMEOUT 2 +#define CONFIG_REG_3 3 +#define CONFIG_REG_4 4 // No. of controller-specific parameters #define NUM_ANF2_PARAMS 2 From 11ee7839bb6e452f24380b19c65d8776337f0948 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 22 Mar 2018 15:05:00 -0500 Subject: [PATCH 20/65] Shortened many delays. Don't print as much info at startup. --- motorApp/AMCISrc/ANF2Driver.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 3bc30475..4e596943 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -324,10 +324,10 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_->reason=%d\n", pasynUserConfWrite_->reason); printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_ offset=%d\n", axisNo_*AXIS_REG_OFFSET); - epicsThreadSleep(1.0); + epicsThreadSleep(0.1); // Read data that is likely to be stale - getInfo(); + //getInfo(); // Send the configuration (array) // assemble the configuration bits; set the start speed to a non-zero value (100), which is required for the configuration to be accepted @@ -338,21 +338,19 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Delay - epicsThreadSleep(1.0); + epicsThreadSleep(0.05); // Read the configuration? Or maybe the command registers? - getInfo(); + //getInfo(); // set position to 0 - //setPosition(0); - setPosition(1337); - //setPosition(3141); + setPosition(0); // Delay - epicsThreadSleep(1.0); + //epicsThreadSleep(1.0); // Read the command registers - getInfo(); + //getInfo(); // Tell the driver the axis has been created pC_->axesCreated_ += 1; @@ -658,6 +656,8 @@ asynStatus ANF2Axis::setPosition(double position) // Clear the command/configuration register status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); + epicsThreadSleep(0.05); + //status = writeReg32(SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); set_position = NINT(position); From 892225f1fcf9f843a27d492b675fffa8aae87c0a Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 22 Mar 2018 15:09:58 -0500 Subject: [PATCH 21/65] Cleaned up the setPosition method --- motorApp/AMCISrc/ANF2Driver.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 4e596943..776fbc38 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -649,25 +649,13 @@ asynStatus ANF2Axis::setPosition(double position) epicsInt32 posReg[5]; //static const char *functionName = "ANF2Axis::setPosition"; - //set_bit = 0x0; - //status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); - zeroRegisters(posReg); // Clear the command/configuration register status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(0.05); - //status = writeReg32(SPD_UPR, velo, DEFAULT_CONTROLLER_TIMEOUT); set_position = NINT(position); - - //status = pC_->writeReg32(axisNo_, POS_WR_UPR, set_position, DEFAULT_CONTROLLER_TIMEOUT); - - set_bit = 0x200; - //status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); - - //set_bit = 0x0; - //status = pC_->writeReg16(axisNo_, CMD_MSW, set_bit, DEFAULT_CONTROLLER_TIMEOUT); posReg[0] = 0x200 << 16; posReg[1] = set_position; @@ -678,6 +666,13 @@ asynStatus ANF2Axis::setPosition(double position) // Write all the registers atomically status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); + //epicsThreadSleep(0.05); + + // The ANG1 driver does this; do we need to? + //zeroRegisters(posReg); + // Clear the command/configuration register + //status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); + return status; } From 6c500efd327006f8ee0ae5d31c539ee9dd4a83ad Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 22 Mar 2018 15:39:25 -0500 Subject: [PATCH 22/65] Added an unsuccessful attempt to get autosave to work. --- motorApp/AMCISrc/ANF2Driver.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 776fbc38..8e5fed15 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -345,6 +345,8 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // set position to 0 setPosition(0); + //setDoubleParam(pC_->motorPosition_, 0.0); + //callParamCallbacks(); // Delay //epicsThreadSleep(1.0); From 53b7b23b4a042dfcc718e2af4448a11e72152def Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 22 Mar 2018 15:43:02 -0500 Subject: [PATCH 23/65] Print fewer things --- motorApp/AMCISrc/ANF2Driver.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 8e5fed15..b932dfbc 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -315,14 +315,13 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi //printf("%s:%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver %s\n", pC_->inputDriver_, pC_->functionName, myModbusInputDriver); printf("%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver\n", pC_->inputDriver_); } - printf("ANF2Axis::ANF2Axis : pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); + //printf("ANF2Axis::ANF2Axis : pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); status = pasynInt32ArraySyncIO->connect(ANF2ConfName, axisNo_*AXIS_REG_OFFSET, &pasynUserConfWrite_, NULL); if (status) { printf("%s: Error, unable to connect pasynUserConfWrite_ to Modbus input driver\n", ANF2ConfName); } - printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_->reason=%d\n", pasynUserConfWrite_->reason); - printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_ offset=%d\n", axisNo_*AXIS_REG_OFFSET); + //printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_->reason=%d\n", pasynUserConfWrite_->reason); epicsThreadSleep(0.1); @@ -527,7 +526,7 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou status = sendAccelAndVelocity(acceleration, maxVelocity); if (relative) { - printf(" ** relative move called\n"); + //printf(" ** relative move called\n"); distance = NINT(position); @@ -537,10 +536,10 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou } else { // absolute - printf(" ** absolute move called\n"); + //printf(" ** absolute move called\n"); distance = NINT(position); - printf(" ** distance = %d\n", distance); + //printf(" ** distance = %d\n", distance); // Set position and cmd registers motionReg_[1] = NINT(position); From 687cccb55465e2385fbe3b0e0aae7d41d3f737d7 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 22 Mar 2018 16:43:26 -0500 Subject: [PATCH 24/65] Modifed reconfig to accept a position. Use a dedicated array of zeros for clearing controller registers (doesn't solve the failure-to-autosave-every-other-time problem). --- motorApp/AMCISrc/ANF2Driver.cpp | 49 +++++++++++++++++---------------- motorApp/AMCISrc/ANF2Driver.h | 3 +- motorApp/Db/ANF2Aux.template | 2 +- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index b932dfbc..8b740cdb 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -179,7 +179,7 @@ asynStatus ANF2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) } else if (function == ANF2Reconfig_) { // reconfig regardless of the value - pAxis->reconfig(); + pAxis->reconfig(value); } else { // Call base class method status = asynMotorController::writeInt32(pasynUser, value); @@ -308,8 +308,9 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi axisNo_ = axisNo; //this->axisNo_ = axisNo; - zeroRegisters(confReg_); - + // These registers will always be zero + zeroRegisters(zeroReg_); + status = pasynInt32SyncIO->connect(pC_->inputDriver_, axisNo_*AXIS_REG_OFFSET, &pasynUserForceRead_, "MODBUS_READ"); if (status) { //printf("%s:%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver %s\n", pC_->inputDriver_, pC_->functionName, myModbusInputDriver); @@ -328,6 +329,9 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // Read data that is likely to be stale //getInfo(); + // These registers will always have the last config that was sent to the controller + zeroRegisters(confReg_); + // Send the configuration (array) // assemble the configuration bits; set the start speed to a non-zero value (100), which is required for the configuration to be accepted confReg_[CONFIGURATION] = config; @@ -389,8 +393,8 @@ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which con driverName, functionName, hexConfig); return asynError; } else { - printf("%s:%s: Config=>%s=%x\n", - driverName, functionName, hexConfig, config); + printf("%s:%s: Config=0x%x\n", + driverName, functionName, config); } pC->lock(); @@ -427,39 +431,37 @@ void ANF2Axis::getInfo() } } -void ANF2Axis::reconfig() +void ANF2Axis::reconfig(epicsInt32 value) { asynStatus status; epicsInt32 confReg[5]; printf("Reconfiguring axis %i\n", axisNo_); - // The command/cfg register must first be zeroed - //reg = 0x0; - //status = pC_->writeReg16(axisNo_, CMD_MSW, reg, DEFAULT_CONTROLLER_TIMEOUT); - - zeroRegisters(confReg); // Clear the command/configuration register - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Construct the new config + zeroRegisters(confReg); confReg[CONFIGURATION] = 0x86000000; confReg[BASE_SPEED] = 0x00000064; //confReg[HOME_TIMEOUT] = 0x0; //confReg[CONFIG_REG_3] = 0x0; //confReg[CONFIG_REG_4] = 0x0; - epicsThreadSleep(2.0); + epicsThreadSleep(0.05); getInfo(); // Send the new config status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg, 5, DEFAULT_CONTROLLER_TIMEOUT); - epicsThreadSleep(2.0); + epicsThreadSleep(0.05); getInfo(); // Set the position to clear the invalid position error - setPosition(2048); + setPosition(value); + + epicsThreadSleep(0.05); getInfo(); } @@ -514,14 +516,16 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou asynStatus status; epicsInt32 distance; - printf(" ** ANF2Axis::move called, relative = %d, axisNo_ = %i\n", relative, this->axisNo_); + //printf(" ** ANF2Axis::move called, relative = %d, axisNo_ = %i\n", relative, this->axisNo_); - zeroRegisters(motionReg_); // Clear the command/configuration register - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(0.05); + // Clear the motition registers + zeroRegisters(motionReg_); + // This sets indices 2 & 3 of motionReg_ status = sendAccelAndVelocity(acceleration, maxVelocity); @@ -590,7 +594,7 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double functionName, minVelocity, maxVelocity, acceleration); velo = NINT(fabs(maxVelocity)); - + status = sendAccelAndVelocity(acceleration, velo); /* ANF2 does not have jog command. Move 1 million steps */ @@ -650,14 +654,14 @@ asynStatus ANF2Axis::setPosition(double position) epicsInt32 posReg[5]; //static const char *functionName = "ANF2Axis::setPosition"; - zeroRegisters(posReg); // Clear the command/configuration register - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(0.05); set_position = NINT(position); + zeroRegisters(posReg); posReg[0] = 0x200 << 16; posReg[1] = set_position; //posReg[2] = 0x0; @@ -670,9 +674,8 @@ asynStatus ANF2Axis::setPosition(double position) //epicsThreadSleep(0.05); // The ANG1 driver does this; do we need to? - //zeroRegisters(posReg); // Clear the command/configuration register - //status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); + //status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); return status; } diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 444a3cde..e3783e7b 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -79,7 +79,7 @@ private: * Abbreviated because it is used very frequently */ asynStatus sendAccelAndVelocity(double accel, double velocity); void getInfo(); - void reconfig(); + void reconfig(epicsInt32 value); void zeroRegisters(epicsInt32 *reg); asynUser *pasynUserForceRead_; asynUser *pasynUserConfWrite_; @@ -87,6 +87,7 @@ private: epicsInt32 config_; epicsInt32 motionReg_[5]; epicsInt32 confReg_[5]; + epicsInt32 zeroReg_[5]; friend class ANF2Controller; }; diff --git a/motorApp/Db/ANF2Aux.template b/motorApp/Db/ANF2Aux.template index 93a7b6c8..c506c89e 100644 --- a/motorApp/Db/ANF2Aux.template +++ b/motorApp/Db/ANF2Aux.template @@ -8,7 +8,7 @@ record(bo,"$(P)$(R)GetInfo") { field(OUT,"@asyn($(PORT),$(ADDR))ANF2_GET_INFO") } -record(bo,"$(P)$(R)Reconfig") { +record(longout,"$(P)$(R)Reconfig") { field(DESC,"Reconfig") field(PINI, "0") field(VAL,"0") From 079779cf13ca8ac91c97123d0e54f98ac7b6da62 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 22 Mar 2018 17:10:10 -0500 Subject: [PATCH 25/65] Tried more things that don't fix the autosave problem --- motorApp/AMCISrc/ANF2Driver.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 8b740cdb..df11fe25 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -329,6 +329,12 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // Read data that is likely to be stale //getInfo(); + // Clear the command/configuration register + //status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + + // Delay + //epicsThreadSleep(0.05); + // These registers will always have the last config that was sent to the controller zeroRegisters(confReg_); @@ -359,6 +365,8 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // Tell the driver the axis has been created pC_->axesCreated_ += 1; + + //epicsThreadSleep(1.0); } /* @@ -654,10 +662,12 @@ asynStatus ANF2Axis::setPosition(double position) epicsInt32 posReg[5]; //static const char *functionName = "ANF2Axis::setPosition"; + printf("setPosition(%lf) for axisNo_=%i\n", position, axisNo_); + // Clear the command/configuration register status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); - epicsThreadSleep(0.05); + epicsThreadSleep(0.1); set_position = NINT(position); @@ -671,7 +681,7 @@ asynStatus ANF2Axis::setPosition(double position) // Write all the registers atomically status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); - //epicsThreadSleep(0.05); + epicsThreadSleep(0.20); // The ANG1 driver does this; do we need to? // Clear the command/configuration register From 798a7336f5dadd2574f0ee14ce09216e9fe84cbe Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 11:46:53 -0500 Subject: [PATCH 26/65] Fixed the autosave problem by requiring the poller to be explicitly started after iocInit. --- motorApp/AMCISrc/ANF2Driver.cpp | 45 ++++++++++++++++++++++++++++++--- motorApp/AMCISrc/ANF2Driver.h | 5 +++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index df11fe25..8b071fe2 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -52,6 +52,9 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, // Keep track of the number of axes created, so the poller can wait for all the axes to be created before starting axesCreated_ = 0; + movingPollPeriod_ = movingPollPeriod; + idlePollPeriod_ = idlePollPeriod; + inputDriver_ = epicsStrDup(ANF2InPortName); // Set this before calls to create Axis objects // Create controller-specific parameters @@ -81,7 +84,7 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, /* Create the poller thread for this controller (do 2 forced-fast polls) * NOTE: at this point the axis objects don't yet exist, but the poller tolerates this */ - startPoller(movingPollPeriod, idlePollPeriod, 2); + //startPoller(movingPollPeriod, idlePollPeriod, 2); } @@ -106,6 +109,31 @@ extern "C" int ANF2CreateController(const char *portName, const char *ANF2InPort return(asynSuccess); } +extern "C" asynStatus ANF2StartPoller(const char *ANF2Name) /* specify which controller by port name */ +{ + ANF2Controller *pC; + static const char *functionName = "ANF2StartPoller"; + + pC = (ANF2Controller*) findAsynPortDriver(ANF2Name); + if (!pC) { + printf("%s:%s: Error port %s not found\n", + driverName, functionName, ANF2Name); + return asynError; + } + + pC->lock(); + pC->doStartPoller(); + pC->unlock(); + return asynSuccess; +} + +void ANF2Controller::doStartPoller() +{ + // + startPoller(movingPollPeriod_, idlePollPeriod_, 2); +} + + /** Reports on status of the driver * \param[in] fp The file pointer on which report information will be written * \param[in] level The level of report detail desired @@ -329,7 +357,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // Read data that is likely to be stale //getInfo(); - // Clear the command/configuration register + // Clear the command/configuration register (a good thing to do but doesn't appear to be necessary) //status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Delay @@ -352,10 +380,10 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi // Read the configuration? Or maybe the command registers? //getInfo(); - // set position to 0 + // set position to 0 to clear the "position invalid" status that results from configuring the axis setPosition(0); + // Tell asynMotor device support the position is zero so that autosave will restore the saved position (doesn't appear to be necessary) //setDoubleParam(pC_->motorPosition_, 0.0); - //callParamCallbacks(); // Delay //epicsThreadSleep(1.0); @@ -843,6 +871,14 @@ static void ANF2CreateControllerCallFunc(const iocshArgBuf *args) ANF2CreateController(args[0].sval, args[1].sval, args[2].sval, args[3].ival, args[4].ival, args[5].ival); } +/* ANF2StartPoller */ +static const iocshArg ANF2StartPollerArg0 = {"Port name", iocshArgString}; +static const iocshArg * const ANF2StartPollerArgs[] = {&ANF2StartPollerArg0}; +static const iocshFuncDef ANF2StartPollerDef = {"ANF2StartPoller", 1, ANF2StartPollerArgs}; +static void ANF2StartPollerCallFunc(const iocshArgBuf *args) +{ + ANF2StartPoller(args[0].sval); +} /* ANF2CreateAxis */ static const iocshArg ANF2CreateAxisArg0 = {"Port name", iocshArgString}; @@ -863,6 +899,7 @@ static void ANF2CreateAxisCallFunc(const iocshArgBuf *args) static void ANF2Register(void) { iocshRegister(&ANF2CreateControllerDef, ANF2CreateControllerCallFunc); + iocshRegister(&ANF2StartPollerDef, ANF2StartPollerCallFunc); iocshRegister(&ANF2CreateAxisDef, ANF2CreateAxisCallFunc); } diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index e3783e7b..c631ce3a 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -95,7 +95,8 @@ friend class ANF2Controller; class ANF2Controller : public asynMotorController { public: ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, double movingPollPeriod, double idlePollPeriod); - + void doStartPoller(); + void report(FILE *fp, int level); ANF2Axis* getAxis(asynUser *pasynUser); ANF2Axis* getAxis(int axisNo); @@ -122,6 +123,8 @@ private: asynStatus readReg16(int, int, epicsInt32*, double); asynStatus readReg32(int, int, epicsInt32*, double); char *inputDriver_; + double movingPollPeriod_; + double idlePollPeriod_; int axesCreated_; friend class ANF2Axis; From 2d3dc8abfae99448d31dd45bf4d4fd4b051b659d Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 14:09:04 -0500 Subject: [PATCH 27/65] Moved poll periods to poller call. Require numModules and axesPerModule instead of numAxes for the CreateController call. --- motorApp/AMCISrc/ANF2Driver.cpp | 82 +++++++++++++++++++-------------- motorApp/AMCISrc/ANF2Driver.h | 16 ++++--- 2 files changed, 58 insertions(+), 40 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 8b071fe2..817fc9f1 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -32,13 +32,12 @@ static const char *driverName = "ANF2MotorDriver"; * \param[in] portName The name of the asyn port that will be created for this driver * \param[in] ANF2InPortName The name of the drvAsynSerialPort that was created previously to connect to the ANF2 controller * \param[in] ANF2OutPortName The name of the drvAsynSerialPort that was created previously to connect to the ANF2 controller - * \param[in] numAxes The number of axes that this controller supports - * \param[in] movingPollPeriod The time between polls when any axis is moving - * \param[in] idlePollPeriod The time between polls when no axis is moving + * \param[in] numModules The number of modules on the controller stack + * \param[in] axesPerModule The number of axes per module (ANF1=1, ANF2=2) */ -ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, - double movingPollPeriod, double idlePollPeriod) - : asynMotorController(portName, numAxes, NUM_ANF2_PARAMS, +ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, + int numModules, int axesPerModule) + : asynMotorController(portName, (numModules*axesPerModule), NUM_ANF2_PARAMS, asynInt32ArrayMask, // One additional interface beyond those in base class asynInt32ArrayMask, // One additional callback interface beyond those in base class ASYN_CANBLOCK | ASYN_MULTIDEVICE, @@ -52,20 +51,17 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, // Keep track of the number of axes created, so the poller can wait for all the axes to be created before starting axesCreated_ = 0; - movingPollPeriod_ = movingPollPeriod; - idlePollPeriod_ = idlePollPeriod; - inputDriver_ = epicsStrDup(ANF2InPortName); // Set this before calls to create Axis objects // Create controller-specific parameters createParam(ANF2GetInfoString, asynParamInt32, &ANF2GetInfo_); createParam(ANF2ReconfigString, asynParamInt32, &ANF2Reconfig_); - if (numAxes > MAX_AXES) { - numAxes = MAX_AXES; - } + numModules_ = numModules; + axesPerModule_ = axesPerModule; + numAxes_ = numModules * axesPerModule; - for (j=0; jconnect(ANF2InPortName, i+j*AXIS_REG_OFFSET, &pasynUserInReg_[j][i], NULL); @@ -93,23 +89,35 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, * \param[in] portName The name of the asyn port that will be created for this driver * \param[in] ANF2InPortName The name of the drvAsynIPPPort that was created previously to connect to the ANF2 controller * \param[in] ANF2OutPortName The name of the drvAsynIPPPort that was created previously to connect to the ANF2 controller - * \param[in] numAxes The number of axes that this controller supports - * \param[in] movingPollPeriod The time in ms between polls when any axis is moving - * \param[in] idlePollPeriod The time in ms between polls when no axis is moving + * \param[in] numModules The number of modules on the controller stack + * \param[in] axesPerModule The number of axes per module (ANF1=1, ANF2=2) */ -extern "C" int ANF2CreateController(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, - int movingPollPeriod, int idlePollPeriod) +extern "C" int ANF2CreateController(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, + int numModules, int axesPerModule) { + // Enforce max values + if (numModules > MAX_MODULES) { + numModules = MAX_MODULES; + } + if (axesPerModule > MAX_AXES_PER_MODULE) { + axesPerModule = MAX_AXES_PER_MODULE; + } + /* ANF2Controller *pANF2Controller - = new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numAxes, movingPollPeriod/1000., idlePollPeriod/1000.); + = new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numModules, axesPerModule); pANF2Controller = NULL; */ - new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numAxes, movingPollPeriod/1000., idlePollPeriod/1000.); + new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numModules, axesPerModule); return(asynSuccess); } -extern "C" asynStatus ANF2StartPoller(const char *ANF2Name) /* specify which controller by port name */ +/** Starts the poller for a given controller + * \param[in] ANF2Name The name of the asyn port that for the controller + * \param[in] movingPollPeriod The time in ms between polls when any axis is moving + * \param[in] idlePollPeriod The time in ms between polls when no axis is moving + */ +extern "C" asynStatus ANF2StartPoller(const char *ANF2Name, int movingPollPeriod, int idlePollPeriod) { ANF2Controller *pC; static const char *functionName = "ANF2StartPoller"; @@ -122,13 +130,17 @@ extern "C" asynStatus ANF2StartPoller(const char *ANF2Name) /* specify which co } pC->lock(); - pC->doStartPoller(); + pC->doStartPoller(movingPollPeriod/1000.0, idlePollPeriod/1000.0); pC->unlock(); return asynSuccess; } -void ANF2Controller::doStartPoller() +void ANF2Controller::doStartPoller(double movingPollPeriod, double idlePollPeriod) { + // + movingPollPeriod_ = movingPollPeriod; + idlePollPeriod_ = idlePollPeriod; + // startPoller(movingPollPeriod_, idlePollPeriod_, 2); } @@ -149,7 +161,7 @@ void ANF2Controller::report(FILE *fp, int level) this->portName, numAxes_, movingPollPeriod_, idlePollPeriod_); fprintf(fp, " axesCreated=%i\n", axesCreated_); - for (j=0; j #include -#define MAX_AXES 2 +#define MAX_MODULES 6 +#define MAX_AXES_PER_MODULE 2 #define MAX_INPUT_REGS 10 #define MAX_OUTPUT_REGS 10 @@ -94,15 +95,15 @@ friend class ANF2Controller; class ANF2Controller : public asynMotorController { public: - ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, double movingPollPeriod, double idlePollPeriod); - void doStartPoller(); + ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numModules, int axesPerModule); + void doStartPoller(double movingPollPeriod, double idlePollPeriod); void report(FILE *fp, int level); ANF2Axis* getAxis(asynUser *pasynUser); ANF2Axis* getAxis(int axisNo); - asynUser *pasynUserInReg_[MAX_AXES][MAX_INPUT_REGS]; - asynUser *pasynUserOutReg_[MAX_AXES][MAX_OUTPUT_REGS]; - //asynUser *pasynUserOutArrayReg_[MAX_AXES][MAX_OUTPUT_REGS]; + asynUser *pasynUserInReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_INPUT_REGS]; + asynUser *pasynUserOutReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_OUTPUT_REGS]; + //asynUser *pasynUserOutArrayReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_OUTPUT_REGS]; /* These are the methods that we override from asynMotorDriver */ asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); @@ -123,6 +124,9 @@ private: asynStatus readReg16(int, int, epicsInt32*, double); asynStatus readReg32(int, int, epicsInt32*, double); char *inputDriver_; + int numAxes_; + int numModules_; + int axesPerModule_; double movingPollPeriod_; double idlePollPeriod_; int axesCreated_; From db987bd34911ba2dd0f0b58dec66d897d869e431 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 15:29:15 -0500 Subject: [PATCH 28/65] Implement the jog functionality with the move method, rather than duplicating code. --- motorApp/AMCISrc/ANF2Driver.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 817fc9f1..b5b30501 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -634,7 +634,7 @@ asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceler asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double acceleration) { asynStatus status; - int velo, distance, move_bit; + int velo, distance; static const char *functionName = "ANF2Axis::moveVelocity"; asynPrint(pasynUser_, ASYN_TRACE_FLOW, @@ -643,27 +643,16 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double velo = NINT(fabs(maxVelocity)); - status = sendAccelAndVelocity(acceleration, velo); - /* ANF2 does not have jog command. Move 1 million steps */ + distance = 1000000; if (maxVelocity > 0.) { /* This is a positive move in ANF2 coordinates */ - //printf(" ** relative move (JOG pos) called\n"); - distance = 1000000; - status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x2; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + //printf(" ** relative move (JOG pos) called\n"); + status = move(distance, 0, minVelocity, velo, acceleration); } else { /* This is a negative move in ANF2 coordinates */ //printf(" ** relative move (JOG neg) called\n"); - distance = -1000000; - status = pC_->writeReg32(axisNo_, POS_WR_UPR, distance, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); - move_bit = 0x2; - status = pC_->writeReg16(axisNo_, CMD_MSW, move_bit, DEFAULT_CONTROLLER_TIMEOUT); + status = move((distance * -1.0), 0, minVelocity, velo, acceleration); } // Delay the first status read, give the controller some time to return moving status epicsThreadSleep(0.05); @@ -697,7 +686,6 @@ asynStatus ANF2Axis::stop(double acceleration) asynStatus ANF2Axis::setPosition(double position) { asynStatus status; - int set_bit; epicsInt32 set_position; epicsInt32 posReg[5]; //static const char *functionName = "ANF2Axis::setPosition"; From be825dd68871fcb05614eb0187d9385114203727 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 15:44:35 -0500 Subject: [PATCH 29/65] Modified the stop method to use array writes. --- motorApp/AMCISrc/ANF2Driver.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index b5b30501..5ad64619 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -664,20 +664,21 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double asynStatus ANF2Axis::stop(double acceleration) { asynStatus status; - int stop_bit; + epicsInt32 stopReg; //static const char *functionName = "ANF2Axis::stop"; printf("\n STOP \n\n"); - // do nothing (for testing) - //return asynSuccess; + // The stop commands ignore all 32-bit registers beyond the first - stop_bit = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, stop_bit, DEFAULT_CONTROLLER_TIMEOUT); + // Clear the command/configuration register + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 1, DEFAULT_CONTROLLER_TIMEOUT); -// stop_bit = 0x10; Immediate stop - stop_bit = 0x4; // Hold move - status = pC_->writeReg16(axisNo_, CMD_MSW, stop_bit, DEFAULT_CONTROLLER_TIMEOUT); + //stopReg = 0x10 << 16; Immediate stop + stopReg = 0x4 << 16; // Hold move + + // + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, &stopReg, 1, DEFAULT_CONTROLLER_TIMEOUT); return status; } From 3fa5f9fadfc95e6a3cd247b7c19731a92d828238 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 15:45:33 -0500 Subject: [PATCH 30/65] Added a comment about the jog command --- motorApp/AMCISrc/ANF2Driver.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 5ad64619..c46e6610 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -643,7 +643,8 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double velo = NINT(fabs(maxVelocity)); - /* ANF2 does not have jog command. Move 1 million steps */ + /* ANF2 does have a jog command, but don't use it yet */ + /* ANG1 does not have jog command. Move 1 million steps */ distance = 1000000; if (maxVelocity > 0.) { /* This is a positive move in ANF2 coordinates */ From 192b396a993264ac935b2dc7fcbe6b5bbd574a5f Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 16:21:49 -0500 Subject: [PATCH 31/65] Made the setClosedLoop function do nothing. Tried to send the clear command error command,but that caused a command error from which I couldn't recover (presumably reconfiguring the axis would have resolved that problem. --- motorApp/AMCISrc/ANF2Driver.cpp | 55 ++++++++++++++------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index c46e6610..865dbc14 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -724,34 +724,26 @@ asynStatus ANF2Axis::setPosition(double position) asynStatus ANF2Axis::setClosedLoop(bool closedLoop) { asynStatus status; - int enable = 0x8000; - int disable = 0x0000; - int cmd; - - printf(" ** setClosedLoop called \n"); + epicsInt32 clReg[5]; + //static const char *functionName = "ANF2Axis::setClosedLoop"; + + // The ANF2 doesn't have a closed-loop enable/disable command, so do nothing. + // The configuration of an axis: + // * can be changed so that an axis is disabled, but that doesn't disable torque + // * can be changed to disable the use of encoder inputs, but that isn't currently allowed on-the-fly + + /*printf(" ** setClosedLoop called \n"); if (closedLoop) { - printf("setting enable %X\n", enable); - // Let's reset errors first - cmd = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, cmd, DEFAULT_CONTROLLER_TIMEOUT); - - cmd = 0x400; - status = pC_->writeReg16(axisNo_, CMD_MSW, cmd, DEFAULT_CONTROLLER_TIMEOUT); - - cmd = 0x0; - status = pC_->writeReg16(axisNo_, CMD_MSW, cmd, DEFAULT_CONTROLLER_TIMEOUT); - /* - status = pC_->writeReg16(axisNo_, CMD_LSW, enable, DEFAULT_CONTROLLER_TIMEOUT); - setIntegerParam(pC_->motorStatusPowerOn_, 1); - */ - + printf("setting enable true\n"); + + setIntegerParam(pC_->motorStatusPowerOn_, 1); } else { - printf("setting disable %X\n", disable); - status = pC_->writeReg16(axisNo_, CMD_LSW, disable, DEFAULT_CONTROLLER_TIMEOUT); + printf("setting disable false\n"); setIntegerParam(pC_->motorStatusPowerOn_, 0); } + return status;*/ - return status; + return asynSuccess; } // POLL @@ -805,6 +797,14 @@ asynStatus ANF2Axis::poll(bool *moving) setIntegerParam(pC_->motorStatusDone_, done); *moving = done ? false:true; //printf("done is %d\n", done); + + // Check for enable/disable (not actually the torque status) and set accordingly. + // Enable/disable is determined by the configuration and it isn't obvious why one would disable an axis. + enabled = (read_val & 0x4000); + if (enabled) + setIntegerParam(pC_->motorStatusPowerOn_, 1); + else + setIntegerParam(pC_->motorStatusPowerOn_, 0); // Read the limit status // @@ -837,15 +837,6 @@ asynStatus ANF2Axis::poll(bool *moving) // Should be in init routine? Allows CNEN to be used. setIntegerParam(pC_->motorStatusGainSupport_, 1); - // Check for the torque status and set accordingly. - // The ANG1 driver does the wrong thing for torque enable/disable - //enabled = (read_val & 0x8000); - enabled = 1; - if (enabled) - setIntegerParam(pC_->motorStatusPowerOn_, 1); - else - setIntegerParam(pC_->motorStatusPowerOn_, 0); - // Notify asynMotorController polling routine that we're ready callParamCallbacks(); From c70152574ccb1fe0dee706662fd1bbe55e813874 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 16:30:15 -0500 Subject: [PATCH 32/65] Implemented home with array writes. Causes a command error with my test configuration. --- motorApp/AMCISrc/ANF2Driver.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 865dbc14..acfba4d4 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -614,19 +614,30 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceleration, int forwards) { asynStatus status; - int home_bit; // static const char *functionName = "ANF2Axis::home"; - //status = sendAccelAndVelocity(acceleration, maxVelocity); + // Clear the command/configuration register + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + + epicsThreadSleep(0.05); + + // Clear the motition registers + zeroRegisters(motionReg_); + + // This sets indices 2 & 3 of motionReg_ + status = sendAccelAndVelocity(acceleration, maxVelocity); if (forwards) { printf(" ** HOMING FORWARDS **\n"); - home_bit = 0x20; - status = pC_->writeReg16(axisNo_, CMD_MSW, home_bit, DEFAULT_CONTROLLER_TIMEOUT); + motionReg_[0] = 0x20 << 16; } else { - home_bit = 0x40; - status = pC_->writeReg16(axisNo_, CMD_MSW, home_bit, DEFAULT_CONTROLLER_TIMEOUT); + printf(" ** HOMING REVERSE **\n"); + motionReg_[0] = 0x40 << 16; } + + // Write all the registers atomically + status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + return status; } @@ -723,8 +734,8 @@ asynStatus ANF2Axis::setPosition(double position) // ENABLE TORQUE asynStatus ANF2Axis::setClosedLoop(bool closedLoop) { - asynStatus status; - epicsInt32 clReg[5]; + //asynStatus status; + //epicsInt32 clReg[5]; //static const char *functionName = "ANF2Axis::setClosedLoop"; // The ANF2 doesn't have a closed-loop enable/disable command, so do nothing. From 6b447ffdc99c24410db1214e1021cc124ff09056 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 16:44:03 -0500 Subject: [PATCH 33/65] Removed non-array write methods. --- motorApp/AMCISrc/ANF2Driver.cpp | 53 +-------------------------------- motorApp/AMCISrc/ANF2Driver.h | 1 - 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index acfba4d4..d3ab4d0c 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -67,7 +67,6 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, status = pasynInt32SyncIO->connect(ANF2InPortName, i+j*AXIS_REG_OFFSET, &pasynUserInReg_[j][i], NULL); } for (i=0; iconnect(ANF2OutPortName, i+j*AXIS_REG_OFFSET, &pasynUserOutReg_[j][i], NULL); // Maybe send the outputs with Array calls in the future //status = pasynInt32ArraySyncIO->connect(ANF2OutPortName, i, &pasynUserOutArrayReg_[j][i], NULL); } @@ -164,7 +163,7 @@ void ANF2Controller::report(FILE *fp, int level) for (j=0; jpasynUserSelf, ASYN_TRACEIO_DRIVER,"writeReg16: writing %d to register %d\n", output, axisReg); - status = pasynInt32SyncIO->write(pasynUserOutReg_[axisNo][axisReg], output, timeout); - //status = pasynInt32ArraySyncIO->write(pasynUserOutArrayReg_[axisNo][axisReg], &output, 1, timeout); - epicsThreadSleep(0.01); - - return status ; -} - // This could be useful in the future, but it isn't needed yet /*asynStatus ANF2Controller::writeReg32Array(int axisNo, int axisReg, epicsInt32* output, int nElements, double timeout) { @@ -265,43 +251,6 @@ asynStatus ANF2Controller::writeReg16(int axisNo, int axisReg, int output, doubl return status ; }*/ -asynStatus ANF2Controller::writeReg32(int axisNo, int axisReg, int output, double timeout) -{ -//.. break 32-bit integer into 2 pieces -//.. write the pieces into ANF2 registers - - asynStatus status; - - int lower,upper; - - // This is the way the ANG1 driver does it, and the code doesn't appear to work - /*float fnum; - - fnum = (output / 1000.0); - upper = (int)fnum; - fnum = fnum - upper; - fnum = NINT(fnum * 1000); - lower = (int)fnum;*/ - - upper = (output >> 16) & 0x0000FFFF; - lower = output & 0x0000FFFF; - - printf("upper = 0x%x\t= %i\n", upper, upper); - printf("lower = 0x%x\t= %i\n", lower, lower); - - // writeReg16(piece1 ie MSW ... - status = writeReg16(axisNo, axisReg, upper, DEFAULT_CONTROLLER_TIMEOUT); - - // writeReg16(piece2 ie LSW ... - axisReg++; - status = writeReg16(axisNo, axisReg, lower, DEFAULT_CONTROLLER_TIMEOUT); - - // No breaking up the output value required when writing an array - maybe do this in the future - //status = pasynInt32ArraySyncIO->write(pasynUserOutArrayReg_[axisNo][axisReg], &output, 2, timeout); - - return status ; -} - asynStatus ANF2Controller::readReg16(int axisNo, int axisReg, epicsInt32 *input, double timeout) { asynStatus status; diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 8bf2b6b7..01fc9398 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -102,7 +102,6 @@ public: ANF2Axis* getAxis(asynUser *pasynUser); ANF2Axis* getAxis(int axisNo); asynUser *pasynUserInReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_INPUT_REGS]; - asynUser *pasynUserOutReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_OUTPUT_REGS]; //asynUser *pasynUserOutArrayReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_OUTPUT_REGS]; /* These are the methods that we override from asynMotorDriver */ From d8c24ee12b1c97940c82c12b9271546a11d4bed6 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 16:48:30 -0500 Subject: [PATCH 34/65] Added todo comment --- motorApp/AMCISrc/ANF2Driver.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index d3ab4d0c..c5d01954 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -313,6 +313,13 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi } //printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_->reason=%d\n", pasynUserConfWrite_->reason); + /* TODO: + * test config bits and set status bits to prevent methods from sending commands that would generate errors + * reduce the sleeps to see which ones are necessary + * make pasynUserConfWrite_ an output array; create a corresponding controller method to simplify calls + * read encoder position + */ + epicsThreadSleep(0.1); // Read data that is likely to be stale From 5f819fb8a1f66035840082725f5fd1301bc048c4 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 16:53:26 -0500 Subject: [PATCH 35/65] Added more todo comments. --- motorApp/AMCISrc/ANF2Driver.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index c5d01954..825076c7 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -317,7 +317,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi * test config bits and set status bits to prevent methods from sending commands that would generate errors * reduce the sleeps to see which ones are necessary * make pasynUserConfWrite_ an output array; create a corresponding controller method to simplify calls - * read encoder position + * allow the base speed to be passed as an argument */ epicsThreadSleep(0.1); @@ -440,6 +440,8 @@ void ANF2Axis::reconfig(epicsInt32 value) asynStatus status; epicsInt32 confReg[5]; + // TODO: modify this to use the base speed from the parameter, and instead accept a string for a new config + printf("Reconfiguring axis %i\n", axisNo_); // Clear the command/configuration register @@ -478,6 +480,8 @@ void ANF2Axis::reconfig(epicsInt32 value) */ void ANF2Axis::report(FILE *fp, int level) { + // TODO: make this more useful + if (level > 0) { fprintf(fp, " axis %d\n", axisNo_); fprintf(fp, " this->axisNo_ %i\n", this->axisNo_); @@ -754,6 +758,8 @@ asynStatus ANF2Axis::poll(bool *moving) setDoubleParam(pC_->motorPosition_, position); //printf("ANF2Axis::poll: Motor #%i position: %f\n", axisNo_, position); + // TODO: read encoder position + // Read the moving status of this motor // status = pC_->readReg16(axisNo_, STATUS_1, &read_val, DEFAULT_CONTROLLER_TIMEOUT); From dc09abbd14dab27ef06ac8c17d9691f106192f3d Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 23 Mar 2018 17:10:07 -0500 Subject: [PATCH 36/65] Improved report output --- motorApp/AMCISrc/ANF2Driver.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 825076c7..8ea6d666 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -155,19 +155,31 @@ void ANF2Controller::doStartPoller(double movingPollPeriod, double idlePollPerio void ANF2Controller::report(FILE *fp, int level) { int i, j; + ANF2Axis *pAxis; - fprintf(fp, "ANF2 motor driver %s, numAxes=%d, moving poll period=%f, idle poll period=%f\n", - this->portName, numAxes_, movingPollPeriod_, idlePollPeriod_); - fprintf(fp, " axesCreated=%i\n", axesCreated_); + fprintf(fp, "====================================\n"); + fprintf(fp, "ANF2 motor driver:\n"); + fprintf(fp, " asyn port: %s\n", this->portName); + fprintf(fp, " num axes: %i\n", numAxes_); + fprintf(fp, " axes created: %i\n", axesCreated_); + fprintf(fp, " moving poll period: %lf\n", movingPollPeriod_); + fprintf(fp, " idle poll period: %lf\n", idlePollPeriod_); for (j=0; jgetInfo(); + + /*for (i=0; iwrite(pasynUserForceRead_, 1, DEFAULT_CONTROLLER_TIMEOUT); - printf("Info for axis %i\n", axisNo_); + printf("Registers for axis %i:\n", axisNo_); for( i=0; ireadReg16(axisNo_, i, &read_val, DEFAULT_CONTROLLER_TIMEOUT); - printf(" status=%d, register=%i, val=0x%x\n", status, i, read_val); + //printf(" status=%d, register=%i, val=0x%x\n", status, i, read_val); + printf(" register=%i, val=0x%x\n", i, read_val); } } From 70d252c44a9e52c4d94ca76149383355d1da4d3c Mon Sep 17 00:00:00 2001 From: kpetersn Date: Mon, 26 Mar 2018 15:25:49 -0500 Subject: [PATCH 37/65] Added writeReg32Array method. Made the default output asyn port use array writes. Eliminated the conf asyn port. --- motorApp/AMCISrc/ANF2Driver.cpp | 70 +++++++++++++-------------------- motorApp/AMCISrc/ANF2Driver.h | 7 ++-- 2 files changed, 31 insertions(+), 46 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 8ea6d666..84bce299 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -66,10 +66,7 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, for (i=0; iconnect(ANF2InPortName, i+j*AXIS_REG_OFFSET, &pasynUserInReg_[j][i], NULL); } - for (i=0; iconnect(ANF2OutPortName, i, &pasynUserOutArrayReg_[j][i], NULL); - } + status = pasynInt32ArraySyncIO->connect(ANF2OutPortName, j*AXIS_REG_OFFSET, &pasynUserOutReg_[j], NULL); } if (status) { asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, @@ -252,16 +249,15 @@ asynStatus ANF2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) return status; } -// This could be useful in the future, but it isn't needed yet -/*asynStatus ANF2Controller::writeReg32Array(int axisNo, int axisReg, epicsInt32* output, int nElements, double timeout) +asynStatus ANF2Controller::writeReg32Array(int axisNo, epicsInt32* output, int nElements, double timeout) { asynStatus status; - asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"writeReg32Array: writing %d elements starting at register %d\n", nElements, axisReg); - status = pasynInt32ArraySyncIO->write(pasynUserOutArrayReg_[axisNo][axisReg], output, nElements, timeout); - - return status ; -}*/ + asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"writeReg32Array: writing %d elements starting for axis %d\n", nElements, axisNo); + status = pasynInt32ArraySyncIO->write(pasynUserOutReg_[axisNo], output, nElements, timeout); + + return status; +} asynStatus ANF2Controller::readReg16(int axisNo, int axisReg, epicsInt32 *input, double timeout) { @@ -300,7 +296,7 @@ asynStatus ANF2Controller::readReg32(int axisNo, int axisReg, epicsInt32 *combo, * * Initializes register numbers, etc. */ -ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epicsInt32 config) +ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) : asynMotorAxis(pC, axisNo), pC_(pC) { @@ -319,16 +315,9 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi } //printf("ANF2Axis::ANF2Axis : pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); - status = pasynInt32ArraySyncIO->connect(ANF2ConfName, axisNo_*AXIS_REG_OFFSET, &pasynUserConfWrite_, NULL); - if (status) { - printf("%s: Error, unable to connect pasynUserConfWrite_ to Modbus input driver\n", ANF2ConfName); - } - //printf("ANF2Axis::ANF2Axis : pasynUserConfWrite_->reason=%d\n", pasynUserConfWrite_->reason); - /* TODO: * test config bits and set status bits to prevent methods from sending commands that would generate errors * reduce the sleeps to see which ones are necessary - * make pasynUserConfWrite_ an output array; create a corresponding controller method to simplify calls * allow the base speed to be passed as an argument */ @@ -338,7 +327,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi //getInfo(); // Clear the command/configuration register (a good thing to do but doesn't appear to be necessary) - //status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Delay //epicsThreadSleep(0.05); @@ -352,7 +341,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi confReg_[BASE_SPEED] = 0x00000064; // Write all the registers - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, confReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Delay epicsThreadSleep(0.05); @@ -387,7 +376,6 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epi */ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which controller by port name */ - const char *ANF2ConfName, /* specify which config port name */ int axis, /* axis number 0-1 */ const char *hexConfig) /* desired configuration in hex */ { @@ -414,7 +402,7 @@ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which con } pC->lock(); - new ANF2Axis(pC, ANF2ConfName, axis, config); + new ANF2Axis(pC, axis, config); pC->unlock(); return asynSuccess; } @@ -458,8 +446,8 @@ void ANF2Axis::reconfig(epicsInt32 value) printf("Reconfiguring axis %i\n", axisNo_); // Clear the command/configuration register - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); - + status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + // Construct the new config zeroRegisters(confReg); confReg[CONFIGURATION] = 0x86000000; @@ -472,7 +460,7 @@ void ANF2Axis::reconfig(epicsInt32 value) getInfo(); // Send the new config - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, confReg, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, confReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(0.05); getInfo(); @@ -540,7 +528,7 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou //printf(" ** ANF2Axis::move called, relative = %d, axisNo_ = %i\n", relative, this->axisNo_); // Clear the command/configuration register - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(0.05); @@ -576,7 +564,7 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou // Write all the registers atomically // The number of elements refers to the number of epicsInt32s registers_ - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); // Delay the first status read, give the controller some time to return moving status epicsThreadSleep(0.05); @@ -590,7 +578,7 @@ asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceler // static const char *functionName = "ANF2Axis::home"; // Clear the command/configuration register - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(0.05); @@ -609,7 +597,7 @@ asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceler } // Write all the registers atomically - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); return status; } @@ -657,13 +645,13 @@ asynStatus ANF2Axis::stop(double acceleration) // The stop commands ignore all 32-bit registers beyond the first // Clear the command/configuration register - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 1, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, zeroReg_, 1, DEFAULT_CONTROLLER_TIMEOUT); //stopReg = 0x10 << 16; Immediate stop stopReg = 0x4 << 16; // Hold move // - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, &stopReg, 1, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, &stopReg, 1, DEFAULT_CONTROLLER_TIMEOUT); return status; } @@ -679,7 +667,7 @@ asynStatus ANF2Axis::setPosition(double position) printf("setPosition(%lf) for axisNo_=%i\n", position, axisNo_); // Clear the command/configuration register - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(0.1); @@ -693,13 +681,13 @@ asynStatus ANF2Axis::setPosition(double position) //posReg[4] = 0x0; // Write all the registers atomically - status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->writeReg32Array(axisNo_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(0.20); // The ANG1 driver does this; do we need to? // Clear the command/configuration register - //status = pasynInt32ArraySyncIO->write(pasynUserConfWrite_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); return status; } @@ -863,17 +851,15 @@ static void ANF2StartPollerCallFunc(const iocshArgBuf *args) /* ANF2CreateAxis */ static const iocshArg ANF2CreateAxisArg0 = {"Port name", iocshArgString}; -static const iocshArg ANF2CreateAxisArg1 = {"Config port name", iocshArgString}; -static const iocshArg ANF2CreateAxisArg2 = {"Axis number", iocshArgInt}; -static const iocshArg ANF2CreateAxisArg3 = {"Hex config", iocshArgString}; +static const iocshArg ANF2CreateAxisArg1 = {"Axis number", iocshArgInt}; +static const iocshArg ANF2CreateAxisArg2 = {"Hex config", iocshArgString}; static const iocshArg * const ANF2CreateAxisArgs[] = {&ANF2CreateAxisArg0, &ANF2CreateAxisArg1, - &ANF2CreateAxisArg2, - &ANF2CreateAxisArg3}; -static const iocshFuncDef ANF2CreateAxisDef = {"ANF2CreateAxis", 4, ANF2CreateAxisArgs}; + &ANF2CreateAxisArg2}; +static const iocshFuncDef ANF2CreateAxisDef = {"ANF2CreateAxis", 3, ANF2CreateAxisArgs}; static void ANF2CreateAxisCallFunc(const iocshArgBuf *args) { - ANF2CreateAxis(args[0].sval, args[1].sval, args[2].ival, args[3].sval); + ANF2CreateAxis(args[0].sval, args[1].ival, args[2].sval); } diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 01fc9398..bce8a25b 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -65,7 +65,7 @@ class ANF2Axis : public asynMotorAxis { public: /* These are the methods we override from the base class */ - ANF2Axis(class ANF2Controller *pC, const char *ANF2ConfName, int axisNo, epicsInt32 config); + ANF2Axis(class ANF2Controller *pC, int axisNo, epicsInt32 config); void report(FILE *fp, int level); asynStatus move(double position, int relative, double min_velocity, double max_velocity, double acceleration); asynStatus moveVelocity(double min_velocity, double max_velocity, double acceleration); @@ -83,7 +83,6 @@ private: void reconfig(epicsInt32 value); void zeroRegisters(epicsInt32 *reg); asynUser *pasynUserForceRead_; - asynUser *pasynUserConfWrite_; int axisNo_; epicsInt32 config_; epicsInt32 motionReg_[5]; @@ -102,7 +101,7 @@ public: ANF2Axis* getAxis(asynUser *pasynUser); ANF2Axis* getAxis(int axisNo); asynUser *pasynUserInReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_INPUT_REGS]; - //asynUser *pasynUserOutArrayReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_OUTPUT_REGS]; + asynUser *pasynUserOutReg_[MAX_MODULES*MAX_AXES_PER_MODULE]; /* These are the methods that we override from asynMotorDriver */ asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); @@ -119,7 +118,7 @@ protected: private: asynStatus writeReg16(int, int, int, double); asynStatus writeReg32(int, int, int, double); - //asynStatus writeReg32Array(int, int, epicsInt32*, int, double); + asynStatus writeReg32Array(int, epicsInt32*, int, double); asynStatus readReg16(int, int, epicsInt32*, double); asynStatus readReg32(int, int, epicsInt32*, double); char *inputDriver_; From a877f4c188a90490890ddb7f06cdb08ebc688f08 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 27 Mar 2018 13:49:12 -0500 Subject: [PATCH 38/65] Parse the config string and store some info about the axes. This can be done better in the future. --- motorApp/AMCISrc/ANF2Driver.cpp | 42 +++++++++++++++++++++++++++++++++ motorApp/AMCISrc/ANF2Driver.h | 19 +++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 84bce299..02de3fa9 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -349,6 +349,34 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) // Read the configuration? Or maybe the command registers? //getInfo(); + // Parse the configuration (mostly for asynReport purposes) + // MSW + CaptInput_ = (config & (0x1 << 16)) >> 16; + ExtInput_ = (config & (0x2 << 16)) >> 17; + HomeInput_ = (config & (0x4 << 16)) >> 18; + CWInput_ = (config & (0x18 << 16)) >> 19; + CCWInput_ = (config & (0x60 << 16)) >> 21; + BHPO_ = (config & (0x80 << 16)) >> 23; + QuadEnc_ = (config & (0x100 << 16)) >> 24; + DiagFbk_ = (config & (0x200 << 16)) >> 25; + OutPulse_ = (config & (0x400 << 16)) >> 26; + HomeOp_ = (config & (0x800 << 16)) >> 27; + CardAxis_ = (config & (0x4000 << 16)) >> 30; + OpMode_ = (config & (0x8000 << 16)) >> 31; + // LSW + CaptInputAS_ = config & 0x1; + ExtInputAS_ = (config & 0x2) >> 1; + HomeInputAS_ = (config & 0x4) >> 2; + CWInputAS_ = (config & 0x8) >> 3; + CCWInputAS_ = (config & 0x10) >> 4; + + // Only allow UEIP to be used if the axis is configured to have a quadrature encoder + if (QuadEnc_ != 0x0) { + setIntegerParam(pC_->motorStatusHasEncoder_, 1); + } else { + setIntegerParam(pC_->motorStatusHasEncoder_, 0); + } + // set position to 0 to clear the "position invalid" status that results from configuring the axis setPosition(0); // Tell asynMotor device support the position is zero so that autosave will restore the saved position (doesn't appear to be necessary) @@ -426,6 +454,20 @@ void ANF2Axis::getInfo() // For a read (not sure why this is necessary) status = pasynInt32SyncIO->write(pasynUserForceRead_, 1, DEFAULT_CONTROLLER_TIMEOUT); + printf("Configuration for axis %i:\n", axisNo_); + printf(" Capture Input: %i\tActive State: %i\n", CaptInput_, CaptInputAS_); + printf(" External Input: %i\tActive State: %i\n", ExtInput_, ExtInputAS_); + printf(" Home Input: %i\tActive State: %i\n", HomeInput_, HomeInputAS_); + printf(" CW Input: %i\tActive State: %i\n", CWInput_, CWInputAS_); + printf(" CCW Input: %i\tActive State: %i\n", CCWInput_, CCWInputAS_); + printf(" Backplane Home Proximity Operation: %i\n", BHPO_); + printf(" Quadrature Encoder: %i\n", QuadEnc_); + printf(" Diagnostic Feedback: %i\n", DiagFbk_); + printf(" Output Pulse Type: %i\n", OutPulse_); + printf(" Home Operation: %i\n", HomeOp_); + printf(" Card Axis: %i\n", CardAxis_); + printf(" Operation Mode for Axis: %i\n", OpMode_); + printf("Registers for axis %i:\n", axisNo_); for( i=0; i Date: Tue, 27 Mar 2018 14:25:21 -0500 Subject: [PATCH 39/65] Fix for OpMode_ --- motorApp/AMCISrc/ANF2Driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 02de3fa9..11fee7c7 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -362,7 +362,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) OutPulse_ = (config & (0x400 << 16)) >> 26; HomeOp_ = (config & (0x800 << 16)) >> 27; CardAxis_ = (config & (0x4000 << 16)) >> 30; - OpMode_ = (config & (0x8000 << 16)) >> 31; + OpMode_ = (epicsUInt32)(config & (0x8000 << 16)) >> 31; // LSW CaptInputAS_ = config & 0x1; ExtInputAS_ = (config & 0x2) >> 1; From 35ac98f13379648e6260211d91c6430cf56de66e Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 27 Mar 2018 14:50:36 -0500 Subject: [PATCH 40/65] Specify base speed and homing timeout when configuring axis --- motorApp/AMCISrc/ANF2Driver.cpp | 42 ++++++++++++++++++++++++++------- motorApp/AMCISrc/ANF2Driver.h | 4 +++- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 11fee7c7..dae30d2c 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -296,7 +296,7 @@ asynStatus ANF2Controller::readReg32(int axisNo, int axisReg, epicsInt32 *combo, * * Initializes register numbers, etc. */ -ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) +ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 baseSpeed, epicsInt32 homingTimeout) : asynMotorAxis(pC, axisNo), pC_(pC) { @@ -304,6 +304,8 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) axisNo_ = axisNo; //this->axisNo_ = axisNo; + baseSpeed_ = baseSpeed; + homingTimeout_ = homingTimeout; // These registers will always be zero zeroRegisters(zeroReg_); @@ -338,7 +340,8 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) // Send the configuration (array) // assemble the configuration bits; set the start speed to a non-zero value (100), which is required for the configuration to be accepted confReg_[CONFIGURATION] = config; - confReg_[BASE_SPEED] = 0x00000064; + confReg_[BASE_SPEED] = baseSpeed; + confReg_[HOME_TIMEOUT] = homingTimeout << 16; // Write all the registers status = pC_->writeReg32Array(axisNo_, confReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); @@ -404,8 +407,10 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config) */ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which controller by port name */ - int axis, /* axis number 0-1 */ - const char *hexConfig) /* desired configuration in hex */ + int axis, /* axis number 0-1 */ + const char *hexConfig, /* desired configuration in hex */ + epicsInt32 baseSpeed, /* base speed */ + epicsInt32 homingTimeout) /* homing timeout */ { ANF2Controller *pC; epicsInt32 config; @@ -429,8 +434,24 @@ extern "C" asynStatus ANF2CreateAxis(const char *ANF2Name, /* specify which con driverName, functionName, config); } + // baseSpeed is steps/second (1-1,000,000) + if (baseSpeed < 1) { + baseSpeed = 1; + } + if (baseSpeed > 1000000) { + baseSpeed = 1000000; + } + + // homingTimeout is seconds (0-300) + if (homingTimeout < 0) { + homingTimeout = 0; + } + if (homingTimeout > 300) { + homingTimeout = 300; + } + pC->lock(); - new ANF2Axis(pC, axis, config); + new ANF2Axis(pC, axis, config, baseSpeed, homingTimeout); pC->unlock(); return asynSuccess; } @@ -455,6 +476,7 @@ void ANF2Axis::getInfo() status = pasynInt32SyncIO->write(pasynUserForceRead_, 1, DEFAULT_CONTROLLER_TIMEOUT); printf("Configuration for axis %i:\n", axisNo_); + printf(" Base Speed: %i\tHoming Timeout: %i\n", baseSpeed_, homingTimeout_); printf(" Capture Input: %i\tActive State: %i\n", CaptInput_, CaptInputAS_); printf(" External Input: %i\tActive State: %i\n", ExtInput_, ExtInputAS_); printf(" Home Input: %i\tActive State: %i\n", HomeInput_, HomeInputAS_); @@ -895,13 +917,17 @@ static void ANF2StartPollerCallFunc(const iocshArgBuf *args) static const iocshArg ANF2CreateAxisArg0 = {"Port name", iocshArgString}; static const iocshArg ANF2CreateAxisArg1 = {"Axis number", iocshArgInt}; static const iocshArg ANF2CreateAxisArg2 = {"Hex config", iocshArgString}; +static const iocshArg ANF2CreateAxisArg3 = {"Base speed", iocshArgInt}; +static const iocshArg ANF2CreateAxisArg4 = {"Homing timeout", iocshArgInt}; static const iocshArg * const ANF2CreateAxisArgs[] = {&ANF2CreateAxisArg0, &ANF2CreateAxisArg1, - &ANF2CreateAxisArg2}; -static const iocshFuncDef ANF2CreateAxisDef = {"ANF2CreateAxis", 3, ANF2CreateAxisArgs}; + &ANF2CreateAxisArg2, + &ANF2CreateAxisArg3, + &ANF2CreateAxisArg4}; +static const iocshFuncDef ANF2CreateAxisDef = {"ANF2CreateAxis", 5, ANF2CreateAxisArgs}; static void ANF2CreateAxisCallFunc(const iocshArgBuf *args) { - ANF2CreateAxis(args[0].sval, args[1].ival, args[2].sval); + ANF2CreateAxis(args[0].sval, args[1].ival, args[2].sval, args[3].ival, args[4].ival); } diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 7e9127ef..b6e82ff8 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -65,7 +65,7 @@ class ANF2Axis : public asynMotorAxis { public: /* These are the methods we override from the base class */ - ANF2Axis(class ANF2Controller *pC, int axisNo, epicsInt32 config); + ANF2Axis(class ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 baseSpeed, epicsInt32 homingTimeout); void report(FILE *fp, int level); asynStatus move(double position, int relative, double min_velocity, double max_velocity, double acceleration); asynStatus moveVelocity(double min_velocity, double max_velocity, double acceleration); @@ -84,6 +84,8 @@ private: void zeroRegisters(epicsInt32 *reg); asynUser *pasynUserForceRead_; int axisNo_; + epicsInt32 baseSpeed_; + epicsInt32 homingTimeout_; epicsInt32 config_; epicsInt32 motionReg_[5]; epicsInt32 confReg_[5]; From 3a231a90ef980c2e16c1205ddec3b9e3e41d9fd1 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 27 Mar 2018 14:52:28 -0500 Subject: [PATCH 41/65] Remove item from todo list --- motorApp/AMCISrc/ANF2Driver.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index dae30d2c..4d1377fc 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -320,7 +320,6 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 /* TODO: * test config bits and set status bits to prevent methods from sending commands that would generate errors * reduce the sleeps to see which ones are necessary - * allow the base speed to be passed as an argument */ epicsThreadSleep(0.1); From 690281fd24a968d032d1fe135a350fb67b4b00dd Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 27 Mar 2018 15:08:18 -0500 Subject: [PATCH 42/65] Correct the acceleration --- motorApp/AMCISrc/ANF2Driver.cpp | 30 ++++++++++++++++++++++++++++++ motorApp/AMCISrc/ANF2Driver.h | 1 + 2 files changed, 31 insertions(+) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 4d1377fc..a6a30652 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -582,6 +582,30 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) return asynSuccess; } +/* + * This driver only sets the base speed at initialization when the configuration is sent. + * It is possible that the base speed (VBAS) in the motor record is inconsistent with the + * base speed set at initialization, since there is no way for an asyn motor driver to force + * the base speed to be reset when a user changes it. The resulting acceleration calculated + * by the motor record is likely to be incorrect. The following method calculates the + * acceleration that will give the correct acceleration time (ACCL) for the base speed that + * was specified at initialization. + */ +double ANF2Axis::correctAccel(double minVelocity, double maxVelocity, double acceleration) +{ + double accelTime; + double newAccel; + + accelTime = (maxVelocity - minVelocity) / acceleration; + newAccel = (maxVelocity - (double)baseSpeed_) / accelTime; + + printf("old acceleration = %lf\n", acceleration); + printf("new acceleration = %lf\n", newAccel); + + return newAccel; +} + + // MOVE asynStatus ANF2Axis::move(double position, int relative, double minVelocity, double maxVelocity, double acceleration) { @@ -598,6 +622,9 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou // Clear the motition registers zeroRegisters(motionReg_); + // Correct the acceleration + acceleration = correctAccel(minVelocity, maxVelocity, acceleration); + // This sets indices 2 & 3 of motionReg_ status = sendAccelAndVelocity(acceleration, maxVelocity); @@ -648,6 +675,9 @@ asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceler // Clear the motition registers zeroRegisters(motionReg_); + // Correct the acceleration + acceleration = correctAccel(minVelocity, maxVelocity, acceleration); + // This sets indices 2 & 3 of motionReg_ status = sendAccelAndVelocity(acceleration, maxVelocity); diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index b6e82ff8..6a2fd393 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -79,6 +79,7 @@ private: ANF2Controller *pC_; /**< Pointer to the asynMotorController to which this axis belongs. * Abbreviated because it is used very frequently */ asynStatus sendAccelAndVelocity(double accel, double velocity); + double correctAccel(double minVelocity, double maxVelocity, double acceleration); void getInfo(); void reconfig(epicsInt32 value); void zeroRegisters(epicsInt32 *reg); From 0f52af42b28051dae0308daff872085b30521bd4 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 27 Mar 2018 15:15:05 -0500 Subject: [PATCH 43/65] Also read the encoder position, which isn't helpful with diagnostic feedback. --- motorApp/AMCISrc/ANF2Driver.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index a6a30652..e0c25c64 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -823,6 +823,7 @@ asynStatus ANF2Axis::poll(bool *moving) int limit; int enabled; double position; + double encPosition; asynStatus status; epicsInt32 read_val; // don't use a pointer here. The _address_ of read_val should be passed to the read function. @@ -853,6 +854,11 @@ asynStatus ANF2Axis::poll(bool *moving) //printf("ANF2Axis::poll: Motor #%i position: %f\n", axisNo_, position); // TODO: read encoder position + status = pC_->readReg32(axisNo_, EN_POS_UPR, &read_val, DEFAULT_CONTROLLER_TIMEOUT); + //printf("ANF2Axis::poll: Motor encoder position raw: %d\n", read_val); + encPosition = (double) read_val; + setDoubleParam(pC_->motorEncoderPosition_, encPosition); + //printf("ANF2Axis::poll: Motor #%i encoder position: %f\n", axisNo_, encPosition); // Read the moving status of this motor // From dbdd1814dfe8f325edb427e3faf2c4e39053bf49 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 27 Mar 2018 16:09:41 -0500 Subject: [PATCH 44/65] Enforce controller speed limits. Added an alternate jog implemention that doesn't work well (the ANF2 jog commands appear to require immediate stops, which don't play nicely with subsequent move commands). --- motorApp/AMCISrc/ANF2Driver.cpp | 70 ++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index e0c25c64..7e61bf10 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -562,18 +562,26 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) { // static const char *functionName = "ANF2::sendAccelAndVelocity"; + // ANF2 speed range is 1 to 1,000,000 steps/sec + if (velocity > 1000000.0) { + velocity = 1000000.0; + } + if (velocity < 1.0) { + velocity = 1.0; + } + // Set the velocity register motionReg_[2] = NINT(velocity); // ANF2 acceleration range 1 to 2000 steps/ms/sec // Therefore need to limit range received by motor record from 1000 to 2e6 steps/sec/sec - if (acceleration < 1000) { + if (acceleration < 1000.0) { //printf("Acceleration is < 1000: %lf\n", acceleration); - acceleration = 1000; + acceleration = 1000.0; } - if (acceleration > 2000000) { + if (acceleration > 2000000.0) { //printf("Acceleration is > 2000: %lf\n", acceleration); - acceleration = 2000000; + acceleration = 2000000.0; } // Set the accel/decel register @@ -706,20 +714,59 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double "%s: minVelocity=%f, maxVelocity=%f, acceleration=%f\n", functionName, minVelocity, maxVelocity, acceleration); + /* + // The jog command doesn't work well. It seems to require stopping with an immediate stop, + // but immediate stops cause problems for normal moves. + + // Clear the command/configuration register + status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + + epicsThreadSleep(0.05); + + // Clear the motition registers + zeroRegisters(motionReg_); + + // Note: the jog acceleration doesn't need to be corrected; the JAR field has units of egu/s/s + + if (maxVelocity > 0.0) { + //printf(" ** positive jog called\n"); + + // Set cmd register + motionReg_[0] = 0x80 << 16; + + // Do nothing to the velocity + + } else { + //printf(" ** negative jog called\n"); + + // Set cmd register + motionReg_[0] = 0x100 << 16; + + // ANF2 only accepts speeds > 0 + maxVelocity = fabs(maxVelocity); + } + + // This sets indices 2 & 3 of motionReg_ + status = sendAccelAndVelocity(acceleration, maxVelocity); + + // Write all the registers atomically + status = pC_->writeReg32Array(axisNo_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + */ + velo = NINT(fabs(maxVelocity)); - /* ANF2 does have a jog command, but don't use it yet */ - /* ANG1 does not have jog command. Move 1 million steps */ + // Simulate a jog like the ANG1 driver does. Move 1 million steps distance = 1000000; if (maxVelocity > 0.) { - /* This is a positive move in ANF2 coordinates */ + // This is a positive move in ANF2 coordinates //printf(" ** relative move (JOG pos) called\n"); status = move(distance, 0, minVelocity, velo, acceleration); } else { - /* This is a negative move in ANF2 coordinates */ + // This is a negative move in ANF2 coordinates //printf(" ** relative move (JOG neg) called\n"); status = move((distance * -1.0), 0, minVelocity, velo, acceleration); } + // Delay the first status read, give the controller some time to return moving status epicsThreadSleep(0.05); return status; @@ -740,12 +787,17 @@ asynStatus ANF2Axis::stop(double acceleration) // Clear the command/configuration register status = pC_->writeReg32Array(axisNo_, zeroReg_, 1, DEFAULT_CONTROLLER_TIMEOUT); - //stopReg = 0x10 << 16; Immediate stop + // Immediate stop works well with jogs, but breaks the first normal move + //stopReg = 0x10 << 16; // Immediate stop + // Hold move works very well with normal moves stopReg = 0x4 << 16; // Hold move // status = pC_->writeReg32Array(axisNo_, &stopReg, 1, DEFAULT_CONTROLLER_TIMEOUT); + // Clear the command/configuration register + //status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + return status; } From 860474c1ae341ce669b7b10299e84731244d69dd Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 27 Mar 2018 16:45:42 -0500 Subject: [PATCH 45/65] Be quieter. --- motorApp/AMCISrc/ANF2Driver.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 7e61bf10..b1632c99 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -607,8 +607,8 @@ double ANF2Axis::correctAccel(double minVelocity, double maxVelocity, double acc accelTime = (maxVelocity - minVelocity) / acceleration; newAccel = (maxVelocity - (double)baseSpeed_) / accelTime; - printf("old acceleration = %lf\n", acceleration); - printf("new acceleration = %lf\n", newAccel); + //printf("old acceleration = %lf\n", acceleration); + //printf("new acceleration = %lf\n", newAccel); return newAccel; } @@ -780,7 +780,7 @@ asynStatus ANF2Axis::stop(double acceleration) epicsInt32 stopReg; //static const char *functionName = "ANF2Axis::stop"; - printf("\n STOP \n\n"); + //printf("\n STOP \n\n"); // The stop commands ignore all 32-bit registers beyond the first From 021228e0e73c8f7716c4f21a173af5a2abc128c7 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 27 Mar 2018 17:31:07 -0500 Subject: [PATCH 46/65] Improved asynReport output --- motorApp/AMCISrc/ANF2Driver.cpp | 82 ++++++++++++++++++++------------- motorApp/AMCISrc/ANF2Driver.h | 1 + 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index b1632c99..12e5359c 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -152,7 +152,7 @@ void ANF2Controller::doStartPoller(double movingPollPeriod, double idlePollPerio void ANF2Controller::report(FILE *fp, int level) { int i, j; - ANF2Axis *pAxis; + ANF2Axis* pAxis[numAxes_]; fprintf(fp, "====================================\n"); fprintf(fp, "ANF2 motor driver:\n"); @@ -161,21 +161,35 @@ void ANF2Controller::report(FILE *fp, int level) fprintf(fp, " axes created: %i\n", axesCreated_); fprintf(fp, " moving poll period: %lf\n", movingPollPeriod_); fprintf(fp, " idle poll period: %lf\n", idlePollPeriod_); + fprintf(fp, "\n"); + fprintf(fp, "Input registers:\n\n"); for (j=0; jgetInfo(); + } - pAxis = getAxis(j); - pAxis->getInfo(); + fprintf(fp, " Reg\t"); + for (j=0; jinputReg_[i]); + + } + fprintf(fp, "\n"); + } + + fprintf(fp, "\n"); /*for (i=0; iwrite(pasynUserForceRead_, 1, DEFAULT_CONTROLLER_TIMEOUT); - printf("Configuration for axis %i:\n", axisNo_); - printf(" Base Speed: %i\tHoming Timeout: %i\n", baseSpeed_, homingTimeout_); - printf(" Capture Input: %i\tActive State: %i\n", CaptInput_, CaptInputAS_); - printf(" External Input: %i\tActive State: %i\n", ExtInput_, ExtInputAS_); - printf(" Home Input: %i\tActive State: %i\n", HomeInput_, HomeInputAS_); - printf(" CW Input: %i\tActive State: %i\n", CWInput_, CWInputAS_); - printf(" CCW Input: %i\tActive State: %i\n", CCWInput_, CCWInputAS_); - printf(" Backplane Home Proximity Operation: %i\n", BHPO_); - printf(" Quadrature Encoder: %i\n", QuadEnc_); - printf(" Diagnostic Feedback: %i\n", DiagFbk_); - printf(" Output Pulse Type: %i\n", OutPulse_); - printf(" Home Operation: %i\n", HomeOp_); - printf(" Card Axis: %i\n", CardAxis_); - printf(" Operation Mode for Axis: %i\n", OpMode_); - - printf("Registers for axis %i:\n", axisNo_); + //printf("Registers for axis %i:\n", axisNo_); for( i=0; ireadReg16(axisNo_, i, &read_val, DEFAULT_CONTROLLER_TIMEOUT); + status = pC_->readReg16(axisNo_, i, &inputReg_[i], DEFAULT_CONTROLLER_TIMEOUT); + //status = pC_->readReg16(axisNo_, i, &read_val, DEFAULT_CONTROLLER_TIMEOUT); //printf(" status=%d, register=%i, val=0x%x\n", status, i, read_val); - printf(" register=%i, val=0x%x\n", i, read_val); + //printf(" register=%i, val=0x%x\n", i, read_val); } } @@ -547,14 +547,35 @@ void ANF2Axis::report(FILE *fp, int level) // TODO: make this more useful if (level > 0) { - fprintf(fp, " axis %d\n", axisNo_); + fprintf(fp, "Configuration for axis %i:\n", axisNo_); + fprintf(fp, " Base Speed: %i\tHoming Timeout: %i\n", baseSpeed_, homingTimeout_); + fprintf(fp, " Capture Input: %i\tActive State: %i\n", CaptInput_, CaptInputAS_); + fprintf(fp, " External Input: %i\tActive State: %i\n", ExtInput_, ExtInputAS_); + fprintf(fp, " Home Input: %i\tActive State: %i\n", HomeInput_, HomeInputAS_); + fprintf(fp, " CW Input: %i\tActive State: %i\n", CWInput_, CWInputAS_); + fprintf(fp, " CCW Input: %i\tActive State: %i\n", CCWInput_, CCWInputAS_); + fprintf(fp, " Backplane Home Proximity Operation: %i\n", BHPO_); + fprintf(fp, " Quadrature Encoder: %i\n", QuadEnc_); + fprintf(fp, " Diagnostic Feedback: %i\n", DiagFbk_); + fprintf(fp, " Output Pulse Type: %i\n", OutPulse_); + fprintf(fp, " Home Operation: %i\n", HomeOp_); + fprintf(fp, " Card Axis: %i\n", CardAxis_); + fprintf(fp, " Operation Mode for Axis: %i\n", OpMode_); + fprintf(fp, "\n"); + + /*fprintf(fp, " axis %d\n", axisNo_); fprintf(fp, " this->axisNo_ %i\n", this->axisNo_); fprintf(fp, " this->config_ %x\n", this->config_); - fprintf(fp, " config_ %x\n", config_); + fprintf(fp, " config_ %x\n", config_);*/ } + //printf("ANF2Axis::report -> BEFORE asynMotorAxis::report!!\n"); + // Call the base class method asynMotorAxis::report(fp, level); + + //printf("ANF2Axis::report -> AFTER asynMotorAxis::report!!\n"); + } // SET VEL & ACCEL @@ -809,7 +830,7 @@ asynStatus ANF2Axis::setPosition(double position) epicsInt32 posReg[5]; //static const char *functionName = "ANF2Axis::setPosition"; - printf("setPosition(%lf) for axisNo_=%i\n", position, axisNo_); + //printf("setPosition(%lf) for axisNo_=%i\n", position, axisNo_); // Clear the command/configuration register status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); @@ -821,9 +842,6 @@ asynStatus ANF2Axis::setPosition(double position) zeroRegisters(posReg); posReg[0] = 0x200 << 16; posReg[1] = set_position; - //posReg[2] = 0x0; - //posReg[3] = 0x0; - //posReg[4] = 0x0; // Write all the registers atomically status = pC_->writeReg32Array(axisNo_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 6a2fd393..3f20443b 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -81,6 +81,7 @@ private: asynStatus sendAccelAndVelocity(double accel, double velocity); double correctAccel(double minVelocity, double maxVelocity, double acceleration); void getInfo(); + epicsInt32 inputReg_[10]; void reconfig(epicsInt32 value); void zeroRegisters(epicsInt32 *reg); asynUser *pasynUserForceRead_; From 9e0b87ee7486bc4c75805a12795ced49b5de021a Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 28 Mar 2018 10:32:30 -0500 Subject: [PATCH 47/65] Implement jogging using the actual jog command. Stopping a jog is different than a normal move, so the stop method had to get smarter. Removed the extra call to base class's writeInt32 that was resulting in double stop commands being sent. --- motorApp/AMCISrc/ANF2Driver.cpp | 41 ++++++++++++++++++++------------- motorApp/AMCISrc/ANF2Driver.h | 1 + 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 12e5359c..908b9c3e 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -247,9 +247,6 @@ asynStatus ANF2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) status = asynMotorController::writeInt32(pasynUser, value); } - // Call base class method - status = asynMotorController::writeInt32(pasynUser, value); - /* Do callbacks so higher layers see any changes */ pAxis->callParamCallbacks(); if (status) @@ -735,9 +732,11 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double "%s: minVelocity=%f, maxVelocity=%f, acceleration=%f\n", functionName, minVelocity, maxVelocity, acceleration); - /* - // The jog command doesn't work well. It seems to require stopping with an immediate stop, - // but immediate stops cause problems for normal moves. + // + // The jog command requires a different stop than a move command + + // Set a jogging flag + jogging_ = true; // Clear the command/configuration register status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); @@ -772,8 +771,9 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double // Write all the registers atomically status = pC_->writeReg32Array(axisNo_, motionReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); - */ + // + /* velo = NINT(fabs(maxVelocity)); // Simulate a jog like the ANG1 driver does. Move 1 million steps @@ -787,6 +787,7 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double //printf(" ** relative move (JOG neg) called\n"); status = move((distance * -1.0), 0, minVelocity, velo, acceleration); } + */ // Delay the first status read, give the controller some time to return moving status epicsThreadSleep(0.05); @@ -805,19 +806,27 @@ asynStatus ANF2Axis::stop(double acceleration) // The stop commands ignore all 32-bit registers beyond the first - // Clear the command/configuration register + // Clear the command/configuration register (this causes a jog to stop) status = pC_->writeReg32Array(axisNo_, zeroReg_, 1, DEFAULT_CONTROLLER_TIMEOUT); - // Immediate stop works well with jogs, but breaks the first normal move - //stopReg = 0x10 << 16; // Immediate stop - // Hold move works very well with normal moves - stopReg = 0x4 << 16; // Hold move + if (jogging_ == false) + { + //printf("stopping a normal move\n"); + // The immediate stop command cuts the pulses off without any deceleration and causes the position to become invalid + //stopReg = 0x10 << 16; // Immediate stop + // Hold move works very well with normal moves + stopReg = 0x4 << 16; // Hold move - // - status = pC_->writeReg32Array(axisNo_, &stopReg, 1, DEFAULT_CONTROLLER_TIMEOUT); + // This causes a normal move to stop + status = pC_->writeReg32Array(axisNo_, &stopReg, 1, DEFAULT_CONTROLLER_TIMEOUT); - // Clear the command/configuration register - //status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + // Clear the command/configuration register + //status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); + } else { + // Reset the jogging flag (assume the stop was successful) + //printf("resetting the jog flag\n"); + jogging_ = false; + } return status; } diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 3f20443b..a46f18c2 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -92,6 +92,7 @@ private: epicsInt32 motionReg_[5]; epicsInt32 confReg_[5]; epicsInt32 zeroReg_[5]; + bool jogging_; // Configuration bits short CaptInput_; short ExtInput_; From c6a2b4ee0b512c43e7e7ae89ccd025e46d518e6c Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 28 Mar 2018 10:43:29 -0500 Subject: [PATCH 48/65] Also allow UEIP=Yes when Diagnostic Feedback is used. --- motorApp/AMCISrc/ANF2Driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 908b9c3e..9332b723 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -384,7 +384,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 CCWInputAS_ = (config & 0x10) >> 4; // Only allow UEIP to be used if the axis is configured to have a quadrature encoder - if (QuadEnc_ != 0x0) { + if ((QuadEnc_ != 0x0) || (DiagFbk_ != 0x0)) { setIntegerParam(pC_->motorStatusHasEncoder_, 1); } else { setIntegerParam(pC_->motorStatusHasEncoder_, 0); From d760620579a9dfd441ebbe72a36e4c68a305d61a Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 28 Mar 2018 11:02:33 -0500 Subject: [PATCH 49/65] Allow errors to be reset via a PV. --- motorApp/AMCISrc/ANF2Driver.cpp | 27 ++++++++++++++++++++++++++- motorApp/AMCISrc/ANF2Driver.h | 11 +++++++---- motorApp/Db/ANF2Aux.template | 10 ++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 9332b723..1424c204 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -54,6 +54,7 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, inputDriver_ = epicsStrDup(ANF2InPortName); // Set this before calls to create Axis objects // Create controller-specific parameters + createParam(ANF2ResetErrorsString, asynParamInt32, &ANF2ResetErrors_); createParam(ANF2GetInfoString, asynParamInt32, &ANF2GetInfo_); createParam(ANF2ReconfigString, asynParamInt32, &ANF2Reconfig_); @@ -230,7 +231,15 @@ asynStatus ANF2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) /* Set the parameter and readback in the parameter library. */ status = setIntegerParam(pAxis->axisNo_, function, value); - if (function == ANF2GetInfo_) + if (function == ANF2ResetErrors_) + { + // Only reset errors when value is 1 + if (value == 1) { + printf("ANF2Controller:writeInt32: Resetting errors for axis = %d\n", pAxis->axisNo_); + pAxis->resetErrors(); + + } + } else if (function == ANF2GetInfo_) { // Only get info when value is 1 if (value == 1) { @@ -476,6 +485,22 @@ void ANF2Axis::zeroRegisters(epicsInt32 *reg) } } +asynStatus ANF2Axis::resetErrors() +{ + asynStatus status; + epicsInt32 errorReg[5]; + //static const char *functionName = "ANF2Axis::resetErrors"; + + zeroRegisters(errorReg); + + errorReg[0] = 0x800 << 16; + + // Send the reset error command + status = pC_->writeReg32Array(axisNo_, errorReg, 5, DEFAULT_CONTROLLER_TIMEOUT); + + return status; +} + void ANF2Axis::getInfo() { asynStatus status; diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index a46f18c2..d7e99cdb 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -55,11 +55,12 @@ K. Goetze 2014-03-24 #define CONFIG_REG_4 4 // No. of controller-specific parameters -#define NUM_ANF2_PARAMS 2 +#define NUM_ANF2_PARAMS 3 /** drvInfo strings for extra parameters that the ACR controller supports */ +#define ANF2ResetErrorsString "ANF2_RESET_ERRORS" #define ANF2GetInfoString "ANF2_GET_INFO" -#define ANF2ReconfigString "ANF2_RECONFIG" +#define ANF2ReconfigString "ANF2_RECONFIG" class ANF2Axis : public asynMotorAxis { @@ -80,6 +81,7 @@ private: * Abbreviated because it is used very frequently */ asynStatus sendAccelAndVelocity(double accel, double velocity); double correctAccel(double minVelocity, double maxVelocity, double acceleration); + asynStatus resetErrors(); void getInfo(); epicsInt32 inputReg_[10]; void reconfig(epicsInt32 value); @@ -135,8 +137,9 @@ public: /* These are the methods that are new to this class */ protected: - int ANF2GetInfo_; /**< Jerk time parameter index */ - int ANF2Reconfig_; /**< Jerk time parameter index */ + int ANF2ResetErrors_; /** Reset Errors parameter index */ + int ANF2GetInfo_; /**< Get Info parameter index */ + int ANF2Reconfig_; /**< Reconfig parameter index */ private: diff --git a/motorApp/Db/ANF2Aux.template b/motorApp/Db/ANF2Aux.template index c506c89e..aeaeace6 100644 --- a/motorApp/Db/ANF2Aux.template +++ b/motorApp/Db/ANF2Aux.template @@ -1,5 +1,15 @@ # Database for extra PVs for AMCI ANG1 controllers +record(bo,"$(P)$(R)ResetErrors") { + field(DESC,"Reset Errors") + field(PINI, "0") + field(VAL,"0") + field(DTYP, "asynInt32") + field(OUT,"@asyn($(PORT),$(ADDR))ANF2_RESET_ERRORS") + field(ZNAM, "Done") + field(ONAM, "Reset") +} + record(bo,"$(P)$(R)GetInfo") { field(DESC,"Get Info") field(PINI, "0") From f1aefccbeb6ada94d5f542529fdddb1748cc9f0b Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 29 Mar 2018 10:48:42 -0500 Subject: [PATCH 50/65] Added comments about homing --- motorApp/AMCISrc/ANF2Driver.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 1424c204..d6a90522 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -732,11 +732,14 @@ asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceler // This sets indices 2 & 3 of motionReg_ status = sendAccelAndVelocity(acceleration, maxVelocity); + // Note: if the home input is active when the home command is sent, the axis will appear to move in the wrong direction if (forwards) { printf(" ** HOMING FORWARDS **\n"); + // The +Find Home (CW) command motionReg_[0] = 0x20 << 16; } else { printf(" ** HOMING REVERSE **\n"); + // The -Find Home (CCW) command motionReg_[0] = 0x40 << 16; } From 14bb36e0aa7c3dd06d14b592c6a1aeb6584b04c5 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Thu, 29 Mar 2018 16:28:18 -0500 Subject: [PATCH 51/65] Read and set the direction. Read and clear command errors. Only set the limit if moving in that direction (doesn't solve the problem of being unable to absolute-move off a limit--jogging works though). --- motorApp/AMCISrc/ANF2Driver.cpp | 53 ++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index d6a90522..25b23745 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -927,8 +927,11 @@ asynStatus ANF2Axis::setClosedLoop(bool closedLoop) asynStatus ANF2Axis::poll(bool *moving) { int done; - int limit; + int lowLimit; + int highLimit; int enabled; + int cmdError; + int direction; double position; double encPosition; asynStatus status; @@ -978,6 +981,21 @@ asynStatus ANF2Axis::poll(bool *moving) *moving = done ? false:true; //printf("done is %d\n", done); + // Direction (only set the direction of the controller is moving) + if (!done) { + if (read_val & 0x1) { + direction = 1; + setIntegerParam(pC_->motorStatusDirection_, 1); + } + if ((read_val & 0x2) > 1) { + direction = 0; + setIntegerParam(pC_->motorStatusDirection_, 0); + } + } + + // Check for command errors + cmdError = (read_val & 0x1000) ? 1 : 0; + // Check for enable/disable (not actually the torque status) and set accordingly. // Enable/disable is determined by the configuration and it isn't obvious why one would disable an axis. enabled = (read_val & 0x4000); @@ -991,28 +1009,21 @@ asynStatus ANF2Axis::poll(bool *moving) status = pC_->readReg16(axisNo_, STATUS_2, &read_val, DEFAULT_CONTROLLER_TIMEOUT); //printf("status 2 is 0x%X\n", read_val); - limit = (read_val & 0x8); // a cw limit has been reached - setIntegerParam(pC_->motorStatusHighLimit_, limit); - //printf("+limit %d\n", limit); - if (limit) { // reset error and set position so we can move off of the limit - // Reset error - setClosedLoop(1); - // Reset position - //printf(" Reset Position\n"); - setPosition(position); - } + // Set the high limit only when moving in the positive direction + highLimit = (read_val & 0x8) ? (direction & 1) : 0; // a cw limit has been reached + setIntegerParam(pC_->motorStatusHighLimit_, highLimit); + //printf("+limit %d\n", highLimit); - limit = (read_val & 0x10); // a ccw limit has been reached - setIntegerParam(pC_->motorStatusLowLimit_, limit); - //printf("-limit %d\n", limit); - if (limit) { // reset error and set position so we can move off of the limit - // Reset error - setClosedLoop(1); - // Reset position - setPosition(position); - } + // Set the low limit only when moving in the negative direction + lowLimit = (read_val & 0x10) ? (!direction & 1) : 0; // a ccw limit has been reached + setIntegerParam(pC_->motorStatusLowLimit_, lowLimit); + //printf("-limit %d\n", lowLimit); - // test for home + // Clear command errors so we can attempt to move again + if (cmdError) { + printf("poll: resetting errors\n"); + resetErrors(); + } // Should be in init routine? Allows CNEN to be used. setIntegerParam(pC_->motorStatusGainSupport_, 1); From 8f05579e826608fbaca0db369cad2abe04a1ae1c Mon Sep 17 00:00:00 2001 From: kpetersn Date: Mon, 9 Apr 2018 11:29:56 -0500 Subject: [PATCH 52/65] Cleaned up the code somewhat --- motorApp/AMCISrc/ANF2Driver.cpp | 63 +++++++++++++++++---------------- motorApp/AMCISrc/ANF2Driver.h | 19 ++++------ 2 files changed, 39 insertions(+), 43 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 25b23745..68425f00 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -340,6 +340,8 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 /* TODO: * test config bits and set status bits to prevent methods from sending commands that would generate errors * reduce the sleeps to see which ones are necessary + * print out useful info for asyn traces + * make reconfig useful */ epicsThreadSleep(0.1); @@ -493,7 +495,7 @@ asynStatus ANF2Axis::resetErrors() zeroRegisters(errorReg); - errorReg[0] = 0x800 << 16; + errorReg[COMMAND] = 0x800 << 16; // Send the reset error command status = pC_->writeReg32Array(axisNo_, errorReg, 5, DEFAULT_CONTROLLER_TIMEOUT); @@ -505,7 +507,6 @@ void ANF2Axis::getInfo() { asynStatus status; int i; - epicsInt32 read_val; // For a read (not sure why this is necessary) status = pasynInt32SyncIO->write(pasynUserForceRead_, 1, DEFAULT_CONTROLLER_TIMEOUT); @@ -515,9 +516,7 @@ void ANF2Axis::getInfo() for( i=0; ireadReg16(axisNo_, i, &inputReg_[i], DEFAULT_CONTROLLER_TIMEOUT); - //status = pC_->readReg16(axisNo_, i, &read_val, DEFAULT_CONTROLLER_TIMEOUT); - //printf(" status=%d, register=%i, val=0x%x\n", status, i, read_val); - //printf(" register=%i, val=0x%x\n", i, read_val); + //printf(" status=%d, register=%i, val=0x%x\n", status, i, inputReg_[i]); } } @@ -614,7 +613,7 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) } // Set the velocity register - motionReg_[2] = NINT(velocity); + motionReg_[SPEED] = NINT(velocity); // ANF2 acceleration range 1 to 2000 steps/ms/sec // Therefore need to limit range received by motor record from 1000 to 2e6 steps/sec/sec @@ -628,7 +627,7 @@ asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) } // Set the accel/decel register - motionReg_[3] = (NINT(acceleration/1000.0) << 16) | (NINT(acceleration/1000.0)); + motionReg_[ACCEL_DECEL] = (NINT(acceleration/1000.0) << 16) | (NINT(acceleration/1000.0)); return asynSuccess; } @@ -661,7 +660,7 @@ double ANF2Axis::correctAccel(double minVelocity, double maxVelocity, double acc asynStatus ANF2Axis::move(double position, int relative, double minVelocity, double maxVelocity, double acceleration) { asynStatus status; - epicsInt32 distance; + epicsInt32 posInt; //printf(" ** ANF2Axis::move called, relative = %d, axisNo_ = %i\n", relative, this->axisNo_); @@ -679,29 +678,27 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou // This sets indices 2 & 3 of motionReg_ status = sendAccelAndVelocity(acceleration, maxVelocity); + posInt = NINT(position); + if (relative) { //printf(" ** relative move called\n"); - - distance = NINT(position); // Set position and cmd registers - motionReg_[1] = NINT(position); - motionReg_[0] = 0x2 << 16; + motionReg_[COMMAND] = 0x2 << 16; + motionReg_[POSITION] = posInt; } else { - // absolute //printf(" ** absolute move called\n"); - - distance = NINT(position); - //printf(" ** distance = %d\n", distance); // Set position and cmd registers - motionReg_[1] = NINT(position); - motionReg_[0] = 0x1 << 16; + motionReg_[COMMAND] = 0x1 << 16; + motionReg_[POSITION] = posInt; } + + //printf(" ** position = %d\n", posInt); - // The final registers are zero for absolute and relative moves - motionReg_[4] = 0x0; + // The final registers are zero for absolute and relative moves (this shouldn't be necessary--DELETEME) + motionReg_[CMD_REG_4] = 0x0; // Write all the registers atomically // The number of elements refers to the number of epicsInt32s registers_ @@ -736,11 +733,11 @@ asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceler if (forwards) { printf(" ** HOMING FORWARDS **\n"); // The +Find Home (CW) command - motionReg_[0] = 0x20 << 16; + motionReg_[COMMAND] = 0x20 << 16; } else { printf(" ** HOMING REVERSE **\n"); // The -Find Home (CCW) command - motionReg_[0] = 0x40 << 16; + motionReg_[COMMAND] = 0x40 << 16; } // Write all the registers atomically @@ -753,7 +750,7 @@ asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceler asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double acceleration) { asynStatus status; - int velo, distance; + //int velo, distance; static const char *functionName = "ANF2Axis::moveVelocity"; asynPrint(pasynUser_, ASYN_TRACE_FLOW, @@ -780,7 +777,7 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double //printf(" ** positive jog called\n"); // Set cmd register - motionReg_[0] = 0x80 << 16; + motionReg_[COMMAND] = 0x80 << 16; // Do nothing to the velocity @@ -788,7 +785,7 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double //printf(" ** negative jog called\n"); // Set cmd register - motionReg_[0] = 0x100 << 16; + motionReg_[COMMAND] = 0x100 << 16; // ANF2 only accepts speeds > 0 maxVelocity = fabs(maxVelocity); @@ -877,13 +874,14 @@ asynStatus ANF2Axis::setPosition(double position) set_position = NINT(position); zeroRegisters(posReg); - posReg[0] = 0x200 << 16; - posReg[1] = set_position; + posReg[COMMAND] = 0x200 << 16; + posReg[POSITION] = set_position; // Write all the registers atomically status = pC_->writeReg32Array(axisNo_, posReg, 5, DEFAULT_CONTROLLER_TIMEOUT); - epicsThreadSleep(0.20); + // Can this delay be shorter? + epicsThreadSleep(0.2); // The ANG1 driver does this; do we need to? // Clear the command/configuration register @@ -938,6 +936,7 @@ asynStatus ANF2Axis::poll(bool *moving) epicsInt32 read_val; // don't use a pointer here. The _address_ of read_val should be passed to the read function. // Don't do any polling until ALL the axes have been created; this ensures that we don't interpret the configuration values as command values + // This is probably not necessary now that the poller can be started after iocInit if (pC_->axesCreated_ != pC_->numAxes_) { *moving = false; return asynSuccess; @@ -981,16 +980,18 @@ asynStatus ANF2Axis::poll(bool *moving) *moving = done ? false:true; //printf("done is %d\n", done); + // Initialize the direction bit to the last value + status = pC_->getIntegerParam(pC_->motorStatusDirection_, &direction); + // Direction (only set the direction of the controller is moving) if (!done) { if (read_val & 0x1) { direction = 1; - setIntegerParam(pC_->motorStatusDirection_, 1); } - if ((read_val & 0x2) > 1) { + if ((read_val & 0x2) >> 1) { direction = 0; - setIntegerParam(pC_->motorStatusDirection_, 0); } + setIntegerParam(pC_->motorStatusDirection_, direction); } // Check for command errors diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index d7e99cdb..d7bf39d4 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -23,7 +23,7 @@ K. Goetze 2014-03-24 #define AXIS_REG_OFFSET 10 -/*** Input CMD Registers ***/ +/*** Input CMD Registers (16-bit) ***/ #define STATUS_1 0 #define STATUS_2 1 #define POS_RD_UPR 2 @@ -35,17 +35,12 @@ K. Goetze 2014-03-24 // Not used must equal zero #define RESERVED 8 #define NET_CONN 9 -/*** Output CMD Registers ***/ -#define CMD_MSW 0 // module 0 starts at register address 1024. This is set in drvModbusAsynConfigure. -#define CMD_LSW 1 -#define POS_WR_UPR 2 -#define POS_WR_LWR 3 -#define SPD_UPR 4 -#define SPD_LWR 5 -#define ACCEL 6 -#define DECEL 7 -// Not used must equal zero #define RESERVED 8 -// Not used must equal zero #define RESERVED 9 +/*** Output Command Registers (32-bit) ***/ +#define COMMAND 0 +#define POSITION 1 +#define SPEED 2 +#define ACCEL_DECEL 3 +#define CMD_REG_4 4 /*** Output Configuration Registers (32-bit) ***/ #define CONFIGURATION 0 From 16141699d8fcf7ed89986d6fb897158ddf4bd754 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Mon, 9 Apr 2018 13:07:47 -0500 Subject: [PATCH 53/65] Improved report output --- motorApp/AMCISrc/ANF2Driver.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 68425f00..16c6fdd2 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -569,12 +569,13 @@ void ANF2Axis::report(FILE *fp, int level) if (level > 0) { fprintf(fp, "Configuration for axis %i:\n", axisNo_); - fprintf(fp, " Base Speed: %i\tHoming Timeout: %i\n", baseSpeed_, homingTimeout_); - fprintf(fp, " Capture Input: %i\tActive State: %i\n", CaptInput_, CaptInputAS_); - fprintf(fp, " External Input: %i\tActive State: %i\n", ExtInput_, ExtInputAS_); - fprintf(fp, " Home Input: %i\tActive State: %i\n", HomeInput_, HomeInputAS_); - fprintf(fp, " CW Input: %i\tActive State: %i\n", CWInput_, CWInputAS_); - fprintf(fp, " CCW Input: %i\tActive State: %i\n", CCWInput_, CCWInputAS_); + fprintf(fp, " Base Speed: %i\n", baseSpeed_); + fprintf(fp, " Homing Timeout: %i\n", homingTimeout_); + fprintf(fp, " Capture Input: %i (Active State: %i)\n", CaptInput_, CaptInputAS_); + fprintf(fp, " External Input: %i (Active State: %i)\n", ExtInput_, ExtInputAS_); + fprintf(fp, " Home Input: %i (Active State: %i)\n", HomeInput_, HomeInputAS_); + fprintf(fp, " CW Input: %i (Active State: %i)\n", CWInput_, CWInputAS_); + fprintf(fp, " CCW Input: %i (Active State: %i)\n", CCWInput_, CCWInputAS_); fprintf(fp, " Backplane Home Proximity Operation: %i\n", BHPO_); fprintf(fp, " Quadrature Encoder: %i\n", QuadEnc_); fprintf(fp, " Diagnostic Feedback: %i\n", DiagFbk_); From 9b6764b0e044ec0613afe74b0d1ae6eeca2fcc6e Mon Sep 17 00:00:00 2001 From: kpetersn Date: Mon, 9 Apr 2018 13:20:58 -0500 Subject: [PATCH 54/65] Removed reconfig funcationlity (only useful for testing as written). --- motorApp/AMCISrc/ANF2Driver.cpp | 12 ++++++++---- motorApp/AMCISrc/ANF2Driver.h | 9 ++++----- motorApp/Db/ANF2Aux.template | 15 ++++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 16c6fdd2..f45020d9 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -56,7 +56,7 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, // Create controller-specific parameters createParam(ANF2ResetErrorsString, asynParamInt32, &ANF2ResetErrors_); createParam(ANF2GetInfoString, asynParamInt32, &ANF2GetInfo_); - createParam(ANF2ReconfigString, asynParamInt32, &ANF2Reconfig_); + //createParam(ANF2ReconfigString, asynParamInt32, &ANF2Reconfig_); numModules_ = numModules; axesPerModule_ = axesPerModule; @@ -247,10 +247,12 @@ asynStatus ANF2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) pAxis->getInfo(); } + /* } else if (function == ANF2Reconfig_) { // reconfig regardless of the value pAxis->reconfig(value); + */ } else { // Call base class method status = asynMotorController::writeInt32(pasynUser, value); @@ -338,10 +340,9 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 //printf("ANF2Axis::ANF2Axis : pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); /* TODO: - * test config bits and set status bits to prevent methods from sending commands that would generate errors * reduce the sleeps to see which ones are necessary * print out useful info for asyn traces - * make reconfig useful + * make reconfig useful? */ epicsThreadSleep(0.1); @@ -520,6 +521,9 @@ void ANF2Axis::getInfo() } } +/* +// reconfig was used during development. It won't be generally useful without effort. +// It isn't obvious that this is a feature that should exist on-the-fly void ANF2Axis::reconfig(epicsInt32 value) { asynStatus status; @@ -555,7 +559,7 @@ void ANF2Axis::reconfig(epicsInt32 value) epicsThreadSleep(0.05); getInfo(); } - +*/ /** Reports on status of the axis * \param[in] fp The file pointer on which report information will be written diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index d7bf39d4..6cc241bb 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -50,12 +50,12 @@ K. Goetze 2014-03-24 #define CONFIG_REG_4 4 // No. of controller-specific parameters -#define NUM_ANF2_PARAMS 3 +#define NUM_ANF2_PARAMS 2 /** drvInfo strings for extra parameters that the ACR controller supports */ #define ANF2ResetErrorsString "ANF2_RESET_ERRORS" #define ANF2GetInfoString "ANF2_GET_INFO" -#define ANF2ReconfigString "ANF2_RECONFIG" +//#define ANF2ReconfigString "ANF2_RECONFIG" class ANF2Axis : public asynMotorAxis { @@ -79,7 +79,7 @@ private: asynStatus resetErrors(); void getInfo(); epicsInt32 inputReg_[10]; - void reconfig(epicsInt32 value); + //void reconfig(epicsInt32 value); void zeroRegisters(epicsInt32 *reg); asynUser *pasynUserForceRead_; int axisNo_; @@ -134,8 +134,7 @@ public: protected: int ANF2ResetErrors_; /** Reset Errors parameter index */ int ANF2GetInfo_; /**< Get Info parameter index */ - int ANF2Reconfig_; /**< Reconfig parameter index */ - + //int ANF2Reconfig_; /**< Reconfig parameter index */ private: asynStatus writeReg16(int, int, int, double); diff --git a/motorApp/Db/ANF2Aux.template b/motorApp/Db/ANF2Aux.template index aeaeace6..93a255d7 100644 --- a/motorApp/Db/ANF2Aux.template +++ b/motorApp/Db/ANF2Aux.template @@ -18,10 +18,11 @@ record(bo,"$(P)$(R)GetInfo") { field(OUT,"@asyn($(PORT),$(ADDR))ANF2_GET_INFO") } -record(longout,"$(P)$(R)Reconfig") { - field(DESC,"Reconfig") - field(PINI, "0") - field(VAL,"0") - field(DTYP, "asynInt32") - field(OUT,"@asyn($(PORT),$(ADDR))ANF2_RECONFIG") -} +# Reconfig isn't yet implemented in a generally-useful way +#record(longout,"$(P)$(R)Reconfig") { +# field(DESC,"Reconfig") +# field(PINI, "0") +# field(VAL,"0") +# field(DTYP, "asynInt32") +# field(OUT,"@asyn($(PORT),$(ADDR))ANF2_RECONFIG") +#} From 2e49fb473dd6cb779eadb8899af19f0988a987e3 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Mon, 9 Apr 2018 13:25:40 -0500 Subject: [PATCH 55/65] Removed unused getInfo() calls. --- motorApp/AMCISrc/ANF2Driver.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index f45020d9..f4db66cc 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -347,9 +347,6 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 epicsThreadSleep(0.1); - // Read data that is likely to be stale - //getInfo(); - // Clear the command/configuration register (a good thing to do but doesn't appear to be necessary) //status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); @@ -371,9 +368,6 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 // Delay epicsThreadSleep(0.05); - // Read the configuration? Or maybe the command registers? - //getInfo(); - // Parse the configuration (mostly for asynReport purposes) // MSW CaptInput_ = (config & (0x1 << 16)) >> 16; @@ -410,9 +404,6 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 // Delay //epicsThreadSleep(1.0); - // Read the command registers - //getInfo(); - // Tell the driver the axis has been created pC_->axesCreated_ += 1; @@ -545,19 +536,16 @@ void ANF2Axis::reconfig(epicsInt32 value) //confReg[CONFIG_REG_4] = 0x0; epicsThreadSleep(0.05); - getInfo(); // Send the new config status = pC_->writeReg32Array(axisNo_, confReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); epicsThreadSleep(0.05); - getInfo(); // Set the position to clear the invalid position error setPosition(value); epicsThreadSleep(0.05); - getInfo(); } */ @@ -947,8 +935,6 @@ asynStatus ANF2Axis::poll(bool *moving) return asynSuccess; } - //getInfo(); - // Force a read operation //printf(" . . . . . Calling pasynInt32SyncIO->write\n"); //printf("Calling pasynInt32SyncIO->write(pasynUserForceRead_, 1, TIMEOUT), pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); @@ -956,8 +942,6 @@ asynStatus ANF2Axis::poll(bool *moving) //printf(" . . . . . status = %d\n", status); // if status goto end - //getInfo(); - // Read the current motor position // //readReg32(int reg, epicsInt32 *combo, double timeout) From a46564cc3c4316f4e1a95dcca8f9994b4999b3f3 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Mon, 9 Apr 2018 14:41:31 -0500 Subject: [PATCH 56/65] Initialize parameters to avoid asynTraceFlow errors. --- motorApp/AMCISrc/ANF2Driver.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index f4db66cc..57647c3a 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -404,6 +404,14 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 // Delay //epicsThreadSleep(1.0); + // Initialize parameters to avoid ASYN_TRACE_FLOW errors + setIntegerParam(pC_->motorStatusDirection_, 1); + // The following are necessary after this commit: + // https://github.com/epics-modules/motor/commit/36dfab4a78725866fab5bd212c4c128a86e9f044 + setIntegerParam(pC_->motorPowerAutoOnOff_, 0); + setDoubleParam(pC_->motorPowerOnDelay_, 0.0); + setDoubleParam(pC_->motorPowerOffDelay_, 0.0); + // Tell the driver the axis has been created pC_->axesCreated_ += 1; From dad0f34037c5c8e458a4728066a55d41301345fd Mon Sep 17 00:00:00 2001 From: kpetersn Date: Tue, 17 Apr 2018 16:51:53 -0500 Subject: [PATCH 57/65] Print somewhat helpful info in asyn traces. --- motorApp/AMCISrc/ANF2Driver.cpp | 65 +++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 57647c3a..d474ff85 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -274,8 +274,13 @@ asynStatus ANF2Controller::writeInt32(asynUser *pasynUser, epicsInt32 value) asynStatus ANF2Controller::writeReg32Array(int axisNo, epicsInt32* output, int nElements, double timeout) { asynStatus status; - - asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"writeReg32Array: writing %d elements starting for axis %d\n", nElements, axisNo); + ANF2Axis *pAxis = getAxis(axisNo); + static const char *functionName = "ANF2Controller::writeReg32Array"; + + // This message isn't very helpful. Print something better in the future. + asynPrint(pAxis->pasynUser_, ASYN_TRACEIO_DRIVER, + "%s: axisNo=%i, nElements=%d\n", + functionName, axisNo, nElements); status = pasynInt32ArraySyncIO->write(pasynUserOutReg_[axisNo], output, nElements, timeout); return status; @@ -286,7 +291,7 @@ asynStatus ANF2Controller::readReg16(int axisNo, int axisReg, epicsInt32 *input, asynStatus status; //printf("axisReg = %d\n", axisReg); - asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"readReg16 reg = %d\n", axisReg); + //asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,"readReg16 reg = %d\n", axisReg); status = pasynInt32SyncIO->read(pasynUserInReg_[axisNo][axisReg], input, timeout); return status ; @@ -325,7 +330,7 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 int status; axisNo_ = axisNo; - //this->axisNo_ = axisNo; + config_ = config; baseSpeed_ = baseSpeed; homingTimeout_ = homingTimeout; @@ -337,11 +342,9 @@ ANF2Axis::ANF2Axis(ANF2Controller *pC, int axisNo, epicsInt32 config, epicsInt32 //printf("%s:%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver %s\n", pC_->inputDriver_, pC_->functionName, myModbusInputDriver); printf("%s: Error, unable to connect pasynUserForceRead_ to Modbus input driver\n", pC_->inputDriver_); } - //printf("ANF2Axis::ANF2Axis : pasynUserForceRead_->reason=%d\n", pasynUserForceRead_->reason); /* TODO: * reduce the sleeps to see which ones are necessary - * print out useful info for asyn traces * make reconfig useful? */ @@ -491,7 +494,9 @@ asynStatus ANF2Axis::resetErrors() { asynStatus status; epicsInt32 errorReg[5]; - //static const char *functionName = "ANF2Axis::resetErrors"; + static const char *functionName = "ANF2Axis::resetErrors"; + + asynPrint(pasynUser_, ASYN_TRACEIO_DRIVER, "%s: axisNo=%i\n", functionName, axisNo_); zeroRegisters(errorReg); @@ -568,7 +573,7 @@ void ANF2Axis::report(FILE *fp, int level) // TODO: make this more useful if (level > 0) { - fprintf(fp, "Configuration for axis %i:\n", axisNo_); + fprintf(fp, "Configuration for axis %i [0x%x]:\n", axisNo_, config_); fprintf(fp, " Base Speed: %i\n", baseSpeed_); fprintf(fp, " Homing Timeout: %i\n", homingTimeout_); fprintf(fp, " Capture Input: %i (Active State: %i)\n", CaptInput_, CaptInputAS_); @@ -584,11 +589,6 @@ void ANF2Axis::report(FILE *fp, int level) fprintf(fp, " Card Axis: %i\n", CardAxis_); fprintf(fp, " Operation Mode for Axis: %i\n", OpMode_); fprintf(fp, "\n"); - - /*fprintf(fp, " axis %d\n", axisNo_); - fprintf(fp, " this->axisNo_ %i\n", this->axisNo_); - fprintf(fp, " this->config_ %x\n", this->config_); - fprintf(fp, " config_ %x\n", config_);*/ } //printf("ANF2Axis::report -> BEFORE asynMotorAxis::report!!\n"); @@ -603,7 +603,7 @@ void ANF2Axis::report(FILE *fp, int level) // SET VEL & ACCEL asynStatus ANF2Axis::sendAccelAndVelocity(double acceleration, double velocity) { - // static const char *functionName = "ANF2::sendAccelAndVelocity"; + // static const char *functionName = "ANF2Axis::sendAccelAndVelocity"; // ANF2 speed range is 1 to 1,000,000 steps/sec if (velocity > 1000000.0) { @@ -646,12 +646,14 @@ double ANF2Axis::correctAccel(double minVelocity, double maxVelocity, double acc { double accelTime; double newAccel; + static const char *functionName = "ANF2Axis::correctAccel"; accelTime = (maxVelocity - minVelocity) / acceleration; newAccel = (maxVelocity - (double)baseSpeed_) / accelTime; - //printf("old acceleration = %lf\n", acceleration); - //printf("new acceleration = %lf\n", newAccel); + asynPrint(pasynUser_, ASYN_TRACEIO_DRIVER, + "%s: axisNo=%i, old acceleration=%lf, new acceleration=%lf\n", + functionName, axisNo_, acceleration, newAccel); return newAccel; } @@ -662,8 +664,11 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou { asynStatus status; epicsInt32 posInt; - - //printf(" ** ANF2Axis::move called, relative = %d, axisNo_ = %i\n", relative, this->axisNo_); + static const char *functionName = "ANF2Axis::move"; + + asynPrint(pasynUser_, ASYN_TRACEIO_DRIVER, + "%s: axisNo=%i, relative=%i, minVelocity=%f, maxVelocity=%f, acceleration=%f\n", + functionName, axisNo_, relative, minVelocity, maxVelocity, acceleration); // Clear the command/configuration register status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); @@ -714,7 +719,11 @@ asynStatus ANF2Axis::move(double position, int relative, double minVelocity, dou asynStatus ANF2Axis::home(double minVelocity, double maxVelocity, double acceleration, int forwards) { asynStatus status; - // static const char *functionName = "ANF2Axis::home"; + static const char *functionName = "ANF2Axis::home"; + + asynPrint(pasynUser_, ASYN_TRACEIO_DRIVER, + "%s: axisNo=%i, forwards=%i, minVelocity=%f, maxVelocity=%f, acceleration=%f\n", + functionName, axisNo_, forwards, minVelocity, maxVelocity, acceleration); // Clear the command/configuration register status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); @@ -754,9 +763,9 @@ asynStatus ANF2Axis::moveVelocity(double minVelocity, double maxVelocity, double //int velo, distance; static const char *functionName = "ANF2Axis::moveVelocity"; - asynPrint(pasynUser_, ASYN_TRACE_FLOW, - "%s: minVelocity=%f, maxVelocity=%f, acceleration=%f\n", - functionName, minVelocity, maxVelocity, acceleration); + asynPrint(pasynUser_, ASYN_TRACEIO_DRIVER, + "%s: axisNo=%d, minVelocity=%f, maxVelocity=%f, acceleration=%f\n", + functionName, axisNo_, minVelocity, maxVelocity, acceleration); // // The jog command requires a different stop than a move command @@ -826,7 +835,9 @@ asynStatus ANF2Axis::stop(double acceleration) { asynStatus status; epicsInt32 stopReg; - //static const char *functionName = "ANF2Axis::stop"; + static const char *functionName = "ANF2Axis::stop"; + + asynPrint(pasynUser_, ASYN_TRACEIO_DRIVER, "%s: axisNo=%i\n", functionName, axisNo_); //printf("\n STOP \n\n"); @@ -863,9 +874,9 @@ asynStatus ANF2Axis::setPosition(double position) asynStatus status; epicsInt32 set_position; epicsInt32 posReg[5]; - //static const char *functionName = "ANF2Axis::setPosition"; + static const char *functionName = "ANF2Axis::setPosition"; - //printf("setPosition(%lf) for axisNo_=%i\n", position, axisNo_); + asynPrint(pasynUser_, ASYN_TRACEIO_DRIVER, "%s: axisNo=%i, position=%lf\n", functionName, axisNo_, position); // Clear the command/configuration register status = pC_->writeReg32Array(axisNo_, zeroReg_, 5, DEFAULT_CONTROLLER_TIMEOUT); @@ -951,15 +962,13 @@ asynStatus ANF2Axis::poll(bool *moving) // if status goto end // Read the current motor position - // - //readReg32(int reg, epicsInt32 *combo, double timeout) status = pC_->readReg32(axisNo_, POS_RD_UPR, &read_val, DEFAULT_CONTROLLER_TIMEOUT); //printf("ANF2Axis::poll: Motor position raw: %d\n", read_val); position = (double) read_val; setDoubleParam(pC_->motorPosition_, position); //printf("ANF2Axis::poll: Motor #%i position: %f\n", axisNo_, position); - // TODO: read encoder position + // Read encoder position status = pC_->readReg32(axisNo_, EN_POS_UPR, &read_val, DEFAULT_CONTROLLER_TIMEOUT); //printf("ANF2Axis::poll: Motor encoder position raw: %d\n", read_val); encPosition = (double) read_val; From 17a8fa08a94721ba2953dd7b62f7f29a8a8edd39 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 18 Apr 2018 11:26:13 -0500 Subject: [PATCH 58/65] Added ANF2 example config --- iocBoot/iocWithAsyn/motor.cmd.ANF2 | 108 +++++++++++++++++++ iocBoot/iocWithAsyn/motor.substitutions.ANF2 | 54 ++++++++++ 2 files changed, 162 insertions(+) create mode 100644 iocBoot/iocWithAsyn/motor.cmd.ANF2 create mode 100644 iocBoot/iocWithAsyn/motor.substitutions.ANF2 diff --git a/iocBoot/iocWithAsyn/motor.cmd.ANF2 b/iocBoot/iocWithAsyn/motor.cmd.ANF2 new file mode 100644 index 00000000..9e3da72c --- /dev/null +++ b/iocBoot/iocWithAsyn/motor.cmd.ANF2 @@ -0,0 +1,108 @@ +# ANF2 motors command file example (run in iocsh) +# +### Note: Modbus support (the EPICS modbus module) is required to be included in the +### EPICS application where the ANF2 support will be loaded. This file is an +### example of how to load the ANF2 support, in an ioc that is built with the +### EPICS modbus module. + +epicsEnvSet("PORT1", "ANF2_C1") +epicsEnvSet("PORT2", "ANF2_C2") + +# drvAsynIPPortConfigure("portName", "hostInfo", priority, noAutoConnect, noProcessEos); +drvAsynIPPortConfigure("$(PORT1)_IP","192.168.1.101:502",0,0,1) +drvAsynIPPortConfigure("$(PORT2)_IP","192.168.1.102:502",0,0,1) + +# modbusInterposeConfig("portName", linkType, timeoutMsec, writeDelayMsec) +modbusInterposeConfig("$(PORT1)_IP",0,2000,0) +modbusInterposeConfig("$(PORT2)_IP",0,2000,0) + +# NOTE: modbusLength = 10 * number of axes +# drvModbusAsynConfigure("portName", "tcpPortName", slaveAddress, modbusFunction, +# modbusStartAddress, modbusLength, dataType, pollMsec, "plcType") +drvModbusAsynConfigure("$(PORT1)_In", "$(PORT1)_IP", 0, 4, 0, 120, 0, 100, "ANF2_stepper") +drvModbusAsynConfigure("$(PORT2)_In", "$(PORT2)_IP", 0, 4, 0, 60, 0, 100, "ANF2_stepper") + +# NOTE: modbusLength = 10 * number of axes +# drvModbusAsynConfigure("portName", "tcpPortName", slaveAddress, modbusFunction, +# modbusStartAddress, modbusLength, dataType, pollMsec, "plcType") +drvModbusAsynConfigure("$(PORT1)_Out", "$(PORT1)_IP", 0, 16, 1024, 120, 6, 1, "ANF2_stepper") +drvModbusAsynConfigure("$(PORT2)_Out", "$(PORT2)_IP", 0, 16, 1024, 60, 6, 1, "ANF2_stepper") + +# Asyn traces for debugging +#!asynSetTraceIOMask "$(PORT1)_In",0,4 +#!asynSetTraceMask "$(PORT1)_In",0,9 +#!asynSetTraceIOMask "$(PORT1)_Out",0,4 +#!asynSetTraceMask "$(PORT1)_Out",0,9 +#!asynSetTraceInfoMask "$(PORT1)_Out",0,15 + +# Asyn records for debugging +#!dbLoadRecords("$(ASYN)/db/asynRecord.db","P=IOC:,R=asyn:c1ip,PORT=$(PORT1)_IP,ADDR=0,OMAX=256,IMAX=256") +#!dbLoadRecords("$(ASYN)/db/asynRecord.db","P=IOC:,R=asyn:c1in,PORT=$(PORT1)_In,ADDR=0,OMAX=256,IMAX=256") +#!dbLoadRecords("$(ASYN)/db/asynRecord.db","P=IOC:,R=asyn:c1out,PORT=$(PORT1)_Out,ADDR=0,OMAX=256,IMAX=256") +#!dbLoadRecords("$(ASYN)/db/asynRecord.db","P=IOC:,R=asyn:c1,PORT=$(PORT1),ADDR=0,OMAX=256,IMAX=256") + +# Load the motor records +dbLoadTemplate("templates/motor.substitutions.ANF2") + +# AMCI ANF2 stepper controller driver support +# +# ANF2CreateController( +# portName, The name of the asyn port that will be created by this driver +# ANF2InPortName, The name of the In drvAsynIPPPort to read from the ANF2 controller +# ANF2OutPortName, The name of the Out drvAsynIPPPort to write to the ANF2 controller +# numModules, The number of modules in the stack (Max=6) +# axesPerModule) The number of axes per module (ANF1=1, ANF2=2) +# +# ANF2CreateAxis( +# ANF2Name, The controller's asyn port +# axis, The axis to be configured (zero-based numbering) +# hexConfig, The desired hex configuration (see manual & AMCI Net Configurator for details) +# baseSpeed, The base speed (steps/second; min=1, max=1,000,000) +# homingTimeout) The homing timeout (integer number of seconds; min=0, max=300) +# +# Note: The base speed can't be changed using the VBAS field of the motor record, but the driver +# does correct the acceleration sent by the motor record to give the desired acceleration time. + +# Controller 1 (One ANF2E, Five ANF2's) +ANF2CreateController("$(PORT1)", "$(PORT1)_In", "$(PORT1)_Out", 6, 2) +# Axes for Controller 1 +ANF2CreateAxis("$(PORT1)", 0, "0x86280000", 100, 0) +ANF2CreateAxis("$(PORT1)", 1, "0x86000000", 57, 32) +ANF2CreateAxis("$(PORT1)", 2, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT1)", 3, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT1)", 4, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT1)", 5, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT1)", 6, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT1)", 7, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT1)", 8, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT1)", 9, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT1)", 10, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT1)", 11, "0x84000000", 100, 0) + +# Controller 2 (One ANF1E, Five ANF1's) +ANF2CreateController("$(PORT2)", "$(PORT2)_In", "$(PORT2)_Out", 6, 1) +# Axes for Controller 2 +ANF2CreateAxis("$(PORT2)", 0, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT2)", 1, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT2)", 2, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT2)", 3, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT2)", 4, "0x84000000", 100, 0) +ANF2CreateAxis("$(PORT2)", 5, "0x84000000", 100, 0) + +# NOTE: the poller needs to be started after iocInit + + + +########## +# iocInit +########## + + + +# ANF2StartPoller( +# portName, The controller's asyn port +# movingPollPeriod, The time in ms between polls when any axis is moving +# idlePollPeriod) The time in ms between polls when no axis is moving +# +ANF2StartPoller("$(PORT1)", 200, 1000) +ANF2StartPoller("$(PORT2)", 200, 1000) diff --git a/iocBoot/iocWithAsyn/motor.substitutions.ANF2 b/iocBoot/iocWithAsyn/motor.substitutions.ANF2 new file mode 100644 index 00000000..a29a9eb5 --- /dev/null +++ b/iocBoot/iocWithAsyn/motor.substitutions.ANF2 @@ -0,0 +1,54 @@ +file "$(MOTOR)/motorApp/Db/asyn_motor.db" +{ +pattern +{P, M, DTYP, PORT, ADDR, DESC, EGU, DIR, VELO, VBAS, ACCL, BDST, BVEL, BACC, MRES, PREC, DHLM, DLLM, INIT, RTRY} + +{IOC:, "m1", "asynMotor", "ANF2_C1", 0, "ANF2 C1 M1", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m2", "asynMotor", "ANF2_C1", 1, "ANF2 C1 M2", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m3", "asynMotor", "ANF2_C1", 2, "ANF2 C1 M3", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m4", "asynMotor", "ANF2_C1", 3, "ANF2 C1 M4", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m5", "asynMotor", "ANF2_C1", 4, "ANF2 C1 M5", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m6", "asynMotor", "ANF2_C1", 5, "ANF2 C1 M6", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m7", "asynMotor", "ANF2_C1", 6, "ANF2 C1 M7", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m8", "asynMotor", "ANF2_C1", 7, "ANF2 C1 M8", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m9", "asynMotor", "ANF2_C1", 8, "ANF2 C1 M9", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m10", "asynMotor", "ANF2_C1", 9, "ANF2 C1 M10", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m11", "asynMotor", "ANF2_C1", 10, "ANF2 C1 M11", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m12", "asynMotor", "ANF2_C1", 11, "ANF2 C1 M12", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} + +{IOC:, "m13", "asynMotor", "ANF2_C2", 0, "ANF2 C2 M1", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m14", "asynMotor", "ANF2_C2", 1, "ANF2 C2 M2", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m15", "asynMotor", "ANF2_C2", 2, "ANF2 C2 M3", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m16", "asynMotor", "ANF2_C2", 3, "ANF2 C2 M4", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m17", "asynMotor", "ANF2_C2", 4, "ANF2 C2 M5", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} +{IOC:, "m18", "asynMotor", "ANF2_C2", 5, "ANF2 C2 M6", steps, Pos, 100, 0, .2, 0, 50, .2, 1, 5, 1e9, -1e9, ""} + +} + +file "$(MOTOR)/motorApp/Db/ANF2Aux.template" +{ +pattern +{P, R, PORT, ADDR} + +{IOC:, m1:, "ANF2_C1", 0} +{IOC:, m2:, "ANF2_C1", 1} +{IOC:, m3:, "ANF2_C1", 2} +{IOC:, m4:, "ANF2_C1", 3} +{IOC:, m5:, "ANF2_C1", 4} +{IOC:, m6:, "ANF2_C1", 5} +{IOC:, m7:, "ANF2_C1", 6} +{IOC:, m8:, "ANF2_C1", 7} +{IOC:, m9:, "ANF2_C1", 8} +{IOC:, m10:, "ANF2_C1", 9} +{IOC:, m11:, "ANF2_C1", 10} +{IOC:, m12:, "ANF2_C1", 11} + +{IOC:, m13:, "ANF2_C2", 0} +{IOC:, m14:, "ANF2_C2", 1} +{IOC:, m15:, "ANF2_C2", 2} +{IOC:, m16:, "ANF2_C2", 3} +{IOC:, m17:, "ANF2_C2", 4} +{IOC:, m18:, "ANF2_C2", 5} + +} + From 28a642cf798f09f010c6134a3342aee06964a080 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 18 Apr 2018 11:42:30 -0500 Subject: [PATCH 59/65] Use the default IP address provided at the factory. --- iocBoot/iocWithAsyn/motor.cmd.ANF2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iocBoot/iocWithAsyn/motor.cmd.ANF2 b/iocBoot/iocWithAsyn/motor.cmd.ANF2 index 9e3da72c..de8248a7 100644 --- a/iocBoot/iocWithAsyn/motor.cmd.ANF2 +++ b/iocBoot/iocWithAsyn/motor.cmd.ANF2 @@ -9,8 +9,8 @@ epicsEnvSet("PORT1", "ANF2_C1") epicsEnvSet("PORT2", "ANF2_C2") # drvAsynIPPortConfigure("portName", "hostInfo", priority, noAutoConnect, noProcessEos); -drvAsynIPPortConfigure("$(PORT1)_IP","192.168.1.101:502",0,0,1) -drvAsynIPPortConfigure("$(PORT2)_IP","192.168.1.102:502",0,0,1) +drvAsynIPPortConfigure("$(PORT1)_IP","192.168.0.50:502",0,0,1) +drvAsynIPPortConfigure("$(PORT2)_IP","192.168.0.51:502",0,0,1) # modbusInterposeConfig("portName", linkType, timeoutMsec, writeDelayMsec) modbusInterposeConfig("$(PORT1)_IP",0,2000,0) From c5316018b90d5eb32a8b080e9cf46d2508af3287 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 18 Apr 2018 14:41:19 -0500 Subject: [PATCH 60/65] Only require user to specify numAxes so any combination of controller modules can be used. --- iocBoot/iocWithAsyn/motor.cmd.ANF2 | 9 +++---- motorApp/AMCISrc/ANF2Driver.cpp | 41 ++++++++++-------------------- motorApp/AMCISrc/ANF2Driver.h | 9 +++---- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/iocBoot/iocWithAsyn/motor.cmd.ANF2 b/iocBoot/iocWithAsyn/motor.cmd.ANF2 index de8248a7..f501ae27 100644 --- a/iocBoot/iocWithAsyn/motor.cmd.ANF2 +++ b/iocBoot/iocWithAsyn/motor.cmd.ANF2 @@ -50,8 +50,7 @@ dbLoadTemplate("templates/motor.substitutions.ANF2") # portName, The name of the asyn port that will be created by this driver # ANF2InPortName, The name of the In drvAsynIPPPort to read from the ANF2 controller # ANF2OutPortName, The name of the Out drvAsynIPPPort to write to the ANF2 controller -# numModules, The number of modules in the stack (Max=6) -# axesPerModule) The number of axes per module (ANF1=1, ANF2=2) +# numAxes) The number of axes in the stack (max=12) # # ANF2CreateAxis( # ANF2Name, The controller's asyn port @@ -64,10 +63,10 @@ dbLoadTemplate("templates/motor.substitutions.ANF2") # does correct the acceleration sent by the motor record to give the desired acceleration time. # Controller 1 (One ANF2E, Five ANF2's) -ANF2CreateController("$(PORT1)", "$(PORT1)_In", "$(PORT1)_Out", 6, 2) +ANF2CreateController("$(PORT1)", "$(PORT1)_In", "$(PORT1)_Out", 12) # Axes for Controller 1 ANF2CreateAxis("$(PORT1)", 0, "0x86280000", 100, 0) -ANF2CreateAxis("$(PORT1)", 1, "0x86000000", 57, 32) +ANF2CreateAxis("$(PORT1)", 1, "0x86000000", 100, 0) ANF2CreateAxis("$(PORT1)", 2, "0x84000000", 100, 0) ANF2CreateAxis("$(PORT1)", 3, "0x84000000", 100, 0) ANF2CreateAxis("$(PORT1)", 4, "0x84000000", 100, 0) @@ -80,7 +79,7 @@ ANF2CreateAxis("$(PORT1)", 10, "0x84000000", 100, 0) ANF2CreateAxis("$(PORT1)", 11, "0x84000000", 100, 0) # Controller 2 (One ANF1E, Five ANF1's) -ANF2CreateController("$(PORT2)", "$(PORT2)_In", "$(PORT2)_Out", 6, 1) +ANF2CreateController("$(PORT2)", "$(PORT2)_In", "$(PORT2)_Out", 6) # Axes for Controller 2 ANF2CreateAxis("$(PORT2)", 0, "0x84000000", 100, 0) ANF2CreateAxis("$(PORT2)", 1, "0x84000000", 100, 0) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index d474ff85..83d258cd 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -32,12 +32,11 @@ static const char *driverName = "ANF2MotorDriver"; * \param[in] portName The name of the asyn port that will be created for this driver * \param[in] ANF2InPortName The name of the drvAsynSerialPort that was created previously to connect to the ANF2 controller * \param[in] ANF2OutPortName The name of the drvAsynSerialPort that was created previously to connect to the ANF2 controller - * \param[in] numModules The number of modules on the controller stack - * \param[in] axesPerModule The number of axes per module (ANF1=1, ANF2=2) + * \param[in] numAxes The number of axes on the controller stack */ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, - int numModules, int axesPerModule) - : asynMotorController(portName, (numModules*axesPerModule), NUM_ANF2_PARAMS, + int numAxes) + : asynMotorController(portName, numAxes, NUM_ANF2_PARAMS, asynInt32ArrayMask, // One additional interface beyond those in base class asynInt32ArrayMask, // One additional callback interface beyond those in base class ASYN_CANBLOCK | ASYN_MULTIDEVICE, @@ -58,9 +57,7 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, createParam(ANF2GetInfoString, asynParamInt32, &ANF2GetInfo_); //createParam(ANF2ReconfigString, asynParamInt32, &ANF2Reconfig_); - numModules_ = numModules; - axesPerModule_ = axesPerModule; - numAxes_ = numModules * axesPerModule; + numAxes_ = numAxes; for (j=0; j MAX_MODULES) { - numModules = MAX_MODULES; - } - if (axesPerModule > MAX_AXES_PER_MODULE) { - axesPerModule = MAX_AXES_PER_MODULE; + if (numAxes > MAX_AXES) { + numAxes = MAX_AXES; } - /* - ANF2Controller *pANF2Controller - = new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numModules, axesPerModule); - pANF2Controller = NULL; - */ - new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numModules, axesPerModule); + new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numAxes); return(asynSuccess); } @@ -1047,17 +1034,15 @@ asynStatus ANF2Axis::poll(bool *moving) static const iocshArg ANF2CreateControllerArg0 = {"Port name", iocshArgString}; static const iocshArg ANF2CreateControllerArg1 = {"ANF2 In port name", iocshArgString}; static const iocshArg ANF2CreateControllerArg2 = {"ANF2 Out port name", iocshArgString}; -static const iocshArg ANF2CreateControllerArg3 = {"Number of modules", iocshArgInt}; -static const iocshArg ANF2CreateControllerArg4 = {"Axes per module", iocshArgInt}; +static const iocshArg ANF2CreateControllerArg3 = {"Number of axes", iocshArgInt}; static const iocshArg * const ANF2CreateControllerArgs[] = {&ANF2CreateControllerArg0, &ANF2CreateControllerArg1, &ANF2CreateControllerArg2, - &ANF2CreateControllerArg3, - &ANF2CreateControllerArg4}; -static const iocshFuncDef ANF2CreateControllerDef = {"ANF2CreateController", 5, ANF2CreateControllerArgs}; + &ANF2CreateControllerArg3}; +static const iocshFuncDef ANF2CreateControllerDef = {"ANF2CreateController", 4, ANF2CreateControllerArgs}; static void ANF2CreateControllerCallFunc(const iocshArgBuf *args) { - ANF2CreateController(args[0].sval, args[1].sval, args[2].sval, args[3].ival, args[4].ival); + ANF2CreateController(args[0].sval, args[1].sval, args[2].sval, args[3].ival); } /* ANF2StartPoller */ diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 6cc241bb..3949e664 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -15,8 +15,7 @@ K. Goetze 2014-03-24 //#include #include -#define MAX_MODULES 6 -#define MAX_AXES_PER_MODULE 2 +#define MAX_AXES 12 #define MAX_INPUT_REGS 10 #define MAX_OUTPUT_REGS 10 @@ -115,14 +114,14 @@ friend class ANF2Controller; class ANF2Controller : public asynMotorController { public: - ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numModules, int axesPerModule); + ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes); void doStartPoller(double movingPollPeriod, double idlePollPeriod); void report(FILE *fp, int level); ANF2Axis* getAxis(asynUser *pasynUser); ANF2Axis* getAxis(int axisNo); - asynUser *pasynUserInReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_INPUT_REGS]; - asynUser *pasynUserOutReg_[MAX_MODULES*MAX_AXES_PER_MODULE]; + asynUser *pasynUserInReg_[MAX_AXES][MAX_INPUT_REGS]; + asynUser *pasynUserOutReg_[MAX_AXES]; /* These are the methods that we override from asynMotorDriver */ asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); From 12c6237ef113ac643bed4c6b6e44e56e2e77baf5 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 18 Apr 2018 15:23:22 -0500 Subject: [PATCH 61/65] Added README_ANF2.md --- motorApp/AMCISrc/README_ANF2.md | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 motorApp/AMCISrc/README_ANF2.md diff --git a/motorApp/AMCISrc/README_ANF2.md b/motorApp/AMCISrc/README_ANF2.md new file mode 100644 index 00000000..b867e0b0 --- /dev/null +++ b/motorApp/AMCISrc/README_ANF2.md @@ -0,0 +1,71 @@ +# AMCI ANF2 + +Asyn model 3 driver support for the AMCI ANF2 stepper motor controller + +Modbus/TCP communication, using Mark Rivers' modbus module + +## Supported Controller Models + +The following ANF controller versions are supported: + +ANF1E: 1-axis stepper controller, modbus tcp/ip +ANF1: 1-axis stepper controller, no network interface +ANF2E: 2-axis stepper controller, modbus tcp/ip +ANF2: 2-axis stepper controller, no network interface + +A stack of controller can contain up to 6 modules, one of +which needs to have the ethernet option. A single-channel +implementation would need the module with ethernet. + +## Vendor Software + +ANF2 configuration software is available from AMCI's website: + +www.amci.com/product-software.asp + +Note: The AMCI Net Configurator only works (allows a motor to be moved) if +the controller is configured for EtherNet/IP, however, the EPICS support +requires the device to be configured for Modbus-TCP. + +## Controller Quirks + +* The controller doesn't allow absolute moves when a limit is active; +The only way to move a motor off of a limit is by jogging. + +* The base speed is set when an axis is configured. This driver corrects +the acceleration sent by the motor record (VBAS isn't guaranteed to match +the base speed) and sends the acceleration necessary to achieve the desired +acceleration time. + +* The controller doesn't remember its configuration after it is power-cycled. + +* Sending the configuration to the controller invalidates the position +requiring either a home search or the redefinition of the current position. + +* The configuration can't be read after a configuration is accepted by the +controller, after which it automatically switches into command mode. + +* The command to stop an abosolute move generates an error if a jog is in +progress. The command to stop a jog doesn't stop an absolute move. + +## Controller Configuration + +The AMCI Net Configurator can be used to: + +* Change the ip address from the default (192.168.0.50) + +* Change the protocol to Modbus-TCP + +* Determine hex config strings for each axis + +### Example hex configurations + +The AMCI Net Configurator can be used to generate hex configurations. Here are some example: +``` +0x86000000 - Step & Direction pulses, Diagnostic Feedback, No home switch, No limits +0x86280000 - Step & Direction pulses, Diagnostic Feedback, No home switch, Active-low CW/CCW limits +0x84000000 - Step & Direction pulses, No Feedback, No home switch, No Limits +0x84280000 - Step & Direction pulses, No Feedback, No home switch, Active-low CW/CCW limits +0x842C0004 - Step & Direction pulses, No Feedback, Active-high home switch, Active-low CW/CCW limits +0x85280000 - Step & Direction pulses, Quadrature Feedback, No home switch, Active-low CW/CCW limits +``` From 35f5cf08496ca4b86b5188e0d186b9484d6e3f05 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 18 Apr 2018 15:26:49 -0500 Subject: [PATCH 62/65] Minor improvements to README_ANF2.md --- motorApp/AMCISrc/README_ANF2.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/motorApp/AMCISrc/README_ANF2.md b/motorApp/AMCISrc/README_ANF2.md index b867e0b0..f72ca191 100644 --- a/motorApp/AMCISrc/README_ANF2.md +++ b/motorApp/AMCISrc/README_ANF2.md @@ -7,12 +7,12 @@ Modbus/TCP communication, using Mark Rivers' modbus module ## Supported Controller Models The following ANF controller versions are supported: - +``` ANF1E: 1-axis stepper controller, modbus tcp/ip ANF1: 1-axis stepper controller, no network interface ANF2E: 2-axis stepper controller, modbus tcp/ip ANF2: 2-axis stepper controller, no network interface - +``` A stack of controller can contain up to 6 modules, one of which needs to have the ethernet option. A single-channel implementation would need the module with ethernet. @@ -30,7 +30,7 @@ requires the device to be configured for Modbus-TCP. ## Controller Quirks * The controller doesn't allow absolute moves when a limit is active; -The only way to move a motor off of a limit is by jogging. +The only way to move a motor off of a limit is by **jogging**. * The base speed is set when an axis is configured. This driver corrects the acceleration sent by the motor record (VBAS isn't guaranteed to match @@ -58,9 +58,8 @@ The AMCI Net Configurator can be used to: * Determine hex config strings for each axis -### Example hex configurations +### Example axis configuration -The AMCI Net Configurator can be used to generate hex configurations. Here are some example: ``` 0x86000000 - Step & Direction pulses, Diagnostic Feedback, No home switch, No limits 0x86280000 - Step & Direction pulses, Diagnostic Feedback, No home switch, Active-low CW/CCW limits From c13b1b43ab52142b5e6485da5e904f5fb1529fae Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 18 Apr 2018 15:32:43 -0500 Subject: [PATCH 63/65] Added AMCI controllers to motorRecord.html --- documentation/motorRecord.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/documentation/motorRecord.html b/documentation/motorRecord.html index 95301a19..9ded5f88 100644 --- a/documentation/motorRecord.html +++ b/documentation/motorRecord.html @@ -117,6 +117,9 @@ Channel support):
  • Phytron I1AM01 Stepper Motor Controller.
  • +
  • + AMCI ANG1 Stepper Motor Controller/Driver, ANF1E/ANF1/ANF2E/ANF2 Stepper Motor Controllers. +
  • The record maintains two coordinate systems for motor position ("user" and "dial " coordinates); displays drive and readback values; enforces limits to motor From a827730f7151b1b4cbca97356f9d69501bf67859 Mon Sep 17 00:00:00 2001 From: kpetersn Date: Wed, 18 Apr 2018 15:39:57 -0500 Subject: [PATCH 64/65] Updated the comment in the .h file. --- motorApp/AMCISrc/ANF2Driver.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/motorApp/AMCISrc/ANF2Driver.h b/motorApp/AMCISrc/ANF2Driver.h index 3949e664..97e7d841 100644 --- a/motorApp/AMCISrc/ANF2Driver.h +++ b/motorApp/AMCISrc/ANF2Driver.h @@ -2,11 +2,9 @@ FILENAME... ANF2Driver.h USAGE... Motor driver support for the AMCI ANF2 controller. -Based on MCB-4B driver written by -Mark Rivers -March 1, 2012 +Kevin Peterson -K. Goetze 2014-03-24 +Based on the AMCI ANG1 Model 3 device driver written by Kurt Goetze */ From ed95506bb1ea8b4f838412c3374ba32ca84f7870 Mon Sep 17 00:00:00 2001 From: Kevin Peterson Date: Thu, 19 Apr 2018 11:09:28 -0500 Subject: [PATCH 65/65] Fix for building on Windows --- motorApp/AMCISrc/ANF2Driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 83d258cd..993a0a46 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -140,7 +140,7 @@ void ANF2Controller::doStartPoller(double movingPollPeriod, double idlePollPerio void ANF2Controller::report(FILE *fp, int level) { int i, j; - ANF2Axis* pAxis[numAxes_]; + ANF2Axis* pAxis[MAX_AXES]; fprintf(fp, "====================================\n"); fprintf(fp, "ANF2 motor driver:\n");