MATLAB ROS Transform Error

4 views (last 30 days)
Carl Stahoviak
Carl Stahoviak on 14 Feb 2019
Commented: Cam Salzberger on 1 May 2020
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
Carl Stahoviak
Carl Stahoviak on 14 Feb 2019
Edited: Carl Stahoviak on 14 Feb 2019
Thank you Cam. The problem was that only the very first radar message had a timestamp that just barely (in the Nsecs range) pre-dated the first transfrom message. So all other messages in the bag can be properly transformed.
I have a follow up question though. I think there is an error in the following documentation page: https://www.mathworks.com/help/robotics/ref/apply.html#buqbf3f-entity
The list of transformable entities includes the type: geometry_msgs/PointCloud2Stamped
However, in ROS, there is no such thing as a PointCloud2Stamped message. Did the documentation mean to refer to the sensor_msgs/PointCloud2 message type?
This message type is listed in the entity types under the documentation page that describes the transform() function: https://www.mathworks.com/help/robotics/ref/transform.html#buqbzo2-entity
Cam Salzberger
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

Sign in to comment.

Answers (0)

Categories

Find more on ROS Log Files and Transformations in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!