Skip to content

Commit a8e5793

Browse files
committed
allow passing initFOC if only current sense
1 parent 38801b3 commit a8e5793

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

src/common/base_classes/FOCMotor.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,19 @@ void FOCMotor::updateMotionControlType(MotionControlType new_motion_controller)
499499
switch(new_motion_controller)
500500
{
501501
case(MotionControlType::angle_nocascade):
502-
if(controller != MotionControlType::angle && controller != MotionControlType::angle_openloop) break;
502+
if(controller == MotionControlType::angle || controller == MotionControlType::angle_openloop) break;
503503
case MotionControlType::angle:
504-
if(controller != MotionControlType::angle_openloop && controller != MotionControlType::angle_nocascade) break;
504+
if(controller == MotionControlType::angle_openloop || controller == MotionControlType::angle_nocascade) break;
505505
case MotionControlType::angle_openloop:
506-
if(controller != MotionControlType::angle && controller != MotionControlType::angle_nocascade) break;
506+
if(controller == MotionControlType::angle || controller == MotionControlType::angle_nocascade) break;
507507
// if the previous controller was not angle control
508508
// set target to current angle
509509
target = shaft_angle;
510510
break;
511511
case MotionControlType::velocity:
512-
if(controller != MotionControlType::velocity_openloop) break; // nothing to do if we are already in velocity control
512+
if(controller == MotionControlType::velocity_openloop) break; // nothing to do if we are already in velocity control
513513
case MotionControlType::velocity_openloop:
514-
if(controller != MotionControlType::velocity) break;
514+
if(controller == MotionControlType::velocity) break;
515515
// if the previous controller was not velocity control
516516
// stop the motor
517517
target = 0;
@@ -764,23 +764,6 @@ int FOCMotor::initFOC() {
764764
// added the shaft_angle update
765765
sensor->update();
766766
shaft_angle = shaftAngle();
767-
768-
// aligning the current sensor - can be skipped
769-
// checks if driver phases are the same as current sense phases
770-
// and checks the direction of measuremnt.
771-
if(exit_flag){
772-
if(current_sense){
773-
if (!current_sense->initialized) {
774-
motor_status = FOCMotorStatus::motor_calib_failed;
775-
SIMPLEFOC_MOTOR_ERROR("Init FOC error, current sense not init");
776-
exit_flag = 0;
777-
}else{
778-
exit_flag *= alignCurrentSense();
779-
}
780-
}
781-
else { SIMPLEFOC_MOTOR_ERROR("No current sense"); }
782-
}
783-
784767
} else {
785768
SIMPLEFOC_MOTOR_DEBUG("No sensor.");
786769
if ((controller == MotionControlType::angle_openloop || controller == MotionControlType::velocity_openloop)){
@@ -790,6 +773,22 @@ int FOCMotor::initFOC() {
790773
exit_flag = 0; // no FOC without sensor
791774
}
792775
}
776+
777+
// aligning the current sensor - can be skipped
778+
// checks if driver phases are the same as current sense phases
779+
// and checks the direction of measuremnt.
780+
if(exit_flag){
781+
if(current_sense){
782+
if (!current_sense->initialized) {
783+
motor_status = FOCMotorStatus::motor_calib_failed;
784+
SIMPLEFOC_MOTOR_ERROR("Init FOC error, current sense not init");
785+
exit_flag = 0;
786+
}else{
787+
exit_flag *= alignCurrentSense();
788+
}
789+
}
790+
else { SIMPLEFOC_MOTOR_ERROR("No current sense"); }
791+
}
793792

794793
if(exit_flag){
795794
SIMPLEFOC_MOTOR_DEBUG("Ready.");

0 commit comments

Comments
 (0)