Setting current limits in main loop

Hi folks - posted this in the Discord channel but adding here in case that’s not monitored often.

When using FOC current mode, what variables should be set in the main loop to limit the DC current magnitude? I set motor.current_limit in my setup function, and that limit is respected, but attempting to reset that limit in the loop doesn’t seem to work.


Hey @wrcman555,

The questions about real-time updates limits are popping up a lot, and it is a bug on our side. We will fix it soon.

Basically, in order to change the current limit you’ll need to change the PID limits as well.

motor.current_limit=1;  // amps
motor.PID_velocity.limit = motor.current_limit;

If you’re using the voltage control and setting the voltage limit you’ll need to change both:

motor.voltage_limit=1;  // volts
motor.PID_velocity.limit = motor.voltage_limit;

We have been concentrated on the commander interface (where we do this automatically) and neglected this programmatic way of changing the limit values.


Thanks so much! This works great for my use case.