The Robot Module

class crh_botnet.Robot
network

An instance of RobotNetwork.

id

The robot’s ID. int. It is None until run() is called.

run(namespace: dict, id: int = None, looping_interval: float = 0.05, ignore_exceptions=False, offline=False, debug=False)

Runs the main event loop. This function must be called only once. It should be placed on the last line of the robot’s script because this function does not return.

Parameters
  • namespace (dict) – The global namespace (technically, the namespace that contains setup() and loop()) the robot program. This is what makes all the magic happen. If you have no idea what it is, use globals().

  • id – The robot’s ID. If the program is running on an robotics lab’s Raspberry Pi, it is automatically calculated. This is not necessary if the robot is operating under offline mode.

  • looping_interval (float) – Looping interval in seconds. Defaults to :code`0.05` (that is, the loop runs 20 times per second).

  • ignore_exceptions (bool) – Whether or not the robot should continue running if an exception occurs when the loop is running. Note that it does not mean the program will continue executing the next line, but will run the next iteration of the loop instead. Defaults to False. It is dangerous to enable and use only if you are confident that your program can recover from unhandled exceptions. Regardless of this value, KeyboardInterrupt (ctrl-c) will always shutdown the robot.

  • offline (bool) – Whether the robot should operate offline. That is, if offline is set to True, the robot will not attempt to connect to the network. You also don’t have to supply a robot ID if this is set to True.

  • debug (bool) – Whether to enable debugging mode or not, default to False. This will enable the verbose mode, good to enable if you ever wonder what’s going on inside the robot.

set_looping_interval(interval: float) → None

Set the looping interval.

Parameters

interval – float, looping interval in seconds.

Returns

None

shutdown(exit_code=0)

Shutdown the robot cleanly.

Parameters

exit_code (int) – Optional. Program exit code (if you don’t know what it is, leave it to the default value.)

Returns

None

emergency_shutdown(exit_code=1)

Shutdown the robot immediately. All pending tasks will be discarded.

Parameters

exit_code (int) – Optional. Program exit code (if you don’t know what it is, leave it to the default value.)

Returns

None