Odrive as BMW X-drive controller

Using the SPI interface is pretty simple, and it’s much more robust because you don’t have to do an open-loop movement for index search (remember that if you have any significant load on the motor, then index search and encoder offset calibration are likely to fail).
On the RazorsEdge branch, AS5047P works out of the box with SPI. You just have to connect the MISO/MOSI/SCK/CS wires (plus VCC and GND) and then set the encoder type to ENCODER_TYPE_ABS_AMS, and also set the GPIO pin that you are using for CS.

1 degree might be enough for you in terms of positioning, but what about noise? It’s pretty normal and usually unavoidable for any motor controller to vibrate at least +/- 1 encoder count when holding position, and the frequency of that vibration depends on the gains you set - the tighter your tuning the more severe that vibration (limit cycling) gets, until it becomes completely unstable. The motor’s natural cogging effectively puts a variable offset on the torque that the drive applies, depending on position, and disturbs the usually linear relationship between current and torque.
With a higher resolution encoder you give the odrive a chance to reduce the motor vibration, and even to measure/model the cogging and calibrate it out, which helps linearise the dynamic system and achieve better performance without becoming unstable.

Edit: As to the behaviour in your video, try using the liveplotter to check that the odrive is aware of this position error. If it is, It may be that your gains are set SO low (to avoid instability) that the only thing still active is the velocity integrator, and it is jumping between two poles due to cogging.
If you are unable to tune the motor better than this, then perhaps you are in trouble.
If it’s not aware (ie the odrive doesn’t see the huge discrepancy between commanded and actual position) then there is something wrong with your encoder.

Since you only need on/off control, you could try a different approach- what if you had no position feedback at all, and just drive the motor like a 3-phase stepper (this is what the encoder offset calibration and index search do) until it hits a limit switch? (or until you see your encoder position stop changing)

Also, try setting the position gain to 0 and seeing if it is stable in CTRL_MODE_VELOCITY_CONTROL - you can probably increase the vel_gain and vel_integrator_gain a bit.

Once you’ve got that working, you could then try increasing pos_gain, maybe you will get something which works well enough…

Hi!

This project is not moving forward very fast, i’m still testing if the hardware will to what I want, when sending commands to the Odrive.

First question: is it possible to swap the rotation direction of the calibration sequence at startup?
At my 0 point, I have nothing to go in the CCW direction. if it could go CW first, then CCW, it would be good.
I also wanted the motor in general to go opposite direction, because all my values are in negatives now.

Tried swapping B-C leads, but no difference.
Maybe its just defining the direction based on encoder feedback during startup sequence?

Hey,

Did you fix this?

Swapping two of your motor phase wires should flip the direction the motor rotates, both for calibration and actual usage.

If that’s not working you could try clearing your saved settings and rerunning calibration. The motor.config.direction parameter is written to after calibration but afaik swapping to leads should still work… Also note that motor.config.direction is set automatically and shouldn’t be changed.

Hi!
I’ve decided that this task is too much to chew over for myself :confused:

So instead, I decided to ask for help, and for that, I needed to write a project description and function flow diagram.

If anyone is interested in helping out, for $$ of course, take a look at this PDF (shared through OneDrive) and see if you’re up to it (including comment description in code, so I can understand and edit myself), and what you would charge to do it.

https://1drv.ms/b/s!AgfHYz1R1kvdgvgOCh2SVB50lu8qOQ?e=drR8Iy&fbclid=IwAR0Tss3Mp7gjIF5b0-vzLWRA02rGCElaTpOWdi04V6V-Aszg0qMuPjaKYeI

Hi!

This project have been on hold for a while, since I bricked my odrive 3.6 while trying to load a custom firmware.

Now an oDrive Pro 4.4 is on the way, and hopefully I don’t need to load custom firmware to use CAN-BUS without RTR bits.

Wish me luck :stuck_out_tongue:

You can’t brick it by loading custom firmware - it’s always recoverable. If the firmware you loaded crashes, then the DFU-mode switch should boot straight to bootloader. Failing that use a Nucleo board or ST-Link programmer to flash it via SWD.

:green_heart: v4 tho

2 Likes