Skip to content

Commit

Permalink
Fix DMOV set true whilst controller still outputting step pulses
Browse files Browse the repository at this point in the history
  • Loading branch information
ics committed Jan 24, 2025
1 parent 7a0c7f7 commit c2fe8a3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
43 changes: 28 additions & 15 deletions GalilSup/src/GalilAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ asynStatus GalilAxis::move(double position, int relative, double minVelocity, do
static const char *functionName = "GalilAxis::move";
int deferredMode; //Deferred move mode
//Is controller using main or auxillary encoder register for positioning
double readback = (ctrlUseMain_) ? encoder_position_ : motor_position_;
double readback = (motorIsServo_) ? encoder_position_ : motor_position_;
asynStatus status = asynError;

//If this axis is being driven by a CSAxis
Expand Down Expand Up @@ -1022,7 +1022,7 @@ asynStatus GalilAxis::checkLimits(const char *caller, char callaxis, double posi

if (!status) {
//Readback in steps
readback = (ctrlUseMain_) ? encoder_position_ : motor_position_;
readback = (motorIsServo_) ? encoder_position_ : motor_position_;
//Check physical limits
if ((position < readback && rev) || (position > readback && fwd)) {
mesg = string(caller) + " " + string(1, callaxis) + " failed, " + string(1, axisName_) + " ";
Expand Down Expand Up @@ -1625,7 +1625,7 @@ asynStatus GalilAxis::invert_ssi(void)
//Retrieve SSI dataform
pC_->getIntegerParam(axisNo_, pC_->GalilSSIData_, &ssidataform);
//Direction invert only for stepper and binary dataform combination
if (ssidataform == 0 && !ctrlUseMain_)
if (ssidataform == 0 && !motorIsServo_)
{
//Binary data form
//Invert encoder direction
Expand Down Expand Up @@ -1668,6 +1668,7 @@ asynStatus GalilAxis::getStatus(void)
int brakeport; //Brake port for this axis
int limitDisable = 0; //Limit disabled param
bool ctrlType; //Controller type
double reference_position; //Reference position

//If data record query success in GalilController::acquireDataRecord
if (pC_->recstatus_ == asynSuccess) {
Expand Down Expand Up @@ -1722,6 +1723,18 @@ asynStatus GalilAxis::getStatus(void)
strcpy(src, "_TPx");
src[3] = axisName_;
encoder_position_ = pC_->sourceValue(pC_->recdata_, src);
//If this is a stepper then profile might be done, but the pulse output might not be done yet
//Pulse output done when reference_position (commanded target) = motor position (steps output by controller)
if (!motorIsServo_ && !inmotion_) {
//Reference position (commanded target)
strcpy(src, "_RPx");
src[3] = axisName_;
reference_position = pC_->sourceValue(pC_->recdata_, src);
if (motor_position_ != reference_position) {
//Profile complete, but pulse output isn't
inmotion_ = true;
}
}
//Invert SSI encoder direction
if (invert_ssi_)
invert_ssi();
Expand Down Expand Up @@ -1785,7 +1798,7 @@ void GalilAxis::setStatus(bool *moving)

//Encoder move status
encoderMove_ = false;
if (ueip_ || ctrlUseMain_)
if (ueip_ || motorIsServo_)
{
//Check encoder move
if (last_encoder_position_ > (encoder_position_ + enc_tol_))
Expand Down Expand Up @@ -1825,7 +1838,7 @@ void GalilAxis::checkEncoder(void)
double estall_time; //Allowed encoder stall time specified by user
double pestall_time; //Possible encoder stall has been happening for this many secs

if (((ueip_ || ctrlUseMain_) && !done_ && !deferredMove_ && (!encoderMove_ || !encDirOk_)))
if (((ueip_ || motorIsServo_) && !done_ && !deferredMove_ && (!encoderMove_ || !encDirOk_)))
{
//Record time when possible stall was first detected
if (!pestall_detected_)
Expand Down Expand Up @@ -1861,7 +1874,7 @@ void GalilAxis::checkEncoder(void)
}
}
}
else if (((ueip_ || ctrlUseMain_) && !done_ && encoderMove_ && encDirOk_ && !stopSent_) || (!done_ && !ueip_ && !ctrlUseMain_ && !stopSent_))
else if (((ueip_ || motorIsServo_) && !done_ && encoderMove_ && encDirOk_ && !stopSent_) || (!done_ && !ueip_ && !motorIsServo_ && !stopSent_))
{
//Reset stalled encoder flag when moving ok
//Pass stall status to higher layers
Expand Down Expand Up @@ -1894,7 +1907,7 @@ void GalilAxis::syncEncodedStepper(void)
pC_->getIntegerParam(axisNo_, pC_->GalilHoming_, &homing);

//Motor just stopped
if (ueip_ && !ctrlUseMain_ && done_ && !last_done_ && !syncEncodedStepperAtStopSent_ &&
if (ueip_ && !motorIsServo_ && done_ && !last_done_ && !syncEncodedStepperAtStopSent_ &&
!homing_ && !homing) {
//Request encoder value be copied to step register
pollRequest_.send((void*)&MOTOR_STEP_SYNC_ATSTOP, sizeof(int));
Expand All @@ -1910,7 +1923,7 @@ void GalilAxis::syncEncodedStepper(void)
mreadback = motor_position_ * mres;
ereadback = encoder_position_ * eres;
//Stepper motor not moving, but encoder moved more than retry deadband
if (ueip_ && !ctrlUseMain_ && done_ && last_done_ && !homing_ && !homing &&
if (ueip_ && !motorIsServo_ && done_ && last_done_ && !homing_ && !homing &&
!syncEncodedStepperAtEncSent_ && (mreadback < ereadback - rdbd || mreadback > ereadback + rdbd)) {
//Request encoder value be copied to step register
pollRequest_.send((void*)&MOTOR_STEP_SYNC_ATENC, sizeof(int));
Expand Down Expand Up @@ -1972,7 +1985,7 @@ void GalilAxis::checkHoming(void)
softlimits = (bool)(lowLimit_ == highLimit_ && lowLimit_ == 0.0) ? false : true;

//Is controller using main or auxillary encoder register for positioning
double readback = (ctrlUseMain_) ? encoder_position_ : motor_position_;
double readback = (motorIsServo_) ? encoder_position_ : motor_position_;

if ((homing_ && (stoppedTime_ >= HOMING_TIMEOUT) && !cancelHomeSent_) ||
(((readback > highLimit_ && softlimits) || (readback < lowLimit_ && softlimits)) && homing_ && !cancelHomeSent_ && done_))
Expand Down Expand Up @@ -2411,7 +2424,7 @@ asynStatus GalilAxis::beginMotion(const char *caller, double position, bool rela
if (!relative)
{
//Retrieve readback
readback = (ctrlUseMain_) ? encoder_position_ : motor_position_;
readback = (motorIsServo_) ? encoder_position_ : motor_position_;
//If new position differs from readback, then write new position
if (trunc(position) == trunc(readback))
return asynSuccess;//Nothing to do
Expand Down Expand Up @@ -2473,7 +2486,7 @@ asynStatus GalilAxis::jogAfterHome(void) {
sprintf(pC_->cmd_, "DP%c=0", axisName_);
pC_->sync_writeReadController();
//Program encoder position register
if (ueip_ || ctrlUseMain_) {
if (ueip_ || motorIsServo_) {
sprintf(pC_->cmd_, "DE%c=0", axisName_);
pC_->sync_writeReadController();
}
Expand Down Expand Up @@ -2906,7 +2919,7 @@ void GalilAxis::set_ssi_connectflag(void)
//set connect flag accordingly
if ((ssiinput == 1 && !encoderSwapped_) || (ssiinput == 2 && encoderSwapped_)) //Main encoder
ssi_connect = (encoder_position_ == disconnect_val) ? 0 : 1;
if ((ssiinput == 2 && !encoderSwapped_ && ctrlUseMain_) || (ssiinput == 1 && encoderSwapped_ && ctrlUseMain_)) //Aux encoder
if ((ssiinput == 2 && !encoderSwapped_ && motorIsServo_) || (ssiinput == 1 && encoderSwapped_ && motorIsServo_)) //Aux encoder
ssi_connect = (motor_position_ == disconnect_val) ? 0 : 1;
//Set motorRecord MSTA bit 15 motorStatusHomed_
//With SSI encoder, just move it where you want it
Expand Down Expand Up @@ -3020,7 +3033,7 @@ asynStatus GalilAxis::set_ssi(void)
pC_->sync_writeReadController();
encoderSwapped_ = (bool)atoi(pC_->resp_);

if ((ssiinput == 2 && !encoderSwapped_ && !ctrlUseMain_) || (ssiinput == 1 && encoderSwapped_ && !ctrlUseMain_))
if ((ssiinput == 2 && !encoderSwapped_ && !motorIsServo_) || (ssiinput == 1 && encoderSwapped_ && !motorIsServo_))
{
sprintf(mesg, "%c cannot use auxillary encoder for SSI whilst motor is stepper", axisName_);
pC_->setCtrlError(mesg);
Expand Down Expand Up @@ -3134,8 +3147,8 @@ asynStatus GalilAxis::set_biss(void)
//Figure out if we have a stepper
stepper = ((motortype >= 2) && (motortype <= 5));

if ((bissInput == 2 && !encoderSwapped_ && !ctrlUseMain_ && stepper)
|| (bissInput == 1 && encoderSwapped_ && !ctrlUseMain_ && stepper)) {
if ((bissInput == 2 && !encoderSwapped_ && !motorIsServo_ && stepper)
|| (bissInput == 1 && encoderSwapped_ && !motorIsServo_ && stepper)) {
sprintf(mesg, "%c cannot use auxillary encoder for BiSS whilst motor is stepper", axisName_);
pC_->setCtrlError(mesg);
status = asynError;
Expand Down
4 changes: 3 additions & 1 deletion GalilSup/src/GalilAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ class GalilAxis : public asynMotorAxis

int ueip_; //motorRecord ueip. User wants to read main encoder if true, aux if false
int enc_tol_; //encoder tolerance. Used for determining encoder direction in setStatus()
bool ctrlUseMain_; //Based on selected motor type controller will use main or aux encoder register for positioning
bool motorIsServo_; //If true, controller will use main encoder for positioning
//If false, controller will use aux encoder for positioning

bool setPositionIn_; //Flag to indicate associated CSAxis position change via motor record set/use field
//Set by GalilCSAxis, consumed by GalilAxis
bool setPositionOut_; //Flag to indicate this axis position change via motor record set/use field
Expand Down
6 changes: 3 additions & 3 deletions GalilSup/src/GalilCSAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ asynStatus GalilCSAxis::checkMotorVelocities(double npos[], double nvel[], doubl
//Calculate incremental move distance in steps
//Here we must use the register the controller uses for positioning
//This may differ from the real axis motor record readback as set by ueip
incmove[i] = (pAxis->ctrlUseMain_) ? npos[i] - epos : npos[i] - mpos;
incmove[i] = (pAxis->motorIsServo_) ? npos[i] - epos : npos[i] - mpos;
//Sum vector distance, velocity for non zero move increments
if (fabs(incmove[i]) != 0.0)
{
Expand Down Expand Up @@ -1013,7 +1013,7 @@ asynStatus GalilCSAxis::moveVelocity(double minVelocity, double maxVelocity, dou
{
//Sync start stop move
//Calculate this motors readback
readback = (pAxis->ctrlUseMain_) ? pAxis->encoder_position_ : pAxis->motor_position_;
readback = (pAxis->motorIsServo_) ? pAxis->encoder_position_ : pAxis->motor_position_;
//Convert absolute position back to incremental distance for sanity check
axisIncrement = npos[i] - readback;
}
Expand Down Expand Up @@ -1912,7 +1912,7 @@ asynStatus GalilCSAxis::reverseTransform(double pos, double vel, double accel, d
// Calculate direction multiplier
dirm = (dir == 0) ? 1 : -1;
// Determine reverse axis readback in dial coordinates
readback = (pAxis->ctrlUseMain_) ? (pAxis->encoder_position_ * eres) : (pAxis->motor_position_ * mres);
readback = (pAxis->motorIsServo_) ? (pAxis->encoder_position_ * eres) : (pAxis->motor_position_ * mres);
// Convert readback to user coordinates
readback = (readback * dirm) + off;

Expand Down
8 changes: 6 additions & 2 deletions GalilSup/src/GalilController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@
//
// 16/01/2025 M.Clift
// Fix unknown amplifier messages at ioc start when no controller
// 24/01/2025 R.Riley, M.Rivers
// Fix DMOV set true whilst controller still outputting step pulses that occurred
// when the step smoothing factor (motor_extras) set higher than controller default
//

#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -475,7 +479,7 @@ using namespace std; //cout ostringstream vector string
#include <epicsExport.h>

static const char *driverName = "GalilController";
static const char *driverVersion = "3-6-100";
static const char *driverVersion = "3-6-101";

static void GalilProfileThreadC(void *pPvt);
static void GalilArrayUploadThreadC(void *pPvt);
Expand Down Expand Up @@ -4145,7 +4149,7 @@ asynStatus GalilController::writeInt32(asynUser *pasynUser, epicsInt32 value)
status = sync_writeReadController();

//Determine if controller will use main or auxillary register with selected motor type
pAxis->ctrlUseMain_ = (value < 2 || (value >= 6 && value <= 12)) ? true : false;
pAxis->motorIsServo_ = (value < 2 || (value >= 6 && value <= 12)) ? true : false;

//IF motor was servo, and now stepper
//Galil hardware MAY push main encoder to aux encoder (stepper count reg)
Expand Down

0 comments on commit c2fe8a3

Please sign in to comment.