PatWie / ros-core-rs

This Rust library provides a standalone implementation of the ROS (Robot Operating System) core, allowing you to build ROS nodes entirely in Rust without needing other ROS dependencies. Start the ROS core, run any ROS stack, and use the provided examples to create publishers and subscribers. Contributions are welcome!
MIT License
8 stars 2 forks source link

Some problems I had testing connectivity with the ros1 framework #4

Open jackyliu16 opened 1 year ago

jackyliu16 commented 1 year ago

I was trying to simple use ros-core-rs as a kind of standalone software, unlike sync application you provide, I using the publisher subscriber example of rosrust.

Environment: Ubuntu 22.04

nix-ros-overlay noetic ``` { pkgs ? import ../. {} }: with pkgs; with rosPackages.noetic; with pythonPackages; mkShell { buildInputs = [ glibcLocales (buildEnv { paths = [ catkin ros-core roslaunch ros-comm roslaunch rospy rosbag rostopic rospy-tutorials # cmake-modules rosbash ros-tutorials # turtlebot3-description # turtlebot3-teleop # turtlebot3-gazebo gazebo-plugins xacro ]; }) ]; ROS_HOSTNAME = "localhost"; ROS_MASTER_URI = "http://localhost:11311"; TURTLEBOT3_MODEL = "burger"; } ```

=====

publisher.rs ```rust const TOPIC_NAME: &str = "/chatter"; fn main() { env_logger::init(); // Initialize node rosrust::init("talker"); // Create publisher let chatter_pub = rosrust::publish(TOPIC_NAME, 2).unwrap(); chatter_pub.wait_for_subscribers(None).unwrap(); let log_names = rosrust::param("~log_names").unwrap().get().unwrap_or(false); let mut count = 0; // Create object that maintains 10Hz between sleep requests let rate = rosrust::rate(10.0); // Breaks when a shutdown signal is sent while rosrust::is_ok() { // Create string message let msg = rosrust_msg::std_msgs::String { data: format!("hello world from rosrust {}", count), }; // Log event rosrust::ros_info!("Publishing: {}", msg.data); // Send string message to topic via publisher chatter_pub.send(msg).unwrap(); if log_names { rosrust::ros_info!("Subscriber names: {:?}", chatter_pub.subscriber_names()); } // Sleep to maintain 10Hz rate rate.sleep(); count += 1; } } ```
subscriber.rs ```rust const TOPIC_NAME: &str = "/chatter"; fn main() { env_logger::init(); // Initialize node rosrust::init("listener"); // Create subscriber // The subscriber is stopped when the returned object is destroyed let subscriber_info = rosrust::subscribe(TOPIC_NAME, 2, |v: rosrust_msg::std_msgs::String| { // Callback for handling received messages rosrust::ros_info!("Received: {}", v.data); }) .unwrap(); let log_names = rosrust::param("~log_names").unwrap().get().unwrap_or(false); if log_names { let rate = rosrust::rate(1.0); while rosrust::is_ok() { rosrust::ros_info!("Publisher uris: {:?}", subscriber_info.publisher_uris()); rate.sleep(); } } else { // Block the thread until a shutdown signal is received rosrust::spin(); } } ```

When I'm trying to use this kind of packages, connect with local rospy package talker_listern from beginner_learnning, using cargo run as a kind of master. I found rosrust example is capable to connection to master and send message to rospy packages though topic.

  1. when using the roscore tools from ros1 framework, if a subscriber is register after publisher then it will not receiver any kind of message, until publisher has register. But in ros-core-rs, if a subscriber register before publisher, both node will be clogging (which haven't received and send any message)
  2. it seems this unable to using tools in ros1 framework to detect the master node , which other node could be detected as node but master as topic
    $ rosnode list
    /talker
  3. it seems is unable to using rosbag to register into master to record the message.
    $ rosbag record -O bag chatter
    [ INFO] [1690180687.903903404]: Subscribing to chatter
    [ WARN] [1690180687.905659229]: couldn't register subscriber on topic [/chatter]
    [ INFO] [1690180687.906254249]: Recording to 'bag.bag'.
  4. it seems it's unable to use rostopic to echo the message has been sent in topic
    $ rostopic echo chatter
    Traceback (most recent call last):
    File "/nix/store/9587crxh9llk7h13zzb4qf7p439w93v4-ros-noetic-rostopic-1.16.0-r1/bin/.rostopic-wrapped", line 36, in <module>
    rostopic.rostopicmain()
    File "/nix/store/ppg86vx0n6dacfv4spbmkmz97hf8ia9p-ros-env/lib/python3.10/site-packages/rostopic/__init__.py", line 2130, in rostopicmain
    _rostopic_cmd_echo(argv)
    File "/nix/store/ppg86vx0n6dacfv4spbmkmz97hf8ia9p-ros-env/lib/python3.10/site-packages/rostopic/__init__.py", line 1406, in _rostopic_cmd_echo
    _rostopic_echo(topic, callback_echo, bag_file=options.bag)
    File "/nix/store/ppg86vx0n6dacfv4spbmkmz97hf8ia9p-ros-env/lib/python3.10/site-packages/rostopic/__init__.py", line 1017, in _rostopic_echo
    _check_master()
    File "/nix/store/ppg86vx0n6dacfv4spbmkmz97hf8ia9p-ros-env/lib/python3.10/site-packages/rostopic/__init__.py", line 90, in _check_master
    rosgraph.Master('/rostopic').getPid()
    File "/nix/store/ppg86vx0n6dacfv4spbmkmz97hf8ia9p-ros-env/lib/python3.10/site-packages/rosgraph/masterapi.py", line 292, in getPid
    return self._succeed(self.handle.getPid(self.caller_id))
    File "/nix/store/6qk2ybm2yx2dxmx9h4dikr1shjhhbpfr-python3-3.10.11/lib/python3.10/xmlrpc/client.py", line 1122, in __call__
    return self.__send(self.__name, args)
    File "/nix/store/6qk2ybm2yx2dxmx9h4dikr1shjhhbpfr-python3-3.10.11/lib/python3.10/xmlrpc/client.py", line 1464, in __request
    response = self.__transport.request(
    File "/nix/store/6qk2ybm2yx2dxmx9h4dikr1shjhhbpfr-python3-3.10.11/lib/python3.10/xmlrpc/client.py", line 1166, in request
    return self.single_request(host, handler, request_body, verbose)
    File "/nix/store/6qk2ybm2yx2dxmx9h4dikr1shjhhbpfr-python3-3.10.11/lib/python3.10/xmlrpc/client.py", line 1182, in single_request
    return self.parse_response(resp)
    File "/nix/store/6qk2ybm2yx2dxmx9h4dikr1shjhhbpfr-python3-3.10.11/lib/python3.10/xmlrpc/client.py", line 1354, in parse_response
    return u.close()
    File "/nix/store/6qk2ybm2yx2dxmx9h4dikr1shjhhbpfr-python3-3.10.11/lib/python3.10/xmlrpc/client.py", line 668, in close
    raise Fault(**self._stack[0])
    xmlrpc.client.Fault: <Fault 404: 'Unknown method.'>

These are a few questions I had during my brief test, and I would appreciate it if anyone could answer them or helpping in it.

PatWie commented 1 year ago

Thanks for the detailed write-up! I never intended this as a drop in replacement (more to bridge custom tools to the ROS world eg. for visualization).

both node will be clogging I was under the impression that the subscriber will talk to the publisher directly. Need to have a look

I might help to have RUST_LOG=DEBUG in the core for standard ros tooling compatibility (rostopic echo chatter,...)

jackyliu16 commented 1 year ago

Thank you for your reply, I will take a serious look.

jobafr commented 3 months ago

Hi @jackyliu16,

I know it's been a year, but if this is still of interest to you, could you check again with the current version? I had similar issues with rosbag, and it turned out the bug was fixed in one of ros-core-rs's dependencies a while ago. The current git main version of ros-core-rs does pull in that fix now.