
Embedded Robotics (Thomas Braunl, 2 ed, 2006)
.pdf
Interrupts and Timer-Activated Tasks
general rule, ISRs should have a short duration and are required to clean up any stack changes they performed, in order not to interfere with the foreground task. Initialization of ISRs often requires assembly commands, since interrupt lines are directly linked to the CPU and are therefore machine-dependent (Figure 5.2).
data bus
Interrupt
CPU |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ext |
|
|
|
|
|
|
|
|
|
CS / enable
GND
Figure 5.2: Interrupt generation from external device
Somewhat more general are interrupts activated by software instead of external hardware. Most important among software interrupts are timer interrupts, which occur at regular time intervals.
In the RoBIOS operating system, we have implemented a general purpose 100Hz timing interrupt. User programs can attach or detach up to 16 timer interrupt ISRs at a rate between 100Hz (0.01s) and 4.7 10-8Hz (248.6 days), by specifying an integer frequency divider. This is achieved with the following operations:
TimerHandle |
OSAttachTimer(int scale, TimerFnc function); |
int |
OSDetachTimer(TimerHandle handle); |
The timing scale parameter (range 1..100) is used to divide the 100Hz timer and thereby specifies the number of timer calls per second (1 for 100Hz, 100 for 1Hz). Parameter TimerFct is simply the name of a function without parameters or return value (void).
An application program can now implement a background task, for example a PID motor controller (see Section 4.2), which will be executed several times per second. Although activation of an ISR is handled in the same way as preemptive multitasking (see Section 5.2), an ISR itself will not be preempted, but will keep processor control until it terminates. This is one of the reasons why an ISR should be rather short in time. It is also obvious that the execution time of an ISR (or the sum of all ISR execution times in the case of multiple ISRs) must not exceed the time interval between two timer interrupts, or regular activations will not be possible.
The example in Program 5.7 shows the timer routine and the corresponding main program. The main program initializes the timer interrupt to once every second. While the foreground task prints consecutive numbers to the screen, the background task generates an acoustic signal once every second.
81

5 Multitasking
Program 5.7: Timer-activated example
1 |
void timer() |
|
2 |
{ |
AUBeep(); /* background task */ |
3 |
} |
|
1int main()
2{ TimerHandle t; int i=0;
3t = OSAttachTimer(100, timer);
4/* foreground task: loop until key press */
5while (!KEYRead()) LCDPrintf("%d\n", i++);
6OSDetachTimer(t);
7return 0;
8}
5.6References
BRÄUNL, T. Parallel Programming - An Introduction, Prentice Hall, Englewood Cliffs NJ, 1993
BRINCH HANSEN, P. The Architecture of Concurrent Programs, Prentice Hall, Englewood Cliffs NJ, 1977
BRINCH HANSEN, P. (Ed.) Classic Operating Systems, Springer-Verlag, Berlin, 2001
DIJKSTRA, E. Communicating Sequential Processes, Technical Report EWD123, Technical University Eindhoven, 1965
HOARE, C.A.R. Communicating sequential processes, Communications of the ACM, vol. 17, no. 10, Oct. 1974, pp. 549-557 (9)
82
WIRELESS |
|
6 |
COMMUNICATION |
|
|
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
|
|
.. . . . . . . . |
|
There are a number of tasks where a self-configuring network based on wireless communication is helpful for a group of autonomous mobile robots or a single robot and a host computer:
1.To allow robots to communicate with each other
For example, sharing sensor data or cooperating on a common task or devising a shared plan.
2.To remote-control one or several robots
For example, giving low-level driving commands or specifying highlevel goals to be achieved.
3.To monitor robot sensor data
For example, displaying camera data from one or more robots or recording a robot's distance sensor data over time.
4.To run a robot with off-line processing
For example, combining the two previous points, each sensor data packet is sent to a host where all computation takes place, the resulting driving commands being relayed back to the robot.
5.To create a monitoring console for single or multiple robots
For example, monitoring each robot’s position, orientation, and status in a multi-robot scenario in a common environment. This will allow a postmortem analysis of a robot team’s performance and effectiveness for a particular task.
The network needs to be self-configuring. This means there will be no fixed or pre-determined master node. Each agent can take on the role of master. Each agent must be able to sense the presence of another agent and establish a communication link. New incoming agents must be detected and integrated in the network, while exiting agents will be deleted from it. A special error protocol is required because of the high error rate of mobile wireless data exchange. Further details of this project can be found in [Bräunl, Wilke 2001].
8383

6 Wireless Communication
6.1 Communication Model
In principle, a wireless network can be considered as a fully connected network, with every node able to access every other node in one hop, i.e. data is always transmitted directly without the need of a third party.
However, if we allowed every node to transmit data at any point in time, we would need some form of collision detection and recovery, similar to CSMA/ CD [Wang, Premvuti 94]. Since the number of collisions increases quadratically with the number of agents in the network, we decided to implement a time division network instead. Several agents can form a network using a TDMA (time division multiple access) protocol to utilize the available bandwidth. In TDMA networks, only one transceiver may transmit data at a time, which eliminates data loss from transmission collisions. So at no time may two transceiver modules send data at once. There are basically two techniques available to satisfy this condition (Figure 6.1):
Figure 6.1: Polling versus Virtual Token Ring
•Polling:
One agent (or a base station) is defined as the “master” node. In a round-robin fashion, the master talks to each of the agents subsequently to let it send one message, while each agent is listening to all messages and can filter out only those messages that apply to it.
•Virtual Token Ring:
A token (special data word) is sent from one agent to the next agent in a circular list. Whoever has the token may send its messages and then pass the token on to the next agent. Unlike before, any agent can become master, initiating the ring mechanism and also taking over in case a problem occurs (for example the loss of a token, see Section 6.3).
While both approaches are similar, the token approach has the advantage of less overhead and higher flexibility, yet has the same functionality and safety. Therefore, we chose the “Virtual Token Ring” approach.
84

Communication Model
1.The master has to create a list of all active robot nodes in the network by a polling process at initialization time. This list has also to be maintained during the operation of the network (see below) and has to be broadcast to all robots in the network (each robot has to know its successor for passing on the token).
2.The master has to monitor the data communication traffic with a timeout watchdog. If no data exchange happens during a fixed amount of time, the master has to assume that the token got lost (for example, the robot that happened to have the token was switched off), and create a new one.
3.If the token is lost several times in a row by the same agent (for example three times), the master decides that this agent is malfunctioning and takes it off the list of active nodes.
4.The master periodically checks for new agents that have become available (for example just switched on or recovered from an earlier malfunction) by sending a “wild card” message. The master will then update the list of active agents, so they will participate in the token ring network.
All agents (and base stations) are identified by a unique id-number, which is used to address an agent. A specific id-number is used for broadcasts, which follows exactly the same communication pattern. In the same way, subgroups of nodes can be implemented, so a group of agents receive a particular message.
The token is passed from one network node to another according to the set of rules that have been defined, allowing the node with the token to access the network medium. At initialization, a token is generated by the master station and passed around the network once to ensure that all stations are functioning correctly.
A node may only transmit data when it is in possession of the token. A node must pass the token after it has transmitted an allotted number of frames. The procedure is as follows:
1.A logical ring is established that links all nodes connected to the wireless network, and the master control station creates a single token.
2.The token is passed from node to node around the ring.
3.If a node that is waiting to send a frame receives the token, it first sends its frame and then passes the token on to the next node.
The major error recovery tool in the network layer is the timer in the master station. The timer monitors the network to ensure that the token is not lost. If the token is not passed across the network in a certain period of time, a new token is generated at the master station and the control loop is effectively reset.
We assume we have a network of about 10 mobile agents (robots), which should be physically close enough to be able to talk directly to each other without the need for an intermediate station. It is also possible to include a base station (for example PC or workstation) as one of the network nodes.
85

6 Wireless Communication
6.2 Messages
Messages are transmitted in a frame structure, comprising the data to be sent plus a number of fields that carry specific information.
Frame structure:
•Start byte
A specific bit pattern as the frame preamble.
•Message type
Distinction between user data, system data, etc. (see below).
•Destination ID
ID of the message’s receiver agent or ID of a subgroup of agents or broadcast to all agents.
•Source ID
ID of the sending agent.
•Next sender’s ID
ID of the next active agent in the token ring.
•Message length
Number of bytes contained in message (may be 0).
•Message contents
Actual message contents limited by message length (may be empty).
•Checksum
Cyclic redundancy checksum (CRC) over whole frame; automatic error handling for bad checksum.
So each frame contains the id-numbers of the transmitter, receiver, and the next-in-line transmitter, together with the data being sent. The message type is used for a number of organizational functions. We have to distinguish three major groups of messages, which are:
1.Messages exchanged at application program level.
2.Messages exchanged to enable remote control at system level (i.e. keypresses, printing to LCD, driving motors).
3.System messages in relation to the wireless network structure that require immediate interpretation.
Distinguishing between the first two message types is required because the network has to serve more than one task. Application programs should be able to freely send messages to any other agent (or group of agents). Also, the network should support remote control or just monitor the behavior of an agent by sending messages, transparent to the application program.
This requires the maintenance of two separate receive buffers, one for user messages and one for system messages, plus one send buffer for each agent. That way it can be guaranteed that both application purposes (remote control
86

Fault-Tolerant Self-Configuration
and data communication between agents) can be executed transparently at the same time.
Message types:
•USER
A message sent between agents.
•OS
A message sent from the operating system, for example transparently monitoring an agent’s behavior on a base station.
•TOKEN
No message contents are supplied, i.e. this is an empty message.
•WILD CARD
The current master node periodically sends a wild card message instead of enabling the next agent in the list for sending. Any new agent that wants to be included in the network structure has to wait for a wild card message.
•ADDNEW
This is the reply message to the “wild card” of a new agent trying to connect to the network. With this message the new agent tells the current master its id-number.
•SYNC
If the master has included a new agent in the list or excluded a nonresponding agent from the list, it generates an updated list of active agents and broadcasts it to all agents.
6.3Fault-Tolerant Self-Configuration
The token ring network is a symmetric network, so during normal operation there is no need for a master node. However, a master is required to generate the very first token and in case of a token loss due to a communication problem or an agent malfunction, a master is required to restart the token ring.
There is no need to have the master role fixed to any particular node; in fact the role of master can be assigned temporarily to any of the nodes, if one of the functions mentioned above has to be performed. Since there is no master node, the network has to self-configure at initialization time and whenever a problem arises.
When an agent is activated (i.e. a robot is being switched on), it knows only its own id-number, but not the total number of agents, nor the IDs of other agents, nor who the master is. Therefore, the first round of communication is performed only to find out the following:
•How many agents are communicating?
•What are their id-numbers?
•Who will be master to start the ring or to perform recovery?
87

6 Wireless Communication
|
|
|
|
|
|
|
|
D |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
R |
|
|
|
|
|
|
|
A |
|
|
|
|
|
|
|
C |
|
|
|
|
|
|
|
D |
|
|
|
|
|
|
|
IL |
|
|
|
|
|
|
|
|
W |
|
|
|
|
|
new agent
current master established network
Step1: Master broadcasts WILDCARD
|
|
|
|
|
|
|
|
|
W |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
E |
|
|
|
|
|
|
|
|
N |
|
|
|
|
|
|
|
|
D |
|
|
|
|
|
|
|
|
D |
|
|
|
|
|
|
|
|
|
A |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Step2: New agent replies with ADDNEW
|
|
|
|
|
|
|
C |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
N |
|
|
|
|
|
|
|
Y |
|
|
|
|
|
|
|
|
S |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Step3: Master updates network with SYNC broadcast
Figure 6.2: Adding a node to the network
Agent IDs are used to trigger the initial communication. When the wireless network initialization is called for an agent, it first listens to any messages currently being sent. If no messages are picked up within a certain time interval multiplied by the node’s own ID, the agent assumes it is the lowest ID and therefore becomes master.
The master will keep sending “wild card” messages at regular time intervals, allowing a new incoming robot to enter and participate in the ring. The master will receive the new agent's ID and assign it a position in the ring. All other agents will be notified about the change in total robot number and the new virtual ring neighborhood structure via a broadcast SYNC message (Figure 6.2). It is assumed that there is only a single new agent waiting at any time.
88

User Interface and Remote Control
Each agent has an internal timer process. If, for a certain time, no communication takes place, it is assumed that the token has been lost, for example due to a communication error, an agent malfunction, or simply because one agent has been switched off. In the first case, the message can be repeated, but in the second case (if the token is repeatedly lost by the same agent), that particular agent has to be taken out of the ring.
If the master node is still active, that agent recreates a token and monitors the next round for repeated token loss at the same node. If that is the case, the faulty agent will be decommissioned and a broadcast message will update all agents about the reduced total number and the change in the virtual ring neighborhood structure.
If there is no reply after a certain time period, each agent has to assume that it is the previous master itself which became faulty. In this case, the previous master’s successor in the virtual ring structure now takes over its role as master. However, if this process does not succeed after a certain time period, the network start-up process is repeated and a new master is negotiated.
For further reading on related projects in this area, refer to [Balch, Arkin 1995], [Fukuda, Sekiyama 1994], [MacLennan 1991] [Wang, Premvuti 1994], [Werner, Dyer 1990].
6.4 User Interface and Remote Control
As has been mentioned before, the wireless robot communication network EyeNet serves two purposes:
•message exchange between robots for application-specific purposes under user program control and
•monitoring and remote controlling one or several robots from a host workstation.
Both communication protocols are implemented as different message types using the same token ring structure, transparent to both the user program and the higher levels of the RoBIOS operating system itself.
In the following, we discuss the design and implementation of a multi-robot console that allows the monitoring of robot behavior, the robots’ sensor readings, internal states, as well as current position and orientation in a shared environment. Remote control of individual robots, groups of robots, or all robots is also possible by transmitting input button data, which is interpreted by each robot’s application program.
The optional host system is a workstation running Unix or Windows, accessing a serial port linked to a wireless module, identical to the ones on the robots. The workstation behaves logically exactly like one of the robots, which make up the other network nodes. That is, the workstation has a unique ID and also receives and sends tokens and messages. System messages from a robot to the host are transparent from the user program and update the robot display window and the robot environment window. All messages being sent in the
89

6 Wireless Communication
entire network are monitored by the host without the need to explicitly send them to the host. The EyeBot Master Control Panel has entries for all active robots.
The host only then actively sends a message if a user intervention occurs, for example by pressing an input button in one of the robot’s windows. This information will then be sent to the robot in question, once the token is passed to the host. The message is handled via low-level system routines on the robot, so for the upper levels of the operating system it cannot be distinguished whether the robot’s physical button has been pressed or whether it was a remote command from the host console. Implementation of the host system largely reuses communication routines from the EyeCon and only makes a few system-dependent changes where necessary.
Remote control One particular application program using the wireless libraries for the EyeCon and PC under Linux or Windows is the remote control program. A wireless network is established between a number of robots and a host PC, with the application “remote” being run on the PC and the “remote option” being activated on the robots (Hrd / Set / Rmt / On). The remote control can be operated via a serial cable (interface Serial1) or the wireless port (interface Serial2), provided that a wireless key has been entered on the EyeCon (<I> / Reg).
The remote control protocol runs as part of the wireless communication between all network nodes (robots and PC). However, as mentioned before, the network supports a number of different message types. So the remote control protocol can be run in addition to any inter-robot communication for any application. Switching remote control on or off will not affect the inter-robot communication.
Start screen |
Color image transmission |
Figure 6.3: Remote control windows
Remote control operates in two directions, which can be enabled independently of each other. All LCD output of a robot is sent to the host PC, where it is displayed in the same way on an EyeCon console window. In the other direction, it is possible to press a button via a mouse-click on the host PC, and this
90