diff --git a/huberApp/src/SMC9300Driver.cpp b/huberApp/src/SMC9300Driver.cpp index 16640e0..6d92afe 100644 --- a/huberApp/src/SMC9300Driver.cpp +++ b/huberApp/src/SMC9300Driver.cpp @@ -199,6 +199,7 @@ asynStatus SMC9300Axis::move(double position, int relative, double minVelocity, asynStatus SMC9300Axis::home(double minVelocity, double maxVelocity, double acceleration, int forwards) { asynStatus status; + // set homing direction on axis so that it can be passed into thread. if(forwards ==1){ this->forward = true; }else{ @@ -214,33 +215,41 @@ asynStatus SMC9300Axis::home(double minVelocity, double maxVelocity, double acce } static void huberHomingThreadC(void *pPvt){ + //static function to handle homing in a different thread. SMC9300Axis *axis = (SMC9300Axis*)pPvt; axis->homing(); } asynStatus SMC9300Axis::homing() { + // reset stop status this->stopStatus = false; asynStatus status; char limitDirection, referenceDirection; + // Always consider the hardware reference to be 0. epicsFloat64 homePos = 0.0; asynStatus lockStatus; - int highLimit = 0, lowLimit = 0, atRest = 0; + + int limit = 0, limitCheck = 0, atRest = 0; + + // Set directions of travel and limit to check. if(this->forward){ limitDirection='+'; referenceDirection='-'; + limitCheck = pC_->motorStatusHighLimit_; + }else{ limitDirection='-'; referenceDirection='+'; + limitCheck = pC_->motorStatusLowLimit_; } - + // First go to a limit to ensure the reference point cannot be missed. lockStatus = pC_->lock(); sprintf(pC_->outString_, "fast%d%c", axisNo_, limitDirection); status = pC_->writeController(); - while(highLimit == 0 && lowLimit == 0){ - pC_->getIntegerParam(axisNo_, pC_->motorStatusHighLimit_, &highLimit); - pC_->getIntegerParam(axisNo_, pC_->motorStatusLowLimit_, &lowLimit); + while(limit == 0){ + pC_->getIntegerParam(axisNo_, limitCheck, &limit); lockStatus = pC_->unlock(); if(this->stopStatus){ return status; @@ -248,11 +257,13 @@ asynStatus SMC9300Axis::homing() epicsThreadSleep(0.1); lockStatus = pC_->lock(); } + // Now search for the reference point, moving away from the limit. sprintf(pC_->outString_, "eref%d%c", axisNo_, referenceDirection); status = pC_->writeController(); pC_->unlock(); // sleep needed to avoid race condition with polling. epicsThreadSleep(1); + //Always loop at least once to allow the move to reference to start. do{ if(this->stopStatus){ return status; @@ -261,15 +272,25 @@ asynStatus SMC9300Axis::homing() pC_->lock(); pC_->getIntegerParam(axisNo_, pC_->motorStatusDone_, &atRest); pC_->unlock(); - + // Due to the sleep + the initial loop, when atRest is 0 we must either be at the reference, + // Or have reached the other limit. } while (atRest == 0); + if(this->stopStatus){ return status; } pC_->lock(); - sprintf(pC_->outString_, "pos%d:%f", axisNo_, homePos); + + // Set the current position to be 0. + sprintf(pC_->outString_, "pos%d:%f", axisNo_, homePos / STEPS_PER_EGU); status = pC_->writeController(); + + // reset the set point to also be 0. + pC_->setDoubleParam(axisNo_, pC_->motorMoveAbs_, homePos); + callParamCallbacks(); + pC_->unlock(); + asynPrint(pasynUser_, ASYN_TRACE_FLOW, "Axis %i Completed Home.\n", axisNo_); return status; } diff --git a/system_tests/lewis_emulators/huber/device.py b/system_tests/lewis_emulators/huber/device.py index 4bdb1de..dd9e4b5 100644 --- a/system_tests/lewis_emulators/huber/device.py +++ b/system_tests/lewis_emulators/huber/device.py @@ -13,7 +13,7 @@ def _initialize_data(self): self._target = 0.0 self.initial_speed = 2.0 self.current_speed = 0 - self.high_speed = 10000 + self.high_speed = 1000 self.high_speed_move = False self.number_axis = 3 self.acceleration = 0.01 diff --git a/system_tests/lewis_emulators/huber/interfaces/stream_interface.py b/system_tests/lewis_emulators/huber/interfaces/stream_interface.py index 68fd226..2fa1d55 100644 --- a/system_tests/lewis_emulators/huber/interfaces/stream_interface.py +++ b/system_tests/lewis_emulators/huber/interfaces/stream_interface.py @@ -105,7 +105,7 @@ def get_position(self, axis): def goto_reference(self, axis, direction): self.device.high_speed_move = True - self.device.set_target(0) + self.device.set_target(self.device.reference_point) def get_state(self, axis): """ diff --git a/system_tests/tests/huber.py b/system_tests/tests/huber.py index 0a8fbf2..e924181 100644 --- a/system_tests/tests/huber.py +++ b/system_tests/tests/huber.py @@ -70,24 +70,23 @@ def test_GIVEN_move_AND_stop_THEN_stop(self): self.ca.assert_that_pv_is_not(MTR1, float(0)) def test_GIVEN_home_forwards_THEN_motor_moves_to_limit_at_fast_speed_THEN_motor_moves_to_eref_AND_sets_position(self): - home = 10 - self._lewis.backdoor_set_on_device("reference_point", home) + self._lewis.backdoor_set_on_device("reference_point", 0) self.ca.set_pv_value(f"{MTR1}.HOMF", 1) self.ca.assert_that_pv_is_number(f"{MTR1}.RBV", 1000, 1, timeout=30) self.ca.assert_that_pv_is_not_number(f"{MTR1}.RBV", 1000, 1, timeout=30) self.ca.assert_that_pv_is_number(f"{MTR1}.RBV", 0, 1, timeout=30) + self.ca.assert_that_pv_is_number(f"{MTR1}.VAL", 0, 1, timeout=30) def test_GIVEN_home_reverse_THEN_motor_moves_to_limit_at_fast_speed_THEN_motor_moves_to_eref_AND_sets_position(self): - home = 10 - self._lewis.backdoor_set_on_device("reference_point", home) + self._lewis.backdoor_set_on_device("reference_point", 0) self.ca.set_pv_value(f"{MTR1}.HOMR", 1) self.ca.assert_that_pv_is_number(f"{MTR1}.RBV", -1000, 1, timeout=30) self.ca.assert_that_pv_is_not_number(f"{MTR1}.RBV", -1000, 1, timeout=30) self.ca.assert_that_pv_is_number(f"{MTR1}.RBV", 0, 1, timeout=30) + self.ca.assert_that_pv_is_number(f"{MTR1}.VAL", 0, 1, timeout=30) def test_GIVEN_home_reverse_THEN_motor_moves_to_limit_at_fast_speed_THEN_stop_THEN_motor_STOPS(self): - home = 10 - self._lewis.backdoor_set_on_device("reference_point", home) + self._lewis.backdoor_set_on_device("reference_point", 0) self._lewis.backdoor_set_on_device("high_speed", 5) self.ca.set_pv_value(f"{MTR1}.HOMR", 1) self.ca.assert_that_pv_is_not_number(f"{MTR1}.RBV", 0, 1, timeout=30) @@ -96,8 +95,7 @@ def test_GIVEN_home_reverse_THEN_motor_moves_to_limit_at_fast_speed_THEN_stop_TH self.ca.assert_that_pv_is_not_number(f"{MTR1}.RBV", -1000, 1, timeout=30) def test_GIVEN_home_reverse_THEN_motor_moves_to_limit_at_fast_speed_THEN_THEN_STOP(self): - home = 10 - self._lewis.backdoor_set_on_device("reference_point", home) + self._lewis.backdoor_set_on_device("reference_point", 0) self._lewis.backdoor_set_on_device("high_speed", 5) self.ca.set_pv_value(f"{MTR1}.HOMR", 1) self.ca.assert_that_pv_is_number(f"{MTR1}.RBV", -1000, 1, timeout=30)