Skip to content

Manual Drive

Margarita Matson edited this page Jul 8, 2026 · 1 revision

Mission: Manual Drive

This page documents the Marsy manual drive mission.

Run in simulator mode with:

MARSY_MODE=sim python -m missions.manual_drive

Manual drive lets you control Marsy directly from the keyboard while still using the shared Marsy backend, motion, sensor, safety, and telemetry layers.

The same mission can run either in the simulator or on the real rover.

What Manual Drive Does

Manual drive is an interactive mission for direct rover control.

It supports:

  • forward and reverse movement;
  • left and right steering;
  • stop and brake;
  • mast movement;
  • ultrasonic distance readout;
  • speed changes;
  • emergency stop and reset;
  • background safety monitoring;
  • simulator UI stop handling.

Manual drive is useful for:

  • checking that the backend is working;
  • testing the simulator UI;
  • testing real rover motors and steering;
  • checking mast direction;
  • checking ultrasonic distance readings;
  • testing safety behavior before autonomous missions.

Project Files

Relevant files:

missions/manual_drive.py          # manual drive mission runner
marsy_core/motion.py              # high-level movement and mast calibration
marsy_core/sensors.py             # sensor access wrapper
marsy_core/safety.py              # speed, timeout, obstacle, and emergency safety logic
marsy_core/telemetry.py           # terminal and simulator telemetry logging
marsy_backends/loader.py          # selects simulator or real backend
marsy_backends/sim_backend.py     # simulator backend
marsy_backends/real_backend.py    # real rover backend

The mission is backend-neutral:

MARSY_MODE=sim   -> commands go to the Marsy simulator
MARSY_MODE=real  -> commands go to the real 4tronix rover hardware

Start the Simulator

First start the Marsy simulator UI from the project root:

python simulator/marsy_sim_ui.py

Keep this terminal open.

Then open a second terminal from the same project root and run:

MARSY_MODE=sim python -m missions.manual_drive

Basic Simulator Run

MARSY_MODE=sim python -m missions.manual_drive

The mission prints the keyboard controls when it starts.

Stop the mission with:

q

or:

Ctrl+C

The simulator UI stop button should also stop the manual drive mission cleanly.

Keyboard Controls

w / ↑      forward
z / ↓      reverse
a / ←      steer left
s / β†’      steer right
space      stop
b          brake
e          emergency stop
r          reset emergency stop
c          center wheels
j          mast left
l          mast right
k          mast center
d          read distance
, / <      speed down
. / >      speed up
h          help
q          quit

For debugging, prefer letter keys over arrow keys. Some macOS and VS Code terminals print arrow-key escape sequences such as ^[[A.

Command-Line Options

Manual drive supports these options.

Initial Speed

--speed 60

Initial driving speed.

Default:

60

Speed is clamped by the safety layer.

Maximum Speed

--max-speed 70

Maximum allowed speed.

Default:

70

This prevents accidental high-speed driving.

Steering Angle

--steer-angle 20

Wheel steering angle in degrees.

Default:

20

Mast Angle

--mast-angle 45

Mast movement angle in degrees for left/right commands.

Default:

45

Safe Distance

--safe-distance 30

Minimum safe front distance in centimetres.

Default:

30 cm

If Marsy is driving forward and the distance sensor reports an object closer than this threshold, the safety monitor stops the rover and blocks forward movement.

Reverse remains allowed so the rover can back away.

Maximum Drive Time

--max-drive-seconds 30

Maximum allowed continuous forward or reverse drive time.

Default:

30 seconds

This prevents the rover from continuing to drive forever if no new command is given.

Safety Monitor Interval

--monitor-interval 0.15

How often the background safety monitor checks sensors and timeout state.

Default:

0.15 seconds

Simulator UI Stop Poll Interval

--ui-stop-poll-interval 0.15

How often manual drive checks whether the simulator UI requested mission stop.

Default:

0.15 seconds

This matters because keyboard input normally waits for a key. The timeout-based polling lets the simulator UI stop button terminate the mission cleanly.

Example Simulator Commands

Basic Manual Drive

MARSY_MODE=sim python -m missions.manual_drive

Conservative Manual Drive

MARSY_MODE=sim python -m missions.manual_drive \
  --speed 35 \
  --max-speed 50 \
  --safe-distance 40

Test Obstacle Blocking

MARSY_MODE=sim MARSY_SIM_DISTANCE_CM=20 python -m missions.manual_drive

Expected behavior:

  • pressing w should be blocked;
  • the mission should report that an obstacle is too close;
  • pressing z should still allow reverse movement.

Test Clear Path

MARSY_MODE=sim MARSY_SIM_DISTANCE_CM=100 python -m missions.manual_drive

Expected behavior:

  • pressing w should drive forward;
  • pressing space should stop;
  • pressing d should show approximately 100 cm.

Test Distance Sequence

MARSY_MODE=sim MARSY_SIM_DISTANCE_SEQUENCE=100,80,60,40,25,20 python -m missions.manual_drive

Expected behavior:

  • forward movement is initially allowed;
  • when the simulated distance becomes smaller than safe_distance, the safety monitor stops the rover;
  • reverse remains allowed.

Safety Behavior

Manual drive includes a background safety monitor.

The safety monitor keeps running even while the keyboard loop is waiting for input.

This is important on the real rover: after pressing w, the terminal waits for the next key, but the rover may still be moving.

The monitor checks:

  • whether the rover has been driving too long;
  • whether emergency stop is active;
  • whether an obstacle is too close while driving forward.

If an obstacle is detected while driving forward:

  • motors stop;
  • forward movement is blocked;
  • reverse remains allowed;
  • the event is logged to terminal and simulator telemetry.

Emergency Stop

Press:

e

to activate emergency stop.

Emergency stop behavior:

  • motors stop;
  • movement commands are refused;
  • the rover remains blocked until reset.

Press:

r

to reset emergency stop.

After reset, manual control can continue.

Stop vs Brake vs Emergency Stop

Stop

space

Stops normal movement.

Use this for ordinary stopping.

Brake

b

Stops more aggressively and centers the wheels.

Use this when the rover should stop quickly.

Emergency Stop

e

Stops the rover and blocks future movement until reset.

Use this when behavior is unsafe or unexpected.

Mast Control

The mast is controlled with:

j    mast left
l    mast right
k    mast center

Marsy uses logical mast directions.

In marsy_core/motion.py:

logical mast angle < 0  -> sensor looks left
logical mast angle > 0  -> sensor looks right

The real rover mast may be physically reversed. Marsy hides this in the motion layer so mission code can use logical left/right commands.

The simulator normally uses non-reversed mast logic.

To force mast behavior:

MARSY_MAST_REVERSED=1 MARSY_MODE=real python -m missions.manual_drive

or:

MARSY_MAST_REVERSED=0 MARSY_MODE=sim python -m missions.manual_drive

What to Check in the Simulator UI

While manual drive is running, check that:

  • the mode is manual;
  • forward and reverse commands move the simulated rover;
  • steering commands update wheel direction;
  • mast commands update mast direction;
  • stop stops movement;
  • brake stops movement and centers wheels;
  • emergency stop blocks further movement;
  • reset emergency stop allows movement again;
  • the telemetry panel shows manual drive events;
  • the UI stop button ends the manual drive mission, not only the simulated motors.

Stopping Manual Drive

Preferred stop:

q

or:

Ctrl+C

Expected cleanup:

  • safety monitor stops;
  • motors stop;
  • wheels center;
  • mast centers;
  • backend cleanup runs.

If using the simulator UI, the top-level stop button should also stop the manual drive mission process cleanly.

If Manual Drive Does Not Stop

First try:

Ctrl+C

If the mission keeps running, find the process:

ps aux | grep -E "marsy_sim_ui.py|roversimulator.py|missions.manual_drive" | grep -v grep

Stop the manual drive mission:

pkill -f "python -m missions.manual_drive"

If needed, stop the simulator UI:

pkill -f marsy_sim_ui.py

Use force kill only if normal stop does not work:

pkill -9 -f "python -m missions.manual_drive"
pkill -9 -f marsy_sim_ui.py

Conservative Real-Rover Test

Use real mode only after simulator tests pass.

A conservative real-rover command is:

MARSY_MODE=real python -m missions.manual_drive \
  --speed 30 \
  --max-speed 45 \
  --safe-distance 45 \
  --max-drive-seconds 10

Before running on the real rover:

  • place the rover on the floor in a clear area;
  • keep your hand near the power switch;
  • keep fingers away from wheels and servos;
  • use fresh or charged AA batteries;
  • make sure the Raspberry Pi has stable power;
  • start at low speed;
  • test stop, brake, and emergency stop first.

Recommended Test Checklist

In simulator mode:

  1. Start the simulator UI.
  2. Run MARSY_MODE=sim python -m missions.manual_drive.
  3. Press h and check that help prints.
  4. Press w, then space.
  5. Press z, then space.
  6. Press a, s, and c.
  7. Press j, l, and k.
  8. Press d and check distance output.
  9. Press e, confirm movement is blocked.
  10. Press r, confirm movement works again.
  11. Press the simulator UI stop button and confirm the mission exits.
  12. Test MARSY_SIM_DISTANCE_CM=20 and confirm forward is blocked.

Only after this, test real mode with conservative speeds.

Notes

Manual drive is not just a raw keyboard script.

It is a proper Marsy mission using:

marsy_backends.loader.load_rover
MarsyMotion
MarsySensors
MarsySafety
marsy_core.telemetry.log

This makes it useful for validating the same architecture used by autonomous missions.

Clone this wiki locally