> For the complete documentation index, see [llms.txt](https://campus-rover.gitbook.io/lab-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://campus-rover.gitbook.io/lab-notebook/fiiva/using-conditionals-in-roslaunch.md).

# using-conditionals-in-roslaunch.md

## Author: Lisandro Mayancela

This tutorial assumes the reader knows how to use/access args and parameters in a launch file.

When making launch files you may sometimes want aspects of your launch (Such as the urdf file that is used) to be dependent on certain conditions

![All of these robots use the same launch file but the urdf file that is loaded is different based on robot team and type](https://i.ibb.co/ZSYpkLf/630de797bf9efc23a45847f3cc37a1fc.png)

In order to have this functionality you can use the group tag with an if parameter like so:

```
<group if="condition goes here">
    If statement body
</group>
```

## Examples

For a better example let's look at a launch file which spawns a robot into a gazebo world:

```
<launch>
    <arg name="robot_name"/>
    <arg name="init_pose"/>
    <arg name="team"/>
    <arg name="type"/>

    <group if="$(eval team == 'Red')">
        <group if="$(eval type == 'painter')">
            <param name="robot_description" 
                command="$(find xacro)/xacro.py $(find robopaint)/urdf/red/painterbot_red_burger.urdf.xacro" />
        </group>
        <group if="$(eval type == 'attacker')">
            <param name="robot_description" 
                command="$(find xacro)/xacro.py $(find robopaint)/urdf/red/attackerbot_red_burger.urdf.xacro" />
        </group>
    </group>

    <group if="$(eval team == 'Blue')">
        <group if="$(eval type == 'painter')">
            <param name="robot_description" 
                command="$(find xacro)/xacro.py $(find robopaint)/urdf/blue/painterbot_blue_burger.urdf.xacro" />
        </group>
        <group if="$(eval type == 'attacker')">
            <param name="robot_description" 
                command="$(find xacro)/xacro.py $(find robopaint)/urdf/blue/attackerbot_blue_burger.urdf.xacro" />
        </group>
    </group>

    node name="spawn_minibot_model" pkg="gazebo_ros" type="spawn_model"
     args="$(arg init_pose) -urdf -param robot_description -model $(arg robot_name)"
     respawn="false" output="screen" />

    <node pkg="robot_state_publisher" type="robot_state_publisher" 
          name="robot_state_publisher" output="screen"/>
</launch>
```

In lines 7-27 we see a chain of these if statements which then end up deciding one out of four urdf files to load as the robot\_description which then gets passed into the spawn\_minibot\_model node.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://campus-rover.gitbook.io/lab-notebook/fiiva/using-conditionals-in-roslaunch.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
