# Rospy2: A cringe-worthy ROS1-like interface for ROS2

**URL:** <https://discourse.openrobotics.org/t/rospy2-a-cringe-worthy-ros1-like-interface-for-ros2/21067>\
**Category:** ROS General\
**Tags:** ros2\
**Created:** [June 25, 2021, 1:09am UTC](https://discourse.openrobotics.org/t/rospy2-a-cringe-worthy-ros1-like-interface-for-ros2/21067 "2021-06-25T01:09:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dheera](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/dheera/32/837_2.png) [@dheera](https://discourse.openrobotics.org/u/dheera)\
**Post date:** [June 25, 2021, 1:09am UTC](https://discourse.openrobotics.org/t/rospy2-a-cringe-worthy-ros1-like-interface-for-ros2/21067/1 "2021-06-25T01:09:52Z")

</div>

Hi everyone,  
This might make some people cringe, but let’s face it – you have a lot of ROS1 code and you aren’t switching to ROS2 yet because you have to rewrite a LOT of nodes.

So I wrote a legacy interface that behaves like `rospy` but speaks ROS2 behind the curtain. This is very different from a ROS1/ROS2 bridge in that you don’t need to run a ROS1 master at all.

The idea is to be able to take any ROS1 node, replace  
`import rospy`  
with  
`import rospy2 as rospy`  
and **BAM** it should work on ROS2.

[https://github.com/dheera/rospy2](https://github.com/dheera/rospy2)

This is far from complete but here’s an initial effort with a test node.

Feedback and contributions welcome!

Before continuing with this, I’m also trying to gauge interest as to:

(0) How many people would actually use something like this, if it was more fully-fledged?

(1) What ROS1 features do you absolutely need that this doesn’t yet support?

(2) Is there strong interest in a C++ version of this? Minding of course that it might be much harder to build a C++ equivalent considering that I’ve hugely abused Python’s lack of strong typing to make this work.

Thanks!

---

<div class="post-metadata">

**Author:** ![parzival](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/parzival/32/17071_2.png) [@parzival](https://discourse.openrobotics.org/u/parzival)\
**Post date:** [June 25, 2021, 4:01am UTC](https://discourse.openrobotics.org/t/rospy2-a-cringe-worthy-ros1-like-interface-for-ros2/21067/2 "2021-06-25T04:01:11Z")

</div>

This can be a nightmare when reading someone else’s code, akin to getting fake transparent images in search 😂

---

<div class="post-metadata">

**Author:** ![mvollrath](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/mvollrath/32/1304_2.png) [@mvollrath](https://discourse.openrobotics.org/u/mvollrath)\
**Post date:** [June 25, 2021, 4:17am UTC](https://discourse.openrobotics.org/t/rospy2-a-cringe-worthy-ros1-like-interface-for-ros2/21067/3 "2021-06-25T04:17:49Z")

</div>

I would use this.

Desires (looks like most things already available):

- params
- pubsub
- services
- rospy-like threading (each Subscriber on its own thread)

Some interest in C++ version but mostly interested in Python because it seems like the lower-hanging fruit for this kind of portability lib.

---

<div class="post-metadata">

**Author:** ![gavanderhoorn](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/gavanderhoorn/32/969_2.png) [@gavanderhoorn](https://discourse.openrobotics.org/u/gavanderhoorn)\
**Post date:** [June 25, 2021, 6:52am UTC](https://discourse.openrobotics.org/t/rospy2-a-cringe-worthy-ros1-like-interface-for-ros2/21067/4 "2021-06-25T06:52:16Z")

</div>

I’m not sure why you edited the title to include _cringe_; there’s nothing really wrong with doing this and it seems quite useful, if only for the fact it essentially provides an executable migration guide.

In the form of a document, this would show snippets of code (like a cookbook). That would already be great, as it would answer many questions of the form “_in ROS 1 we did X, how do I do X in ROS 2?_”

This just takes it one step further. If done well, that’s a valuable resource to make available 👍

(it might not always show the best possible or most efficient way to approach such a migration, but it could still provide a good first stepping stone in migrating code)

---

<div class="post-metadata">

**Author:** ![victor\_sillerico](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/victor_sillerico/32/10536_2.png) [@victor\_sillerico](https://discourse.openrobotics.org/u/victor_sillerico)\
**Post date:** [June 25, 2021, 5:07pm UTC](https://discourse.openrobotics.org/t/rospy2-a-cringe-worthy-ros1-like-interface-for-ros2/21067/5 "2021-06-25T17:07:34Z")

</div>

It could be great to have a C++ version of this!

---

<div class="post-metadata">

**Author:** ![dheera](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/dheera/32/837_2.png) [@dheera](https://discourse.openrobotics.org/u/dheera)\
**Post date:** [June 25, 2021, 5:40pm UTC](https://discourse.openrobotics.org/t/rospy2-a-cringe-worthy-ros1-like-interface-for-ros2/21067/6 "2021-06-25T17:40:21Z")

</div>

I’ll take a stab at it when I get a chance. I’m wondering if anyone knows what the deprecation schedule for ConstPtr is? e.g. from `/opt/ros/galactic/include/std_msgs/msg /detail/string__struct.hpp`:

```auto
  typedef DEPRECATED __std_msgs__ msg__String
    std::shared_ptr<std_msgs::msg::String_<ContainerAllocator> const>
    ConstPtr;

```

Having access to these ConstPtr might be perhaps critical to making a C++ equivalent work.

Writing something that occuies the `ros::` namespace and provides `ros::NodeHandle`, `ros::Publisher`, etc. is easy, since it doesn’t conflict with ROS2’s `rclcpp::` namespace, and `ros::` can contain a bunch of proxy objects of sorts that behave like roscpp and speak `rclcpp::` behind the curtain.

But the message callbacks in existing code are all going to be `void some_callback(const std_msgs::String::ConstPtr& msg) { ... }`
