Skip to content

on_status_change

Runs in the client Sends nothing to the robot

Set a function to call each time the robot's status arrives. The function receives a copy of the latest status, the dict latest_status() returns. The robot sends its status once when the client connects, then whenever it changes, checking 50 times a second, and at once after take_control(), release_control() and set_force_confirm(). Set the function before connect() to receive the first status too. A client has one such function: a new call replaces it, and None removes it.

Syntax

robot.on_status_change(fn)

Arguments

Name Type Default Description
fn Callable[[dict], None] required The function, called with the status dict. None removes it.

Returns

Nothing.

Examples

robot.on_status_change(lambda s: print(s.get("mode"), s.get("state")))
robot.enter_exec_mode(wait=True)

Further details

Note

The function runs on the client's callback thread, one call at a time, in the order the events arrived, so a command or a wait called from it works. Keep it short: the next events wait for it. If the function raises, the client prints the exception and goes on.

See also