-
Notifications
You must be signed in to change notification settings - Fork 10
Improvements during debug session at Inria testbed #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,26 @@ | ||
| # DotBot Simulator Experiments | ||
| # DotBot Examples | ||
|
|
||
| This directory contains **experimental control scripts** for the DotBot simulator. | ||
| The goal is to prototype, test, and iterate on the testbed without needing to deploy anything, | ||
| with the same API that will run on a real testbed. **without touching the controller internals**. | ||
| This directory contains example scenarios for DotBots. | ||
| Examples can run against either real robots or the simulator, using the same controller APIs. | ||
| The simulator setup is documented as the default path because it is the most common way to reproduce experiments. | ||
| Each scenario has its own folder with dedicated instructions, initial states, and run commands. | ||
|
|
||
| All interaction with the simulator is done **via HTTP**, exactly like a real deployment. | ||
| ## Available scenarios | ||
|
|
||
| --- | ||
| - `minimum_naming_game/`: naming game examples (with and without motion) | ||
| - `work_and_charge/`: work/charge alternation scenario | ||
| - `charging_station/`: queue-and-charge scenario | ||
|
|
||
| ## 1. Start the simulator | ||
| We also provide a stop.py helper script to halt the simulator (without needing to stop robots via SwarmIT). | ||
|
|
||
| First, start the DotBot controller in **simulator mode** with the correct configuration: | ||
| ## Common usage pattern (default: simulator) | ||
|
|
||
| ```bash | ||
| dotbot-controller \ | ||
| --config-path config_sample.toml \ | ||
| -a dotbot-simulator | ||
| ``` | ||
|
|
||
| ## 2. Run the experiments | ||
|
|
||
| For example, if you want to run the charging station proof-of-concept | ||
| 1. Pick a scenario and read its local `README.md`. | ||
| 2. Set `simulator_init_state_path` in `config_sample.toml` as described by that scenario. | ||
| 3. Start the controller in simulator mode: | ||
|
|
||
| ```bash | ||
| python3 dotbot/examples/charging_station.py | ||
| python -m dotbot.controller_app --config-path config_sample.toml -a dotbot-simulator | ||
| ``` | ||
|
|
||
| 4. Run the selected example using its documented command. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Charging Station | ||
|
|
||
| This demo runs a charging-station scenario: | ||
| robots first form a queue, then move through charging and parking phases. | ||
| It works with real robots or with the simulator via the same controller API. | ||
| The simulator setup below is the default path for reproducibility. | ||
|
|
||
| ## How to run (default: simulator) | ||
|
|
||
| ### 1. Specify the initial state | ||
|
|
||
| Set `simulator_init_state_path` in `config_sample.toml` to: | ||
|
|
||
| ```toml | ||
| simulator_init_state_path = "dotbot/examples/charging_station/charging_station_init_state.toml" | ||
| ``` | ||
|
|
||
| ### 2. Start the controller in simulator mode | ||
|
|
||
| ```bash | ||
| python -m dotbot.controller_app --config-path config_sample.toml -a dotbot-simulator | ||
| ``` | ||
|
|
||
| ### 3. Run the charging-station scenario | ||
|
|
||
| From the `PyDotBot/` root in a new terminal: | ||
|
|
||
| ```bash | ||
| python -m dotbot.examples.charging_station.charging_station | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from dotbot.examples.charging_station.charging_station import DT as DT | ||
| from dotbot.examples.charging_station.charging_station import ( | ||
| PARK_SPACING as PARK_SPACING, | ||
| ) | ||
| from dotbot.examples.charging_station.charging_station import PARK_X as PARK_X | ||
| from dotbot.examples.charging_station.charging_station import PARK_Y as PARK_Y | ||
| from dotbot.examples.charging_station.charging_station import ( | ||
| QUEUE_HEAD_X as QUEUE_HEAD_X, | ||
| ) | ||
| from dotbot.examples.charging_station.charging_station import ( | ||
| QUEUE_HEAD_Y as QUEUE_HEAD_Y, | ||
| ) | ||
| from dotbot.examples.charging_station.charging_station import ( | ||
| QUEUE_SPACING as QUEUE_SPACING, | ||
| ) | ||
| from dotbot.examples.charging_station.charging_station import ( | ||
| charge_robots as charge_robots, | ||
| ) | ||
| from dotbot.examples.charging_station.charging_station import ( | ||
| queue_robots as queue_robots, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Shared helpers for DotBot examples.""" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import asyncio | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain the use case of this example?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes: when we run any of the examples in a real robot, then when (1) when we stop the example with ctrl+c or (2) the example script crashes, the robots just keep running like crazy. This stop commands make them stop, without having to call swamit stop (and then swarmit start again). Technically we could just use swarmit stop, but right now it takes like 5 seconds or more, which is annoying from a development experience PoV.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but could it be done in the example script directly? |
||
| import os | ||
|
|
||
| from dotbot.models import DotBotQueryModel, DotBotStatus, DotBotWaypoints, WSWaypoints | ||
| from dotbot.rest import rest_client | ||
| from dotbot.websocket import DotBotWsClient | ||
|
|
||
| """ | ||
| This example shows how to stop a dotbot swarm. Run it with: | ||
| python -m dotbot.examples.stop | ||
| """ | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| url = os.getenv("DOTBOT_CONTROLLER_URL", "localhost") | ||
| port = os.getenv("DOTBOT_CONTROLLER_PORT", "8000") | ||
| use_https = os.getenv("DOTBOT_CONTROLLER_USE_HTTPS", False) | ||
|
|
||
| async with rest_client(url, port, use_https) as client: | ||
| dotbots = await client.fetch_dotbots( | ||
| query=DotBotQueryModel(status=DotBotStatus.ACTIVE) | ||
| ) | ||
|
|
||
| ws = DotBotWsClient(url, port) | ||
| await ws.connect() | ||
| try: | ||
| for dotbot in dotbots: | ||
| await ws.send( | ||
| WSWaypoints( | ||
| cmd="waypoints", | ||
| address=dotbot.address, | ||
| application=dotbot.application, | ||
| data=DotBotWaypoints( | ||
| threshold=0, | ||
| waypoints=[], | ||
| ), | ||
| ) | ||
| ) | ||
| finally: | ||
| await ws.close() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about keeping this module empty and modify the import in the corresponding test module? I would find it more convenient as it's only a one liner, even if you have to do
import from dotbot.examples.charging_station.charging_station import ....