Code Monkey home page Code Monkey logo

rospy2's Introduction

rospy2: A ROS1-like interface for ROS2

Many people are still using ROS1 because it takes time to rewrite all your nodes for ROS2.

There is a ROS1-ROS2 bridge but it unfortunately requires installing both ROS1 and ROS2 at the same time.

This provides a radically different solution: A Python library that masquerades as rospy but secretly speaks ROS2 behind the curtain. Your ROS1 code can work directly on the ROS2 network, as long as you aren't doing any crazy things. (I'm also working on a C++ analogue but it's going to be slower to implement, obviously.)

All you need to do is install this package to your system:

sudo python3 setup.py install

And then in your node, change the line

import rospy

to

import rospy2 as rospy

You can even make nodes that work in both ROS1 and ROS2:

import os
if os.environ.get("ROS_VERSION") == "1":
    import rospy
elif os.environ.get("ROS_VERSION") == "2":
    import rospy2 as rospy

You should then be able to just run your node and it should work on ROS2. A test node that works in either ROS1 or ROS2 is provided:

ROS1:

source /opt/ros/noetic/setup.bash
./test_node.py

ROS2:

source /opt/ros/foxy/setup.bash
./test_node.py

Status

Supported

  • Publishers

  • Subscribers

  • rospy.Rate, rospy.Time, rospy.Time.now(), rospy.Duration

  • Parameters (in the same namespace as the node)

  • ROS1-style positional constructors e.g. String("hello") or Quaternion(1,2,3,4) that ROS2 does not allow, for a few commonly-used types

Not supported yet

  • Parameters in other namespaces

  • Service calls (supported but not tested)

Caveats

  • seq is not supported in ROS2 headers. rospy2 adds this back as a property, but it will always return 0. seq is deprecated even in ROS1 though I believe (?), so AFAIK you shouldn't be using it.

  • This library will alias ROS1's rosgraph_msgs/Log in ROS2's rcl_interfaces/Log so it should work seamlessly. However (a) ROS2 no longer a "topics" subfield, so you will get an error if you try to use it, and (b) The aggregation topic /rosout_agg does not exist by default in ROS2.

  • There is no "parameter server" in ROS2, so ROS1 nodes that expect global parameters aren't going to work. Future functionality may allow rospy2 to fetch parameters from other nodes, but it will not possible to have parameters in a global namespace due to ROS2's design.

  • Since your callbacks will receive actual ROS2 messages, those messages that have numeric array fields (e.g. std_msgs/Int32MultiArray or sensor_msgs/Image) will see those data fields as an array.array or numpy.ndarray instead of a Python list. This may trip up some code that expects a Python list. If your ROS1 code only accesses the data by index or constructs a numpy array as its first thing it does, it should theoretically not be an issue. If it is an issue, you can enable an experimental parameter that allows conversion to Python lists, ROS1 style:

    import rospy2 as rospy
    rospy.ARRAY_TO_LIST = True

rospy2's People

Contributors

dheera avatar timple avatar reinzor avatar

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.