4.5 Traffic Light Intersections
4.5.3 Communication Protocol
This sub-section describes the simulator main data structures responsible for handling the incomming and outgoing information. It also describes the protocol messages for the implemented communication features.
Traffic light intersections can be managed by independent applications. Using a specific communication protocol, through UDP sockets, an outside application can modify a traffic light plan of an intersection based on traffic flow information of the entering and exiting roads of the intersection. In the implemented prototype a traffic light management application may:
Specification and Implementation of an Artificial Transport System Prototype Development
67
register as the traffic light control manager, and receive the necessary intersection and traffic light topology information;
receive traffic light state information and timings; change the traffic light plan of an intersection;
receive information about the traffic flow of all road entering and road exiting of the intersection, as well as the traffic flow that is affected by each traffic light.
There are two main classes in the simulator responsible for outside applications message handling, the SimulationMessageHandler class and the CommunicationPortHandler class. The CommunicationPortHandler class contains the basic low level methods that allow communication through UDP sockets. The SimulationMessageHandler class is responsible for all outside communication (using the CommunicationPortHandler), for identifying message types (driver’s messages, traffic light messages, graphic interface messages, statistics messages and so on), and for using an appropriate class to construct or to interpret a specific message. In the current developed prototype only traffic light management can be made outside the simulation application. Every time the SimulationMessageHandler receives or sends a traffic light message it must use the class SemaphoreMessageHandler class that correctly interprets a received message or correctly constructs a message that must be sent to semaphore-based control application. This shows the modularity of this communication system. For example, in the future driver agents will also be controlling the simulation cars from outside applications. Only the DriverMessageHandler has to be implemented and no change must be done to the rest of the messages classes.
The communication protocol is basically represented by strings that are sent through UDP sockets. All the simulation messages that are received by the simulator must have a header separated by the pipe character (―|‖) that represents the type of the received command. Figure 4.15 illustrates the simulator messages format. Traffic Light messages are identified by a header equals to 0.
For traffic light messages the COMMAND_BODY also has a header that identifies the request action. For an intersection list request this header must be 0, whereas for a registration request this header must be 1 and for a traffic light plan change request this header should be
2.
There are three different requests for obtaining an unregister TLI list: Lists all unregistered traffic light intersections;
List a limited number of traffic light intersections;
List all traffic light intersections between two given intersections.
Figure 4.15 Simulation message string format
Specification and Implementation of an Artificial Transport System Prototype Development
68
The string format of the message for each of these different types of listing requests is illustrated in Figure 4.16.
There are two different types of responses that the simulator can make to list requests, which are illustrated in Figure 4.17.
To control and to receive traffic light information from a certain intersection, a TLMA must first register as the control manager of that same intersection. Only a registered application may manage a traffic light intersection, and there can be only one application per traffic light intersection. Figure 4.18 depicts the message format that a TLMA needs to send to the simulator so as to register itself as the controller of an intersection.
Figure 4.18 Register Traffic Light request format
Figure 4.17 Simulator unregister intersection list response format
Figure 4.16 Traffic Light unregister intersection list request protocol
Specification and Implementation of an Artificial Transport System Prototype Development
69
Again two types of responses may be received in answer to this type of request. The command failed message is similar to the one previously described by Figure 4.17. If the register request is successfully executed the simulator answers with all the necessary information for that intersection. The format of the response is described in Figure 4.19.
When the simulator accepts the TLMA registration it saves the TLMA IP address in the intersection object representation to be able to contact it and send it TLI information updates. The TLMA must activate a listener to a pre-defined port so it can receive the simulator updates. After a TLMA registers the control of an intersection it will periodically receive information updates. In the current prototype two types of information updates are sent from the simulator to the registered TLMA:
Traffic light states and time updates Intersection sensor information updates
The traffic light states and time updates are sent every time there is a state change in any of the traffic lights of the intersection. The intersection sensor information update basically gives enough information to calculate the traffic flow on entries or exits of intersections, as well as the percentage of traffic flow that each traffic light affects. Figure 4.20 illustrates the traffic light update message format.
Figure 4.19 Simulator Register Traffic Light Responses Format
Specification and Implementation of an Artificial Transport System Prototype Development
70
The intersection sensor information format is described in Figure 4.21. In the figure a description of ―traffic light fromNode‖ is mentioned, and should be understood as the direction that cars take from an intersection to the traffic light position in the registered intersection.