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!