Effacer les filtres
Effacer les filtres

getTransform from ROS2 bag

3 vues (au cours des 30 derniers jours)
Antoine Harlé
Antoine Harlé le 21 Juin 2022
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.

Réponses (1)

Jagadeesh Konakalla
Jagadeesh Konakalla le 23 Juin 2022
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 commentaires
Yuan Wei
Yuan Wei le 11 Mar 2023
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 le 13 Mar 2023
The current release of R2022b and R2023a releases does not have this capability.
It is work in porgress for near Future release of MATLAB.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Network Connection and Exploration dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by