Skip to content

Commit 921f41a

Browse files
Add methods for getting string for disable and restore limits
1 parent f574781 commit 921f41a

File tree

7 files changed

+108
-88
lines changed

7 files changed

+108
-88
lines changed

pmacApp/src/pmacAxis.cpp

Lines changed: 33 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pmacAxis::pmacAxis(pmacController *pC, int axisNo)
7575
highLimit_ = 0.0;
7676
lowLimit_ = 0.0;
7777
limitsDisabled_ = 0;
78+
limitsEnabled_ = true;
7879
stepSize_ = 1; //Don't need?
7980
deferredPosition_ = 0.0;
8081
cachedPosition_ = 0.0;
@@ -92,6 +93,7 @@ pmacAxis::pmacAxis(pmacController *pC, int axisNo)
9293
fatal_following_ = 0;
9394
encoder_axis_ = 0;
9495
limitsCheckDisable_ = 0;
96+
limitsEnableAddr_ = "";
9597
nowTimeSecs_ = 0.0;
9698
lastTimeSecs_ = 0.0;
9799
printNextError_ = false;
@@ -330,13 +332,12 @@ asynStatus pmacAxis::move(double position, int relative, double min_velocity, do
330332
}
331333

332334
#ifdef REMOVE_LIMITS_ON_HOME
333-
if (limitsDisabled_) {
335+
if (!limitsEnabled_) {
334336
char buffer[PMAC_MAXBUF] = {0};
335337
/* Re-enable limits */
336-
// LMDS
337-
sprintf(buffer, "i%d24=i%d24&$FDFFFF", axisNo_, axisNo_);
338+
strncat(buffer, pC_->pHardware_->getRestoreAxisLimitsCmd(axisNo_, limitsEnableAddr_).c_str(), PMAC_MAXBUF - 1);
338339
strncat(command, buffer, PMAC_MAXBUF - 1);
339-
limitsDisabled_ = 0;
340+
limitsEnabled_ = true;
340341
}
341342
#endif
342343
debug(DEBUG_TRACE, functionName, "Axis Move command", command);
@@ -394,57 +395,22 @@ pmacAxis::home(double min_velocity, double max_velocity, double acceleration, in
394395
double home_velocity = 0.0;
395396
char buffer[PMAC_MAXBUF] = {0};
396397

397-
// /* Discover type of controller */
398-
// strncpy(buffer, "cid", PMAC_MAXBUF);
399-
// status = pC_->lowLevelWriteRead(buffer, response);
400-
// if (status != asynSuccess) {
401-
// asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
402-
// "Controller %s Addr %d. %s: ERROR Reading Controller Type.\n", pC_->portName, axisNo_,
403-
// functionName);
404-
// return asynError;
405-
// }
406-
// nvals = sscanf(response, "%d", &controller_type);
407-
408-
// if (controller_type == pC_->PMAC_CID_GEOBRICK_ || controller_type == pC_->PMAC_CID_CLIPPER_) {
409-
// asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
410-
// "Controller %s Addr %d. %s: This is a Geobrick LV.\n", pC_->portName, axisNo_,
411-
// functionName);
412-
// } else if (controller_type == pC_->PMAC_CID_PMAC_) {
413-
// asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
414-
// "Controller %s Addr %d. %s: This is a Turbo PMAC 2 Ultralite.\n", pC_->portName,
415-
// axisNo_, functionName);
416-
// } else if (controller_type == pC_->PMAC_CID_POWER_) {
417-
// asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
418-
// "Controller %s Addr %d. %s: This is a Power Brick.\n", pC_->portName,
419-
// axisNo_, functionName);
420-
// } else {
421-
// asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
422-
// "Controller %s Addr %d. %s: ERROR Unknown controller type = %d.\n", pC_->portName,
423-
// axisNo_, functionName, controller_type);
424-
// return asynError;
425-
// }
426-
427-
428-
429398
controller_type = pC_->cid_;
430399
if ( controller_type == pC_->PMAC_CID_POWER_) {
431400
/* Read home flags and home direction from PowerBrick LV */
432401
// ixx23 and ixx26 are just valid up to Motor[49], so to avoid execptions the Motor[x] structure was used instead
433402
// ixx24 has a different purpose on PowerPMAC, so Motor[x].pLimits was used instead
434403
// 'Gate3' was used instead of the alias 'PowerBrick' to reduce the number of characters
435404

436-
// int gateIndex = (axisNo_ < 5) ? 0 : 1;
437-
// int chanIndex = (axisNo_ < 5) ? axisNo_ - 1 : axisNo_ - 5;
438-
// char limitsAddress[PMAC_MAXBUF] = {0};
439-
// // Gets limits pointer
440-
// sprintf(buffer, "Motor[%d].pLimits", axisNo_);
441-
// status = pC_->lowLevelWriteRead(buffer, response);
405+
int gateIndex = (axisNo_ < 5) ? 0 : 1;
406+
int chanIndex = (axisNo_ < 5) ? axisNo_ - 1 : axisNo_ - 5;
407+
char limitsAddress[PMAC_MAXBUF] = {0};
442408
// strncpy(limitsAddress, response, PMAC_MAXBUF);
443-
// sprintf(buffer, "Gate3[%d].Chan[%d].CaptCtrl Gate3[%d].Chan[%d].CaptFlag %s Motor[%d].HomeVel Motor[%d].HomeOffset",
444-
// gateIndex, chanIndex, gateIndex, chanIndex, limitsAddress, axisNo_, axisNo_);
445-
// status = pC_->lowLevelWriteRead(buffer, response);
446-
// nvals = sscanf(response, "%d %d $%x %lf %d", &home_type, &home_flag, &flag_mode, &home_velocity,
447-
// &home_offset);
409+
sprintf(buffer, "Gate3[%d].Chan[%d].CaptCtrl Gate3[%d].Chan[%d].CaptFlagSel Motor[%d].pLimits Motor[%d].HomeVel Motor[%d].HomeOffset",
410+
gateIndex, chanIndex, gateIndex, chanIndex, axisNo_, axisNo_, axisNo_);
411+
status = (pC_->lowLevelWriteRead(buffer, response));
412+
nvals = sscanf(response, "%d %d %s %lf %d", &home_type, &home_flag, limitsAddress, &home_velocity,
413+
&home_offset);
448414
}
449415
// TODO: store flag_mode for re-enabling the limits correctly
450416
if (controller_type == pC_->PMAC_CID_GEOBRICK_
@@ -489,12 +455,12 @@ pmacAxis::home(double min_velocity, double max_velocity, double acceleration, in
489455

490456
if ((home_type <= 15) &&
491457
(home_type % 4 >= 2) &&
492-
!(flag_mode & 0x20000) && // are the limits disabled?
458+
limitsEnabled_ &&
493459
((home_velocity > 0 && home_flag == 1 && home_offset <= 0) ||
494460
(home_velocity < 0 && home_flag == 2 && home_offset >= 0))) {
495-
sprintf(buffer, " i%d24=i%d24|$20000", axisNo_, axisNo_); // Disable limits
496-
strncat(command, buffer, PMAC_MAXBUF - 1);
497-
limitsDisabled_ = 1;
461+
// Concatenate string to disable limits to command
462+
strncat(command, pC_->pHardware_->getDisableAxisLimitsCmd(axisNo_).c_str(), PMAC_MAXBUF - 1);
463+
limitsEnabled_ = false;
498464
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
499465
"%s. Disabling limits whilst homing PMAC controller %s, axis %d, type:%d, flag:$%x, vel:%f\n",
500466
functionName, pC_->portName, axisNo_, home_type, home_flag, home_velocity);
@@ -540,12 +506,12 @@ asynStatus pmacAxis::moveVelocity(double min_velocity, double max_velocity, doub
540506
sprintf(command, "%s%s#%d %s", vel_buff, acc_buff, axisNo_, (max_velocity < 0 ? "J-" : "J+"));
541507

542508
#ifdef REMOVE_LIMITS_ON_HOME
543-
if (limitsDisabled_) {
509+
if (!limitsEnabled_) {
544510
char buffer[PMAC_MAXBUF];
545511
/* Re-enable limits */
546-
sprintf(buffer, " i%d24=i%d24&$FDFFFF", axisNo_, axisNo_);
512+
strncat(buffer, pC_->pHardware_->getRestoreAxisLimitsCmd(axisNo_, limitsEnableAddr_).c_str(), PMAC_MAXBUF - 1);
547513
strncat(command, buffer, PMAC_MAXBUF - 1);
548-
limitsDisabled_ = 0;
514+
limitsEnabled_ = true;
549515
}
550516
#endif
551517
debug(DEBUG_TRACE, functionName, "Axis MoveVelocity command", command);
@@ -701,7 +667,6 @@ asynStatus pmacAxis::getAxisStatus(pmacCommandStore *sPtr) {
701667
double enc_position = 0;
702668
int nvals = 0;
703669
int axisProblemFlag = 0;
704-
int limitsStatus = 0;
705670
bool printErrors = true;
706671
char key[16];
707672
std::string value = "";
@@ -863,18 +828,16 @@ asynStatus pmacAxis::getAxisStatus(pmacCommandStore *sPtr) {
863828
// flag, which the user can set to disable this feature.*/
864829
if (!limitsCheckDisable_) {
865830
// Check we haven't intentially disabled limits for homing.
866-
if (!limitsDisabled_) {
867-
// Parse ixx24
868-
retStatus = pC_->pHardware_->parseAxisLimitsCmd(axisNo_, sPtr, &limitsStatus);
869-
if (!(limitsStatus)) {
870-
axisProblemFlag = 1;
871-
if (printErrors) {
872-
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
873-
"*** WARNING *** Limits are disabled on controller %s, axis %d\n",
874-
pC_->portName, axisNo_);
875-
printNextError_ = false;
876-
}
877-
}
831+
// Parse ixx24 or Motor[x].pLimits
832+
retStatus = pC_->pHardware_->parseAxisLimitsCmd(axisNo_, sPtr, &limitsEnabled_, limitsEnableAddr_);
833+
if (!(limitsEnabled_)) {
834+
axisProblemFlag = 1;
835+
if (printErrors) {
836+
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
837+
"*** WARNING *** Limits are disabled on controller %s, axis %d\n",
838+
pC_->portName, axisNo_);
839+
printNextError_ = false;
840+
}
878841
}
879842
}
880843
setIntegerParam(pC_->motorStatusProblem_, axisProblemFlag);
@@ -886,12 +849,12 @@ asynStatus pmacAxis::getAxisStatus(pmacCommandStore *sPtr) {
886849
}
887850

888851
#ifdef REMOVE_LIMITS_ON_HOME
889-
if (limitsDisabled_ && (axStatus.status24Bit2_ & pC_->PMAC_STATUS2_HOME_COMPLETE) &&
852+
if (!limitsEnabled_ && (axStatus.status24Bit2_ & pC_->PMAC_STATUS2_HOME_COMPLETE) &&
890853
(axStatus.status24Bit1_ & pC_->PMAC_STATUS1_DESIRED_VELOCITY_ZERO)) {
891854
// Re-enable limits
892-
sprintf(command, "i%d24=i%d24&$FDFFFF", axisNo_, axisNo_);
855+
strncat(command, pC_->pHardware_->getRestoreAxisLimitsCmd(axisNo_, limitsEnableAddr_).c_str(), PMAC_MAXBUF - 1);
893856
cmdStatus = pC_->lowLevelWriteRead(command, response);
894-
limitsDisabled_ = (cmdStatus != 0);
857+
limitsEnabled_ = (cmdStatus == 0);
895858
}
896859
#endif
897860
// Set amplifier enabled bit.

pmacApp/src/pmacAxis.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/********************************************
22
* pmacAxis.cpp
3-
*
4-
* PMAC Asyn motor based on the
3+
*
4+
* PMAC Asyn motor based on the
55
* asynMotorAxis class.
6-
*
6+
*
77
* Matthew Pearson
88
* 23 May 2012
9-
*
9+
*
1010
********************************************/
1111

1212
#ifndef pmacAxis_H
@@ -101,6 +101,7 @@ class pmacAxis : public asynMotorAxis, pmacCallbackInterface, public pmacDebugge
101101
double highLimit_;
102102
double lowLimit_;
103103
int limitsDisabled_;
104+
bool limitsEnabled_;
104105
double stepSize_;
105106
double deferredPosition_;
106107
double cachedPosition_;
@@ -118,12 +119,14 @@ class pmacAxis : public asynMotorAxis, pmacCallbackInterface, public pmacDebugge
118119
int fatal_following_;
119120
int encoder_axis_;
120121
int limitsCheckDisable_;
122+
std::string limitsEnableAddr_;
121123
epicsTimeStamp nowTime_;
122124
epicsFloat64 nowTimeSecs_;
123125
epicsFloat64 lastTimeSecs_;
124126
bool printNextError_;
125127
bool moving_; // only valid within poll time - used as a hint for validating deferred coordinated moves
126128
axisStatus status_;
129+
bool limitsStatus_;
127130

128131
bool connected_; // Current connection status of the hardware
129132
bool initialised_; // We need to keep a record of this in case the software starts up without a connection

pmacApp/src/pmacHardwareInterface.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ class pmacHardwareInterface {
7474

7575
virtual std::string getAxisLimitsCmd(int axis) = 0;
7676

77-
virtual asynStatus parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, int *limitStatus) = 0;
77+
virtual std::string getDisableAxisLimitsCmd(int axis) = 0;
7878

79-
// virtual asynStatus disableLimitsCmd(int axis, pmacCommandStore *sPtr, int *savedStatus) = 0;
80-
// virtual asynStatus restoreLimitsCmd(int axis, pmacCommandStore *sPtr, int *savedStatus) = 0;
79+
virtual std::string getRestoreAxisLimitsCmd(int axis, const std::string savedStatus) = 0;
80+
81+
virtual asynStatus parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, bool *limitsEnabled, std::string &pLimitsString) = 0;
8182

8283
virtual asynStatus setupCSStatus(int csNo) = 0;
8384

pmacApp/src/pmacHardwarePower.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,39 @@ static inline std::string trim(const std::string& s) {
232232
return (start == std::string::npos) ? "" : s.substr(start, end - start + 1);
233233
}
234234

235-
asynStatus pmacHardwarePower::parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, int *limitStatus) {
236-
asynStatus status = asynSuccess;
237-
int nvals = 0;
238-
std::string pLimitsString = "";
235+
std::string pmacHardwarePower::getDisableAxisLimitsCmd(int axis) {
236+
char cmd[32];
237+
static const char *functionName = "getDisableAxisLimitsCmd";
238+
char savedStatus[32];
239+
240+
debug(DEBUG_TRACE, functionName, "Axis", axis);
241+
sprintf(cmd, this->getAxisLimitsCmd(axis).c_str());
242+
printf("DEBUG: savedStatus= '%s'\n", savedStatus);
243+
sprintf(cmd, "Motor[%d].pLimits=0", axis);
244+
printf("DEBUG: DisableAxisLimitsCmd= '%s'\n", cmd);
245+
246+
return std::string(cmd);
247+
}
248+
249+
std::string pmacHardwarePower::getRestoreAxisLimitsCmd(int axis, const std::string savedStatus) {
250+
char cmd[128];
251+
static const char *functionName = "getRestoreAxisLimitsCmd";
239252

253+
debug(DEBUG_TRACE, functionName, "Axis", axis);
254+
255+
// Re-enable limits
256+
snprintf(cmd, sizeof(cmd), "Motor[%d].pLimits = %s", axis, savedStatus.c_str());
257+
return std::string(cmd);
258+
}
259+
260+
// asynStatus pmacHardwarePower::parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, bool *limitsEnabled, std::string &/*pLimitsString*/) {
261+
asynStatus pmacHardwarePower::parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, bool *limitsEnabled, std::string &pLimitsString) {
262+
asynStatus status = asynSuccess;
263+
// std::string pLimitsString = ""; // TODO move it to argument to store status
240264
static const char *functionName = "parseAxisLimitsCmd";
241265

266+
debug(DEBUG_TRACE, functionName, "Axis", axis);
267+
242268
// Get the symbolic pointer string
243269
pLimitsString = trim(sPtr->readValue(this->getAxisLimitsCmd(axis))); // e.g., "Gate3[0].Chan[0].Status.a" or "0"
244270
debug(DEBUG_VARIABLE, functionName, "pLimit string", pLimitsString);
@@ -252,10 +278,10 @@ asynStatus pmacHardwarePower::parseAxisLimitsCmd(int axis, pmacCommandStore *sPt
252278
// - Case 2
253279
// - it must begin with: "Sys.pushm", or "Sys.piom"
254280
// - it might contain "+$"
255-
*limitStatus = 1;
281+
*limitsEnabled = true;
256282
} else {
257283
// Disabled
258-
*limitStatus = 0;
284+
*limitsEnabled = false;
259285
}
260286

261287
return status;

pmacApp/src/pmacHardwarePower.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ class pmacHardwarePower : public pmacHardwareInterface, pmacDebugger {
3131

3232
std::string getAxisLimitsCmd(int axis);
3333

34-
asynStatus parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, int *limitStatus);
34+
std::string getDisableAxisLimitsCmd(int axis);
3535

36-
// asynStatus disableAxisLimits(int axis, int *addr);
36+
std::string getRestoreAxisLimitsCmd(int axis, const std::string savedStatus);
37+
38+
asynStatus parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, bool *limitsEnabled, std::string &pLimitsString);
3739

3840
asynStatus setupCSStatus(int csNo);
3941

pmacApp/src/pmacHardwareTurbo.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,34 @@ std::string pmacHardwareTurbo::getAxisLimitsCmd(int axis) {
288288
return std::string(cmd);
289289
}
290290

291-
asynStatus pmacHardwareTurbo::parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, int *limitStatus) {
291+
std::string pmacHardwareTurbo::getDisableAxisLimitsCmd(int axis/*, const std::string savedStatus*/) {
292+
char cmd[32];
293+
static const char *functionName = "getDisableAxisLimitsCmd";
294+
295+
debug(DEBUG_TRACE, functionName, "Axis", axis);
296+
sprintf(cmd, " i%d24=i%d24|$20000", axis, axis); // Disable limits
297+
298+
return(cmd);
299+
}
300+
301+
std::string pmacHardwareTurbo::getRestoreAxisLimitsCmd(int axis, const std::string) {
302+
char cmd[32];
303+
static const char *functionName = "getRestoreAxisLimitsCmd";
304+
305+
debug(DEBUG_TRACE, functionName, "Axis", axis);
306+
sprintf(cmd, " i%d24=i%d24&$FDFFFF", axis, axis); // Re-enable limits
307+
return(cmd);
308+
}
309+
310+
311+
asynStatus pmacHardwareTurbo::parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, bool *limitsEnabled, std::string&) {
292312
asynStatus status = asynSuccess;
293313
int nvals = 0;
294314
int limitsBits = 0;
295315
std::string pLimitsString = "";
296316
static const char *functionName = "parseAxisLimitsCmd";
297317

318+
debug(DEBUG_TRACE, functionName, "Axis", axis);
298319
pLimitsString = sPtr->readValue(this->getAxisLimitsCmd(axis));
299320

300321
// Response parsed for PowerPMAC
@@ -306,7 +327,7 @@ asynStatus pmacHardwareTurbo::parseAxisLimitsCmd(int axis, pmacCommandStore *sPt
306327
debug(DEBUG_ERROR, functionName, " response", pLimitsString);
307328
status = asynError;
308329
}
309-
*limitStatus = ~((0x20000 & limitsBits) >> 17);
330+
*limitsEnabled = ~((0x20000 & limitsBits) >> 17);
310331

311332
return status;
312333
}

pmacApp/src/pmacHardwareTurbo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class pmacHardwareTurbo : public pmacHardwareInterface, pmacDebugger {
3131

3232
std::string getAxisLimitsCmd(int axis);
3333

34-
asynStatus parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, int *limitStatus);
34+
std::string getDisableAxisLimitsCmd(int axis);
35+
36+
std::string getRestoreAxisLimitsCmd(int axis, const std::string savedStatus);
37+
38+
asynStatus parseAxisLimitsCmd(int axis, pmacCommandStore *sPtr, bool *limitsEnabled, std::string &pLimitsString);
3539

3640
asynStatus setupCSStatus(int csNo);
3741

0 commit comments

Comments
 (0)