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

Ticket 7277 fix issues with huber #3

Merged
merged 5 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 28 additions & 7 deletions huberApp/src/SMC9300Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -214,45 +215,55 @@ 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;
}
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;
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion system_tests/lewis_emulators/huber/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
14 changes: 6 additions & 8 deletions system_tests/tests/huber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down