Consider a ROS node broadcasting a transform from frame base_link to camera_link with a fixed translation and rotation. What will be the output of the tf tree after running this node?
import rospy import tf2_ros import geometry_msgs.msg def broadcaster(): rospy.init_node('static_tf_broadcaster') br = tf2_ros.StaticTransformBroadcaster() static_transformStamped = geometry_msgs.msg.TransformStamped() static_transformStamped.header.stamp = rospy.Time.now() static_transformStamped.header.frame_id = "base_link" static_transformStamped.child_frame_id = "camera_link" static_transformStamped.transform.translation.x = 1.0 static_transformStamped.transform.translation.y = 0.0 static_transformStamped.transform.translation.z = 0.5 static_transformStamped.transform.rotation.x = 0.0 static_transformStamped.transform.rotation.y = 0.0 static_transformStamped.transform.rotation.z = 0.0 static_transformStamped.transform.rotation.w = 1.0 br.sendTransform(static_transformStamped) rospy.spin() if __name__ == '__main__': broadcaster()
Remember that StaticTransformBroadcaster publishes a fixed transform once and it stays in the tf tree.
The StaticTransformBroadcaster publishes a fixed transform from base_link to camera_link with the given translation and rotation. This transform remains available in the tf tree for all nodes to use.
Given the following ROS transform broadcaster snippet, what will be the value of child_frame_id in the published transform?
import rospy import tf2_ros import geometry_msgs.msg rospy.init_node('tf_broadcaster') br = tf2_ros.TransformBroadcaster() transform = geometry_msgs.msg.TransformStamped() transform.header.stamp = rospy.Time.now() transform.header.frame_id = "odom" transform.child_frame_id = "base_link" transform.transform.translation.x = 0.5 transform.transform.translation.y = 0.0 transform.transform.translation.z = 0.0 transform.transform.rotation.x = 0.0 transform.transform.rotation.y = 0.0 transform.transform.rotation.z = 0.707 transform.transform.rotation.w = 0.707 br.sendTransform(transform) rospy.spin()
The child_frame_id is the frame that is moving relative to the header.frame_id.
The child_frame_id is set explicitly to "base_link" in the code. This means the transform describes the pose of base_link relative to odom.
Identify the code snippet that will cause a syntax error when trying to broadcast a transform in ROS Python.
Look for unmatched parentheses or extra characters.
Option A has an extra closing parenthesis after sendTransform(transform) causing a syntax error.
A ROS node uses tf2_ros.TransformBroadcaster to send a transform once and then exits immediately. Why might the transform not appear in the tf tree?
import rospy import tf2_ros import geometry_msgs.msg def broadcaster(): rospy.init_node('tf_broadcaster') br = tf2_ros.TransformBroadcaster() t = geometry_msgs.msg.TransformStamped() t.header.stamp = rospy.Time.now() t.header.frame_id = "map" t.child_frame_id = "base_link" t.transform.translation.x = 1.0 t.transform.translation.y = 2.0 t.transform.translation.z = 0.0 t.transform.rotation.x = 0.0 t.transform.rotation.y = 0.0 t.transform.rotation.z = 0.0 t.transform.rotation.w = 1.0 br.sendTransform(t) if __name__ == '__main__': broadcaster()
Consider how tf2_ros.TransformBroadcaster works compared to StaticTransformBroadcaster.
TransformBroadcaster publishes transforms dynamically and requires continuous publishing. If the node exits immediately after one send, the transform disappears from the tf tree.
Choose the correct statement about broadcasting transforms in ROS using tf2_ros.
Think about the difference between static and dynamic transform broadcasters.
StaticTransformBroadcaster sends a transform once and it stays in the tf tree indefinitely. TransformBroadcaster requires continuous publishing with valid timestamps.
