Repository navigation
Manual Drive
This page documents the Marsy manual drive mission.
Run in simulator mode with:
MARSY_MODE=sim python -m missions.manual_driveManual 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.
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.
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
First start the Marsy simulator UI from the project root:
python simulator/marsy_sim_ui.pyKeep this terminal open.
Then open a second terminal from the same project root and run:
MARSY_MODE=sim python -m missions.manual_driveMARSY_MODE=sim python -m missions.manual_driveThe 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.
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.
Manual drive supports these options.
--speed 60Initial driving speed.
Default:
60
Speed is clamped by the safety layer.
--max-speed 70Maximum allowed speed.
Default:
70
This prevents accidental high-speed driving.
--steer-angle 20Wheel steering angle in degrees.
Default:
20
--mast-angle 45Mast movement angle in degrees for left/right commands.
Default:
45
--safe-distance 30Minimum 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.
--max-drive-seconds 30Maximum 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.
--monitor-interval 0.15How often the background safety monitor checks sensors and timeout state.
Default:
0.15 seconds
--ui-stop-poll-interval 0.15How 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.
MARSY_MODE=sim python -m missions.manual_driveMARSY_MODE=sim python -m missions.manual_drive \
--speed 35 \
--max-speed 50 \
--safe-distance 40MARSY_MODE=sim MARSY_SIM_DISTANCE_CM=20 python -m missions.manual_driveExpected behavior:
- pressing
wshould be blocked; - the mission should report that an obstacle is too close;
- pressing
zshould still allow reverse movement.
MARSY_MODE=sim MARSY_SIM_DISTANCE_CM=100 python -m missions.manual_driveExpected behavior:
- pressing
wshould drive forward; - pressing
spaceshould stop; - pressing
dshould show approximately100 cm.
MARSY_MODE=sim MARSY_SIM_DISTANCE_SEQUENCE=100,80,60,40,25,20 python -m missions.manual_driveExpected behavior:
- forward movement is initially allowed;
- when the simulated distance becomes smaller than
safe_distance, the safety monitor stops the rover; - reverse remains allowed.
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.
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.
space
Stops normal movement.
Use this for ordinary stopping.
b
Stops more aggressively and centers the wheels.
Use this when the rover should stop quickly.
e
Stops the rover and blocks future movement until reset.
Use this when behavior is unsafe or unexpected.
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_driveor:
MARSY_MAST_REVERSED=0 MARSY_MODE=sim python -m missions.manual_driveWhile 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.
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.
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 grepStop the manual drive mission:
pkill -f "python -m missions.manual_drive"If needed, stop the simulator UI:
pkill -f marsy_sim_ui.pyUse force kill only if normal stop does not work:
pkill -9 -f "python -m missions.manual_drive"
pkill -9 -f marsy_sim_ui.pyUse 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 10Before 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.
In simulator mode:
- Start the simulator UI.
- Run
MARSY_MODE=sim python -m missions.manual_drive. - Press
hand check that help prints. - Press
w, thenspace. - Press
z, thenspace. - Press
a,s, andc. - Press
j,l, andk. - Press
dand check distance output. - Press
e, confirm movement is blocked. - Press
r, confirm movement works again. - Press the simulator UI stop button and confirm the mission exits.
- Test
MARSY_SIM_DISTANCE_CM=20and confirm forward is blocked.
Only after this, test real mode with conservative speeds.
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.