Skip to content

Comments

Feat custom motion control#514

Merged
askuric merged 4 commits intodevfrom
feat_custom_motion_control
Feb 10, 2026
Merged

Feat custom motion control#514
askuric merged 4 commits intodevfrom
feat_custom_motion_control

Conversation

@askuric
Copy link
Member

@askuric askuric commented Feb 10, 2026

A PR adding a possibility to add a custom motion control scheme to the BLDC motor class in a simple way.

  • Extended MotionControlType with custom
  • Added the setCustomMotionControlMethod method
    • it receives a function pointer float (*controlMethod)(FOCMotor* motor, float target) and saves it to customMotionControlCallback
  • Extended the Commander to allow switching to custom motion control MC6
  • Added an example examples/motion_control/custom_motion_control/custom_motion_control.ino

Example usage

....

//define the custom motion control function
// custom PID controller instance for the custom control method
// P controller with gain of 1.0f, no integral or derivative gain
PIDController custom_PID = PIDController(1.0f, 0, 0);
// custom motion control method
float positionPControl(FOCMotor* motor, float target){
  // simple proportional position control
  float error = target - motor->shaft_angle;
  // set the PID output limit to the motor current limit
  custom_PID.limit = motor->current_limit; 
  return custom_PID(error); // return current command based on the error
}

... 

void setup(){
  ...

  // set control loop type to be used
  motor.controller = MotionControlType::custom;
  motor.torque_controller = TorqueControlType::foc_current; 
  motor.linkCustomMotionControl(positionPControl); // set the custom control method

 ... 

@askuric askuric merged commit af997e6 into dev Feb 10, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant