@@ -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.
0 commit comments