TransformStamped

Create transformation message

Description

The TransformStamped object is an implementation of the geometry_msgs/TransformStamped message type in ROS. The object contains meta-information about the message itself and the transformation. The transformation has a translational and rotational component.

Creation

Syntax

tform = getTransform(tftree,targetframe,sourceframe)

Description

example

tform = getTransform(tftree,targetframe,sourceframe) returns the latest known transformation between two coordinate frames. Transformations are structured as a 3-D translation (3-element vector) and a 3-D rotation (quaternion).

Properties

expand all

This property is read-only.

Message type of ROS message, returned as a character vector.

Data Types: char

This property is read-only.

ROS Header message, returned as a Header object. This header message contains the MessageType, sequence (Seq), timestamp (Stamp), and FrameId.

Second coordinate frame to transform point into, specified as a character vector.

This property is read-only.

Transformation message, specified as a Transform object. The object contains the MessageType with a Translation vector and Rotation quaternion.

Object Functions

applyTransform message entities into target frame

Examples

collapse all

This example looks at the TransformStamped object to show the underlying structure of a TransformStamped ROS message. After setting up a network and transformations, you can create a transformation tree and get transformations between specific coordinate systems. Using showdetails lets you inspect the information in the transformation. It contains the ChildFrameId, Header, and Transform.

Start ROS network and setup transformations.

rosinit
Initializing ROS master on http://ah-sradford:11311/.
Initializing global node /matlab_global_node_28474 with NodeURI http://ah-sradford:65007/
exampleHelperROSStartTfPublisher

Create transformation tree and wait for tree to update. Get the transform between the robot base and its camera center.

tftree = rostf;
waitForTransform(tftree,'camera_center','robot_base');
tform = getTransform(tftree,'camera_center','robot_base');

Inspect the TransformStamped object.

showdetails(tform)
  ChildFrameId :  robot_base
  Header          
    Seq     :  20
    FrameId :  camera_center
    Stamp      
      Sec  :  1512065171
      Nsec :  111000064
  Transform       
    Translation    
      X :  0.4999999999999998
      Y :  0
      Z :  -1
    Rotation       
      X :  0
      Y :  -0.7071067811865475
      Z :  0
      W :  0.7071067811865476

Access the Translation vector inside the Transform property.

trans = tform.Transform.Translation
trans = 
  ROS Vector3 message with properties:

    MessageType: 'geometry_msgs/Vector3'
              X: 0.5000
              Y: 0
              Z: -1

  Use showdetails to show the contents of the message

Shutdown ROS network.

rosshutdown
Shutting down global node /matlab_global_node_28474 with NodeURI http://ah-sradford:65007/
Shutting down ROS master on http://ah-sradford:11311/.

Apply a transformation from a TransformStamped object to a PointStamped message.

Start ROS network and setup transformations.

rosinit
Initializing ROS master on http://ah-sradford:11311/.
Initializing global node /matlab_global_node_71764 with NodeURI http://ah-sradford:62552/
exampleHelperROSStartTfPublisher

Create transformation tree and wait for tree to update. Get the transform between the robot base and its camera center. Inspect the transformation.

tftree = rostf;
waitForTransform(tftree,'camera_center','robot_base');
tform = getTransform(tftree,'camera_center','robot_base');
showdetails(tform)
  ChildFrameId :  robot_base
  Header          
    Seq     :  15
    FrameId :  camera_center
    Stamp      
      Sec  :  1512064258
      Nsec :  68999936
  Transform       
    Translation    
      X :  0.4999999999999998
      Y :  0
      Z :  -1
    Rotation       
      X :  0
      Y :  -0.7071067811865475
      Z :  0
      W :  0.7071067811865476

Create point to transform. You could also get this point message off the ROS network.

pt = rosmessage('geometry_msgs/PointStamped');
pt.Header.FrameId = 'camera_center';
pt.Point.X = 3;
pt.Point.Y = 1.5;
pt.Point.Z = 0.2;

Apply the transformation to the point.

tfpt = apply(tform,pt);

Shutdown ROS network.

rosshutdown
Shutting down global node /matlab_global_node_71764 with NodeURI http://ah-sradford:62552/
Shutting down ROS master on http://ah-sradford:11311/.

Introduced in R2015a