Xacro is an XML macro language. Its properties, expressions, conditionals, includes, and macros are evaluated to produce a larger XML document, commonly a URDF robot description. That expansion happens before tools parse the resulting model and before a running robot publishes joint states or transforms. A xacro conditional cannot observe a live encoder, react to a contact event, or change a link while the robot is already operating unless another process regenerates and reloads the description.

This compilation-style boundary is easy to miss because xacro files often appear inside ROS launch systems. Launch may supply arguments at startup, but the result is still a concrete robot-description document for that invocation. Runtime state belongs to robot_state_publisher, controllers, drivers, simulators, and application nodes.

Source and product are different artifacts

The official xacro repository describes xacro as an XML macro language that expands macros into larger XML expressions. The source may contain a compact wheel macro, a property for width, an include, and a conditional sensor block. The expanded output contains explicit link, joint, geometry, and numeric attributes.

Review both artifacts. The xacro source shows intent and reuse. The expanded URDF shows what downstream consumers actually receive. A macro can be elegant while generating duplicate names, incorrect numbers, invalid XML, or different geometry under one argument combination.

Store the exact expansion command, arguments, xacro version, included-file revisions, and output hash. Without those inputs, a checked-in top-level file may not identify the model that ran.

Arguments select a startup variant

Arguments are useful for choosing a robot model, prefix, sensor package, simulation block, or hardware option. A conditional can include a lidar when use_lidar is true and omit it otherwise. This creates two possible expanded descriptions.

It does not create a runtime switch. Turning a physical lidar on after startup does not cause the already-expanded URDF to grow a new link. If the graph needs a new model, the system must define how to regenerate, validate, distribute, and activate it. Many systems instead use a stable kinematic description and manage device availability separately.

Treat each supported argument set as a release variant. Give it an explicit name and generate it in continuous integration. Avoid an unbounded collection of undocumented combinations that no one tests.

Macros reduce repetition, not responsibility

A wheel macro can generate left and right assemblies with a reflection parameter. That saves text, but one sign error can be repeated twice. A generic inertial macro can standardize fields, but a placeholder inertia becomes more dangerous when reused across every link.

Design macro parameters around meaningful concepts. Separate names, geometry, mass properties, and optional blocks. Provide defaults only when a default is physically valid. Reject missing calibration or inertia data rather than silently filling production models with convenient values.

Make names deterministic and unique. Prefixes should propagate consistently through links, joints, frames, transmissions, and plugin references. Expand two instances in one document during testing to expose collisions that a single instance cannot reveal.

Includes create a dependency graph

An include brings other source files into the expansion. The generated result therefore depends on more than the top-level file. A change in a shared macro can alter many robots without changing their entry points.

Pin and record dependency revisions. Detect recursive or unintended includes. Make path resolution reproducible in the build and installed environments. A file that expands only from a developer's source tree is not a portable release artifact.

Error locations can also cross file boundaries. When expansion fails, capture the include stack and examine the referenced source as well as the top-level invocation. After a successful expansion, validate the final XML and URDF semantics separately; well-formed macro source does not guarantee a valid robot tree.

Expressions need unit discipline

Xacro expressions can calculate lengths, angles, and inertia values. The evaluator cannot know whether a number represents meters, millimeters, radians, degrees, kilograms, or a dimensionless ratio. Encode units in property names or convert explicitly at a documented boundary.

Add numeric guards for positive dimensions, nonzero mass, finite values, and valid ranges. Test representative and edge argument values. A division by a tiny dimension or a negative mesh scale can produce output that is syntactically valid and physically unusable.

Do not hide unexplained constants inside macro bodies. Give important dimensions a named source and preserve their provenance. Derived values should be independently checked for at least one reference configuration.

Build an expansion matrix

List every supported variant and its arguments. For each one, run the same xacro implementation used in release, save the expanded URDF, and compute a hash. Fail on warnings that indicate deprecated syntax, missing files, duplicate names, or unresolved substitutions.

Parse the output with the target URDF parser. Check for one connected tree where required, valid parent and child references, finite inertial and geometric values, sensible joint limits, unique names, and expected optional components. Compare counts of links, joints, sensors, and transmissions with a variant-specific expectation.

Then test kinematics and frames. Load fixed joint values, publish representative joint states, and compare selected transforms with independent calculations. Render visual and collision geometry, but do not use appearance as the only acceptance criterion.

Use golden-output comparisons carefully. A textual diff catches surprising changes, while a semantic comparison can ignore harmless formatting and attribute ordering. Require human review when geometry, inertia, limits, frames, or hardware interfaces change.

Separate runtime tests

Once the description is loaded, test the nodes that consume it. Verify robot_state_publisher receives the intended output, controller configuration references existing joints, and simulator or driver plugins resolve expected names. These are runtime integration checks, not xacro expansion checks.

If the system intentionally regenerates descriptions at runtime, specify an atomic transition. Prevent readers from seeing a half-updated parameter set. Define whether old joint states remain valid, how frame authority changes, and how rollback works. Dynamic reconfiguration requires architecture beyond a conditional in source XML.

State the evidence accurately

A defensible report says that a named xacro version expanded a pinned dependency set with specified arguments, producing an output hash that passed XML, URDF, kinematic, and variant checks. It then separately reports runtime consumer tests.

Do not say that a macro responds to live robot state. Xacro generates description text. Keeping expansion and runtime state separate makes robot variants reproducible, reviews meaningful, and failures much easier to locate.