Switching from angle to velocity mode in the program

Can I change the control from angle to velocity and back programmatically inside the loop?
motor.controller = MotionControlType::angle; to
motor.controller = MotionControlType::velocity;

(after a certain serial command was sent)

alternatively, can I use angle control and spin the motor at a constant speed indefinitely?
I can’t just give it a very large number as a setpoint angle, because this angle will be reached after a while.


Hey @Geronimo,

Yes you can change the motion control type anytime you want. You can even change in-between open loop and closed loop as well as different torque cobtrol modes.

There are many ways to do it, but the most elegant way is to use the commander interface and add the motor to it.

// Create the commander instance
Commander command = Commander (Serial);
// Create a motor handler with the command letter 'M'
void doMotor(char* cmd){command.motor(&motor,cmd);}

voir setup (){
 // Add your motor to the commander
command.add('M', doMotor, "my motor");
void loop(){
 // Real time commander runtime

This code will allow you to change many motor parameters, and one of them will be the control type. To get the current motion control type send MC and the motor will respond, for example:

Motion | angle

If you wanna change it send:

  • MC0 for torque control
  • MC1 for velocity
  • MC2 for angle
  • MC3 for openloop velocity
  • MC4 for openloop angle

The other question is a bit more tricky and I’d suggest you not to use angle control to run the motor in constant velocity mode. Rather change the motion control mode. But you can set the velocity in you wish your motor to move in between the positions by seting motor.velocity_limit in the setup. Or if you’re using the commander you can change it in the real time from the serial. To get it send MLV and to set it just send the value after the command, for example MLV20.5 for 20.5 rad/s.

Limits | vel: 10
Limits | vel:100.5

You can look into the commander interface in the docs for more info about what else you can change and configure. And you can aslo see that there are much simpler and memory efficient ways to do the motion control change if necessary using command.scalar instead of command.motor.

Hope it helps

1 Like