Supervisor/Controller system

Supervisor

class supervisor.Supervisor(robot_pose, robot_info)[source]

The supervisor class oversees the control of a single robot. The supervisor does not move the robot directly. Instead, the supervisor selects a controller to do the work and uses the controller outputs to generate the robot inputs.

Parameters:
  • robot_pose (Pose) – The initial pose of the robot,
  • robot_info (Struct) – Info structure, the format defined by the robot’s get_info()

Any extension of pysimiam will require inheriting from this superclass. The important methods that have to be implemented to control a robot are estimate_pose(), process(), init_default_parameters() and get_ui_description().

The base class implements a state machine for switching between different controllers. See add_controller() for more information.

initial_pose
Type :Pose

The initial pose of the robot, as supplied to the constructor. This parameter can be used in the user implementation

pose_est
Type :Pose

The estimated pose of the robot. This variable is updated automatically in the beginning of the calculation cycle using estimate_pose()

parameters
Type :Struct

Current parameter structure of the supervisor. Updated in set_parameters()

current
Type :Controller

The current controller to be executed in execute(). The subclass can set this value in process() or in the constructor. In case the state machine is used, the current controller will be switched automatically.

states
Type :{Controller: [(condition()->bool,:class:~controller.Controller)]}

The transition table of the state machine. The keys of the dictionary are the state. The conditions are executed one after another until one returns True or the list is through. If one of the conditions evaluates to True, its corresponding controller is made current.

robot
Type :Struct

The robot information structure given by the robot.

robot_color
Type :int

The color of the robot in the view (useful for drawing).

add_controller(controller, *args)[source]

Add a transition table for a state with controller

The arguments are (function, controller) tuples. The functions cannot take any arguments. Each step, the functions are executed in the order they were supplied to this function. If a function evaluates to True, the current controller switches to the one specified with this function. The target controller is restarted using controller.Controller.restart().

The functions are guaranteed to be called after process(). Thus, robot should contain actual information about the robot.

create_controller(module_string, parameters)[source]

Create and return a controller instance for a given controller class.

Parameters:
  • module_string (string) – a string specifying a class in a module. See Module strings
  • parameters – a parameter structure to be passed to the controller constructor
draw_background(renderer)[source]

Draw anything in the view before anything else is drawn (except the grid)

Parameters:renderer (Renderer) – A renderer to draw with
draw_foreground(renderer)[source]

Draw anything in the view after everything else is drawn

Parameters:renderer (Renderer) – A renderer to draw with
estimate_pose()[source]

Updates the pose using odometry calculations.

Returns:The estimated robot pose
Return type:Pose

The result of the evaluation of this function will be used to set self.pose_est

Must be implemented in subclasses.

execute(robot_info, dt)[source]

Based on robot state and elapsed time, return the parameters for robot motion.

Parameters:
  • robot_info (Struct) – The state of the robot
  • dt (float) – The amount of time elapsed since the last call of execute.
Returns:

An object (normally a tuple) that will be passed to the robot’s set_inputs() method.

The default implementation proceeds as follows:

  1. Proccess the state information using process_state_info()
    1. Store robot information in robot
    2. Estimate the new robot pose with odometry and store it in pose_est
  2. Check if the controller has to be switched

  3. Get controller state from get_controller_state()

  4. Execute currently selected controller with the parameters from previous step

  5. Return unicycle model parameters as an output (velocity, omega)

get_controller_state()[source]

Get the parameters that the current controller needs for operation

Returns:A parameter structure in the format appropriate for the current controller.
Return type:Struct

The result of this function will be used to run the controller.

Must be implemented in subclasses

get_parameters()[source]

Get the parameter structure of the supervisor. A call to supervisor.set_parameters(supervisor.get_parameters()) should not change the supervisor’s state

Returns:A supervisor-specific parameter structure.
Return type:Struct
get_ui_description(params=None)[source]

Return a list describing the parameters available to the user.

Parameters:params (Struct) – An instance of the paramaters structure as returned from get_parameters. If not specified, this method should use parameters
Returns:A list describing the interface

The structure returned by this function is used in the interface to show a window where the user can adjust the supervisor parameters. When the user confirms the changed parameters, this structure is used to create the structure that will be passed to set_parameters().

The format of the returned object is as follows:

  • The object is a list of tuples. The order of tuples defines the order of fields.
  • The first part of a tuple (key) is either a string or a tuple. If it is a tuple, then the first value is the name of the parameter field, the second value is an UI label, and the third is an optional string identifier if the parameter structure has several fields, identical in structure. If the key is a string, it is used both as a label, capitalized, and as a field name.
  • The second part of a tuple (value) describes the contents of a UI element. It can be either a primitive type, such as an int, a bool or a float, in which case it describes one parameter, or a (string, list of strings) tuple, for multiple-choice parameters, or an object of type Parameter, that allows one to describe the interface more precisely. This value can also be a list, structured the same way the root list is structured, in which case this element contains a subwindow.

Must be implemented in subclasses.

init_default_parameters()[source]

Populate parameters with default values

Must be implemented in subclasses.

process_state_info(state)[source]

Evaluate the information about the robot and set state variables.

set_parameters(params)[source]

Update this supervisor parameters. The params will have the same structure as specified by get_ui_description()

Parameters:params (Struct) – An instance of the paramaters structure as can be returned from get_parameters().

Controller

class controller.Controller(params)[source]

The controller class defines a behavior for the supervisor class. Any implemention must inherit from this class and implement the Controller,execute() method to return a unicycle model output.

Parameters:params (Struct) – A structure containing the internal controller parameters, such as PID constants.
execute(state, dt)[source]

Given a state and elapsed time, calculate and return robot motion parameters

Parameters:
  • state (Struct) – Output from the supervisor process() method
  • dt (float) – Time elapsed since last call to execute()

To be implemented in subclasses.

restart()[source]

Reset the controller to the initial state.

set_parameters(params)[source]

Set the internal parameters of the controller.

Parameters:params (Struct) – A structure containing the internal controller parameters, such as PID constants.

To be implemented in subclasses,

Table Of Contents

Previous topic

Robots and the world

Next topic

Graphical Interface

This Page