Connect perception to action without blocking control

Use a small state machine that expires observations and isolates slow inference.

Exercise brief·Intermediate·3 min read

Opening the Python editor…

Requirements and learning goals

Before you start

  • Structured intents
  • A simulated controller

You will be able to

  • Separate model and control loops
  • Handle stale observations
  • Make cancellation explicit

The browser exercise above works without extra setup. The project brief below assumes the listed prerequisites and gives you a task and checks to perform. Need a guided first project?

Perception estimates what is around the robot; control decides how it moves. A state machine records which stage the task is in and which transitions are allowed. Separating these jobs lets a slow model finish without blocking stop requests. Here you will test the decision rules for waiting, approaching, and stopping.

Use separate app services for and control, then pause simulated sensors to verify that the controller stops on stale input.

Separate the rates

Camera inference may take hundreds of milliseconds while a controller needs frequent updates. Keep inference outside the motor loop. The controller reads the latest accepted observation and decides whether it is fresh enough for the current action.

The Sassy ROSMASTER demo keeps visual and language inference outside its motion loop. braking has independent freshness checks.

Try a state transition

def next_state(request, fresh_target, route_clear, arrived):
    if request == "stop":
        return "stopped"
    if not fresh_target:
        return "waiting_for_observation"
    if not route_clear:
        return "blocked"
    if arrived:
        return "complete"
    return "approaching"
 
assert next_state("approach", False, True, False) == "waiting_for_observation"
assert next_state("stop", True, True, False) == "stopped"

This is decision logic, not a motor controller. Define the output of every state. Waiting, blocked, and stopped should request the appropriate robot-specific stop behavior. Completion requires measured arrival, not merely sending a goal.

Rendering diagram…
The rules in next_state, checked in this order. A stop request wins over everything else.
Checkpoint 1 of 2

A detection was captured at 4.2 seconds. The controller runs at 5.0 seconds with a maximum observation age of 0.5 seconds. The object was detected and no stop was requested. What should the controller do?

Commit to an answer. Every choice explains itself.

Test interruptions

In simulation, delay inference, remove the target, invalidate the route, and send stop during an approach. Log state transitions with the observation ID and reason. A late response from an earlier request must not reactivate a canceled action. Use request IDs or cancellation tokens to reject it.

Common snag: refreshing an old frame's timestamp when inference finishes. Preserve capture time and record completion time separately.

Checkpoint 2 of 2

The user requests an approach, then sends stop while inference is still running. That inference then returns a fresh target with a clear route. What should happen?

Commit to an answer. Every choice explains itself.

Finish with a transition log showing that slow perception does not prevent stopping. Optional extension: add a timeout and a bounded recovery action, such as requesting a new observation, while keeping the physical controller responsible for its own limits.

Can you do each of these?

  • Separate model and control loops
  • Handle stale observations
  • Make cancellation explicit

0 of 2 checkpoints solved. Try checkpoint 1

Previous: Ground a request in supported robot skills
All lessons in this topic
  1. 1. Run a VLM on a live camera
  2. 2. Understand vision-language-action models
  3. 3. Inspect a VLA action chunk
  4. 4. Ground a request in supported robot skills
  5. 5. Connect perception to action without blocking control
  6. 6. Record the evidence around a failed action
  7. 7. Compare a learned approach with a scripted baseline

Ask Wendy

Answers about Wendy and WendyOS

What would you like to know?

Ask about devices, development, and deployment.

Check linked docs for technical details.