Committing the last status of selene work in the corona lockdown.

The problem is in the MCU, probably
This commit is contained in:
2020-03-18 15:53:44 +01:00
parent a25f8cabb9
commit f56ef2c74c
6 changed files with 277 additions and 19 deletions

View File

@ -44,6 +44,9 @@
#define MULT 1000.
#define IDLEPOLL 2.
#define BUSYPOLL .05
#define ABS(x) (x < 0 ? -(x) : (x))
extern "C" void shutdownCallback(void *pPvt)
@ -56,9 +59,10 @@ extern "C" void shutdownCallback(void *pPvt)
}
// These are the pmacAxis class methods
pmacAxis::pmacAxis(pmacController *pC, int axisNo)
pmacAxis::pmacAxis(pmacController *pC, int axisNo, bool enable)
: SINQAxis(pC, axisNo),
pC_(pC)
pC_(pC),
autoEnable(enable)
{
static const char *functionName = "pmacAxis::pmacAxis";
@ -80,6 +84,7 @@ pmacAxis::pmacAxis(pmacController *pC, int axisNo)
status6Time = 0;
starting = 0;
homing = 0;
next_poll = -1;
/* Set an EPICS exit handler that will shut down polling before asyn kills the IP sockets */
epicsAtExit(shutdownCallback, pC_);
@ -156,13 +161,18 @@ asynStatus pmacAxis::getAxisInitialStatus(void)
}
// Enable the axis. After startup, the axis are disabled on the controller...
sprintf(command, "M%2.2d14=1", axisNo_);
cmdStatus = pC_->lowLevelWriteRead(axisNo_,command, response);
if (cmdStatus ) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR, "%s: Error: enaabling axis %d failed.\n", functionName, axisNo_);
return asynError;
}
// Warning: Selene lift axis should not be automatically enabled
if (autoEnable) {
sprintf(command, "M%2.2d14=1\n", axisNo_);
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR, "Enable axis %d: %s",axisNo_,command);
cmdStatus = pC_->lowLevelWriteRead(axisNo_,command, response);
if (cmdStatus ) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR, "%s: Error: enaabling axis %d failed.\n", functionName, axisNo_);
return asynError;
}
}
callParamCallbacks();
return asynSuccess;
@ -202,7 +212,9 @@ asynStatus pmacAxis::move(double position, int relative, double min_velocity, do
sprintf( command, "P%2.2d23=0 Q%2.2d01=%12.4f M%2.2d=1", axisNo_, axisNo_, realPosition, axisNo_);
status = pC_->lowLevelWriteRead(axisNo_,command, response);
next_poll = -1;
return status;
}
@ -224,6 +236,8 @@ asynStatus pmacAxis::home(double min_velocity, double max_velocity, double accel
status = pC_->lowLevelWriteRead(axisNo_,command, response);
homing = 1;
next_poll = time(NULL) + BUSYPOLL;
return status;
}
@ -277,6 +291,11 @@ asynStatus pmacAxis::poll(bool *moving)
static const char *functionName = "pmacAxis::poll";
char message[132];
// Protect against excessive polling
if(time(NULL) < next_poll){
return asynSuccess;
}
sprintf(message, "%s: Polling axis: %d", functionName, this->axisNo_);
pC_->debugFlow(message);
@ -285,7 +304,13 @@ asynStatus pmacAxis::poll(bool *moving)
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
"%s: getAxisStatus failed to return asynSuccess. Controller: %s, Axis: %d.\n", functionName, pC_->portName, axisNo_);
}
if(*moving){
next_poll = time(NULL) + BUSYPOLL;
} else {
next_poll = time(NULL) + IDLEPOLL;
}
callParamCallbacks();
return status ? asynError : asynSuccess;
}
@ -346,8 +371,8 @@ asynStatus pmacAxis::getAxisStatus(bool *moving)
int done = 0, posChanging = 0;
double position = 0;
int nvals = 0;
int axisProblemFlag = 0;
epicsUInt32 axErr = 0, axStat = 0, highLim = 0, lowLim= 0;
int axisProblemFlag = 0, axStat = 0;
epicsUInt32 axErr = 0, highLim = 0, lowLim= 0;
char message[132], *axMessage;
@ -420,7 +445,7 @@ asynStatus pmacAxis::getAxisStatus(bool *moving)
previous_position_ = position;
previous_direction_ = direction;
// errlogPrintf("Polling, axStat = %d, axErr = %d, position = %f\n", axStat, axErr, position);
errlogPrintf("Polling %d, axStat = %d, axErr = %d, position = %f\n", axisNo_, axStat, axErr, position);
/* are we done? */
if((axStat == 0 || axStat == 14 || axStat < 0) && starting == 0 ){
@ -618,7 +643,9 @@ asynStatus SeleneAxis::move(double position, int relative, double min_velocity,
errlogPrintf("Sending drive command: %s\n", command);
status = pC_->lowLevelWriteRead(axisNo_,command, response);
next_poll = -1;
return status;
}
/*----------------------------------------------------------------------------------------------------*/
@ -656,6 +683,8 @@ asynStatus LiftAxis::move(double position, int relative, double min_velocity,
status = pC_->lowLevelWriteRead(axisNo_,command, response);
waitStart = 1;
next_poll = -1;
return status;
}
/*--------------------------------------------------------------------------------------------------------
@ -666,6 +695,11 @@ asynStatus LiftAxis::poll(bool *moving)
{
asynStatus status;
// Protect against excessive polling
if(time(NULL) < next_poll){
return asynSuccess;
}
status = getAxisStatus(moving);
if(*moving == false && waitStart == 1){
*moving = true;
@ -675,6 +709,12 @@ asynStatus LiftAxis::poll(bool *moving)
if(*moving){
waitStart = 0;
}
if(*moving){
next_poll = time(NULL) + BUSYPOLL;
} else {
next_poll = time(NULL) + IDLEPOLL;
}
callParamCallbacks();
return status;
}

View File

@ -28,7 +28,7 @@ class pmacAxis : public SINQAxis
{
public:
/* These are the methods we override from the base class */
pmacAxis(pmacController *pController, int axisNo);
pmacAxis(pmacController *pController, int axisNo, bool enable=true);
virtual ~pmacAxis();
asynStatus move(double position, int relative, double min_velocity, double max_velocity, double acceleration);
asynStatus moveVelocity(double min_velocity, double max_velocity, double acceleration);
@ -62,6 +62,10 @@ class pmacAxis : public SINQAxis
int homing;
double statusPos;
time_t next_poll;
bool autoEnable;
friend class pmacController;
};
@ -84,7 +88,7 @@ class SeleneAxis : public pmacAxis
{
public:
SeleneAxis(SeleneController *pController, int axisNo, double limitTarget) : pmacAxis((pmacController *)pController,axisNo)
SeleneAxis(SeleneController *pController, int axisNo, double limitTarget) : pmacAxis((pmacController *)pController, axisNo, false)
{
this->limitTarget = limitTarget;
};
@ -113,11 +117,15 @@ class SeleneAxis : public pmacAxis
Mark Koennecke, February 2020
The axis should not be enabled automatically
Michele Brambilla, February 2020
*/
class LiftAxis : public pmacAxis
{
public:
LiftAxis(pmacController *pController, int axisNo) : pmacAxis((pmacController *)pController,axisNo) {};
LiftAxis(pmacController *pController, int axisNo) : pmacAxis((pmacController *)pController,axisNo,false) {};
asynStatus move(double position, int relative, double min_velocity, double max_velocity, double acceleration);
asynStatus poll(bool *moving);
asynStatus stop(double acceleration);

View File

@ -726,14 +726,14 @@ asynStatus SeleneController::writeFloat64(asynUser *pasynUser, epicsFloat64 valu
// TODO: somethign is really shitty here: lowLimit and highLimit cannot be on the command
if (function == motorLowLimit_) {
sprintf(command, "Q%d54=%d", pAxis->axisNo_, (int)(value/MULT));
sprintf(command, "Q%d54=%f", pAxis->axisNo_, value/MULT);
// sprintf(command, "Q%d54=%d", pAxis->axisNo_, (int)(value/pAxis->scale_/MULT));
asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW,
"%s: Setting low limit on controller %s, axis %d to %f\n",
functionName, portName, pAxis->axisNo_, value);
errlogPrintf("Setting low limit of axis %d to %f, command = %s\n", pAxis->axisNo_, value, command);
} else if (function == motorHighLimit_) {
sprintf(command, "Q%d53=%d", pAxis->axisNo_, (int)(value/MULT));
sprintf(command, "Q%d53=%f", pAxis->axisNo_, value/MULT);
// sprintf(command, "Q%d53=%d", pAxis->axisNo_, (int)(value/pAxis->scale_/MULT));
asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW,
"%s: Setting high limit on controller %s, axis %d to %f\n",