MATLAB Examples

Convert A ROS Pose Message To A Homogeneous Transformation

This model subcribes to a Pose message on the ROS network. Use bus selectors to extract the rotation and translation vectors. The Coordinate Transformation Conversion block takes the rotation vector (euler angles) and translation vector in and gives the homogeneous transformation for the message.

Connect to a ROS network. Create a publisher for the '/pose' topic using a 'geometry_msgs/Pose' message type.

[pub,msg] = rospublisher('/pose','geometry_msgs/Pose');
Initializing ROS master on http://bat7778maci:59179/.
Initializing global node /matlab_global_node_57476 with NodeURI http://bat7778maci:59191/

Specify the detailed pose information. The message contains a translation (Position) and quaternion (Orientation) to express the pose. Sned the message via the publisher.

msg.Position.X = 1;
msg.Position.Y = 2;
msg.Position.Z = 3;
msg.Orientation.X = sqrt(2)/2;
msg.Orientation.Y = sqrt(2)/2;
msg.Orientation.Z = 0;
msg.Orientation.W = 0;


Open the 'pose_to_transformation_model' model. This model subscribes to the '/pose' topic in ROS. The bus selectors extract the quaternion and position vectors from the ROS message. The Coordinate Transformation Conversion block then converts the position (translation) and quaternion to a homogeneous transformation.

For more details, inspect the bus selector in the model to see how the message information is extracted.


Run the model to display the homogeneous transformation.

Modify the position or orientation components of the message. Resend the message and run model to see the change in the homogeneous transformation.

msg.Position.X = 4;
msg.Position.Y = 5;
msg.Position.Z = 6;

Shutdown the ROS network.

Shutting down global node /matlab_global_node_57476 with NodeURI http://bat7778maci:59191/
Shutting down ROS master on http://bat7778maci:59179/.