Tutorials

AI-generated illustration of a compact wheeled robot on a light grid map, with dark wall blocks, a teal traveled path, a remaining gold waypoint route, and a forward safety volume ahead of the robot. Simulation only.
Tutorial

How I built a Flutter operator for a simulated diff-drive robot with robot-side safety

A portfolio, simulation-only walkthrough of flutter-robot-operator: a Flutter mission operator for one simulated differential-drive robot, with a latched e-stop, a heartbeat deadman, and a protective stop enforced on the robot side. How to build it, run the tests, and what the GitHub Pages demo actually shows, including the honest gaps.

Arpan Bom8 min read
ShareXLinkedIn

This is a simulation only

This is a portfolio demo, not a real robot and not a certified safety system. The plant is a deterministic Dart simulation of one differential-drive robot on a static 10 m by 6 m grid map. There is no ROS, no lidar, no real emergency hardware, and no functional-safety claim. I built a Flutter operator that loads a waypoint mission, starts, pauses, resumes, and stops it, and a robot-side layer that owns the speed limits, a latched e-stop, a heartbeat deadman, and a protective stop. The UI only asks. I did not invent those safety ideas, and this is not a substitute for a real safety scanner or a certified controller.

Try the live demo

The fastest way to see it working is the browser demo: https://applycoding.github.io/flutter-robot-operator/

The page title is "Robot operator (simulation only)." After the Flutter app boots, the AppBar keeps that phrase and appends the mission and latch state, and an orange banner repeats "Simulation only. Not connected to a robot. Not a certified safety system." You get a map with the planned waypoints, the traveled path, and the robot pose; mission buttons; a latched E-stop; a "Simulate operator link loss" switch; and a short event log.

The GitHub Pages demo of flutter-robot-operator mid demo mission, with the simulation-only title and banner, the map, mission controls, E-stop, and event log. Simulation only.

Image: docs/demo.png from the repository, captured by the Playwright e2e test of the release web build. Simulation only. applycoding.com.

The Pages demo runs the in-process browser simulation, not the WebSocket server. The same Dart protocol and simulation still sit under that UI, but there is no robot_server process in the tab. The server path is covered by the real-socket tests in packages/robot_server/test/ws_integration_test.dart. If the browser tab is suspended, both the UI heartbeat timer and the physics timers pause, so deadman timing is only meaningful while the tab is active.

What the project is

flutter-robot-operator (repo: applycoding/flutter-robot-operator, commit 34836d9) is a Flutter operator for one simulated diff-drive robot. It is mission-level, not velocity teleop: there is no velocity-command message. That is the difference from teleop-console-demo. The stack is:

Layer Role
packages/robot_sim Pure Dart plant, map, mission state machine, and safety layer. No pub dependencies.
packages/robot_protocol Pure Dart JSON codec, strict validation, and SessionGate sequence rules. No pub dependencies.
packages/robot_server A dart:io WebSocket server that owns one RobotSim and one SessionGate.
apps/operator_app Flutter UI. Default web transport is the in-process sim; desktop and Android can attach with --dart-define=ROBOT_WS=....

This is an original implementation, inspired by the projects credited in REFERENCES.md and NOTICE: a small JSON envelope over a WebSocket (rosbridge), a forward approach check (Nav2 Collision Monitor, documentation only), and operator-facing status next to a map (Open-RMF rmf-web). I did not copy those sources, and this repo does not use ROS or Nav2.

The simulation ticks at 20 Hz (dt is 0.05 s). Tests count ticks and do not read the wall clock. The standard limits are 0.6 m/s forward, 0.8 m/s^2 normal accel, 2.0 m/s^2 e-stop and protective-stop braking, and a 10-tick (0.5 s) heartbeat timeout. The robot is a 0.25 m disc. The demo mission is five waypoints ending at (9.2, 2.4), with a 0.15 m waypoint tolerance.

Safety rules on the robot side

E-stop latches immediately and pauses the mission. mission_resume does not clear the latch. Reset is accepted only when the robot is fully stopped, and it leaves the mission paused.

Deadman pauses a running mission when the heartbeat age exceeds 10 ticks. mission_resume before a new heartbeat is rejected; after a fresh heartbeat it is accepted.

Protective stop is a simple forward point check in the grid map, a stand-in for a safety scanner, not a certified sensor. With a test-only constructor that bypasses mission validation, a run straight at the first wall ends in fault / obstacle_ahead.

Build and run locally

CI pins Flutter 3.47.9 (Dart 3.13.7) and unpacks that SDK under $HOME/flutter. The workspace root has a test_api 0.7.15 dependency override. Format in CI is scoped to the project trees, not the whole checkout:

dart pub get
dart format --output=none --set-exit-if-changed packages apps tool
dart test packages/robot_protocol
dart test packages/robot_sim
dart test packages/robot_server

ci.yml formats packages apps tool instead of . because formatting the unpackaged Flutter SDK under $HOME/flutter would fail spuriously. That is recorded in DEVIATIONS.md. All project Dart sources under those three directories are still checked.

Start the WebSocket server, then the operator:

dart run packages/robot_server/bin/robot_server.dart --port 8765
cd apps/operator_app
flutter run -d chrome
flutter run --dart-define=ROBOT_WS=ws://127.0.0.1:8765

flutter run -d chrome uses the local in-process sim, which is also what GitHub Pages serves. The ROBOT_WS form talks to the server. A release web build for the Pages path is:

flutter build web --release --no-web-resources-cdn --base-href /flutter-robot-operator/

Results from the tests

On commit 34836d9, GitHub Actions run 42915917624 completed every job in ci.yml. The dart job reported 71 tests passed in robot_protocol, 19 in robot_sim, and 8 in robot_server, then a clean NOTICE check (12 entries). The flutter job reported 8 tests passed and Built build/web. The e2e job reported 1 Playwright test passed. The android job built app-debug.apk. The mutants job printed all mutants killed and then reran the unmodified Dart suites.

The committed golden demo-mission trace, which lines 1-700 match golden file checks tick by tick, first reaches succeeded at tick 540. At tick 700 the pose is 0.062 m from (9.2, 2.4), the minimum clearance over the run is 0.443 m, and the tests require 0 contact ticks (and clearance at least 0.35 m) on every tick. The same suite also requires running at tick 300 and succeeded with v == 0 at tick 700.

On that same CI run, tool/parity_compare.dart printed that the dart2js / Node trace matches the VM: first success tick 540, max pose difference 0.0 m, over 700 lines. If parity_js.txt is missing, the tool prints parity_js.txt missing (dart2js / Node trace required) and exits 1 rather than skipping.

E-stop tests require an immediate latch, bounded braking, rest by E+7, and at most 0.10 m of travel to E+7. PLAN.md records the measured prototype as rest at E+6 with 0.075 m travelled. Deadman tests require a trip at H+11 (still running at H+10) and v == 0 by H+23; PLAN.md records the measured rest tick as H+22. The protective-stop test records 0 contact ticks with the forward point check enabled, and more than 0 contact ticks when that check is disabled; PLAN.md records the disabled run as 30 contact ticks.

License and references

Apache-2.0. Copyright 2026 Arpan Bom. See LICENSE and NOTICE.

NOTICE lists the pinned dependencies with licenses, including Flutter 3.47.9, Dart 3.13.7, test_api 0.7.15 (the workspace override), web_socket_channel 3.0.3, and the Playwright 1.65.0 pin, and it points at REFERENCES.md for idea-only references and their licences. No third-party robot or safety source is vendored.

How this was verified

I ran the standard portfolio-tutorial checks against commit 34836d9b53ebe8b0a3fae1163a26c443a5864b48 on main.

  • The GitHub repo is not a fork. gh api repos/applycoding/flutter-robot-operator reports "fork": false.
  • Both commits on main have author and committer Arpan Bom (applycoding@gmail.com). git log --format=%B main has no Co-authored-by trailers. The only remote branch at this SHA is main.
  • A search of the tree found no third_party, vendor, or external directories, and no "ported from", "adapted from", or "copied from" markers in the authored source.
  • This is an original implementation, inspired by the rosbridge, Nav2 Collision Monitor, and Open-RMF rmf-web idea references credited above. I did not copy those sources.
  • At 34836d9, NOTICE names the direct pins with licenses, including the test_api 0.7.15 workspace override, and it points at REFERENCES.md for idea-only references. The repo license is Apache-2.0. The LICENSE file is byte-identical to the official Apache-2.0 text from apache.org.
  • Commands, paths, APIs, and the numbers in this tutorial were checked against the repo at 34836d9. The 71, 19, 8, and 8 test counts, the parity line with a 0.0 m max pose difference, the NOTICE check, the Playwright pass, the Android APK, and all mutants killed are from GitHub Actions run 42915917624 on that commit. Pages deploy 42916843562 on this SHA returned HTTP 200 for the live demo, whose title is "Robot operator (simulation only)." Both runs have actor and triggering_actor applycoding. There are no cursor[bot] workflow runs.
  • Independent verification rounds at this SHA: the six source mutants in tool/mutants.sh each fail their own test (M1 stale-seq e-stop exception, M2 e-stop braking at aMax, M3 deadman removed, M4 protective stop removed, M5 duplicate seq re-applied, M6 estop_reset while moving), and the mutants job requires that they are killed before the unmodified suites pass; dart2js versus VM parity over 700 ticks, with a hard fail if the dart2js trace is missing; the moving robot trajectory unchanged under malformed frames test, which drives the live SimStackHarness stack; the WebSocket integration tests in ws_integration_test.dart; and authorship as above.
  • This project is simulation only. It is not connected to a robot and is not a certified safety system.

Limits

This is simulation only. It is not a real robot and not a certified safety system. The Pages demo runs the in-process browser sim, not the WebSocket server; the server is covered by the real-socket tests. A suspended browser tab pauses both the heartbeat and the physics timers. The protective stop is a simple forward point check, a stand-in for a safety scanner. CI formats packages apps tool, not ., because the Flutter SDK is unpacked under $HOME/flutter, as recorded in DEVIATIONS.md. test_api 0.7.15 is a workspace override. The e-stop and deadman figures quoted from PLAN.md (rest at E+6 with 0.075 m travelled, rest at H+22, and 30 contact ticks with the protective check disabled) are the recorded prototype measurements; the automated tests assert the slightly wider bounds described above.