Graphical State Space Programming (GSSP) Tutorials
Home -> GSSP Tutorials -> Section 3.4 Creating TCP Controllers

3.4 Creating TCP Controllers

TCP Controllers are programs that talk to a running GSSP program via TCP. A TCP controller can get the robot's state from the meta-controller, and send executable code to the meta-controller.

In order for a TCP controller to connect to a running GSSP program, a call to the startTCP function must be made in the code attached to a region or waypoint. startTCP accepts one argument, which specifies the port at which the TCP controller will connect.

Example

startTCP(9559)

Once a call to startTCP has been made, the GSSP program is ready to accept TCP connections on the specified port.

Once connected, the GSSP program will continuously send the robot's state to the TCP controller as a string that is returned by repr(state_dic). state_dic is the dictionary that is returned by the driver's getState function (See Section 3.2 Creating Robot Drivers for information on drivers). repr is a built-in python function that returns a string representation of a given data structure. The return value of repr can be passed directly into the eval function. See the python documentation for more information on repr and eval.

At the same time, the GSSP program will accept executable code from the TCP controller. Any valid python code and built-in GSSP functions are accepted. One caveat is that every line of python code must end with a \n (new line character). So, if you just want to send one line of code, it must also end with a new line character.

Any task thread started by the TCP controller will inherit the priority of the region or waypoint that called startTCP. For example, suppose that region A called startTCP(9559), and a TCP controller subsequently connects to the GSSP program on port 9559. If the TCP controller sends startWaypoint('w1') to the GSSP program, the task thread responsible for executing w1 will inherit the priority of region A.

Section 5.1 ROS Integration will provide a concrete example of using a TCP controller. Even if you do not use ROS, you are still encouraged to look at this section as it ties together many elements of GSSP.