Controlling relative position between spinning motors on Odrive v3.6

Hello all,

I have an Odrive v3.6 on the latest firmware. Im driving two motors on closed loop which are coupled together via a differential gearbox.
What I want to achieve is to rotate both at the same speed but opposite directions most of the time but also control the drift/offset between them according to an analog signal.

Currently I am controlling one using velocity control and I have the other mirroring the position of the first (mirror ratio -1). This works beautifully. However, I have no idea how to tell one of the motors to drift/offset. At some point I believe I achieved it with set_linear_count via UART, but it was buggy as hell, probably because the serial buffer was overwhelmed. I am using an ESP32 to ask odrive for position feedback and then tell it to offset using the “esl” command.

Is there a better way to do this? Can I somehow use the Odrive’s analog input feature? Would the above work better using the CAN interface?

Thank you

The other option I might have is using the Native protocol over UART by running it in micropython on the ESP32, but I have never done this so not sure if its possible. I am also not sure if it will be faster and more reliable compared to simply sending UART commands

CAN will definitely be faster overall, though I think Micropython may be a bit of a bottleneck here – not entirely sure though. But you wouldn’t want to use set_linear_count, you’d want to just use position control in circular mode.

Ok, I won’t attempt micropython then. I thought maybe the native protocol would be more reliable but can’t sacrifice speed.

How do I guarantee smooth rotation in position control? Do I make sure to update position at least twice per rotation faster than the motor rotates? Does this mean that I can’t use mirror mode so I would have to send twice as many messages?

Correct, you wouldn’t be able to use mirror mode. You’d need to stream your position at a few hundred Hz minimum, giving velocity feedforwards so that the ODrive doesn’t slow down upon reaching the new setpoint.