lucasw / ros_one2z

Similar node graphs in vanilla ros1 and ros2 and also zenoh, focus on localhost using python but also C++ and maybe rust
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

roslibrust ros1 native example node with multiple subscriber and timed publishing #11

Closed lucasw closed 4 months ago

lucasw commented 5 months ago

Make a ros node with several subscriber and publishers using the roslibrust ros1 native feature:

https://github.com/Carter12s/roslibrust?tab=readme-ov-file#experimental-support-for-ros1-native

https://github.com/lucasw/ros_one2z/tree/main/ros1_rlr

So far roslibrust has seems to be able to find ros messages from ROS_PACKAGE_PATH better than rosrust (certain messages cause the rosrust build to fail, TBD insert link to issue/comments about that).

But maybe roslibrust build times are much longer (haven't tried rosrust recently) - is that because it is building a lot of messages that go unused? This also may be because I'm calling the message codegen macro, try following the example (https://github.com/Carter12s/roslibrust?tab=readme-ov-file#code-generation-of-ros-messages https://github.com/Carter12s/roslibrust/blob/master/example_package/build.rs). Could also try curating ROS_PACKAGE_PATH just for building this, only provide paths to the messages it needs.

Lots of basic ros features are missing (e.g. __name __ns and topic remap https://github.com/Carter12s/roslibrust/issues/113), but really if only publishing and subscribing work the rest can be worked around. The namespace features can be implemented in the node (and then put into a library here, and then probably can figure out how to add them upstream after that).

Probably need Corrosion and build with cmake to get the nodes to a place where rosrun and roslaunch will work, but perhaps the right cargo command (--out-dir?) can place the binaries where needed. But the name and namespacing comes first.

Need to learn tokio to have multiple subscribers and timed publishing in the same node. Seems more complicated than it ought to be but I suppose rospy and roscpp went to a lot of effort to hide inherent complexities.

Haven't tried service calls yet- ultimately want dynamic reconfigure working (or 'dynamic dynamic reconfigure', don't bother with implementing .cfg message building) but could live without that for a while. Can implement the dynamic reconfigure interface manually here then maybe push it upstream or into a standalone crate later.

lucasw commented 5 months ago

roslibrust mentions having to turn on the ros1 feature to get the ros1 native nodes, looks like this happened automatically:

ros1_rlr$ cargo tree -e features | grep roslibrust
├── roslibrust feature "default"
│   └── roslibrust v0.9.0
│       ├── roslibrust_codegen feature "default"
│       │   ├── roslibrust_codegen v0.9.0
│       │   └── roslibrust_codegen feature "tokio"
│       │       └── roslibrust_codegen v0.9.0 (*)
│       ├── roslibrust_codegen_macro feature "default"
│       │   └── roslibrust_codegen_macro v0.9.0 (proc-macro)
│       │       ├── roslibrust_codegen feature "default" (*)
├── roslibrust feature "ros1"
│   └── roslibrust v0.9.0 (*)
├── roslibrust_codegen feature "default" (*)
├── roslibrust_codegen_macro feature "default" (*)
lucasw commented 5 months ago

rostopic echo works on a topic published by this node, but rostopic hz doesn't, no new messages - isn't rostopic hz subscribing no different than echo, or is it doing something behind the scenes not supported here?

-> The difference is that rostopic hz uses rospy.AnyMsg- something is missing from the message (connection header?) to break that?

https://github.com/Carter12s/roslibrust/blob/883057f8d159b0298c243744d65971e746ec5dbc/roslibrust/src/ros1/publisher.rs#L97

lucasw commented 5 months ago

This gets me a much smaller ROS_PACKAGE_PATH, but not sure if build times are improved:

source ~/ros/ros1/install/overlay_2404_ws/install/setup.bash

If I don't want to have to know the right paths and build time, is there a way build.rs could search within ROS_PACKAGE_PATH just for the messages/message packages I need (which could be listed in build.rs). This would be the similar to having to list packages in package.xml. Or call rospack find and build a special ROS_PACKAGE_PATH from that in shell script that needs to be run manually.

lucasw commented 4 months ago

Fixed with updated version of roslibrust 8a0c98c48f8ae12a1256cf37d30fa6f7d751a8dd