# Handle commands

> Receive navigation and door commands and confirm them.

REMI sends one command to one bot at a time. You accept it at once, and report its progress in the bot's state.

| Command | Does | Required |
| --- | --- | --- |
| `navigate_to` | Drive to `lat`, `lng`. | Yes |
| `cancel_navigation` | Stop the current navigation. | Yes |
| `set_door` | Open or close the cargo door. | No |

All fields: [BotCommand](https://docs.remi.robot.com/fleets/partner-api#type-BotCommand).

## Accept, then report

1. REMI calls [`POST /bots/{bot_id}/commands`](https://docs.remi.robot.com/fleets/partner-api#createBotCommand) (or publishes it over MQTT).
2. Answer `202` with a [CommandStatus](https://docs.remi.robot.com/fleets/partner-api#type-CommandStatus) in state `accepted`, as soon as it is queued. Do not wait for the bot.
3. Report its progress in `current_command` of the bot's state: `executing`, then `succeeded` or `failed`.

```steps
accepted: Queued
executing: In progress
succeeded: Done
```

## Rules

- **Idempotent on `(bot_id, id)`.** An unconfirmed command is sent again with the same `id` every 10 seconds, 3 times in total. Answer a repeat exactly as the first one.
- **Only `202` with a valid body counts.** Any other `2xx`, or a bad body, is treated as not received.
- **Reject with a reason.** Answer `404 BOT_NOT_FOUND`, `409 BOT_BUSY`, `409 COMMAND_EXPIRED`, `422 UNSUPPORTED_COMMAND` or `422 DESTINATION_UNREACHABLE`, or report `state: rejected`. A rejection is final.
- **A failed navigation is retried.** After `failed`, REMI sends `navigate_to` again under a new id (`<id>~1`, `<id>~2`), up to 5 times.
- **Interrupting.** If you declared `supports_command_interrupt: true`, a new `navigate_to` replaces the current one. Otherwise REMI sends `cancel_navigation` first and waits.
- **Doors.** `set_door` never goes to a bot with `has_door: false`, and `closed` never to one with `manual_close_door: true`.

## Moved destinations

If a destination is off your network, you may move it: report `corrected_position` and `correction_distance_m` while the command runs. REMI expects the bot to stop there. If you cannot reach it at all, reject with `DESTINATION_UNREACHABLE`.
