odriverobotics / ros_odrive

MIT License
55 stars 33 forks source link

Expose driver enumerations in messages #2

Open AdamPettinger opened 11 months ago

AdamPettinger commented 11 months ago

I was doing some testing commanding ODrive's via ROS 2 with this package, and noticed that it was hard to figure out what to put in some of the uint fields in the control messages or service.

So I pulled the enum values from the docs and put them directly in the message files. This way everybody who compiles the messages will have the enum values come along with the messages themselves (but note that msg constants are not serialized, so this adds no overhead when passing messages).

Obviously, this changes the structure of the original messages, which will break the code of anybody currently using this package. I thought of a few other ways to make these changes without changing the messages, but did not like them as much:

  1. Add the enums as constants in every message that needs them. But it is a lot of repetition and doesn't make it clear which constants belong with which types
  2. Add a header file declaring all these. Again, doesn't make it clear which enums go with which message fields, and to gain access in user code they would have to link/include this package

The changes only really effect the format of the input to the node, but I did test them on hardware anyway and everything looks to be working.

Note: this change would also need to be reflected in the tutorial page. Specifically, the service call near the bottom changes to:

ros2 service call /odrive_axis0/request_axis_state /odrive_can/srv/RequestAxisState '{axis_requested_state: {state: 1}}'