Skip to content

Simulator

Margarita Matson edited this page Jul 23, 2026 · 3 revisions

Marsy Simulator

The Marsy simulator is the recommended environment for testing rover control, autonomous missions, sonar-based navigation, mapping, and LLM-generated plans before running the same code on the physical rover.

Marsy uses its own simulator. It is part of the main repository and uses the same high-level motion, skills, behaviors, mission, and safety layers as the real rover.

The simulator is designed as a practical software-development environment. It is not intended to reproduce Martian terrain or rover physics with scientific accuracy.

image

What can be tested

The simulator supports:

  • manual rover control;
  • steering and in-place rotation;
  • mast movement and ultrasonic scanning;
  • obstacle avoidance;
  • cautious forward movement;
  • mission start and stop behavior;
  • Explore area;
  • SLAM-lite map generation;
  • AI Agent;
  • Groq-generated plans;
  • LLM replanning after recoverable failures;
  • live mission status and sonar telemetry;
  • generated-plan inspection;
  • latest-map viewing;
  • emergency stop and cleanup behavior.

Mission code can normally be moved from simulator mode to real-rover mode without changing the mission itself. The selected backend determines where the commands are sent.


Architecture

Dashboard or CLI mission
        ↓
Marsy mission / agent executor
        ↓
Skills and reusable behaviors
        ↓
Marsy core and safety checks
        ↓
marsy_backends.sim_backend
        ↓
Simulator HTTP API
        ↓
PyQt simulator window

For the AI Agent:

Natural-language goal
        ↓
Groq planner
        ↓
Validated JSON plan
        ↓
Agent executor
        ↓
Marsy skills
        ↓
Simulator backend

The LLM does not control motors directly. It may only select skills from the Marsy whitelist, and every plan is validated before execution.


Important files

marsy/
β”œβ”€β”€ scripts/
β”‚   └── run_simulator.sh        # starts simulator and dashboard together
β”œβ”€β”€ simulator/
β”‚   └── marsy_sim_ui.py         # PyQt simulator and simulator HTTP API
β”œβ”€β”€ marsy_backends/
β”‚   └── sim_backend.py          # simulator backend adapter
β”œβ”€β”€ marsy_web/
β”‚   └── server.py               # dashboard server and mission control
β”œβ”€β”€ behaviors/
β”‚   └── explore_area.py         # shared exploration behavior
β”œβ”€β”€ missions/
β”‚   β”œβ”€β”€ explore_area.py
β”‚   └── agent_mission.py
└── marsy_agent/                # planning, validation, execution, and cache

The simulator should be treated as a first-class Marsy development tool, not as an external demo.


Prerequisites

Use the Python environment prepared for Marsy. It must include PyQt6 and the project dependencies.

For example:

conda activate marsy

Check PyQt6:

python -c "import PyQt6; print('PyQt6 OK')"

To use the AI Agent with new Groq plans or replanning, the same environment must also include the Groq SDK:

python -m pip install groq

Detailed Groq setup is documented on the AI Agent Mission page.


Recommended launch

From the Marsy project root:

chmod +x scripts/run_simulator.sh
./scripts/run_simulator.sh

This is the recommended way to use the simulator.

The launcher automatically:

  1. selects the active Conda Python, the project .venv, or another available Python;
  2. loads the stored Groq key when available;
  3. starts the PyQt simulator;
  4. waits for the simulator API;
  5. starts the Marsy web dashboard in sim mode;
  6. opens the dashboard in the default browser;
  7. stops both processes when the simulator closes or Ctrl+C is pressed.

The default addresses are:

Simulator API: http://127.0.0.1:8523/
Dashboard:     http://127.0.0.1:8080/
Map viewer:    http://127.0.0.1:8080/maps

The terminal should show messages similar to:

Simulator ready: http://127.0.0.1:8523/state
Dashboard ready: http://127.0.0.1:8080/api/state

Marsy simulator is running.
Dashboard: http://127.0.0.1:8080/
Maps: http://127.0.0.1:8080/maps

Keep this terminal open while using the simulator.


Prevent automatic browser opening

MARSY_OPEN_BROWSER=0 ./scripts/run_simulator.sh

Then open the dashboard manually:

http://127.0.0.1:8080/

Select a specific Python interpreter

MARSY_PYTHON="/path/to/python" ./scripts/run_simulator.sh

This is useful when several Conda or virtual environments exist.


Simulator dashboard

The dashboard runs against marsy_backends.sim_backend, so its controls and missions operate on the simulated rover rather than GPIO hardware.

The dashboard provides:

  • manual movement controls;
  • speed and steering settings;
  • mast controls;
  • live simulated telemetry;
  • sonar scan values over the camera/HUD area;
  • current mode and mission status;
  • mission timer;
  • mission stop controls;
  • mission-specific parameters;
  • generated AI plan display;
  • latest-map access.

The simulator window and dashboard represent the same simulated rover state.


Manual control

Use the dashboard manual controls to verify that the simulator stack is working before starting an autonomous mission.

Check:

  • forward and reverse movement;
  • left and right steering;
  • in-place rotation;
  • wheel centering;
  • mast movement;
  • STOP;
  • emergency stop and reset behavior.

The dashboard safety layer remains active in simulator mode. Forward movement may be stopped if the simulated sonar reports an obstacle within the configured safety distance.


Running Explore area

Open:

Missions β†’ Explore area

The mission uses the shared exploration behavior from:

behaviors/explore_area.py

It can:

  • scan the simulated environment;
  • select a movement or turn action;
  • avoid nearby obstacles;
  • use cautious movement when some sonar readings are unknown;
  • continue a committed turn instead of oscillating between directions;
  • save a SLAM-lite occupancy map;
  • stop after the configured time or number of steps.

Typical controls include:

  • maximum steps;
  • run time;
  • step distance;
  • forward speed;
  • safe distance;
  • danger distance;
  • map resolution;
  • optional return-home behavior.

For cautious testing, a useful starting point is:

Step distance: 6 cm
Speed:         22

Start with a short duration and a small number of steps.

Detailed mission behavior is documented on the Explore Area Mission page.


Running AI Agent

Open:

Missions β†’ AI Agent

The AI Agent card contains:

  • a multiline Mission goal field;
  • a Groq model dropdown;
  • Maximum replans;
  • Generate a fresh plan;
  • mission start and stop controls;
  • the Generated plan panel;
  • an Open map button.

The currently available model choices are:

GPT-OSS 20B β€” fast
GPT-OSS 120B β€” stronger

openai/gpt-oss-20b is the recommended default for most simulator tests.


Example AI Agent goal

Look around, choose the clearest direction, make one cautious 6 cm step,
scan again, choose the clearest direction again, make one more cautious
6 cm step, wait for 2 seconds, and stop. If a path is blocked, try another
direction.

For a new goal, enable:

Generate a fresh plan

For repeated tests with exactly the same goal and model, the cached plan can be reused.


Generated plan panel

After planning, the dashboard displays:

  • plan source: Groq, cache, or Groq replan;
  • selected model;
  • plan revision;
  • number of steps;
  • skill names;
  • skill arguments;
  • the currently executing step;
  • the full raw JSON plan.

If replanning occurs, the panel updates to show the replacement remaining plan.

A typical plan may contain:

turn_to_clear_direction
move_forward
scan_arc
wait
explore_for
stop

The plan is validated locally before any movement begins.


Groq key

New plans and replanning require:

GROQ_API_KEY

The launcher automatically loads the key from:

~/.config/marsy/groq.env

The file should contain:

export GROQ_API_KEY="YOUR_GROQ_API_KEY"

Protect it with:

chmod 600 ~/.config/marsy/groq.env

A different key file can be selected with:

MARSY_GROQ_ENV="/path/to/groq.env" ./scripts/run_simulator.sh

A matching cached initial plan may run without a new Groq request, but replanning still requires the key.


Maps

Explore area and AI Agent plans that use explore_for can generate a SLAM-lite occupancy map.

Open the viewer from the mission card or directly:

http://127.0.0.1:8080/maps

The current map files are:

artifacts/maps/explore_area_latest.json
artifacts/maps/explore_area_latest.svg

Marsy keeps the latest map rather than creating a permanent pair for every run.

The map viewer can show:

  • the rover path;
  • visited cells;
  • free cells;
  • occupied cells;
  • map resolution;
  • mapping metadata.

A mission that only scans, turns, or makes isolated movement steps may not generate a map. Use Explore area or include explore_for in the AI Agent goal when map generation is required.


Plan cache and mission journal

The latest AI plan cache is stored in:

artifacts/agent_cache/agent_plan_latest.json

A cache hit requires the same:

  • normalized goal;
  • planner;
  • model;
  • planner prompt/schema fingerprint.

The latest AI mission journal is stored in:

artifacts/agent_runs/agent_mission_latest.json

It contains:

  • goal;
  • model;
  • plan source;
  • initial plan;
  • executed steps;
  • observations;
  • replans;
  • final result;
  • errors, when present.

Only the latest cache and latest mission journal are retained.


Logs

The unified launcher keeps only the latest simulator-stack logs:

artifacts/logs/simulator_latest.log
artifacts/logs/simulator_dashboard_latest.log

Follow the simulator log:

tail -f artifacts/logs/simulator_latest.log

Follow the dashboard log:

tail -f artifacts/logs/simulator_dashboard_latest.log

These files are useful when the browser only reports a generic mission error.


Stopping the simulator

Preferred methods:

  • close the PyQt simulator window; or
  • press Ctrl+C in the terminal running scripts/run_simulator.sh.

The launcher then stops both the dashboard and simulator processes.

The dashboard's Stop current mission button stops the active mission but leaves the simulator stack running.


Alternative two-terminal launch

The unified script is recommended, but the components can be started separately for debugging.

First terminal:

python simulator/marsy_sim_ui.py

Second terminal:

MARSY_MODE=sim python -m marsy_web.server \
  --host 127.0.0.1 \
  --port 8080 \
  --camera-rotation 0

Then open:

http://127.0.0.1:8080/

A CLI mission can also be run while the standalone simulator is active:

MARSY_MODE=sim python -m missions.explore_area

or:

MARSY_MODE=sim python -m missions.agent_mission \
  --goal "Look around, make one cautious step, and stop."

Do not start a dashboard mission and a standalone CLI mission at the same time. Both would attempt to control the same simulated rover.


Environment variables

Variable Default Purpose
MARSY_PYTHON auto-detected Python interpreter used by the launcher
MARSY_SIM_HOST 127.0.0.1 Simulator API host
MARSY_SIM_PORT 8523 Simulator API port
MARSY_WEB_HOST 127.0.0.1 Dashboard host
MARSY_WEB_PORT 8080 Dashboard port
MARSY_OPEN_BROWSER 1 Set to 0 to avoid opening a browser
MARSY_GROQ_ENV ~/.config/marsy/groq.env Groq environment file
MARSY_CAMERA_ROTATION 0 Dashboard camera rotation in simulator mode

Example with custom ports:

MARSY_SIM_PORT=8524 \
MARSY_WEB_PORT=8081 \
./scripts/run_simulator.sh

Recommended development workflow

  1. Activate the Marsy Python environment.
  2. Start ./scripts/run_simulator.sh.
  3. Verify manual movement and STOP.
  4. Run a short Explore area mission.
  5. Inspect sonar telemetry and the latest map.
  6. Run an AI Agent goal with one short movement.
  7. Inspect the generated plan before and during execution.
  8. Test a recoverable blocked condition and replanning.
  9. Stop the mission from the dashboard.
  10. Only after simulator behavior is understood, test the same mission on the physical rover at low speed.

Troubleshooting

PyQt6 is not available

Activate the correct Marsy environment:

conda activate marsy
./scripts/run_simulator.sh

Check the selected interpreter printed by the launcher.

A specific interpreter can be forced with:

MARSY_PYTHON="/path/to/python" ./scripts/run_simulator.sh

Port 8523 or 8080 is already in use

An earlier simulator or dashboard process may still be running.

Check:

ps aux | grep -E "marsy_sim_ui.py|marsy_web.server" | grep -v grep

Stop the matching processes:

pkill -f "simulator/marsy_sim_ui.py"
pkill -f "marsy_web.server"

Then restart:

./scripts/run_simulator.sh

Alternatively, use different ports.


Dashboard opens but does not control the simulator

Check that the simulator API is available:

http://127.0.0.1:8523/state

Inspect:

tail -n 80 artifacts/logs/simulator_latest.log
tail -n 80 artifacts/logs/simulator_dashboard_latest.log

Both components must use the same MARSY_SIM_HOST and MARSY_SIM_PORT.


AI Agent reports that the Groq key is missing

Load the key:

source ~/.config/marsy/groq.env

Check without printing it:

python -c "import os; print('Groq key loaded:', bool(os.getenv('GROQ_API_KEY')))"

Then restart the simulator stack.


The old AI plan is reused

Enable:

Generate a fresh plan

The new plan replaces:

artifacts/agent_cache/agent_plan_latest.json

The map is empty or unavailable

A map is generated by exploration behavior. Run Explore area, or use an AI Agent goal that includes exploration, for example:

Look around, choose the clearest direction, explore for 30 seconds, and stop.

Then reload:

http://127.0.0.1:8080/maps

Browser shows the old dashboard layout

Force-refresh the page:

macOS:   Cmd + Shift + R
Windows: Ctrl + F5

Simulator window closes but another process remains

Check:

ps aux | grep -E "marsy_sim_ui.py|marsy_web.server|missions" | grep -v grep

Stop only the matching Marsy processes:

pkill -f "simulator/marsy_sim_ui.py"
pkill -f "marsy_web.server"
pkill -f "python -m missions"

Use pkill -9 only when normal termination fails.

Clone this wiki locally