getTransform from ROS2 bag

9 ビュー (過去 30 日間)
Antoine Harlé
Antoine Harlé 2022 年 6 月 21 日
Hi,
I want to access Transform from a ROS2bag, the same way you can with the tf2_msgs/LookupTransform action.
I first tried to use getTransform but it only seems to work with ROS1Bags.
>> bag = ros2bag(rosbag_path);
getTransform(bag,'F_FDB','F_RER1',bag.EndTime);
Check for incorrect argument data type or missing argument in call to function 'getTransform'.
I can still access the tf2_msgs/TFMessage in the bag so I worked out a way to convert them to a ROS1bag and access the TF.
bag_tf = readMessages(select(bag,"Topic",["/tf", "/tf_static"]));
bag_writer = rosbagwriter('tf_ros1.bag');
tf2Msg = rosmessage('tf2_msgs/TFMessage',"DataFormat","struct");
tf2Msg.Transforms=rosmessage('geometry_msgs/TransformStamped',"DataFormat","struct");
for bag_idx = 1:length(bag_tf)
bag_msg=bag_tf{bag_idx};
for tf_idx = 1:length(bag_msg.transforms) %Some message contain multiple TFs
tf = bag_msg.transforms(tf_idx);
tf2Msg.Transforms.Header.Stamp.Sec = uint32(tf.header.stamp.sec);
tf2Msg.Transforms.Header.Stamp.Nsec = uint32(tf.header.stamp.nanosec);
tf2Msg.Transforms.Header.FrameId = tf.header.frame_id;
tf2Msg.Transforms.ChildFrameId = tf.child_frame_id;
tf2Msg.Transforms.Transform.Translation.X = tf.transform.translation.x;
tf2Msg.Transforms.Transform.Translation.Y = tf.transform.translation.y;
tf2Msg.Transforms.Transform.Translation.Z = tf.transform.translation.z;
tf2Msg.Transforms.Transform.Rotation.X = tf.transform.rotation.x;
tf2Msg.Transforms.Transform.Rotation.Y = tf.transform.rotation.y;
tf2Msg.Transforms.Transform.Rotation.Z = tf.transform.rotation.z;
tf2Msg.Transforms.Transform.Rotation.W = tf.transform.rotation.w;
write(bag_writer, "/tf", tf2Msg.Transforms.Header.Stamp, tf2Msg);
end
end
delete(bag_writer)
clear bag_writer
reader = rosbagreader('tf_ros1.bag');
getTransform(reader,'F_FDB','F_RER1')
It does work but it's really unpractical. So i was wondering if I missed something to make getTransform directly work with a ROS2bag ?
Thank you in advance for any help !
Antoine H.

回答 (1 件)

Jagadeesh Konakalla
Jagadeesh Konakalla 2022 年 6 月 23 日
Hi Antonie,
Unfortunately, we do not have easy workaround to provide you.
We are working on adding getTransofromations capability to ros2bag. This feature will be available in future releases of MATLAB.
Thanks,
Jagadeesh K.
  2 件のコメント
Yuan Wei
Yuan Wei 2023 年 3 月 11 日
Hi Jagadeesh,
Thank you for your answer. I have a quick question. Has getTransofromations capability been added to the current release of ROS Toolbox in MATLAB yet?
Jagadeesh Konakalla
Jagadeesh Konakalla 2023 年 3 月 13 日
The current release of R2022b and R2023a releases does not have this capability.
It is work in porgress for near Future release of MATLAB.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNetwork Connection and Exploration についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by