Challenge - 5 Problems
Xacro Macro Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateUnderstanding Macro Parameter Substitution
Given the following Xacro macro, what will be the value of the element's xyz attribute after macro expansion?
<macro name="wheel" params="radius width x y z">
<link name="wheel_link">
<visual>
<geometry><cylinder radius="${radius}" length="${width}" /></geometry>
<origin xyz="${x} ${y} ${z}" />
</visual>
</link>
</macro>
<wheel radius="0.3" width="0.1" x="1" y="0" z="0.5" />Attempts:
2 left
💡 Hint
Look at how the macro parameters are used inside the xyz attribute.
✗ Incorrect
The macro parameters x, y, and z are substituted directly into the xyz attribute. Since the macro is called with x="1", y="0", and z="0.5", the xyz becomes "1 0 0.5".
📝 Syntax
intermediateIdentifying Syntax Errors in Xacro Macro Definition
Which option contains a syntax error that will prevent the Xacro macro from expanding correctly?
ROS
<macro name="arm_segment" params="length angle"> <link name="segment_link"> <visual> <geometry> <box size="${length} 0.1 0.1" /> </geometry> <origin rpy="0 0 ${angle}" /> </visual> </link> </macro>
Attempts:
2 left
💡 Hint
Check for proper tag closing and attribute quoting.
✗ Incorrect
Option D is missing the closing '>' for the macro call tag, causing a syntax error. Options B, C, and D are valid ways to call the macro.
❓ state_output
advancedOutput of Nested Macro Expansion
Consider these two macros:
What will be the output of calling
<macro name="joint" params="name parent child">
<joint name="${name}" type="revolute">
<parent link="${parent}" />
<child link="${child}" />
</joint>
</macro>
<macro name="arm" params="segment_length segment_angle">
<link name="base_link" />
<link name="segment_link" />
<joint name="base_to_segment" parent="base_link" child="segment_link" />
</macro>What will be the output of calling
<arm segment_length="1.0" segment_angle="0.5" />?Attempts:
2 left
💡 Hint
Look carefully at how the joint macro is called inside the arm macro.
✗ Incorrect
Inside the 'arm' macro, the 'joint' macro is not called as a macro but as a literal tag. So the output includes the joint tag with attributes but without expanding the joint macro's body.
🔧 Debug
advancedDebugging Macro Parameter Usage
This macro is intended to create a link with a visual box of given size. Why does the following macro produce an error when called?
Called as:
<macro name="box_link" params="size">
<link name="box_link">
<visual>
<geometry>
<box size="${size}" />
</geometry>
</visual>
</link>
</macro>Called as:
<box_link size="1 1 1" />Attempts:
2 left
💡 Hint
Check how parameters with spaces are passed and used in Xacro.
✗ Incorrect
Xacro allows passing strings with spaces as parameter values if quoted properly. Here, '1 1 1' is a valid string for the box size attribute, so no error occurs.
🧠 Conceptual
expertEffect of Property Overriding in Nested Macros
Given these macros:
What color will the
<property name="color" value="red" />
<macro name="painted_link" params="name">
<link name="${name}">
<visual>
<material name="paint">
<color rgba="${color} 1" />
</material>
</visual>
</link>
</macro>
<macro name="robot">
<property name="color" value="blue" />
<painted_link name="link1" />
</macro>What color will the
rgba attribute have when calling <robot />?Attempts:
2 left
💡 Hint
Consider how property overriding works in nested macro calls in Xacro.
✗ Incorrect
The 'robot' macro overrides the 'color' property to 'blue' before calling 'painted_link'. The 'painted_link' macro uses the current 'color' property, so it uses 'blue'.
