# Customize the robot start-up

This tutorial uses the [module manager CLI](../../api_reference/cli/module_manager.md).

## Add your application to the Module Manager

You can add your own custom modules to the Module Manager. You have to register the new module in the `CMakeLists.txt` of a ROS2 package. For example, if you have a package called `hello_world`, with a node called `hello_world_node`, you can add the following lines to the `CMakeLists.txt`:


```sh
find_package(pal_module_cmake QUIET)

if(pal_module_cmake_FOUND)
  pal_register_modules(module/hello_world.yaml)
endif()

```

The module file `hello_world.yaml` should be placed in the `module/` directory of the package. It would look like this:

```yaml
hello_world:
  run: "hello_world hello_world_node"
```

When the package containing this is [deployed](./tutorial_deploy_ros2.md) on the robot, **the module will be available after rebooting the robot**. To start it, do

```sh
pal module start hello_world
```

<!--
[Deploying ROS 2 packages on your robot](getting_started/ros2_packages.md). After a reboot of the robot, the module is available and can be started using the command:
-->

## Add to the start-up

To start the module at startup a **module set** has to be created. To do so, you have to register a new module set in the `CMakeLists.txt` of `hello_world` ROS2 package by adding:

```sh
find_package(pal_module_cmake QUIET)

if(pal_module_cmake_FOUND)
  pal_register_module_sets(module/custom_module_set.yaml)
endif()

```

The module set file `custom_module_set.yaml` should be placed in the `module/` directory of the package, and would look like this:

```yaml
custom_modules:
   - hello_world

```

When such a package would be deployed in the robot, it would run automatically at startup after a reboot of the robot.

<!--
Then, you can deploy the package to the robot as described in [Deploying ROS 2 packages on your robot](getting_started/ros2_packages.md). After a reboot of the robot the module `hello_world` start automatically.
-->

## Customize a startup module

To customize an existing application in the startup sequence of the robot, you can create a new module that overwrites an existing module. First, retrieve the filename of the existing module:

```sh
pal module info foo_module
```

Say the filename is `00_foo_module.yaml`. Register a new module in the `CMakeLists.txt` of your ROS 2 package. The new module file should be placed in the `module/` directory, looking as follows

```yaml
foo_module:
  run: "foo_package different_node"
```

The Module Manager will sort all registered modules based on their filename in lexicographical order. This means to overwrite the existing module in `00_foo_module.yaml` we have to register the new module in a file with a name that comes after `00_foo_module.yaml`, for example `10_foo_module.yaml`.

!!! note
    The registered modules are sorted based on the filename in lexicographical order. Take this into account:
    
    - `00_foo_module.yaml` will be overwritten by `10_foo_module.yaml`.
    - To overwrite `bar_module.yaml`, the new module should be named `bar_module_01.yaml`.

If such a package is deployed, after a reboot the updated version of the `foo_module` would be the one started. Check this by doing:

<!--
Finally, deploy the package to the robot as described in [Deploying ROS 2 packages on your robot](getting_started/ros2_packages.md). After a reboot, the updated version of foo_module is used. Check it with:
-->

```sh
pal module info foo_module
```

## Disable a startup module

To disable or enable modules, use the Module Manager CLI:

- Disable modules:
```sh
pal module disable foo_module bar_module
```

- Enable modules:

```sh
pal module enable foo_module bar_module
```

After that, restart the startup sequence to apply changes:

```sh
pal module_manager restart
```
