The member variable oredMSR of EL734Axis contains the axis status from the previous poll.

Therefore, it needs to initialized with a sensible value (i.e. 1 which
means that the axis is standing still and has no errors.
This commit is contained in:
2024-09-10 08:58:59 +02:00
parent c972cce072
commit a6a8f14b26
2 changed files with 257 additions and 206 deletions

View File

@ -11,7 +11,6 @@ Mark Koennecke, May, August 2017
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@ -30,7 +29,6 @@ Mark Koennecke, May, August 2017
#define IDLEPOLL 60
/** Creates a new EL734Controller object.
* \param[in] portName The name of the asyn port that will be created for this driver
* \param[in] EL734PortName The name of the drvAsynSerialPort that was created previously to connect to the EL734 controller
@ -43,10 +41,10 @@ EL734Controller::EL734Controller(const char *portName, const char *EL734PortName
asynStatus status;
static const char *functionName = "EL734Controller::EL734Controller";
/* Connect to EL734 controller */
status = pasynOctetSyncIO->connect(EL734PortName, 0, &pasynUserController_, NULL);
if (status) {
if (status)
{
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"%s: cannot connect to EL734 controller\n",
functionName);
@ -56,14 +54,14 @@ EL734Controller::EL734Controller(const char *portName, const char *EL734PortName
switchRemote();
for (axis=0; axis<numAxes; axis++) {
for (axis = 0; axis < numAxes; axis++)
{
new EL734Axis(this, axis + 1);
}
startPoller(1000. / 1000., IDLEPOLL, 2);
}
/** Creates a new EL734Controller object.
* Configuration command, called directly or from iocsh
* \param[in] portName The name of the asyn port that will be created for this driver
@ -72,8 +70,7 @@ EL734Controller::EL734Controller(const char *portName, const char *EL734PortName
*/
extern "C" int EL734CreateController(const char *portName, const char *EL734PortName, int numAxes)
{
EL734Controller *pEL734Controller
= new EL734Controller(portName, EL734PortName, numAxes);
EL734Controller *pEL734Controller = new EL734Controller(portName, EL734PortName, numAxes);
pEL734Controller = NULL;
return (asynSuccess);
}
@ -148,8 +145,10 @@ asynStatus EL734Controller::transactController(int axisNo,char command[COMLEN],
status = pasynOctetSyncIO->writeRead(pasynUserController_, command, strlen(command),
reply, COMLEN, 2., &out, &in, &reason);
if(status != asynSuccess){
if(axis!= NULL){
if (status != asynSuccess)
{
if (axis != NULL)
{
axis->updateMsgTxtFromDriver("Lost connection to motor controller");
}
return status;
@ -158,7 +157,8 @@ asynStatus EL734Controller::transactController(int axisNo,char command[COMLEN],
/*
check for the offline reply
*/
if(strstr(reply,"?LOC") != NULL){
if (strstr(reply, "?LOC") != NULL)
{
switchRemote();
return pasynOctetSyncIO->writeRead(pasynUserController_, command, strlen(command),
reply, COMLEN, 1., &out, &in, &reason);
@ -167,7 +167,8 @@ asynStatus EL734Controller::transactController(int axisNo,char command[COMLEN],
/*
check for echos. This means that the thing is offline.
*/
if(strstr(reply,"p ") != NULL || strstr(reply,"u ") != NULL || strstr(reply,"msr ") != NULL){
if (strstr(reply, "p ") != NULL || strstr(reply, "u ") != NULL || strstr(reply, "msr ") != NULL)
{
switchRemote();
return pasynOctetSyncIO->writeRead(pasynUserController_, command, strlen(command),
reply, COMLEN, 1., &out, &in, &reason);
@ -176,27 +177,36 @@ asynStatus EL734Controller::transactController(int axisNo,char command[COMLEN],
check for EL734 errors
*/
strcpy(myReply, reply);
for(i = 0; i < strlen(reply); i++){
for (i = 0; i < strlen(reply); i++)
{
myReply[i] = (char)tolower((int)reply[i]);
}
if(strstr(myReply,"?cmd") != NULL){
if (strstr(myReply, "?cmd") != NULL)
{
snprintf(errTxt, sizeof(errTxt), "Bad command %s at axis %d", command, axisNo);
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, errTxt);
if(axis!= NULL){
if (axis != NULL)
{
axis->updateMsgTxtFromDriver(errTxt);
}
return asynError;
} else if(strstr(myReply,"?par") != NULL){
}
else if (strstr(myReply, "?par") != NULL)
{
snprintf(errTxt, sizeof(errTxt), "Bad parameter in command %s", command);
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, errTxt);
if(axis!= NULL){
if (axis != NULL)
{
axis->updateMsgTxtFromDriver(errTxt);
}
return asynError;
} else if(strstr(myReply,"?rng") != NULL){
}
else if (strstr(myReply, "?rng") != NULL)
{
snprintf(errTxt, sizeof(errTxt), "Parameter out of range in command %s", command);
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, errTxt);
if(axis!= NULL){
if (axis != NULL)
{
axis->updateMsgTxtFromDriver(errTxt);
}
return asynError;
@ -226,24 +236,34 @@ EL734Axis::EL734Axis(EL734Controller *pC, int axisNo)
*/
sprintf(command, "H %d", axisNo_);
status = pC_->transactController(axisNo_, command, reply);
if(status == asynSuccess){
if (status == asynSuccess)
{
count = sscanf(reply, "%f %f", &low, &high);
if(count >= 2){
if (count >= 2)
{
pC_->setDoubleParam(axisNo_, pC_->motorLowLimit_, low);
pC_->setDoubleParam(axisNo_, pC_->motorHighLimit_, high);
callParamCallbacks();
} else {
}
else
{
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
"Bad response - %s - requesting limits at axis %d", reply, axisNo_);
}
} else {
}
else
{
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
"Failed to read limits at axis %d", axisNo_);
}
/*
oredMSR contains the axis status from the previous poll. The initial value
1 means that the axis is not moving and has no errors.
*/
oredMSR = 1;
}
/** 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
@ -252,7 +272,8 @@ EL734Axis::EL734Axis(EL734Controller *pC, int axisNo)
*/
void EL734Axis::report(FILE *fp, int level)
{
if (level > 0) {
if (level > 0)
{
fprintf(fp, " axis %d\n",
axisNo_);
}
@ -261,7 +282,6 @@ void EL734Axis::report(FILE *fp, int level)
// asynMotorAxis::report(fp, level);
}
asynStatus EL734Axis::move(double position, int relative, double minVelocity, double maxVelocity, double acceleration)
{
asynStatus status;
@ -278,10 +298,10 @@ asynStatus EL734Axis::move(double position, int relative, double minVelocity, do
sprintf(command, "J %d %d", axisNo_, (int)maxVelocity);
status = pC_->transactController(axisNo_, command, reply);
if (relative) {
if (relative)
{
position += this->position;
}
oredMSR = 0;
homing = 0;
errorReported = 0;
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
@ -323,12 +343,14 @@ asynStatus EL734Axis::moveVelocity(double minVelocity, double maxVelocity, doubl
// "%s: minVelocity=%f, maxVelocity=%f, acceleration=%f\n",
// functionName, minVelocity, maxVelocity, acceleration);
errorReported = 0;
if (maxVelocity > 0.) {
if (maxVelocity > 0.)
{
/* This is a positive move */
sprintf(command, "FF %d", axisNo_);
} else {
}
else
{
/* This is a negative move */
sprintf(command, "FB %d", axisNo_);
}
@ -347,7 +369,8 @@ asynStatus EL734Axis::stop(double acceleration )
bool moving = false;
this->poll(&moving);
if(moving && errorReported == 0){
if (moving && errorReported == 0)
{
sprintf(command, "S %d", axisNo_);
status = pC_->transactController(axisNo_, command, reply);
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR, "Sent STOP on Axis %d\n", axisNo_);
@ -397,7 +420,8 @@ asynStatus EL734Axis::poll(bool *moving)
char command[COMLEN], reply[COMLEN], errTxt[256];
// protect against excessive polling
if(time(NULL) < next_poll){
if (time(NULL) < next_poll)
{
*moving = false;
return asynSuccess;
}
@ -405,9 +429,11 @@ asynStatus EL734Axis::poll(bool *moving)
// read hardware limits
sprintf(command, "H %d", axisNo_);
comStatus = pC_->transactController(axisNo_, command, reply);
if(comStatus == asynSuccess){
if (comStatus == asynSuccess)
{
count = sscanf(reply, "%f %f", &low, &high);
if(count >= 2){
if (count >= 2)
{
pC_->setDoubleParam(axisNo_, pC_->motorLowLimit_, low);
pC_->setDoubleParam(axisNo_, pC_->motorHighLimit_, high);
callParamCallbacks();
@ -418,11 +444,13 @@ asynStatus EL734Axis::poll(bool *moving)
setIntegerParam(pC_->motorStatusProblem_, false);
sprintf(command, "u %d", axisNo_);
comStatus = pC_->transactController(axisNo_, command, reply);
if(comStatus == asynError){
if (comStatus == asynError)
{
setIntegerParam(pC_->motorStatusProblem_, true);
goto skip;
}
if(strstr(reply,"*ES") != NULL){
if (strstr(reply, "*ES") != NULL)
{
*moving = false;
setIntegerParam(pC_->motorStatusDone_, true);
setIntegerParam(pC_->motorStatusProblem_, true);
@ -430,14 +458,18 @@ asynStatus EL734Axis::poll(bool *moving)
updateMsgTxtFromDriver("Emergency Stop Engaged");
comStatus = asynError;
goto skip;
} else if(strstr(reply,"?BSY") != NULL){
}
else if (strstr(reply, "?BSY") != NULL)
{
*moving = true;
setIntegerParam(pC_->motorStatusDone_, false);
goto skip;
}
count = sscanf(reply, "%lf", &position);
if(count != 1) {
if(!homing) {
if (count != 1)
{
if (!homing)
{
snprintf(errTxt, sizeof(errTxt), "Bad reply %s when reading position for %d", reply, axisNo_);
setIntegerParam(pC_->motorStatusProblem_, true);
errorReported = 1;
@ -445,7 +477,9 @@ asynStatus EL734Axis::poll(bool *moving)
comStatus = asynError;
goto skip;
}
} else {
}
else
{
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
"Axis %d, reply %s, position %lf\n", axisNo_, reply, position);
setDoubleParam(pC_->motorPosition_, position * 1000);
@ -455,7 +489,8 @@ asynStatus EL734Axis::poll(bool *moving)
// Read the moving status of this motor
sprintf(command, "msr %d", axisNo_);
comStatus = pC_->transactController(axisNo_, command, reply);
if(comStatus == asynError){
if (comStatus == asynError)
{
setIntegerParam(pC_->motorStatusProblem_, true);
goto skip;
}
@ -465,35 +500,44 @@ asynStatus EL734Axis::poll(bool *moving)
// axisNo_, reply, msr, oredMSR, position);
oredMSR |= msr;
if( (msr & 0x1) == 0){
if ((msr & 0x1) == 0)
{
// done: check for trouble
// errlogPrintf("Axis %d finished\n", axisNo_);
*moving = false;
setIntegerParam(pC_->motorStatusDone_, true);
next_poll = time(NULL) + IDLEPOLL;
if(oredMSR & 0x10){
if (oredMSR & 0x10)
{
setIntegerParam(pC_->motorStatusLowLimit_, true);
updateMsgTxtFromDriver("Lower Limit Hit");
errorReported = 1;
comStatus = asynError;
goto skip;
} else {
}
else
{
setIntegerParam(pC_->motorStatusLowLimit_, false);
}
if(oredMSR & 0x20){
if (oredMSR & 0x20)
{
setIntegerParam(pC_->motorStatusHighLimit_, true);
updateMsgTxtFromDriver("Upper Limit Hit");
errorReported = 1;
comStatus = asynError;
goto skip;
} else {
}
else
{
setIntegerParam(pC_->motorStatusHighLimit_, false);
}
if(homing){
if (homing)
{
setIntegerParam(pC_->motorStatusAtHome_, true);
}
if(oredMSR & 0x1000){
if (oredMSR & 0x1000)
{
setIntegerParam(pC_->motorStatusProblem_, true);
// errlogPrintf("Detected air cushion error on %d", axisNo_);
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR, "Air cushion problem on %d", axisNo_);
@ -502,7 +546,8 @@ asynStatus EL734Axis::poll(bool *moving)
comStatus = asynError;
goto skip;
}
if(oredMSR & 0x100){
if (oredMSR & 0x100)
{
setIntegerParam(pC_->motorStatusProblem_, true);
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR, "Run failure at %d", axisNo_);
updateMsgTxtFromDriver("Run failure");
@ -510,7 +555,8 @@ asynStatus EL734Axis::poll(bool *moving)
errorReported = 1;
goto skip;
}
if(oredMSR & 0x400){
if (oredMSR & 0x400)
{
setIntegerParam(pC_->motorStatusProblem_, true);
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR, "Positioning failure at %d", axisNo_);
updateMsgTxtFromDriver("Positioning failure");
@ -518,11 +564,14 @@ asynStatus EL734Axis::poll(bool *moving)
errorReported = 1;
goto skip;
}
if(oredMSR & 0x200 || oredMSR & 0x80) {
if (oredMSR & 0x200 || oredMSR & 0x80)
{
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_WARNING, "Positioning fault at %d", axisNo_);
}
setIntegerParam(pC_->motorStatusProblem_, false);
} else {
}
else
{
*moving = true;
next_poll = -1;
setIntegerParam(pC_->motorStatusDone_, false);
@ -551,6 +600,7 @@ static void EL734Register(void)
iocshRegister(&EL734CreateControllerDef, EL734CreateContollerCallFunc);
}
extern "C" {
extern "C"
{
epicsExportRegistrar(EL734Register);
}

View File

@ -39,7 +39,8 @@ private:
friend class EL734Controller;
};
class EL734Controller : public SINQController {
class EL734Controller : public SINQController
{
public:
EL734Controller(const char *portName, const char *EL734PortName, int numAxes);
@ -48,11 +49,11 @@ public:
EL734Axis *getAxis(int axisNo);
friend class EL734Axis;
private:
asynUser *pasynUserController_;
asynStatus transactController(int axis, char command[COMLEN], char reply[COMLEN]);
void switchRemote();
};