Skip to content

Commit

Permalink
Moved the polling from HXPAxis::poll to HXPController::poll
Browse files Browse the repository at this point in the history
  • Loading branch information
kmpeters committed Feb 6, 2019
1 parent e7c9978 commit 808e26e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 72 deletions.
169 changes: 98 additions & 71 deletions newportApp/src/HXPDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,100 @@ void HXPController::postError(HXPAxis *pAxis, int status)
return;
}

/** Polls the controller.
* This function reads the motor position, the limit status, the home status, the moving status,
* and the drive power-on 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 HXPController::poll()
{
int status;
//char readResponse[25];

static const char *functionName = "HXPController::poll";

status = HXPGroupStatusGet(pollSocket_,
GROUP,
&groupStatus_);
if (status) {
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
"%s:%s: [%s]: error calling GroupStatusGet status=%d; pollSocket=%d\n",
driverName, functionName, portName, status, pollSocket_);
goto done;
}

asynPrint(pasynUserSelf, ASYN_TRACE_FLOW,
"%s:%s: [%s]: %s groupStatus=%d\n",
driverName, functionName, portName, GROUP, groupStatus_);
/* Set the status */
setIntegerParam(HXPStatus_, groupStatus_);

/* If the group is not moving then the axis is not moving */
if ((groupStatus_ < 43) || (groupStatus_ > 48))
moving_ = false;
else
moving_ = true;

/* Set the motor done parameter */
setIntegerParam(motorStatusDone_, moving_?0:1);

/*Test for states that mean we cannot move an axis (disabled, uninitialised, etc.)
and set problem bit in MSTA.*/
if ((groupStatus_ < 10) || ((groupStatus_ >= 20) && (groupStatus_ <= 42)) ||
(groupStatus_ == 50) || (groupStatus_ == 64))
{
/* Don't consider a normal disabled status to be a problem */
if ( groupStatus_==20 )
{
setIntegerParam(motorStatusProblem_, 0);
}
else
{
asynPrint(pasynUserSelf, ASYN_TRACE_FLOW,
"%s:%s: [%s]: in unintialised/disabled/not referenced. XPS State Code: %d\n",
driverName, functionName, portName, groupStatus_);
setIntegerParam(motorStatusProblem_, 1);
}

/* Group status indicates power is off */
setIntegerParam(motorStatusPowerOn_, 0);
}
else
{
setIntegerParam(motorStatusProblem_, 0);
setIntegerParam(motorStatusPowerOn_, 1);
}

status = HXPGroupPositionCurrentGet(pollSocket_,
GROUP,
MAX_HXP_AXES,
encoderPosition_);
if (status) {
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
"%s:%s: [%s]: error calling GroupPositionCurrentGet status=%d\n",
driverName, functionName, portName, status);
goto done;
}

status = HXPGroupPositionSetpointGet(pollSocket_,
GROUP,
MAX_HXP_AXES,
setpointPosition_);
if (status) {
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
"%s:%s: [%s]: error calling GroupPositionSetpointGet status=%d\n",
driverName, functionName, portName, status);
goto done;
}

done:
setIntegerParam(motorStatusProblem_, status ? 1:0);
callParamCallbacks();
return status ? asynError : asynSuccess;
}


// These are the HXPAxis methods

/** Creates a new HXPAxis object.
Expand Down Expand Up @@ -581,95 +675,28 @@ asynStatus HXPAxis::poll(bool *moving)

static const char *functionName = "HXPAxis::poll";

status = HXPGroupStatusGet(pollSocket_,
GROUP,
&axisStatus_);
if (status) {
asynPrint(pasynUser_, ASYN_TRACE_ERROR,
"%s:%s: [%s,%d]: error calling GroupStatusGet status=%d; pollSocket=%d\n",
driverName, functionName, pC_->portName, axisNo_, status, pollSocket_);
goto done;
}

asynPrint(pasynUser_, ASYN_TRACE_FLOW,
"%s:%s: [%s,%d]: %s axisStatus=%d\n",
driverName, functionName, pC_->portName, axisNo_, positionerName_, axisStatus_);
/* Set the status */
/* Note: there is only one status PV for the controller. Currently it reflects the status of axis 0.
It might be better to call pC_->setIntegerParam(pC_->HXPStatus_, axisStatus_); */
setIntegerParam(pC_->HXPStatus_, axisStatus_);

/* If the group is not moving then the axis is not moving */
if ((axisStatus_ < 43) || (axisStatus_ > 48))
moving_ = false;
else
moving_ = true;
moving_ = pC_->moving_;

/* Set the axis done parameter */
*moving = moving_;
setIntegerParam(pC_->motorStatusDone_, *moving?0:1);

/*Test for states that mean we cannot move an axis (disabled, uninitialised, etc.)
and set problem bit in MSTA.*/
if ((axisStatus_ < 10) || ((axisStatus_ >= 20) && (axisStatus_ <= 42)) ||
(axisStatus_ == 50) || (axisStatus_ == 64))
{
/* Don't consider a normal disabled status to be a problem */
if ( axisStatus_==20 )
{
setIntegerParam(pC_->motorStatusProblem_, 0);
}
else
{
asynPrint(pasynUser_, ASYN_TRACE_FLOW,
"%s:%s: [%s,%d]: in unintialised/disabled/not referenced. XPS State Code: %d\n",
driverName, functionName, pC_->portName, axisNo_, axisStatus_);
setIntegerParam(pC_->motorStatusProblem_, 1);
}

/* Group status indicates power is off */
setIntegerParam(pC_->motorStatusPowerOn_, 0);
}
else
{
setIntegerParam(pC_->motorStatusProblem_, 0);
setIntegerParam(pC_->motorStatusPowerOn_, 1);
}
encoderPosition_ = pC_->encoderPosition_[axisNo_];
setpointPosition_ = pC_->setpointPosition_[axisNo_];

status = HXPGroupPositionCurrentGet(pollSocket_,
positionerName_,
1,
&encoderPosition_);
if (status) {
asynPrint(pasynUser_, ASYN_TRACE_ERROR,
"%s:%s: [%s,%d]: error calling GroupPositionCurrentGet status=%d\n",
driverName, functionName, pC_->portName, axisNo_, status);
goto done;
}
//setDoubleParam(pC_->motorEncoderPosition_, (encoderPosition_/stepSize_));
setDoubleParam(pC_->motorEncoderPosition_, encoderPosition_ / MRES);

status = HXPGroupPositionSetpointGet(pollSocket_,
positionerName_,
1,
&setpointPosition_);
if (status) {
asynPrint(pasynUser_, ASYN_TRACE_ERROR,
"%s:%s: [%s,%d]: error calling GroupPositionSetpointGet status=%d\n",
driverName, functionName, pC_->portName, axisNo_, status);
goto done;
}
//setDoubleParam(pC_->motorPosition_, (setpointPosition_/stepSize_));
setDoubleParam(pC_->motorPosition_, setpointPosition_ / MRES);

// limit check?

// dir flag?

done:
setIntegerParam(pC_->motorStatusProblem_, status ? 1:0);
callParamCallbacks();
return status ? asynError : asynSuccess;
return asynSuccess;
}

/** Code for iocsh registration */
Expand Down
7 changes: 6 additions & 1 deletion newportApp/src/HXPDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class epicsShareClass HXPAxis : public asynMotorAxis
double setpointPosition_;
int axisStatus_;
double mres_;
int moving_;
bool moving_;

friend class HXPController;
};
Expand All @@ -91,6 +91,7 @@ class epicsShareClass HXPController : public asynMotorController {
void report(FILE *fp, int level);
HXPAxis* getAxis(asynUser *pasynUser);
HXPAxis* getAxis(int axisNo);
asynStatus poll();

/* These are the methods that are new to this class */
int moveAll(HXPAxis* pAxis);
Expand Down Expand Up @@ -150,6 +151,10 @@ class epicsShareClass HXPController : public asynMotorController {
//int moveSocket_;
char firmwareVersion_[100];
char *axisNames_;
int groupStatus_;
double encoderPosition_[MAX_HXP_AXES];
double setpointPosition_[MAX_HXP_AXES];
bool moving_;

friend class HXPAxis;
};

0 comments on commit 808e26e

Please sign in to comment.