# Execute AIM 2024 (Automation Setup)

## Download the automation setup

Download the following package:

{% file src="https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-ce1124608c9c4d0f8e05d0603cd4f6f48e6fb071%2FAIM_2024_launcher.zip?alt=media" %}
sample obstacles
{% endfile %}

Extract this package at location: _**\~/cognipilot/cranium/**_. After extraction your directories should look like the following:

![](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-4c3c6f879f002eea1212457867510c1f329c6751%2Fscript_src_dir.png?alt=media)

![](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-ab5a5f2ed9f7db00e644b8c6af9fd4ed058038db%2Fscript_dir.png?alt=media)

## What does this launcher does?

This launcher will take care of the following steps to execute the AIM 2024 simulation setup:

* Preparation for clean build: deleting previous build's log, build and install folders
* Clean Build: colcon build
* Sourcing the setup.bash: source \~/cognipilot/cranium/install/setup.bash
* Updating the Raceway\_1.sdf world file to include the obstacles, before the build
* Launching the simulation: ros2 launch b3rb\_gz\_bringup sil.launch.py world:=Raceway\_1
* Auto firing of command: ros2 run b3rb\_ros\_line\_follower vectors
* Auto firing of command: ros2 run b3rb\_ros\_line\_follower detect
* Auto firing of command: ros2 run b3rb\_ros\_line\_follower runner

{% hint style="info" %}
This launcher will do all the pre-requiste manual work to run the buggy in the simulation by default i.e. user doesn't need to manually run above said commands.
{% endhint %}

{% hint style="info" %}
The launcher will automatically always clean build the setup before execution, i.e. all changes will be automatically included. No need to separately run build/update commands.
{% endhint %}

## Updating obstacles using the launcher in Raceway\_1.sdf file

To add/remove the obstacle and track models in simulation, using this launcher one doesn't need to manually update the **Raceway\_1.sdf** world file present at _**\~/cognipilot/cranium/src/dream\_world/worlds**_. To add obstacles using the launcher, one need to open and edit the _**models\_config.json**_ file present inside the launcher directory (_**\~/cognipilot/cranium/AIM\_2024\_launcher**_), in the following manner:

![](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-3a1733e415e0f6032c00bb27d30d6c04fab92fa4%2Fadd_obstacle_2.png?alt=media)

#### Explanation of code:

{% hint style="info" %}
Please make sure to save the file before running the launch command and follow proper JSON syntax in the file
{% endhint %}

```
"embed_model_1": {
	"pose": "0.2 -0.45 0.09 0 0 0",
	"type": "start_point"
}
```

* **"embed\_model\_1":** It is a custom unique identifier given to each entity which allows Gazebo to keep track of each model spawned into the simulation.

{% hint style="info" %}
Use unique string values for the _"embed\_model\_1"_ key for each obstacle to be added. As same value will not spawn the obstacles into simulation
{% endhint %}

* **"pose":** This parameter defines the position and orientation of models in simulation. rIt is represented by "x y z R P Y" where: **x is x-coordinate, y is y-coordinate, z is z-coordinate, R is roll, P is pitch and Y is yaw.**
* **"type":** This tag will contain name/type of the model to be spawned into the simulation. This represents the name of the desired model that has to be spawned and is stored either in _**\~/cognipilot/cranium/src/dream\_world/models**\*_ .

{% hint style="info" %}
Please make sure the name of the model passed to the _"type"_ parameter must be case sensitive as well as present in the mentioned folder.
{% endhint %}

{% hint style="info" %}
Please make sure to save the file before running the launch command and follow proper JSON syntax in the file
{% endhint %}

## Executing the launcher

To execute the launcher, open a new terminal in directory: _**\~/cognipilot/cranium/AIM\_2024\_launcher**_.

There are two modes of executing the launcher: start and stop

### Start mode

This mode will do the following steps in mentioned order: - Close the previous running simulation instance - Update the world file in dream\_worlds folder - Perform clean build of stack - Sourcing of bash file - Launch the simulation - Execute commands to make buggy move autonomously in simulation

{% hint style="info" %}
This will automatically include all the changes done by user in **b3rb\_ros\_line\_follower** module/folder.
{% endhint %}

To execute the launcher in start mode, run the following command on terminal:

```
$ python launch_sim.py start
```

On executing the above command you will get output similar to:

![](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-fd907d394c66810532cf34e33ad969c61ce025c3%2Fstart_1.png?alt=media)

![](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-1495b926d9e5f6a7aeda80ed1f848cc702c13bab%2Fstart_2.png?alt=media)

![](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-cf189d0858351968f849a0afd4399bd94403b32b%2Fsim_launch.png?alt=media)

### Stop mode

This mode will only close the running simulation instance

To execute the launcher in stop mode, run the following command on terminal:

```
$ python launch_sim.py stop
```

On executing the above command you will get output similar to below image and simulation instance will terminate, killing all background process needed by simulation to run and communication between ros2 and gazebo:

![](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-4108948a217b0496ea2ab06a6d51b766b630463e%2Fstop.png?alt=media)
