odriverobotics / ODriveArduino

Arduino library for the ODrive
MIT License
7 stars 8 forks source link

ODriveHardwareCAN sendMsg always returns true #4

Open bthacher-crabi opened 2 months ago

bthacher-crabi commented 2 months ago

While trying to write to 6 ODrives using the Arduino GIGA R1 WiFi, I found that only the first 3 messages would successfully be transmitted. At first, I realized that I wasn't checking the output of the ODriveCAN::setPosition function that internally calls can_intf.write, which calls the sendMsg function defined in ODriveHardwareCAN.hpp, but then I realized that since the underlying Arduino_CAN write function (which calls the mbed::CAN write function) returns 1 on success and 0 on failure. This means that the last line in the sendMsg function (return can_intf.write(msg) >= 0;) causes this function to always return true without checking if the message was queued or not. By removing the >= and checking the output to wait until messages were sent, I was able to get my project working. I'm not sure how high the sendMsg is in the firmware stack, so I'm not sure if removing the >= would fix only my platform and break others, but if it would work I think it would be a very important fix. I also understand that 6 ODrives may not be the most common setup, but the code as it is does not work properly on my platform.

The line in question

Let me know if more information is needed, thank you!

samuelsadok commented 2 months ago

Thanks for digging into this and tracking the issue down! After looking at it, it seems that the Arduino mbed core is not behaving according to the Arduino API specs, so I went ahead and opened this issue: https://github.com/arduino/ArduinoCore-mbed/issues/924. Let's see what the response is on that, and then we'll do a fix on this repo. Good to know that you were already able to make it work for you in the meantime!

And yes controlling many ODrives at once is definitely a use case we want to support well.