www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/UseTransformationTreeObjectExample.m
%% Use |TransformationTree| Object % Create a ROS transformation tree. You can then view or use transformation % information for different coordinate frames setup in the ROS network. %% % Start ROS network and broadcast sample transformation data. % Copyright 2015 The MathWorks, Inc. rosinit node = robotics.ros.Node('/testTf'); exampleHelperROSStartTfPublisher %% % Retrieve the |TransformationTree| object. Pause to wait for tftree to % update. tftree = robotics.ros.TransformationTree(node); pause(1) %% % View available coordinate frames and the time when they were last % received. frames = tftree.AvailableFrames updateTime = tftree.LastUpdateTime %% % Wait for the transform between two frames, |'camera_center'| and % |'robot_base'|. This will wait until the transformation is valid and block % all other operations. A time out of 5 seconds is also given. waitForTransform(tftree,'robot_base','camera_center',5) %% % Define a point in the camer's coordinate frame. pt = rosmessage('geometry_msgs/PointStamped'); pt.Header.FrameId = 'camera_center'; pt.Point.X = 3; pt.Point.Y = 1.5; pt.Point.Z = 0.2; %% % Tranform the point into the |'base_link'| frame. tfpt = transform(tftree, 'robot_base', pt) %% % Display the transformed point coordinates. tfpt.Point %% % Clear ROS node. Shut down ROS master. clear('node') rosshutdown