@@ -584,7 +584,8 @@ void FOCMotor::loopFOC() {
584584 if (sensor) sensor->update ();
585585
586586 // if disabled do nothing
587- if (!enabled) return ;
587+ // or if the motor is not ready (e.g. failed to calibrate or not calibrated yet) do nothing
588+ if (!enabled || motor_status != FOCMotorStatus::motor_ready) return ;
588589
589590 // if open-loop do nothing
590591 if ( controller==MotionControlType::angle_openloop || controller==MotionControlType::velocity_openloop )
@@ -691,7 +692,8 @@ void FOCMotor::move(float new_target) {
691692 }
692693
693694 // if disabled do nothing
694- if (!enabled) return ;
695+ // and if
696+ if (!enabled || motor_status != FOCMotorStatus::motor_ready) return ;
695697
696698
697699 // upgrade the current based voltage limit
@@ -745,6 +747,12 @@ void FOCMotor::move(float new_target) {
745747 // returned values correspond to the voltage_limit and current_limit
746748 current_sp = angleOpenloop (shaft_angle_sp);
747749 break ;
750+ case MotionControlType::custom:
751+ // custom control - user provides the function that calculates the current_sp
752+ // based on the target value and the motor state
753+ // user makes sure to use it with appropriate torque control mode
754+ if (customMotionControlCallback)
755+ current_sp = customMotionControlCallback (this , target);
748756 }
749757}
750758
@@ -768,8 +776,8 @@ int FOCMotor::initFOC() {
768776 SIMPLEFOC_MOTOR_DEBUG (" No sensor." );
769777 if ((controller == MotionControlType::angle_openloop || controller == MotionControlType::velocity_openloop)){
770778 exit_flag = 1 ;
771- SIMPLEFOC_MOTOR_ERROR (" Openloop only!" );
772779 }else {
780+ SIMPLEFOC_MOTOR_ERROR (" Only openloop allowed!" );
773781 exit_flag = 0 ; // no FOC without sensor
774782 }
775783 }
@@ -781,13 +789,13 @@ int FOCMotor::initFOC() {
781789 if (current_sense){
782790 if (!current_sense->initialized ) {
783791 motor_status = FOCMotorStatus::motor_calib_failed;
784- SIMPLEFOC_MOTOR_ERROR (" Init FOC error, current sense not init" );
792+ SIMPLEFOC_MOTOR_ERROR (" Current sense not init! " );
785793 exit_flag = 0 ;
786794 }else {
787795 exit_flag *= alignCurrentSense ();
788796 }
789797 }
790- else { SIMPLEFOC_MOTOR_ERROR (" No current sense" ); }
798+ else { SIMPLEFOC_MOTOR_ERROR (" No current sense. " ); }
791799 }
792800
793801 if (exit_flag){
0 commit comments