MATLAB ROS Transform Error
Show older comments
I'm getting the following error when atempting to use getTransform():
"Lookup would require extrapolation into the past. Requested time Wed Feb 13 14:23:57 2019 but the earliest data is at time Wed Feb 13 14:23:57 2019 when looking up transform from frame [base_link] to frame [world]"
This error makes it seem as though the transform should be available... but it's not.
Additionally, canTransform() returns a logical 0 when requesting a transform at that time. What's going on here?
Code below:
bagfile = 'multiradar_2019-02-13_rangeRes_0-04_velRes_0-09_loop.bag'
bag = rosbag(bag_file);
% topic information
radar_topic = 'radar_fwd/mmWaveDataHdl/RScan';
% Understand how to use ROS TFs in MATLAB
radar_bag = select(bag,'Topic',radar_topic);
radar_messages = readMessages(radar_bag);
radar_struct = readMessages(radar_bag,'DataFormat','struct');
radar_x = readField(radar_messages{1}, 'x');
radar_y = readField(radar_messages{1}, 'y');
radar_z = readField(radar_messages{1}, 'z');
for i=1:radar_struct{1}.Width
%transform each point in radar message to 'world' frame
pt = rosmessage('geometry_msgs/PointStamped');
pt.Header.FrameId = radar_struct{1}.Header.FrameId;
pt.Header.Stamp = rostime(radar_struct{1}.Header.Stamp.Sec, ...
radar_struct{1}.Header.Stamp.Nsec);
pt.Point.X = radar_x(i);
pt.Point.Y = radar_y(i);
pt.Point.Z = radar_z(i);
% transform point in 'radar_fwd_link' frame to 'world' frame
tfTime = rostime(radar_struct{attempting 1}.Header.Stamp.Sec, ...
radar_struct{1}.Header.Stamp.Nsec);
if canTransform(bag,'world',radar_struct{1}.Header.FrameId,tfTime)
disp('TF available!')
tf = getTransform(bag,'world',radar_struct{1}.Header.FrameId,tfTime, ...
'Timeout',5);
tfpt = apply(tf,pt);
else
disp('TF not available!')
end
disp([pt.Point.X, pt.Point.Y, pt.Point.Z])
tf = getTransform(bag,'world',radar_struct{1}.Header.FrameId,tfTime)
tfpt2 = apply(tf,pt)
end
3 Comments
Cam Salzberger
on 14 Feb 2019
Hey Carl,
Check the /tf topic in the rosbag, or just list the first several messages. Had it already published on the /tf topic before the timestamp of the message you are trying to get the transform at? It could simply be round-off confusion in the error message (e.g. where the earliest available time is at 57.2 seconds, and you're requesting at 57.0 seconds).
-Cam
Carl Stahoviak
on 14 Feb 2019
Edited: Carl Stahoviak
on 14 Feb 2019
Cam Salzberger
on 1 May 2020
Hey Carl,
Jeeze this took me a long time to get back to you. Yes, that is a typo. If you check the help text for the "apply" method, you'll notice it is correct there:
m = rosmessage('geometry_msgs/TransformStamped');
help apply
I'll put in a note to the appropriate team to update the documentation. Thanks again!
-Cam
Answers (0)
Categories
Find more on Specialized Messages in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!