Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OMS: Synchronize motor position with encoder position before every move #93

Merged
merged 2 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions motorApp/OmsAsynSrc/omsBaseAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
FILENAME... omsBaseAxis.cpp
USAGE... Pro-Dex OMS asyn motor base axes support

Version: $Revision$
Modified By: $Author$
Last Modified: $Date$
HeadURL: $URL$
*/


Expand All @@ -28,6 +32,7 @@ omsBaseAxis::omsBaseAxis(omsBaseController *pController, int axis, char axisChar
stepper = 1;
invertLimit = 0;
lastminvelo = 0;
encoderRatio = 1.0;
}

asynStatus omsBaseAxis::move(double position, int relative, double min_velocity, double max_velocity, double acceleration)
Expand All @@ -36,9 +41,36 @@ asynStatus omsBaseAxis::move(double position, int relative, double min_velocity,
static const char *functionName = "moveAxis";

asynStatus status = asynError;

char buff[100];
char encoderPositionResponse[64];

int hasEncoder = 0;
if (pC_->getIntegerParam(axisNo_, pC_->motorStatusHasEncoder_, &hasEncoder) == asynError)
{
return asynError;
}

if (hasEncoder != 0)
{
sprintf(buff, "A%1c;RE;", axisChar);
status = pC_->sendReceiveLock(buff, encoderPositionResponse, 64);
if (status == asynError)
{
return status;
}

int motorPosition = static_cast<int>(atoi(encoderPositionResponse) / encoderRatio);
asynPrint(pasynUser_, ASYN_TRACE_FLOW,
"%s:%s: Set driver %s motor position %d from encoder position %s\n",
driverName, functionName, pC_->portName, motorPosition, encoderPositionResponse);

sprintf(buff, "A%1c;LO%d;", axisChar, motorPosition);
status = pC_->sendOnlyLock(buff);
}

epicsInt32 minvelo, velo, acc, rela, pos;
char *relabs[2] = {(char *) "MA", (char *) "MR"};
char buff[100];

if (relative)
rela = 1;
Expand Down Expand Up @@ -81,7 +113,7 @@ asynStatus omsBaseAxis::move(double position, int relative, double min_velocity,
status = pC_->sendOnlyLock(buff);

asynPrint(pasynUser_, ASYN_TRACE_FLOW,
"%s:%s: Set driver %s, axis %d move to %f, min vel=%f, max_vel=%f, accel=%f",
"%s:%s: Set driver %s, axis %d move to %f, min vel=%f, max_vel=%f, accel=%f\n",
driverName, functionName, pC_->portName, axisNo_, position, min_velocity, max_velocity, acceleration );

return status;
Expand Down Expand Up @@ -124,7 +156,7 @@ asynStatus omsBaseAxis::home(double min_velocity, double max_velocity, double ac
homing = 1;

asynPrint(pasynUser_, ASYN_TRACE_FLOW,
"%s:%s: Set driver %s, axis %d to home %s, min vel=%f, max_vel=%f, accel=%f",
"%s:%s: Set driver %s, axis %d to home %s, min vel=%f, max_vel=%f, accel=%f\n",
driverName, functionName, pC_->portName, axisNo_, (forwards?"FORWARDS":"REVERSE"), min_velocity, max_velocity, acceleration );

return status;
Expand Down
16 changes: 11 additions & 5 deletions motorApp/OmsAsynSrc/omsBaseAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
FILENAME... omsBaseAxis.h
USAGE... Pro-Dex OMS asyn motor base axes support

Version: $Revision$
Modified By: $Author$
Last Modified: $Date$
HeadURL: $URL$
*/

/*
Expand Down Expand Up @@ -29,11 +33,12 @@ class omsBaseAxis : public asynMotorAxis
virtual asynStatus setPosition(double position);
virtual asynStatus poll(bool *moving);

int getAxis(){return axisNo_;};
int isStepper(){return stepper;};
void setStepper(int val){stepper=val;};
int getLimitInvert(){return invertLimit;};
void setLimitInvert(int val){invertLimit=val;};
int getAxis(){return axisNo_;}
int isStepper(){return stepper;}
void setStepper(int val){stepper=val;}
int getLimitInvert(){return invertLimit;}
void setLimitInvert(int val){invertLimit=val;}
virtual asynStatus setEncoderRatio(double ratio){encoderRatio=ratio; return asynSuccess;}
int card;
int moveDelay;
char axisChar;
Expand All @@ -45,6 +50,7 @@ class omsBaseAxis : public asynMotorAxis
int stepper;
int invertLimit;
epicsInt32 lastminvelo;
double encoderRatio;

friend class omsBaseController;
};
Expand Down