www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/GetTransformationsAndApplyExample.m
%% Get ROS Transformations and Apply to ROS Messages % This example shows how to setup a ROS transformation tree and transform % frames based on this information. It uses time-buffered % transformations to access transformations at different times. %% % Create a ROS transformation tree. You must be connected to a ROS network % using |rosinit|. Replace |ipaddress| with your ROS network address. ipaddress = '172.28.194.91'; rosinit(ipaddress) tftree = rostf; pause(1); %% % Look at the available frames on the transformation tree. tftree.AvailableFrames %% % Check if the desired transformation is available now. This example is % looking for the transformation from |'camera_link'| to |'base_link'|. canTransform(tftree,'base_link','camera_link') %% % Get the transformation for 3 seconds from now. |getTransform| will wait % until the transformation becomes available with the specified timeout. desiredTime = rostime('now')+3; tform = getTransform(tftree,'base_link','camera_link',... desiredTime,'Timeout',5); %% % Create a ROS message to transform. Messages could be retrieved off the ROS % network as well. pt = rosmessage('geometry_msgs/PointStamped'); pt.Header.FrameId = 'camera_link'; pt.Point.X = 3; pt.Point.Y = 1.5; pt.Point.Z = 0.2; %% % Transform the ROS message to the |'base_link'| frame using the % desired time saved from before. tfpt = transform(tftree,'base_link',pt,desiredTime); %% % _Optional:_ You can also use |apply| with the stored |tform| to apply this % transformation to the |pt| message. tfpt2 = apply(tform,pt); %% % Shut down the ROS network. rosshutdown