|
30 | 30 | from cv_bridge import CvBridge, CvBridgeError |
31 | 31 | from dynamic_reconfigure.encoding import decode_config |
32 | 32 | from dynamic_reconfigure.msg import Config |
33 | | -from geometry_msgs.msg import Quaternion, Transform, TransformStamped, Vector3 |
| 33 | +from geometry_msgs.msg import Quaternion, Transform, TransformStamped, Twist, TwistStamped, Vector3 |
34 | 34 | from image_transport_codecs import decode, encode |
35 | 35 | from image_transport_codecs.compressed_depth_codec import has_rvl |
36 | 36 | from image_transport_codecs.parse_compressed_format import guess_any_compressed_image_transport_format |
@@ -61,6 +61,19 @@ def dict_to_str(d, sep='='): |
61 | 61 | k, sep, str(v) if not isinstance(v, dict) else dict_to_str(v, sep)) for k, v in d.items()) + "}" |
62 | 62 |
|
63 | 63 |
|
| 64 | +def create_connection_header(topic, msg_type, latch=False): |
| 65 | + header = { |
| 66 | + "callerid": "/bag_filter", |
| 67 | + "topic": topic, |
| 68 | + "message_definition": msg_type._full_text, # noqa |
| 69 | + "type": msg_type._type, # noqa |
| 70 | + "md5sum": msg_type._md5sum, # noqa |
| 71 | + } |
| 72 | + if latch: |
| 73 | + header["latching"] = "1" |
| 74 | + return header |
| 75 | + |
| 76 | + |
64 | 77 | class SetFields(DeserializedMessageFilter): |
65 | 78 | """Change values of some fields of a message (pass the fields to change as kwargs).""" |
66 | 79 |
|
@@ -1128,6 +1141,46 @@ def _str_params(self): |
1128 | 1141 | return ", ".join(parts) |
1129 | 1142 |
|
1130 | 1143 |
|
| 1144 | +class StampTwist(DeserializedMessageFilter): |
| 1145 | + """Adjust some static transforms.""" |
| 1146 | + |
| 1147 | + def __init__(self, source_topic, stamped_topic=None, frame_id="base_link", *args, **kwargs): |
| 1148 | + # type: (STRING_TYPE, Optional[STRING_TYPE], STRING_TYPE, Any, Any) -> None |
| 1149 | + """ |
| 1150 | + :param source_topic: The Twist topic to stamp. |
| 1151 | + :param stamped_topic: The stamped Twist topic to create. |
| 1152 | + :param frame_id: The frame_id to use in the stamped messages. |
| 1153 | + :param args: Standard include/exclude topics/types and min/max stamp args. |
| 1154 | + :param kwargs: Standard include/exclude topics/types and min/max stamp kwargs. |
| 1155 | + """ |
| 1156 | + super(StampTwist, self).__init__(include_topics=[source_topic], *args, **kwargs) |
| 1157 | + |
| 1158 | + self._source_topic = source_topic |
| 1159 | + self._stamped_topic = stamped_topic if stamped_topic is not None else (source_topic + "_stamped") |
| 1160 | + self._frame_id = frame_id |
| 1161 | + |
| 1162 | + self._connection_header = create_connection_header(self._stamped_topic, TwistStamped) |
| 1163 | + |
| 1164 | + def filter(self, topic, msg, stamp, header): |
| 1165 | + stamped_msg = TwistStamped() |
| 1166 | + stamped_msg.header.frame_id = self._frame_id |
| 1167 | + stamped_msg.header.stamp = stamp |
| 1168 | + stamped_msg.twist = msg |
| 1169 | + |
| 1170 | + return [ |
| 1171 | + (topic, msg, stamp, header), |
| 1172 | + (self._stamped_topic, stamped_msg, stamp, self._connection_header) |
| 1173 | + ] |
| 1174 | + |
| 1175 | + def _str_params(self): |
| 1176 | + parts = [] |
| 1177 | + parts.append('%s=>%s (frame %s)' % (self._source_topic, self._stamped_topic, self._frame_id)) |
| 1178 | + parent_params = self._default_str_params(include_types=False) |
| 1179 | + if len(parent_params) > 0: |
| 1180 | + parts.append(parent_params) |
| 1181 | + return ", ".join(parts) |
| 1182 | + |
| 1183 | + |
1131 | 1184 | class FixExtrinsicsFromIKalibr(DeserializedMessageFilterWithTF): |
1132 | 1185 | """Apply extrinsic calibrations from IKalibr.""" |
1133 | 1186 |
|
@@ -1325,16 +1378,7 @@ def parse_time_str(time_str): |
1325 | 1378 | return subtitles |
1326 | 1379 |
|
1327 | 1380 | def extra_initial_messages(self): |
1328 | | - connection_header = { |
1329 | | - "callerid": "/bag_filter", |
1330 | | - "topic": self._topic, |
1331 | | - "message_definition": String._full_text, |
1332 | | - "type": String._type, |
1333 | | - "md5sum": String._md5sum, |
1334 | | - } |
1335 | | - if self._latch: |
1336 | | - connection_header["latching"] = "1" |
1337 | | - |
| 1381 | + connection_header = create_connection_header(self._topic, String, self._latch) |
1338 | 1382 | for start_time, end_time, subtitle in self._subtitles: |
1339 | 1383 | msg = String(data=subtitle) |
1340 | 1384 | abs_time = self._start_time + start_time |
|
0 commit comments