ODrive integration

There is a lot of interest using ODrive controllers and brushless motors. And this post is just to start the thread in this channel.

Here is a similar thread in the odrive discourse server: Cool but would it work on a Corexy? - Support - ODrive Community

I visited the odrive site and the comments from the odrive experts are that step/dir is the lowest level denominator. And many thought it would be terrible for performance. I think this is because the people trying to connect the two were looking at a low level pin connection. But Kevin. You send velocity and acceleration to the controller.

queue_step oid=7 interval=7458 count=10 add=331

If I recall correctly these commands are meant to compress the info and give precise timings. But they can be converted to distance, velocity and acceleration. The only other comment from the odrive group. Is that they would prefer to receive the commands at regular intervals. I’m not certain that this is a huge issue since the accel odds included. But it would be simple to take those commands buffer them and emit equivalent commands at regular time intervals if needed. It’s only a matter of forwarding the command to odrive from the firmware.

Odrive has multiple protocols. The text for the ascii is nice, so I include the link here:ASCII Protocol | ODrive

At the end are the relevant commands in my opinion. Since Klipper is closest to the end user, it feels that it’s really the one better suited to send the appropriate commands to the ODrive. Since the firmware already does a few more things like LCD rendering. I think it would be best to support direct communication to ODrive through their protocols, if using a Raspberry Pi, and I assume command forwarding could also be convenient depending on what board is used for the firmware.

Motor Position command

For basic use where you send one setpoint at at a time, use the q command. If you have a realtime controller that is streaming setpoints and tracking a trajectory, use the p command.

q motor position velocity_lim torque_lim
  • q for position
  • motor is the motor number, 0 or 1 .
  • position is the desired position, in [turns].
  • velocity_lim is the velocity limit, in [turns/s] (optional).
  • torque_lim is the torque limit, in [Nm] (optional).

Example: q 0 -2 1 0.1

p motor position velocity_ff torque_ff
  • p for position
  • motor is the motor number, 0 or 1 .
  • position is the desired position, in [turns].
  • velocity_ff is the velocity feed-forward term, in [turns/s] (optional).
  • torque_ff is the torque feed-forward term, in [Nm] (optional).

You might want to check ODrive 3D Printer instructions - YouTube

ODrive + Klipper

Early on in the video he says he uses a step and direction pins. It’s amazing that it works. I’ve read some articles that suggest to use trapezoidal acceleration to feed torque/acceleration information to the controller. And it will significantly improve accuracy.

That is precisely what klipper does. But odrive has no clue. It would improve linearity significantly.

I will need to watch the rest of the video. And probably purchase an odrive controller.

It’s certainly possible to integrate Klipper with ODrive. I suspect it would require a lot of work. I don’t know of anyone working on it right now.

I’d guess there are two main approaches - one would be to port Klipper to the ODrive hardware, and the other approach would be to alter Klipper to be able to send commands to the existing ODrive firmware. Each approach has its pros and cons, and I suspect both would take notable work.

I suspect the main challenge with porting Klipper to the ODrive hardware would be in adding all the hardware support.

I suspect the main challenge in trying to control the ODrive from Klipper is in obtaining accurate timing. Klipper is designed to command accurate movements (think microns) at accurate times (think microseconds). Klipper deploys a time synchronization system between micro-controller and host so that the software can accurately predict the micro-controller clocks and schedule motions at precise times. I don’t know how one would do that with the ODrive.

FWIW, this isn’t something I, personally, plan to work on. If someone else is interested, there’s some info on past attempts at servo control in Klipper at: Mechaduino support (and "Smart Stepper", and their clones) by KevinOConnor · Pull Request #1038 · KevinOConnor/klipper · GitHub

Cheers,
-Kevin

1 Like