Skip to content

Commit 6cd7cd7

Browse files
committed
Make it a non-breaking change
1 parent 6864386 commit 6cd7cd7

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/roslibpy/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@
4141
Main ROS concepts
4242
=================
4343
44+
ROS1 vs ROS2
45+
------------
46+
47+
This library has been tested to work with ROS1. ROS2 should work, but it is still
48+
in the works.
49+
50+
One area in which ROS1 and ROS2 differ is in the header interface. To use ROS2, use
51+
the header defined in the `roslibpy.ros2` module.
52+
53+
.. autoclass:: roslibpy.ros2.Header
54+
:members:
55+
56+
4457
Topics
4558
------
4659

src/roslibpy/core.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ def __init__(self, values=None):
4848

4949

5050
class Header(UserDict):
51-
"""Represents a message header of the ROS type std_msgs/Header."""
51+
"""Represents a message header of the ROS type std_msgs/Header.
5252
53-
def __init__(self, stamp=None, frame_id=None):
53+
This header is only compatible with ROS1. For ROS2 headers, use :class:`roslibpy.ros2.Header`.
54+
55+
"""
56+
57+
def __init__(self, seq=None, stamp=None, frame_id=None):
5458
self.data = {}
59+
self.data["seq"] = seq
5560
self.data["stamp"] = Time(stamp["secs"], stamp["nsecs"]) if stamp else None
5661
self.data["frame_id"] = frame_id
5762

src/roslibpy/ros2/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Python 2/3 compatibility import list
2+
try:
3+
from collections import UserDict
4+
except ImportError:
5+
from UserDict import UserDict
6+
7+
from roslibpy import Time
8+
from roslibpy import Header as ROS1Header
9+
10+
__all__ = [
11+
"Header",
12+
]
13+
14+
15+
class Header(ROS1Header):
16+
"""Represents a message header of the ROS type std_msgs/Header."""
17+
18+
def __init__(self, stamp=None, frame_id=None):
19+
super(Header, self).__init__(stamp=stamp, frame_id=frame_id)
20+
self.data["stamp"] = Time(stamp["secs"], stamp["nsecs"]) if stamp else None
21+
self.data["frame_id"] = frame_id
22+
del self.data["seq"]

0 commit comments

Comments
 (0)