Coder Social home page Coder Social logo

patwie / ros-core-rs Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 23 KB

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!

License: MIT License

Rust 98.00% Shell 0.63% Python 1.37%
ros rust ros1

ros-core-rs's Introduction

ROS-core implementation in Rust

Rust License Rust CI

This Rust library provides a standalone implementation of the ROS (Robot Operating System) core. It allows you to run a ROS master and communicate with other ROS nodes without relying on an external ROS installation. You can use this library to build ROS nodes entirely in Rust, including publishers and subscribers, without needing to use any other ROS dependencies.

Examples

Standalone ROS core

To start the ROS core, run the following command:

# start the ros-core
RUST_LOG=debug cargo run

And run any of your ROS stack, eg., the python chatter example.

Talker/Listener

This example creates a single binary which contains:

  • ROS core
  • ROS publisher
  • ROS subscriber

To run the talker/listener example, execute the following command:

RUST_LOG=info ROSRUST_MSG_PATH=`realpath examples/chatter/msgs` cargo run --example chatter --release

This example creates a single binary that includes a standalone implementation of the ROS core, as well as a ROS publisher and ROS subscriber. This implementation is inspired by the official chatter python example from the ROS wiki, which demonstrates a simple communication between two nodes using ROS messages.

Debugging with official ROS docker image

To showcase that this ROS core implementation can be used with official ROS publishers and subscribers in Python, we have provided a debugging script that launches a ROS Docker image and runs a talker and listener example. To run the script, execute the following commands:

# change directory to debugging folder
cd debugging
# make the script executable
chmod +x run.sh
# execute the script
./run.sh

This script will download the official ROS Docker image and launch a container with a ROS environment. Then, it will run a Python script that uses the ROS talker and listener nodes to communicate with the standalone ROS core implementation from this repository. This is intended as an example of how to use the standalone ROS core (ros-core-rs) implementation with other ROS nodes, but it is not necessary to use this script to use the standalone implementation on its own.

Contributions

We welcome contributions to this project! If you find a bug or have a feature request, please create an issue on the GitHub repository. If you want to contribute code, feel free to submit a pull request.

ros-core-rs's People

Contributors

mkiefel avatar patwie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mkiefel

ros-core-rs's Issues

Some problems I had testing connectivity with the ros1 framework

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
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
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
  1. 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'.
  1. 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.