Bird
Raised Fist0
ROSframework~20 mins

Broadcasting transforms in ROS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
ROS Transform Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this ROS transform broadcaster node output?

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?

ROS
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()
AThe tf tree will have no transforms because the broadcaster is static and does not publish continuously.
BThe tf tree will have a dynamic transform from 'camera_link' to 'base_link' with translation (-1.0, 0.0, -0.5) and no rotation.
CThe tf tree will have a static transform from 'base_link' to 'camera_link' with translation (0.0, 0.0, 0.0) and identity rotation.
DThe tf tree will have a static transform from 'base_link' to 'camera_link' with translation (1.0, 0.0, 0.5) and no rotation.
Attempts:
2 left
💡 Hint

Remember that StaticTransformBroadcaster publishes a fixed transform once and it stays in the tf tree.

state_output
intermediate
1:30remaining
What is the value of the child_frame_id after broadcasting?

Given the following ROS transform broadcaster snippet, what will be the value of child_frame_id in the published transform?

ROS
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()
A"map"
B"odom"
C"base_link"
D"world"
Attempts:
2 left
💡 Hint

The child_frame_id is the frame that is moving relative to the header.frame_id.

📝 Syntax
advanced
1:30remaining
Which option will cause a syntax error in broadcasting a transform?

Identify the code snippet that will cause a syntax error when trying to broadcast a transform in ROS Python.

A
transform.header.stamp = rospy.Time.now()
transform.header.frame_id = "world"
transform.child_frame_id = "robot"
br.sendTransform(transform))
B
transform.header.stamp = rospy.Time.now()
transform.header.frame_id = "world"
transform.child_frame_id = "robot"
br.sendTransform(transform
)
C
)mrofsnart(mrofsnarTdnes.rb
"tobor" = di_emarf_dlihc.mrofsnart
"dlrow" = di_emarf.redaeh.mrofsnart
)(won.emiT.ypsor = pmats.redaeh.mrofsnart
D
transform.header.stamp = rospy.Time.now()
transform.header.frame_id = "world"
transform.child_frame_id = "robot"
br.sendTransform(transform)
Attempts:
2 left
💡 Hint

Look for unmatched parentheses or extra characters.

🔧 Debug
advanced
2:00remaining
Why does this transform not appear in the tf tree?

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?

ROS
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()
AThe node exits immediately after sending the transform, so the transform is not continuously published and disappears from the tf tree.
BThe header timestamp is not set to zero, so the transform is ignored.
CThe transform has an invalid rotation quaternion causing it to be rejected.
DThe child_frame_id and header.frame_id are the same, causing a conflict.
Attempts:
2 left
💡 Hint

Consider how tf2_ros.TransformBroadcaster works compared to StaticTransformBroadcaster.

🧠 Conceptual
expert
2:30remaining
Which statement about ROS transform broadcasting is true?

Choose the correct statement about broadcasting transforms in ROS using tf2_ros.

A<p>Transforms published with <code>TransformBroadcaster</code> do not require a valid timestamp.</p>
B<p><code>StaticTransformBroadcaster</code> publishes transforms once and they remain available indefinitely without needing continuous publishing.</p>
C<p><code>TransformBroadcaster</code> publishes static transforms that do not require timestamps.</p>
D<p><code>StaticTransformBroadcaster</code> requires the node to continuously publish the transform at a fixed rate.</p>
Attempts:
2 left
💡 Hint

Think about the difference between static and dynamic transform broadcasters.

Practice

(1/5)
1. What is the main purpose of broadcasting transforms in ROS?
easy
A. To control robot motors directly
B. To send sensor data like images or laser scans
C. To share position and orientation between different coordinate frames
D. To log messages for debugging

Solution

  1. Step 1: Understand the role of transforms in ROS

    Transforms represent the position and orientation of one frame relative to another.
  2. Step 2: Identify broadcasting purpose

    Broadcasting transforms shares this spatial relationship so other nodes can use it.
  3. Final Answer:

    To share position and orientation between different coordinate frames -> Option C
  4. Quick Check:

    Broadcasting transforms = share frames [OK]
Hint: Broadcasting transforms shares frame positions and orientations [OK]
Common Mistakes:
  • Confusing transforms with sensor data
  • Thinking broadcasting controls motors
  • Assuming broadcasting logs messages
2. Which ROS class is used to broadcast transforms in Python?
easy
A. TransformSubscriber
B. TransformListener
C. TransformPublisher
D. TransformBroadcaster

Solution

  1. Step 1: Recall ROS transform classes

    TransformListener listens to transforms, TransformBroadcaster sends them.
  2. Step 2: Identify broadcasting class

    The class to send or broadcast transforms is TransformBroadcaster.
  3. Final Answer:

    TransformBroadcaster -> Option D
  4. Quick Check:

    Broadcasting uses TransformBroadcaster [OK]
Hint: Broadcasting uses TransformBroadcaster class in ROS [OK]
Common Mistakes:
  • Confusing listener with broadcaster
  • Assuming publisher or subscriber classes exist for transforms
  • Mixing up class names
3. Given this Python snippet using ROS TransformBroadcaster:
br = tf2_ros.TransformBroadcaster()
trans = geometry_msgs.msg.TransformStamped()
trans.header.frame_id = "world"
trans.child_frame_id = "robot"
trans.transform.translation.x = 1.0
trans.transform.rotation.w = 1.0
br.sendTransform(trans)
What does this code do?
medium
A. Broadcasts a transform from 'world' to 'robot' with translation x=1.0
B. Listens for transforms from 'robot' to 'world'
C. Publishes sensor data to 'robot' frame
D. Creates a static transform that never updates

Solution

  1. Step 1: Analyze transform setup

    The transform has parent frame 'world' and child frame 'robot' with translation x=1.0 and rotation w=1.0 (identity rotation).
  2. Step 2: Understand sendTransform effect

    sendTransform broadcasts this transform so other nodes know 'robot' is 1 meter along x from 'world'.
  3. Final Answer:

    Broadcasts a transform from 'world' to 'robot' with translation x=1.0 -> Option A
  4. Quick Check:

    sendTransform broadcasts given transform [OK]
Hint: sendTransform broadcasts the given transform between frames [OK]
Common Mistakes:
  • Thinking it listens instead of broadcasts
  • Confusing parent and child frames
  • Assuming static transform without updates
4. What is wrong with this ROS Python code snippet for broadcasting transforms?
br = tf2_ros.TransformBroadcaster()
trans = geometry_msgs.msg.TransformStamped()
trans.header.frame_id = "base"
trans.child_frame_id = "camera"
trans.transform.translation.x = 0.5
br.sendTransform(trans)
medium
A. Incorrect frame_id and child_frame_id order
B. Missing rotation values in the transform
C. TransformBroadcaster cannot send TransformStamped
D. sendTransform should be called before setting fields

Solution

  1. Step 1: Check transform completeness

    The transform sets translation.x but does not set any rotation values (x,y,z,w), which are required.
  2. Step 2: Understand ROS transform requirements

    ROS expects a valid quaternion rotation; missing it can cause errors or undefined behavior.
  3. Final Answer:

    Missing rotation values in the transform -> Option B
  4. Quick Check:

    Transforms need translation and rotation [OK]
Hint: Always set rotation quaternion when broadcasting transforms [OK]
Common Mistakes:
  • Forgetting to set rotation quaternion
  • Mixing up frame_id and child_frame_id
  • Calling sendTransform too early
5. You want to broadcast a transform continuously at 10 Hz from frame 'map' to 'robot' with changing position. Which approach is best in ROS Python?
hard
A. Use a loop with rospy.Rate(10) calling sendTransform each cycle with updated data
B. Call sendTransform once outside any loop to set the transform
C. Use TransformListener to update the transform automatically
D. Publish the transform as a static transform once at startup

Solution

  1. Step 1: Understand continuous broadcasting need

    To keep transforms updated, you must send them repeatedly at the desired rate.
  2. Step 2: Identify correct ROS pattern

    Using a loop with rospy.Rate(10) and calling sendTransform each cycle updates the transform at 10 Hz.
  3. Step 3: Eliminate incorrect options

    Calling sendTransform once won't update continuously; TransformListener listens but doesn't broadcast; static transform is fixed.
  4. Final Answer:

    Use a loop with rospy.Rate(10) calling sendTransform each cycle with updated data -> Option A
  5. Quick Check:

    Continuous broadcast needs loop with sendTransform [OK]
Hint: Broadcast continuously by looping sendTransform at desired rate [OK]
Common Mistakes:
  • Sending transform only once
  • Confusing listener with broadcaster
  • Using static transform for dynamic data