New C++ base class for asyn motor drivers

This commit is contained in:
MarkRivers
2009-12-16 06:13:29 +00:00
parent 4fcaa09d7d
commit d87363f794
2 changed files with 259 additions and 0 deletions
+137
View File
@@ -0,0 +1,137 @@
#include "asynMotorDriver.h"
/** All of the arguments are simply passed to
* the constructor for the asynPortDriver base class. After calling the base class
* constructor this method sets reasonable default values for all of the parameters
* defined in asynMotorDriver.h.
*/
static const char *driverName = "asynMotorDriver";
asynMotorDriver::asynMotorDriver(const char *portName, int maxAddr, int numParams,
int interfaceMask, int interruptMask,
int asynFlags, int autoConnect, int priority, int stackSize)
: asynPortDriver(portName, maxAddr, NUM_MOTOR_DRIVER_PARAMS+numParams,
interfaceMask | asynInt32Mask | asynFloat64Mask,
interruptMask | asynInt32Mask | asynFloat64Mask,
asynFlags, autoConnect, priority, stackSize)
{
static const char *functionName = "asynMotorDriver";
/* Create the base set of motor parameters */
addParam(motorMoveRelString, &motorMoveRel);
addParam(motorMoveAbsString, &motorMoveAbs);
addParam(motorMoveVelString, &motorMoveVel);
addParam(motorHomeString, &motorHome);
addParam(motorStopString, &motorStop);
addParam(motorVelocityString, &motorVelocity);
addParam(motorVelBaseString, &motorVelBase);
addParam(motorAccelString, &motorAccel);
addParam(motorPositionString, &motorPosition);
addParam(motorEncoderPositionString, &motorEncoderPosition);
addParam(motorDeferMovesString, &motorDeferMoves);
addParam(motorResolutionString, &motorResolution);
addParam(motorEncRatioString, &motorEncRatio);
addParam(motorPgainString, &motorPgain);
addParam(motorIgainString, &motorIgain);
addParam(motorDgainString, &motorDgain);
addParam(motorHighLimString, &motorHighLim);
addParam(motorLowLimString, &motorLowLim);
addParam(motorSetClosedLoopString, &motorSetClosedLoop);
addParam(motorStatusString, &motorStatus);
addParam(motorUpdateStatusString, &motorUpdateStatus);
addParam(motorStatusDirectionString, &motorStatusDirection);
addParam(motorStatusDoneString, &motorStatusDone);
addParam(motorStatusHighLimitString, &motorStatusHighLimit);
addParam(motorStatusAtHomeString, &motorStatusAtHome);
addParam(motorStatusSlipString, &motorStatusSlip);
addParam(motorStatusPowerOnString, &motorStatusPowerOn);
addParam(motorStatusFollowingErrorString, &motorStatusFollowingError);
addParam(motorStatusHomeString, &motorStatusHome);
addParam(motorStatusHasEncoderString, &motorStatusHasEncoder);
addParam(motorStatusProblemString, &motorStatusProblem);
addParam(motorStatusMovingString, &motorStatusMoving);
addParam(motorStatusGainSupportString, &motorStatusGainSupport);
addParam(motorStatusCommsErrorString, &motorStatusCommsError);
addParam(motorStatusLowLimitString, &motorStatusLowLimit);
addParam(motorStatusHomedString, &motorStatusHomed);
asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW,
"%s:%s: constructor complete\n",
driverName, functionName);
}
asynStatus asynMotorDriver::readGenericPointer(asynUser *pasynUser, void *pointer)
{
static const char *functionName = "readGenericPointer";
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"%s:%s: not implemented in this driver\n",
driverName, functionName);
return(asynError);
}
asynStatus asynMotorDriver::moveAxis(asynUser *pasynUser, double position, int relative, double min_velocity, double max_velocity, double acceleration)
{
static const char *functionName = "moveAxis";
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"%s:%s: not implemented in this driver\n",
driverName, functionName);
return(asynError);
}
asynStatus asynMotorDriver::moveVelocityAxis(asynUser *pasynUser, double min_velocity, double max_velocity, double acceleration)
{
static const char *functionName = "moveVelocityAxis";
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"%s:%s: not implemented in this driver\n",
driverName, functionName);
return(asynError);
}
asynStatus asynMotorDriver::homeAxis(asynUser *pasynUser, double min_velocity, double max_velocity, double acceleration, int forwards)
{
static const char *functionName = "homeAxis";
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"%s:%s: not implemented in this driver\n",
driverName, functionName);
return(asynError);
}
asynStatus asynMotorDriver::stopAxis(asynUser *pasynUser, double acceleration)
{
static const char *functionName = "stopAxis";
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"%s:%s: not implemented in this driver\n",
driverName, functionName);
return(asynError);
}
asynStatus asynMotorDriver::profileMove(asynUser *pasynUser, int npoints, double positions[], double times[], int relative, int trigger)
{
static const char *functionName = "profileMove";
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"%s:%s: not implemented in this driver\n",
driverName, functionName);
return(asynError);
}
asynStatus asynMotorDriver::triggerProfile(asynUser *pasynUser)
{
static const char *functionName = "triggerProfile";
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"%s:%s: not implemented in this driver\n",
driverName, functionName);
return(asynError);
}
+122
View File
@@ -0,0 +1,122 @@
/* asynMotorDriver.h
*
* Mark Rivers
*
* This file defines the base class for an asynMotorDriver. It is the class
* from which real motor drivers are derived. It derives from asynPortDriver.
*/
#ifndef asynMotorDriver_H
#define asynMotorDriver_H
#include <epicsTypes.h>
#define motorMoveRelString "MOTOR_MOVE_REL"
#define motorMoveAbsString "MOTOR_MOVE_ABS"
#define motorMoveVelString "MOTOR_MOVE_VEL"
#define motorHomeString "MOTOR_HOME"
#define motorStopString "MOTOR_STOP_AXIS"
#define motorVelocityString "MOTOR_VELOCITY"
#define motorVelBaseString "MOTOR_VEL_BASE"
#define motorAccelString "MOTOR_ACCEL"
#define motorPositionString "MOTOR_POSITION"
#define motorEncoderPositionString "MOTOR_ENCODER_POSITION"
#define motorDeferMovesString "MOTOR_DEFER_MOVES"
#define motorResolutionString "MOTOR_RESOLUTION"
#define motorEncRatioString "MOTOR_ENC_RATIO"
#define motorPgainString "MOTOR_PGAIN"
#define motorIgainString "MOTOR_IGAIN"
#define motorDgainString "MOTOR_DGAIN"
#define motorHighLimString "MOTOR_HIGH_LIMIT"
#define motorLowLimString "MOTOR_LOW_LIMIT"
#define motorSetClosedLoopString "MOTOR_SET_CLOSED_LOOP"
#define motorStatusString "MOTOR_STATUS"
#define motorUpdateStatusString "MOTOR_UPDATE_STATUS"
#define motorStatusDirectionString "MOTOR_STATUS_DIRECTION"
#define motorStatusDoneString "MOTOR_STATUS_DONE"
#define motorStatusHighLimitString "MOTOR_STATUS_HIGHLIMIT"
#define motorStatusAtHomeString "MOTOR_STATUS_ATHOME"
#define motorStatusSlipString "MOTOR_STATUS_SLIP"
#define motorStatusPowerOnString "MOTOR_STATUS_POWERED"
#define motorStatusFollowingErrorString "MOTOR_STATUS_FOLLOWINGERROR"
#define motorStatusHomeString "MOTOR_STATUS_HOME"
#define motorStatusHasEncoderString "MOTOR_STATUS_HASENCODER"
#define motorStatusProblemString "MOTOR_STATUS_PROBLEM"
#define motorStatusMovingString "MOTOR_STATUS_MOVING"
#define motorStatusGainSupportString "MOTOR_STATUS_GAINSUPPORT"
#define motorStatusCommsErrorString "MOTOR_STATUS_COMMSERROR"
#define motorStatusLowLimitString "MOTOR_STATUS_LOWLIMIT"
#define motorStatusHomedString "MOTOR_STATUS_HOMED"
typedef struct MotorStatus {
double position;
double encoder_posn;
double velocity;
epicsUInt32 status;
} MotorStatus;
#ifdef __cplusplus
#include <asynPortDriver.h>
/** Class from which motor drivers are directly derived. */
class asynMotorDriver : public asynPortDriver {
public:
/* This is the constructor for the class. */
asynMotorDriver(const char *portName, int maxAxes, int numParams,
int interfaceMask, int interruptMask,
int asynFlags, int autoConnect, int priority, int stackSize);
/* These are the methods that we override from asynPortDriver */
virtual asynStatus readGenericPointer(asynUser *pasynUser, void *pointer);
/* These are the methods that are new to this class */
virtual asynStatus moveAxis(asynUser *pasynUser, double position, int relative, double min_velocity, double max_velocity, double acceleration);
virtual asynStatus moveVelocityAxis(asynUser *pasynUser, double min_velocity, double max_velocity, double acceleration);
virtual asynStatus homeAxis(asynUser *pasynUser, double min_velocity, double max_velocity, double acceleration, int forwards);
virtual asynStatus stopAxis(asynUser *pasynUser, double acceleration);
virtual asynStatus profileMove(asynUser *pasynUser, int npoints, double positions[], double times[], int relative, int trigger);
virtual asynStatus triggerProfile(asynUser *pasynUser);
protected:
int motorMoveRel;
#define FIRST_MOTOR_PARAM motorMoveRel
int motorMoveAbs;
int motorMoveVel;
int motorHome;
int motorStop;
int motorVelocity;
int motorVelBase;
int motorAccel;
int motorPosition;
int motorEncoderPosition;
int motorDeferMoves;
int motorResolution;
int motorEncRatio;
int motorPgain;
int motorIgain;
int motorDgain;
int motorHighLim;
int motorLowLim;
int motorSetClosedLoop;
int motorStatus;
int motorUpdateStatus;
int motorStatusDirection;
int motorStatusDone;
int motorStatusHighLimit;
int motorStatusAtHome;
int motorStatusSlip;
int motorStatusPowerOn;
int motorStatusFollowingError;
int motorStatusHome;
int motorStatusHasEncoder;
int motorStatusProblem;
int motorStatusMoving;
int motorStatusGainSupport;
int motorStatusCommsError;
int motorStatusLowLimit;
int motorStatusHomed;
#define LAST_MOTOR_PARAM motorStatusHomed
};
#define NUM_MOTOR_DRIVER_PARAMS (&LAST_MOTOR_PARAM - &FIRST_MOTOR_PARAM + 1)
#endif /* _cplusplus */
#endif /* asynMotorDriver_H */