getTransform from ROS2 bag
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to access Transform from a ROS2bag, the same way you can with the tf2_msgs/LookupTransform action.
>> 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.
0 个评论
回答(1 个)
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
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
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 Exchange 中查找有关 Network Connection and Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!