Graphical State Space Programming (GSSP) Tutorials
Home -> GSSP Tutorials -> Section 3.2 Creating Robot Drivers

3.2 Creating Robot Drivers

All robot drivers are located in the driver folder. Go into the driver folder and open Dummy.py. This is a robot driver created for educational and testing purposes. A robot driver needs to do the following.

  1. Retrieve the current state of the robot using the robot's API, translate that into something the meta-controller understands, and pass it to the meta-controller.
  2. Receive the desired state changes from the meta-controller, translate that into something the robot's API understands, and pass them to the robot to execute.

Each robot driver needs to have the following components.

  • A class called Driver
  • A function called getState
  • A function called changeState
  • A function called cleanup

You will find all of these in Dummy.py.

getState

The getState function should take no arguments. This is the function that the meta-controller calls to get the current state of the robot. This function must return a dictionary, where the keys are the names of the state-variables specified in the state-variable set you are using, and the values are the current values of these state-variables as detected by the robot's sensors. See Section 2.7 Customizing State-variable Sets for information on creating state-variable sets. Dummy.py is a robot driver that is compatible with the Generic Robot state-variable set. The getState function of Dummy.py doesn't really retrieve the current state from a robot - it simply makes something up. When you create your own robot driver, you will need to get the current state of your robot using your robot's API.

Note that getState does not need to ensure that the returning dictionary contains an entry for every state-variable. In Dummy.py, the getState function only returns values for Position X and Position Y. If a region has a constraint on a state-variable, and the returning dictionary does not have an entry for that state-variable, then the meta-controller will assume that the robot is outside this region.

changeState

The meta-controller calls the changeState function to send the desired state-changes to the robot. The changeState function accepts a dictionary as an argument, where the keys are the names of the state-variables as specified by the state-variable set and the values are the corresponding desired values. If there is no entry for a state-variable in this dictionary, then that means the meta-controller does not require a change in this state-variable. changeState is responsible for realizing the desired changes on the robot. The Dummy driver does not do anything with the argument it receives.

cleanup

The meta-controller calls this function when the GSSP program is terminated. You can use this function to carry out cleanup procedures, or just leave it empty.