Motion Command Flow

flowchart TD
  ui["MovementPanel"] -->|"robotRunMovement(id)"| bridge["robotBridge"]
  bridge -->|"robotRunMovement message"| webview["Native WebView<br/>onMessage"]
  webview -->|"type matches; id is a string"| controller["RobotController.runUserMovement"]

The MovementPanel callback in mogo-src/app/components/settings/MovementPanel.tsx returns when the connection state is not connected. At entry, RobotController.runUserMovement rejects an unknown movement ID, returns unless both the Bluetooth connection and controller phase are connected, and returns for a Classic ESP device when the selected path is not esp-anim.

[!NOTE] For this MovementPanel request, after its entry checks runUserMovement clears the queue, cancels active motion if present, then calls runMotion with supersede: true; this request does not enter the FIFO queue. Source-defined dispatch does not confirm physical movement; a connected-device check is needed to verify the hardware effect.

Queue and engine boundaries

Separately, RobotController.runMotion queues an intent when another motion is active and the incoming intent is neither superseding nor dropped by the busy-motion rules. CommandQueue is FIFO, with a maximum size of 32 in the controller. Enqueuing removes any older item with the same tag before appending the new one; if the queue exceeds its maximum, it removes the oldest items.

The queue worker avoids nested flushes and does not flush while a motion is active. While the controller phase is connected, it dequeues and dispatches items by kind and tag. After its execution block, runMotion requests a flush only when the motion mode is not stopped and both the controller phase and Bluetooth facade report connected. These queue behaviors are implemented in Mogo Robot/src/expo/robot/CommandQueue.ts and Mogo Robot/src/expo/robot/RobotController.ts.

The controller’s separate drive operation wraps its work in runMotion and delegates left power, right power, duration, and cancellation to DriveEngine.drive in Mogo Robot/src/expo/robot/DriveEngine.ts. This software delegation does not itself verify a hardware effect.