diff --git a/iocBoot/iocNewFocus874x/Makefile b/iocBoot/iocNewFocus874x/Makefile new file mode 100644 index 00000000..6512ead1 --- /dev/null +++ b/iocBoot/iocNewFocus874x/Makefile @@ -0,0 +1,6 @@ +TOP = ../.. +include $(TOP)/configure/CONFIG +ARCH = linux-x86_64 +TARGETS += envPaths +include $(TOP)/configure/RULES.ioc + diff --git a/iocBoot/iocNewFocus874x/newfocus8742.asyn.motor.substitutions b/iocBoot/iocNewFocus874x/newfocus8742.asyn.motor.substitutions new file mode 100644 index 00000000..cbc5b8ab --- /dev/null +++ b/iocBoot/iocNewFocus874x/newfocus8742.asyn.motor.substitutions @@ -0,0 +1,8 @@ +file "$(MOTOR)/db/basic_asyn_motor.db" +{ +pattern +{P, N, M, DTYP, PORT, ADDR, C, S, DESC, EGU, DIR, VELO, VBAS, ACCL, BDST, BVEL, BACC, MRES, PREC, DHLM, DLLM, INIT} +{IOC:, 1, "X", "asynMotor", M0, 1, 0, 0, "X", counts, Pos, 100, 25, 1, 0, 0, 50, 1, 0, 0, 0, ""} +{IOC:, 2, "Y", "asynMotor", M0, 2, 0, 0, "Y", counts, Pos, 100, 25, 1, 0, 0, 50, 1, 0, 0, 0, ""} +} + diff --git a/iocBoot/iocNewFocus874x/newfocus8742.asyn.st.cmd.linux-x86 b/iocBoot/iocNewFocus874x/newfocus8742.asyn.st.cmd.linux-x86 new file mode 100644 index 00000000..5aebfe7d --- /dev/null +++ b/iocBoot/iocNewFocus874x/newfocus8742.asyn.st.cmd.linux-x86 @@ -0,0 +1,67 @@ +#!../../bin/linux-x86_64/picoctl + +## You may have to change picoctl to something else +## everywhere it appears in this file + +< envPaths + +epicsEnvSet("EPICS_CA_AUTO_ADDR_LIST", "NO") +epicsEnvSet("EPICS_CA_ADDR_LIST", "10.28.0.255") + +epicsEnvSet("Sys", "Sys") +epicsEnvSet("Port", "P0") +epicsEnvSet("ControllerPort", "M0") +epicsEnvSet("MC", "MC:10") +epicsEnvSet("CT", "CT") +epicsEnvSet("IOC_PREFIX", "$(CT){IOC:MC10}") +epicsEnvSet("MC_PREFIX", "$(CT){$(MC)}") + +cd ${TOP} + +## Register all support components +dbLoadDatabase "dbd/picoctl.dbd" +picoctl_registerRecordDeviceDriver pdbbase + +# Setup IP port for 8742 +drvAsynIPPortConfigure("$(Port)", "10.28.2.111:23") +asynOctetSetInputEos("$(Port)",0,"\r\n") +asynOctetSetOutputEos("$(Port)",0,"\r") + +#db asyn debug traces +asynSetTraceMask("$(Port)",-1,0x1) +asynSetTraceIOMask("$(Port)",-1,0x1) + + +# New Focus Picomotor Network Controller (model 87xx) configuration parameters: +# (1) IP asyn port name (string) +# (2) Controller asyn port name (string) +# (3) Number of axes +# (4) Moving poll period (ms) +# (5) Idle poll period (ms) +nf874xCreateController("$(ControllerPort)", "$(Port)", 4, 200, 1000) + +## Load record instances +dbLoadTemplate("iocBoot/iocNewFocus874x/newfocus8742.asyn.motor.substitutions") + +dbLoadRecords("${ASYN}/db/asynRecord.db", "P=$(MC_PREFIX),R=Asyn,PORT=$(Port),ADDR=,OMAX=80,IMAX=80") + +## autosave/restore machinery +save_restoreSet_Debug(0) +save_restoreSet_IncompleteSetsOk(1) +save_restoreSet_DatedBackupFiles(1) + +set_savefile_path("${TOP}/as","/save") +set_requestfile_path("${TOP}/as","/req") + +set_pass0_restoreFile("info_positions.sav") +set_pass0_restoreFile("info_settings.sav") +set_pass1_restoreFile("info_settings.sav") + +iocInit() + +## more autosave/restore machinery +cd ${TOP}/as/req +makeAutosaveFiles() +create_monitor_set("info_positions.req", 5 , "") +create_monitor_set("info_settings.req", 15 , "") + diff --git a/motorApp/NewFocusSrc/874xMotorDriver.cpp b/motorApp/NewFocusSrc/874xMotorDriver.cpp new file mode 100644 index 00000000..c3130d9b --- /dev/null +++ b/motorApp/NewFocusSrc/874xMotorDriver.cpp @@ -0,0 +1,349 @@ +/* +FILENAME... 874xMotorDriver.cpp +USAGE... Motor driver support for the NewFocus 874x series motor controller + +Based on ACRMotorDriver.cpp by: +Mark Rivers +March 4, 2011 + +== Modifications == +2015-12-01 - Wayne Lewis - Modify for NewFocus 874x series +*/ + +/* + * TODO: Extend for 8743 closed loop functionality + */ + +#include +#include +#include + +#include +#include + +#include + +#include "asynMotorController.h" +#include "asynMotorAxis.h" + +#include +#include "874xMotorDriver.h" + +static const char *driverName = "nf874xMotorDriver"; + +/** Creates a new nf874xController object. + * \param[in] portName The name of the asyn port that will be created for this driver + * \param[in] nf874xPortName The name of the drvAsynIPPPort that was created previously to connect to the nf874x controller + * \param[in] numAxes The number of axes that this controller supports. Create one extra axis to allow for base 1 indexing of NewFocus controllers. + * \param[in] movingPollPeriod The time between polls when any axis is moving + * \param[in] idlePollPeriod The time between polls when no axis is moving + */ +nf874xController::nf874xController(const char *portName, const char *nf874xPortName, int numAxes, + double movingPollPeriod, double idlePollPeriod) + //: asynMotorController(portName, numAxes, NUM_nf874x_PARAMS, + : asynMotorController(portName, numAxes+1, 0, + asynUInt32DigitalMask, + asynUInt32DigitalMask, + ASYN_CANBLOCK | ASYN_MULTIDEVICE, + 1, // autoconnect + 0, 0) // Default priority and stack size +{ + int axis; + asynStatus status; + static const char *functionName = "nf874xController"; + + /* Connect to nf874x controller */ + status = pasynOctetSyncIO->connect(nf874xPortName, 0, &pasynUserController_, NULL); + if (status) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, + "%s:%s: cannot connect to nf874x controller\n", + driverName, functionName); + } + epicsThreadSleep(0.5); + // Create the axis objects + // Axis 0 will remain unused. This allows consistent axis numbering with + // NewFocus convention. + for (axis=1; axis<=numAxes; axis++) { + new nf874xAxis(this, axis); + } + + startPoller(movingPollPeriod, idlePollPeriod, 2); +} + + +/** Creates a new nf874xController 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] nf874xPortName The name of the drvAsynIPPPort that was created previously to connect to the nf874x 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 nf874xCreateController(const char *portName, const char *nf874xPortName, int numAxes, + int movingPollPeriod, int idlePollPeriod) +{ + new nf874xController(portName, nf874xPortName, 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 calls asynMotorController::report() + */ +void nf874xController::report(FILE *fp, int level) +{ + fprintf(fp, "nf874x 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 nf874xMotorAxis object. + * Returns NULL if the axis number encoded in pasynUser is invalid. + * \param[in] pasynUser asynUser structure that encodes the axis index number. */ +nf874xAxis* nf874xController::getAxis(asynUser *pasynUser) +{ + return static_cast(asynMotorController::getAxis(pasynUser)); +} + +/** Returns a pointer to an nf874xMotorAxis object. + * Returns NULL if the axis number encoded in pasynUser is invalid. + * \param[in] axisNo Axis index number. */ +nf874xAxis* nf874xController::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. + * For all other functions it calls asynMotorController::writeInt32. + * Calls any registered callbacks for this pasynUser->reason and address. + * \param[in] pasynUser asynUser structure that encodes the reason and address. + * \param[in] value Value to write. */ +asynStatus nf874xController::writeInt32(asynUser *pasynUser, epicsInt32 value) +{ + int function = pasynUser->reason; + asynStatus status = asynSuccess; + nf874xAxis *pAxis = getAxis(pasynUser); + static const char *functionName = "writeInt32"; + + /* Set the parameter and readback in the parameter library. This may be overwritten when we read back the + * status at the end, but that's OK */ + status = setIntegerParam(pAxis->axisNo_, function, value); + + status = asynMotorController::writeInt32(pasynUser, value); + + /* Do callbacks so higher layers see any changes */ + callParamCallbacks(pAxis->axisNo_); + 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; +} + +/** Called when asyn clients call pasynFloat64->write(). + * Extracts the function and axis number from pasynUser. + * Sets the value in the parameter library. + * Calls any registered callbacks for this pasynUser->reason and address. + * For all other functions it calls asynMotorController::writeFloat64. + * \param[in] pasynUser asynUser structure that encodes the reason and address. + * \param[in] value Value to write. */ +asynStatus nf874xController::writeFloat64(asynUser *pasynUser, epicsFloat64 value) +{ + int function = pasynUser->reason; + asynStatus status = asynSuccess; + nf874xAxis *pAxis = getAxis(pasynUser); + static const char *functionName = "writeFloat64"; + + + /* Set the parameter and readback in the parameter library. */ + status = setDoubleParam(pAxis->axisNo_, function, value); + + status = asynMotorController::writeFloat64(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=%f\n", + driverName, functionName, status, function, value); + else + asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, + "%s:%s: function=%d, value=%f\n", + driverName, functionName, function, value); + return status; +} + +// These are the nf874xAxis methods + +/** Creates a new nf874xAxis object. + * \param[in] pC Pointer to the nf874xController to which this axis belongs. + * \param[in] axisNo Index number of this axis, range 0 to pC->numAxes_-1. + * + * Initializes register numbers, etc. + */ +nf874xAxis::nf874xAxis(nf874xController *pC, int axisNo) + : asynMotorAxis(pC, axisNo), + pC_(pC) +{ + sprintf(axisName_, "%d", axisNo); +} + +/** 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 calls asynMotorController::report() + */ +void nf874xAxis::report(FILE *fp, int level) +{ + if (level > 0) { + fprintf(fp, " axis %d\n", axisNo_ ); + } + + // Call the base class method + asynMotorAxis::report(fp, level); +} + + +asynStatus nf874xAxis::move(double position, int relative, double minVelocity, double maxVelocity, double acceleration) +{ + asynStatus status; + + sprintf(pC_->outString_, "%s AC %f", axisName_, acceleration); + status = pC_->writeController(); + sprintf(pC_->outString_, "%s VA %f", axisName_, maxVelocity); + status = pC_->writeController(); + if (relative) { + sprintf(pC_->outString_, "%s PR %f", axisName_, position); + status = pC_->writeController(); + } else { + sprintf(pC_->outString_, "%s PA %f", axisName_, position); + status = pC_->writeController(); + } + return status; +} + +asynStatus nf874xAxis::home(double minVelocity, double maxVelocity, double acceleration, int forwards) +{ + asynStatus status; + + sprintf(pC_->outString_, "%s AC %f", axisName_, acceleration); + status = pC_->writeController(); + sprintf(pC_->outString_, "%s VA %f", axisName_, acceleration); + status = pC_->writeController(); + sprintf(pC_->outString_, "%s DH", axisName_); + status = pC_->writeController(); + return status; +} + +asynStatus nf874xAxis::moveVelocity(double minVelocity, double maxVelocity, double acceleration) +{ + asynStatus status; + double speed=maxVelocity; + int forwards=1; + + if (speed < 0) { + speed = -speed; + forwards = 0; + } + sprintf(pC_->outString_, "%s AC %f", axisName_, acceleration); + status = pC_->writeController(); + sprintf(pC_->outString_, "%s VA %f", axisName_, speed); + status = pC_->writeController(); + sprintf(pC_->outString_, "%s MV %s", axisName_, forwards ? "+" : "-"); + status = pC_->writeController(); + return status; +} + +asynStatus nf874xAxis::stop(double acceleration ) +{ + asynStatus status; + + sprintf(pC_->outString_, "%s ST", axisName_); + status = pC_->writeController(); + return status; +} + +asynStatus nf874xAxis::setPosition(double position) +{ + asynStatus status; + + sprintf(pC_->outString_, "%s DH %f", axisName_, position); + status = pC_->writeController(); + return status; +} + +/** Polls the axis. + * This function reads the controller position, encoder position, the limit status, the moving status, + * and the drive power-on status. It does not current detect following error, etc. but this could be + * added. + * 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 (1) or done (0). */ +asynStatus nf874xAxis::poll(bool *moving) +{ + int done; + asynStatus comStatus; + + // Read the current encoder position + sprintf(pC_->outString_, "%s TP?", axisName_); + comStatus = pC_->writeReadController(); + if (comStatus) goto skip; + encoderPosition_ = atof(pC_->inString_); + setDoubleParam(pC_->motorEncoderPosition_,encoderPosition_); + + // Read the current theoretical position + setDoubleParam(pC_->motorPosition_, encoderPosition_); + + // Read the current moving status + sprintf(pC_->outString_, "%s MD?", axisName_); + comStatus = pC_->writeReadController(); + if (comStatus) goto skip; + done = atoi(pC_->inString_); + setIntegerParam(pC_->motorStatusDone_, done); + *moving = done ? false:true; + + skip: + setIntegerParam(pC_->motorStatusProblem_, comStatus ? 1:0); + callParamCallbacks(); + return comStatus ? asynError : asynSuccess; +} + +/** Code for iocsh registration */ +static const iocshArg nf874xCreateControllerArg0 = {"Port name", iocshArgString}; +static const iocshArg nf874xCreateControllerArg1 = {"nf874x port name", iocshArgString}; +static const iocshArg nf874xCreateControllerArg2 = {"Number of axes", iocshArgInt}; +static const iocshArg nf874xCreateControllerArg3 = {"Moving poll period (ms)", iocshArgInt}; +static const iocshArg nf874xCreateControllerArg4 = {"Idle poll period (ms)", iocshArgInt}; +static const iocshArg * const nf874xCreateControllerArgs[] = {&nf874xCreateControllerArg0, + &nf874xCreateControllerArg1, + &nf874xCreateControllerArg2, + &nf874xCreateControllerArg3, + &nf874xCreateControllerArg4}; +static const iocshFuncDef nf874xCreateControllerDef = {"nf874xCreateController", 5, nf874xCreateControllerArgs}; +static void nf874xCreateContollerCallFunc(const iocshArgBuf *args) +{ + nf874xCreateController(args[0].sval, args[1].sval, args[2].ival, args[3].ival, args[4].ival); +} + +static void nf874xMotorRegister(void) +{ + iocshRegister(&nf874xCreateControllerDef, nf874xCreateContollerCallFunc); +} + +extern "C" { +epicsExportRegistrar(nf874xMotorRegister); +} diff --git a/motorApp/NewFocusSrc/874xMotorDriver.h b/motorApp/NewFocusSrc/874xMotorDriver.h new file mode 100644 index 00000000..76929258 --- /dev/null +++ b/motorApp/NewFocusSrc/874xMotorDriver.h @@ -0,0 +1,50 @@ +/* +FILENAME... 874xMotorDriver.h +USAGE... Motor driver support for the NewFocus 874x series of controllers + +Based on ACRMotorDriver.h by: +Mark Rivers +March 28, 2011 + +== Modifications == +2015-12-01 - Wayne Lewis - Modify for NewFocus 874x controllers +*/ + +#include "asynMotorController.h" +#include "asynMotorAxis.h" + +class epicsShareClass nf874xAxis : public asynMotorAxis +{ +public: + /* These are the methods we override from the base class */ + nf874xAxis(class nf874xController *pC, int axis); + 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); + +private: + nf874xController *pC_; /**< Pointer to the asynMotorController to which this axis belongs. + * Abbreviated because it is used very frequently */ + char axisName_[10]; /**< Name of each axis, used in commands to nf874x controller */ + double encoderPosition_; /**< Cached copy of the encoder position */ + +friend class nf874xController; +}; + +class epicsShareClass nf874xController : public asynMotorController { +public: + nf874xController(const char *portName, const char *nf874xPortName, int numAxes, double movingPollPeriod, double idlePollPeriod); + + /* 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); + nf874xAxis* getAxis(asynUser *pasynUser); + nf874xAxis* getAxis(int axisNo); + +friend class nf874xAxis; +}; diff --git a/motorApp/NewFocusSrc/Makefile b/motorApp/NewFocusSrc/Makefile index f98bdf64..bc5cf8ee 100644 --- a/motorApp/NewFocusSrc/Makefile +++ b/motorApp/NewFocusSrc/Makefile @@ -11,10 +11,13 @@ DBD += devNewFocus.dbd LIBRARY_IOC = NewFocus -SRCS += NewFocusRegister.cc +NewFocus_SRCS += NewFocusRegister.cc # PMNC87xx (i.e., PMNC87xx) device driver. -SRCS += devPMNC87xx.cc drvPMNC87xx.cc +NewFocus_SRCS += devPMNC87xx.cc drvPMNC87xx.cc + +# NewFocus 874x driver +NewFocus_SRCS += 874xMotorDriver.cpp NewFocus_LIBS += motor asyn NewFocus_LIBS += $(EPICS_BASE_IOC_LIBS) diff --git a/motorApp/NewFocusSrc/devNewFocus.dbd b/motorApp/NewFocusSrc/devNewFocus.dbd index e188256d..d9c6e6ea 100644 --- a/motorApp/NewFocusSrc/devNewFocus.dbd +++ b/motorApp/NewFocusSrc/devNewFocus.dbd @@ -4,3 +4,6 @@ driver(drvPMNC87xx) registrar(NewFocusRegister) variable(drvPMNC87xxdebug) +# NewFocus 874x controller support +registrar(nf874xMotorRegister) +