Skip to content

Commit

Permalink
Fix publishers for ROS1
Browse files Browse the repository at this point in the history
  • Loading branch information
HoangGiang93 committed Aug 12, 2024
1 parent ff1937c commit 4e12b5a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
3 changes: 2 additions & 1 deletion docs/source/tutorials/tutorial_5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ Define ROS Configuration in the MUV file
time_unit: s
handedness: rhs
port: 7302
topic: /odom
odom_topic: /odom
tf_topic: /tf
rate: 60
body: tiago_dual # The body to attach the odometry to
frame_id: map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from typing import Dict, Any, List, Optional
from typing import Dict, Any, List, Optional, Union

from ... import Interface, INTERFACE

Expand All @@ -16,14 +16,14 @@

class MultiversePublisher(MultiverseNode):
_use_meta_data: bool = False
_msg_types: List[Any] = []
_msgs: List[Any] = []
__publishers: List[Publisher] = []
_msg_types: List[Any] = None
_msgs: List[Any] = None
__publishers: List[Publisher] = None

def __init__(
self,
client_addr: SocketAddress,
topic_name: str | List[str],
topic_name: Optional[Union[str, List[str]]] = None,
rate: float = 60.0,
multiverse_meta_data: MultiverseMetaData = MultiverseMetaData(),
**kwargs: Dict
Expand All @@ -33,11 +33,13 @@ def __init__(
multiverse_meta_data=multiverse_meta_data
)
if isinstance(topic_name, str):
self.create_publishers([topic_name], [self._msg_type], rate)
self.create_publishers([topic_name], self._msg_types, rate)
elif isinstance(topic_name, list):
self.create_publishers(topic_name, self._msg_types, rate)

def create_publishers(self, topic_names: List[str], msg_types: List[Any], rate: float) -> None:
self._msgs = []
self.__publishers = []
if INTERFACE == Interface.ROS1:
for topic_name, msg_type in zip(topic_names, msg_types):
self._msgs.append(msg_type())
Expand Down Expand Up @@ -67,11 +69,13 @@ def _run(self) -> None:

def _publisher_callback(self, _=None) -> None:
try:
self._communicate(self._use_meta_data)
if self._use_meta_data:
self._bind_request_meta_data(_)
self._communicate(True)
self._bind_response_meta_data(self.response_meta_data)
else:
self.send_data = [self.world_time + self.sim_time]
self.send_data = [self.sim_time]
self._communicate(False)
self._bind_receive_data(self.receive_data)
self._publish()
except:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def __init__(
client_addr=client_addr,
multiverse_meta_data=multiverse_meta_data,
)
self.request_meta_data["receive"][""] = ["position", "quaternion"]

def _bind_request_meta_data(self, _) -> None:
self.request_meta_data["receive"] = {"": ["position", "quaternion"]}

def _bind_response_meta_data(self, response_meta_data: Dict) -> None:
objects = response_meta_data.get("receive")
Expand Down Expand Up @@ -79,4 +81,4 @@ def _bind_response_meta_data(self, response_meta_data: Dict) -> None:
self._msgs[0].transforms.append(tf_msg)

if INTERFACE == Interface.ROS1:
self._msgs[0] += 1
self._seq += 1
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _bind_request_meta_data(self, request: SocketRequest) -> SocketRequest:
request_meta_data["meta_data"]["time_unit"] = "s" if meta_data.time_unit == "" else meta_data.time_unit
request_meta_data["meta_data"]["handedness"] = "rhs" if meta_data.handedness == "" else meta_data.handedness

send_data = [self.world_time + self.sim_time]
send_data = [self.sim_time]

for object_data in request.send:
is_object_name_empty = object_data.object_name == ""
Expand Down
6 changes: 4 additions & 2 deletions multiverse/resources/muv/default.muv
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ multiverse_clients:
time_unit: s
handedness: rhs
port: 7303
topic: /odom
odom_topic: /odom
tf_topic: /tf
rate: 60
body: tiago_dual_1
frame_id: map_1
Expand Down Expand Up @@ -220,7 +221,8 @@ multiverse_clients:
time_unit: s
handedness: rhs
port: 7803
topic: /odom
odom_topic: /odom
tf_topic: /tf
rate: 60
body: tiago_dual_2
frame_id: map_2
Expand Down
3 changes: 2 additions & 1 deletion multiverse/resources/muv/tiago_dual_in_apartment.muv
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ multiverse_clients:
time_unit: s
handedness: rhs
port: 7302
topic: /odom
odom_topic: /odom
tf_topic: /tf
rate: 60
body: tiago_dual
frame_id: map
Expand Down
3 changes: 2 additions & 1 deletion multiverse/resources/muv/tiago_dual_in_isr_testbed.muv
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ multiverse_clients:
time_unit: s
handedness: rhs
port: 7302
topic: /odom
odom_topic: /odom
tf_topic: /tf
rate: 60
body: tiago_dual
frame_id: map
Expand Down

0 comments on commit 4e12b5a

Please sign in to comment.