%% 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.

rosinit
node = ros.Node('/testTf');
exampleHelperROSStartTfPublisher

%
% Retrieve the TransformationTree object. Pause to wait for tftree to update.

tftree = 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 camera'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;

%
% Transform 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

% Copyright 2019 The MathWorks, Inc.