Switch MotionControlType without reprogramming

Is it possible to change control types on the fly? I am using simplefoc for my rovers hoverboard wheels and i want to use velocity, torque and angle depending on what my rover is doing, torque is most efficient, velocity is ideal for going in a straight line i want to use angle mode for move a specific distance, so can it change between them on the fly without reprogramming?

I seen something about the commander interface but i cant use the serial ports as im using mavlink for control so what would i have to set to change it do i just run this again " motor.controller = MotionControlType::torque;" ?

Both foc loops are on core zero with their own tasks with no delays and watchdog disabled so it runs at full speed.
PWM RC input is handled by a task on core 1
mavlink telemetry is in the main loop.
The rover can drive using mavlink servo output packets or RC PWM inputs, PWM is faster so its recommended for anything moving quickly.

1 Answer

1

Yes, you can set motor.controller to a different value at any time. You’ll have to figure a way to do it with whatever communication methods you have available.

Each mode has different units for target (torque->amps, velocity->rad/s, angle->rad), so that will need to be dealt with. When going into angle mode, set target to motor.shaft_angle initially. If you set to 0 it will unwind all the driving it’s done so far :slight_smile: And don’t set to open loop modes without first setting motor.voltage_limit to a value that won’t overheat, since open loop applies full voltage at all times.