Using 2nd Encoder to set pos_estimate_

I am planning on adding a linear encoder to a CNC mill to deal with backlash. I am thinking of wiring A and B to the GPIO pins so I can get actual table movement and use that as position instead of motor rotation. I am planning to write custom firmware to do this.

Has someone already made something similar to this? Is there a better way to do this?

Also, what is pll in the encoder.cpp file? I thought position would just be encoder counts, but it looks like the Odrive is trying to predict position somehow?

Hi Noodles, we have dual encoder support working in the RazorsEdge branch. Right now though, that means you can only drive one motor per board because it uses the other encoder channel. You don’t really want to use GPIO because then you have to do everything interrupt based. Ideally, you’d use an SPI encoder on the motor and a quadrature encoder on the table and be able to drive two motors from one ODrive but that’s not ready yet.

Yes, it has an observer to reduce phase lag.

1 Like

Thanks, Ill take a look

This is my first time doing something like this outsider of arduino and I’m not exactly sure where to look up programming documentation. I was expecting to find something similar to the arduino reference but after skimming the STM32F4 product page, all I could find was really low level stuff. I’ve looked a little and saw people doing stuff in CubeMX but I am not really sure where to go from here.

I’ve been looking at Tobin Hall’s branch but I’m a little confused without knowing the spi functions and how to use them.

When you said that I wouldn’t want to feed 4 quadrature signals into the odrive it sounds like it is possible to overload a microcontroller with interrupts. Is there a good way to estimate the maximum frequency of interrupts a microcontroller can handle? I am looking at using an ESP32 or an atmega 328p to count encoder pulses and communicate over SPI. In the long run, I should probably switch over to what you said in your previous post but at the moment this is what I have to prototype with.

EDIT: Im guessing I have to read through the C files in the drivers folder for figuring out the functions I can call?

Hi Noodles,

I think I am doing what you require in a few weeks time, where I am currently controlling the ODrive via ASCII commands over serial. The ODrive has the AMT102 connected at the moment, where I will be getting the Arduino to monitor the actual position of the table via a linear encoder.

Although I have just put up a video where I remove the backlash in the Arduino sketch, where the sketch recognises a change of direction and jumps into a while loop until the backlash is taken up at full speed (0.12mm backlash in my case) and then goes back to joypad control (eventually GCode control from an SD card on the Arduino).

Good luck with your project.

Kind Regards,

Neil.