Arduino ( and other.. ) C++ Native library for Odrive -- Development thread

I am back to working on my Native Protocol driver.
I will be using this thread to keep track of information I find out as I travel down this path.

This driver will be intended to use over the serial interface.

It will work with odrive firmware 0.5.1 that has a API signature (CRC) of 0x9b40. It will return errors, or simply not work otherwise.

I hope to have a version available for others to look at in a month or so…

2 Likes

One of the problems I have had, is getting the json spec for the endpoints.

In analyzing the code on the odrive, I found a little gem that allows us to download the json description of the endpoints using odrive tool.

  1. connect odrive
  2. Start odrivetool, wait for connect.
  3. At the odrive prompt, type ‘odrv0._json_data’
  4. Copy the ( lengthy ) response to the clipboard.
  5. Go to json formatter website and past the clipboard to the input field.
  6. the formatter will respond with a nicely formatted json file!

This makes finding endpoints much easier!!. Figuring out how to use them is a little more difficult… :wink:

-John

If you are planning on using the native protocol, be sure to check out

Have you been using the Fibre C++ library? GitHub - samuelsadok/fibre-cpp: C++ implementation of Fibre

You can also use the backup configuration utility ODrive Tool | ODrive.

And VS Code will format your json for you. Right click → Format File

While the backup utility gives me a json document with my config information, that is not what I am looking for.

When I am looking to implement an endpoint I need the endpoint spec.

odrv0._json_data gives me a json file that looks like the json below. This gives me the name, endpoint number, RW status and the datatype:

:rage:AT LEAST IT DID BEFORE 0.5.2 WHEN IT LOOKS LIKE _JSON_DATA WAS REMOVED :face_with_symbols_over_mouth:

Now what do I have to do to get a copy of this? Either through odrivetool or serial.
Why was it removed?

The odrivetool generate-code method does not provide the r/w status of endpoints, plus you have to get information about an endpoint from several places in the code.

{
  "name":"",
  "id":0,
  "type":"json",
  "access":"r"
},
{
  "name":"vbus_voltage",
  "id":1,
  "type":"float",
  "access":"r"
},
{
  "name":"ibus",
  "id":2,
  "type":"float",
  "access":"r"
},
{ 
  "name":"ibus_report_filter_k",
  "id":3,
  "type":"float",
  "access":"rw"
},
{
  "name":"serial_number",
  "id":4,
  "type":"uint64",
  "access":"r"
},
{
  "name":"hw_version_major",
  "id":5,
  "type":"uint8",
  "access":"r"
},
{
  "name":"hw_version_minor",
  "id":6,
  "type":"uint8",
  "access":"r"
},
{
  "name":"hw_version_variant",
  "id":7,
  "type":"uint8",
  "access":"r"
}
1 Like

odrivetool v0.5.2 doesn’t speak on USB directly anymore, instead it binds to the C++ implementation of the protocol linked above. This was done so that we can more easily scale compatibility to more programming languages without inhibiting upgrades to the protocol itself.

libfibre doesn’t expose the JSON directly because future versions of the protocol might use a different JSON (or binary) format and libfibre attempts to shield applications from these kind of changes.

You can instead obtain the endpoint definitions from the firmware build process. The JSON gets dumped into a file called “autogen/endpoints.hpp” by this command:

python -B interface_generator_stub.py --definitions odrive-interface.yaml --generate-endpoints ODrive3 --template fibre-cpp/endpoints_template.j2 --output autogen/endpoints.hpp

Maybe you can directly adapt the template (“endpoints_template.j2”) to suit your needs.

2 Likes

Any updates? I am also looking for a C++ implementation of the Native Protocol for use over Serial. Does anyone have any suggestions? Thanks!

Same here, looking for C++ implementation of the Native Protocol for use over Serial. Any libraries or suggestions

When you say “it binds to the C++ implementation of the protocol linked above”, where would I find that C++ implementation? I don’t know anything about fibre, but it looks generic and not specific to ODrive. Is there a client C++ library that sits on top of fibre? I apologize if it’s obvious. Thank you.

I did built something similar in Java. Maybe some of the stuff I discovered can help?

https://discourse.odriverobotics.com/t/odrive-and-java/

See also this thread:

I wouldn’t use fibre directly, but one of the libraries I linked there.