Graphical State Space Programming (GSSP) Tutorials
Home -> GSSP Tutorials -> Section 2.7 Customizing State-variable Sets

Section 2.7 Customizing State-variable Sets

Until now, we have been using the Generic Robot state-variable set. If you want to run a GSSP program on a real robot, you will need to create a customized state-variable set that is suitable for your robot.

It is important to know that GSSP programs are a layer of abstraction above the robot's API. Therefore, it is possible to write robot-independent GSSP programs that are runnable on multiple different robots, given that those different robots share some state-variables in common. Suppose that we have a flying robot, and a ground robot. Both robots have Position X, Positon Y, and Position Z as state variables. The difference is that for the flying robot, Position Z is a writable state-variable, whereas for the ground robot, Position Z is not a writable state-variable. In this case, it is possible to write a GSSP program that runs on both robots. The GSSP program can send requests to alter the Position X and Position Y of the robot. Such requests would work on both robots. On the other hand, if we create a GSSP program that writes to Position Z, then that program will only work on the flying robot. In order to run a GSSP program on a robot, you will have to write a robot-specific driver. We will cover this in Section 3.2 Creating Robot Drivers.

In the GSSP source code folder, there is a folder called config. Inside it there is a python module called Robots.py. Open this file. should see the following.

class Robots():
    
    # Each entry in stateVarSets is a set of state variables. You can customize
    # the state variables you work with in the GUI by modifying 'Generic Robot'
    # or by creating another entry in stateVarSets. You will get to choose the
    # set you want to use when you do File -> New

    stateVarSets = {    
              
       'Generic Robot': {
           'stateVars' :    {
                                'Position X':       {'unit':'m', 'writable': True, 'error':0.5},
                                'Position Y':       {'unit':'m', 'writable': True, 'error':0.5},
                                'Position Z':       {'unit':'m', 'writable': True, 'error':0.5},
                                'Battery Level':    {'unit':'%', 'writable': False},
                                'Velocity':         {'unit':'m/s', 'writable': True, 'error':0.1},
                                'Front Obstacle':   {'unit':'m', 'writable': False, 'description':'How far the robot is from an obstacle directly in front.'}
                            }
       },
       
       'Custom': {
           'stateVars' :    {
                                'Custom State-var 1':       {'unit':'m', 'writable': True, 'error':2},
                                'Custom State-var 2':       {'unit':'m', 'writable': False},
                                'Custom State-var 3':       {'unit':'m', 'writable': True, 'error':2},
                            }
       }
    }

The Robot class has an attribute called stateVarSets. This is a dictionary that contains all the state-variable sets that you see when you open the New Program dialogue. Simply modify this dictionary to create new state-variable sets. Use the existing state-variable sets as a guide. The properties of each state-variable was explained in Section 2.3 Customizing Region Behavior.