Embedded Motion Control 2011: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
Line 80: Line 80:
The earth computer can be started in the following steps.
The earth computer can be started in the following steps.
# Convince yourself from the fact that the camera is powered on and the camera receiver is connected to the pc.  
# Convince yourself from the fact that the camera is powered on and the camera receiver is connected to the pc.  
# Start the program ''GrandTec Walkguard'' from the start menu. If the camera is connected properly, the camera image appears. Since the color segmentation proces depends heavily on the settings of the camera, these parameters have to be set. In the program GrandTec Walkguard, go to the Tab: Video Set the following values:
# Start the program ''GrandTec Walkguard'' from the start menu. If the camera is connected properly, the camera image appears. Since the color segmentation proces depends heavily on the settings of the camera, these parameters have to be set. In the program GrandTec Walkguard, go to the Tab: <code>Video</code>. Set the following values:
::{|style="background:transparent"
#: Brightness: 149
#: Contrast:  174
#: Saturation:  191
#: Hue:  143 <br />
#:Note that these values are a guideline. Since the values depend on lighting conditions some can deviate from these values. It is possible that the setting of the camera parameters has to be repeated if the camera has been disconnected from the power-plug.
# In order to properly check the geometry of the lakes, the camera should have the right angle with respect to the underground (see Fig. 5.1). Adjust the angle of the camera according to this figure. Exit the program GrandTec Walkguard.
# Color calibration (not needed, or done by tutors).
# Start Matlab and go to the directory <code>D:\MC\vision</code>. Open the Simulink model file <code>communication_and_vision_with_viewers.mdl </code>. In order to guarantee best performance, the priority of Matlab can be increased. Press: <code>Ctrl+Alt+Del</code>, go to <code>Task Manager</code>, <code>processes</code>, right-click matlab.exe. Go to <code>Set Priority</code> and set <code>Real-time</code>. Note that several Simulink schemes are available. If problems occur which could be due to the vision processing: one could chose to run the program: <code>vision_with_viewer</code> to get
more info about the color-classification. Start the Simulink scheme.
 
== Communication ==
LegOS Network Protocol (LNP), which is included in the BrickOS Kernel, allows for communication between BrickOS powered robots and host computers. The communication is realized by the infrared ports. Therefore, first of all make sure that there are no obstacles between two communicating RCX bricks to prevent communication errors. For the purpose of this course there have been made adjustments and modifications in order to make the communication between RCX bricks and between RCX bricks and the host computer a lot easier.
 
A possible configuration of a communication setup is depicted in Fig. 5.4. It contains two RCX
bricks and one host computer equipped with the Lego USB Tower. Each client has its own iden-
tification number. The host computer is identified by ID = 0. The two RCX bricks are identified
by ID = 1 and ID = 2. In the main C-file this ID should be defined, for example
 
<code>#define ID 1</code>
 
for RCX brick one. Next, the C-file com.c should be included using
 
<code>#include "com.c".</code>
 
Make sure that you first define the ID before you include <code>com.c</code>. The C-file <code>com.c</code> is makes it possible to send and receive integers or arrays of integers. The main functions in this file are called <code>com_send</code> and <code>read_from_ir</code>. The source code of the C-file <code>com.c</code> can be found on the CD by choosing ''Source Code Communication''.
 
===com_send===
The main function to send integers is <code>com_send</code>.
 
'''Syntax'''
 
<code>int com_send(int IDs, int IDr, int message_type, int *message)</code>
 
'''Arguments'''
 
:{|style="background:transparent"
|-
|-
| Brightness: || 149
| <code>IDs</code>: || The ID of the sender
|-
|-
| Contrast: || 174
| <code>IDr</code>: || The ID of the receiver
|-
|-
| Saturation: || 191
| <code>message_type</code>: || The message type
|-
|-
| Hue: || 143
| <code>message</code>: || Pointer to an integer or an array of integers
|} Note that these values are a guideline. Since the values depend on lighting conditions some can deviate from these values. It is possible that the setting of the camera parameters has to be repeated if the camera has been disconnected from the power-plug.
|}
# In order to properly check the geometry of the lakes, the camera should have the right angle with respect to the underground (see Fig. 5.1). Adjust the angle of the camera according to this figure. Exit the program GrandTec Walkguard.
 
# Color calibration (not needed, or done by tutors).
'''Description'''
# Start Matlab and go to the directory <code>D:\MC\vision</code>. Open the Simulink model file <code>communication_and_vision_with_viewers.mdl </code>. In order to guarantee best performance, the priority of Matlab can be increased. Press: <code>Ctrl+Alt+Del</code>, go to <code>Task Manager</code>, <code>processes</code>, right-click matlab.exe. Go to <code>Set Priority</code> and set <code>Real-time</code>. Note that several Simulink schemes are available. If problems occur which could be due
to the vision processing: one could chose to run the program: <code>vision_with_viewer</code> to get
more info about the color-classification. Start the Simulink scheme.


Call com_send to send an integer from the sender with ID = IDs to the receiver with ID = IDr. The message that has been send has a message type. There are seven message types: 1 to 7. Each message type is coupled to a global variable:
*Message type 1: <code>TRIGGER1</code> (integer)
*Message type 2: <code>TRIGGER2</code> (integer)
*Message type 3: <code>TRIGGER3</code> (integer)
*Message type 4: <code>TRIGGER4</code> (integer)
*Message type 5: <code>TRIGGER5</code> (integer)
*Message type 6: <code>TEMPERATURE</code> (integer)
*Message type 7: <code>COORDINATES</code> (array of 6 integers)
These global variables can be read in all your functions, for example by calling <code>TRIGGER1</code>. Sending an integer with message type 1 will result in the adjustment of the global variable <code>TRIGGER1</code> at the receiver side.


'''Examples'''
<pre>
/* declare and initalize a */
int a = 1;
/* examples of sending messages */
com_send(1,0,7,&a);
com_send(2,0,7,&a);
com_send(1,2,1,&a);
com_send(2,1,1,&a);
</pre>
The communication in the example correspond with line 1,3, 5 and 6 respectively. A description of the communication lines is shown in Fig. 5.4. At communication line 1, the RCX with ID = 1 asks the coordinates from ”earth”. The coordinates are returned at communication line 2 and are stored in the variable <code>COORDINATES</code>. At communication line 3 RCX with ID = 2 asks the coordinates from ”earth”. The coordinates are returned at communication line 4 and are stored in the variable <code>COORDINATES</code>. The coordinates correspond to the pixel numbering of Fig. 5.2. To read the coordinates simple call <code>COORDINATES[0]</code> for the first coordinate, which is the i-coordinate of the lake that is most nearby. An i-coordinates of 0 means that the center of this lake is seen at the top of screen of the camera. An i-coordinate of 240 means that the center of this lake is seen at the bottom of the screen of the camera. <code>COORDINATES[1]</code> is the j-coordinate of the lake that is most nearby. An j-coordinate of 0 means that the center of this lake is seen at outer left side of the screen of the camera. An j-coordinate of 320 means that the lake is seen at the outer right side of the screen of camera. So the screen can be compared with a matrix with a size of 240 × 320. The element (0,0) is the upper left element of the screen / matrix. The element (240,320) is the bottom right element. A lake is found when the following relations are satisfies 0 < i-coordinate < 240 and 0 < j-coordinate < 320. <code>COORDINATES[2]</code> and <code>COORDINATES[3]</code> represent the i- and j-coordinates of the second lake. Finally <code>COORDINATES[4]</code> and <code>COORDINATES[5]</code> represent the i- and j-coordinates of the lake that is located most far away. At communication line 5, the RCX with ID = 1 sends <code>TRIGGER1=1</code> to RCX with ID = 2. The opposite is the case at communication line 6.


== Communication ==


===com_send===
===read_from_ir===
===read_from_ir===
To use the function <code>read_from_ir</code>, a thread (see [1, page 169]) should be started. The task of this
thread is to constantly detect whether or not a message is received at the infrared port. If a message
is received, the variables <code>TRIGGER1, TRIGGER2, TRIGGER3, TRIGGER4, TRIGGER5, TEMPERATURE</code>
and <code>COORDINATES</code> are adjusted depending on the message type. To start the thread, first define
the thread identification like
<pre>
/* declare thread id for read_from_ir_thread */
tid_t read_from_ir_thread;
</pre>
To start the thread your main file should look like:
<pre>
/* begin main */
int main(int argc, char *argv[]) {
/* initialize communication port */
lnp_integrity_set_handler(port_handler);
/* set ir range to "far" */
lnp_logical_range(1);
/* initialize semaphore for communication */
sem_init(sem_com, 0, 1);
/* start read_from_ir thread */
read_from_ir_thread = execi(&read_from_ir,0,0,PRIO_NORMAL,DEFAULT_STACK_SIZE);
/* return 0 */
return 0;
/* end main */
}
</pre>
In the function <code>lnp_integrity_set_handler</code> the porthandler is defined. If a message is received, the porthandler defines what to do with this message. The function <code>lnp_logical_range</code> is used to set the infrared range of the RCX brick to ”far” in order to communicate over a long range (± 5 m). To prevent that two or more threads are writing the variables <code>TRIGGER1, TRIGGER2, TRIGGER3, TRIGGER4, TRIGGER5, TEMPERATURE, COORDINATES</code> at the same time, semaphores are used (see [7, chapter 6]). For example, if another RCX brick is sending a message to adjust the variable <code>TRIGGER1 and a thread running on this RCX brick is adjusting the variable <code>TRIGGER1</code> at the same time. The function <code>sem_init(sem_com)</code> initializes the semaphore sem_com to one. So if you want to change one of the variables <code>TRIGGER1, TRIGGER2, TRIGGER3, TRIGGER4, TRIGGER5, TEMPERATURE, COORDINATES</code>, semaphores should used. Therefore you cannot simply write
<pre>
TRIGGER=0;
</pre>
but instead it should be
<pre>
sem_wait(sem_com);
TRIGGER=0;
sem_post(sem_com);
</pre>


=Additional information=
=Additional information=

Revision as of 16:05, 9 March 2011

Under construction, references and figures needed.

Introduction

An important question scientists are eager to answer is whether there exists water on the planet Mars. If water is present, perhaps also life is possible on the red planet. In 1997, the first NASA probe landed on Mars. In January 2004, two Mars exploration rovers landed on the Martian globe [citation needed]. The golf cart-sized rovers were autonomous, robotic dune buggies that carried their own science, power and communications equipment. Since January 2004, several experiments and measurements have been performed which indicate that water had been around on the planet for a while. In August 2005, a third exploration rover was sent to Mars, this rover will join Mars Global Surveyor and Odyssey in their exploration of the planet. In the upcoming years, more inquisitive spacecrafts will follow them to investigate Mars, perhaps solving the mystery of what happened to the planet’s water and preparing for the arrival of the ultimate scientific explorers: humans [8]. In the Dynamics and Control Laboratory (WH -1.13) a reproduction of the Mars exploration rover is present. This reproduction is made out of LEGO, especially using LEGO Mindstorms, as shown in Fig. 1.1. The Mars-rover is equipped with two programmable interfaces (LEGO RCX 2.0), a camera, three light sensors, two motors, two encoders and a temperature sensor.

The LEGO Mars-rover is located on a Mars landscape containing three lakes as shown in Fig. 1.2. Now it has been established that water existed on Mars, the next mission is to find the locations of this water and to discover its properties. In this course this is done by determining the temperature of the water in the three lakes of the landscape. However, no software is present on the programmable interfaces of the Mars-rover. This software has to be designed and developed during the course in order to complete the mission. The earth computer can upload programs to the programmable interfaces of the Mars-rover. The interfaces can send and receive data to and from the earth computer. The programs are written in C using the BrickOS environment.

The course will consist of lectures and workshops which will introduce you in the interesting world of embedded motion control. The mission will be performed by groups of 4 people which will be assigned a group tutor. Each group will have weekly meetings with the tutor regarding questions about the mission. Four weeks after the beginning of the course each group will present their software design to the other groups. At the end of the course a final contest will be held where all groups have to perform the mission. Every group also has to deliver a website-as-report, which describes the complete embedded motion design, including an evaluation of the obtained results.

The remainder of this course guide is as follows. The goal of the mission will be described in Chapter 2. Since only one complete setup exist, each group is given an experimental kit at the beginning of the course of which the contents are described in Chapter 3. The experimental kit can be used for developing. The installation procedure of the necessary software to program the RCX is given in Chapter 4 together with some examples. Chapter 5 describes the use of the library which obtains the camera information and the startup procedure of the earth computer and of the library needed to communicate between the 2 RCXs and between the RCX and the earth computer. Additional information regarding the course and some tips and tricks can be found in Chapter 6. Appendix A and Appendix B contain the C application programming interface (API) and the BrickOS API. BrickOS is an alternative operating system for the LEGO RCX which provides a C development environment for the RCX.

Goal

The general setting of the Mars-mission has been described in the introduction. The overall goal of the Mars-mission can be described as

Program the Mars-rover in order to find out if there exists water on Mars. If water is found perform measurements to find out its state.

A description which is more applicable to the course and the setup as shown in Fig. 2.1 is

Write software for the Mars-rover such that it finds the three lakes, measures the temperature of the water and sends the outcome to the earth computer.

This goal can be divided into several subgoals

  • Getting familiar with the LEGO working environment.
  • Learn the C programming language.
  • Design of the software architecture.
  • Programming of the mission software.
  • Completion of the mission.

At the end of the course the Mars-mission will be performed by all groups in a final contest.


Hardware

In this chapter the different LEGO parts are discussed in more detail.

RCX

The RCX contains a CPU, display, memory, three actuator output ports and three sensor input ports. The output ports (A, B and C) can be operated in three modes: on, off or floating. When an output is turned on, it can run either in a forward or reverse direction. The output power level can be adjusted using pulse width modulation (PWM). The sensor ports (1, 2 and 3) can be used for both passive and active (powered) sensors. What kind of sensor is used has to be told to the RCX by a program. For each sensor, the sensor type and sensor mode have to be configured. The sensor type defines the interaction. The sensor mode determines the interpretation of the sensor values. The LCD can display four-digit signed numbers, single-digit unsigned numbers and special indicators. The RCX can communicate with a computer or another RCX through infrared. The RCX is powered by six AA batteries.

Temperature sensor

The LEGO temperature sensor measures using a thermistor (temperature sensitive resistor), i.e. the resistance of the thermistor changes with temperature. The resistance is measured by a circuit and converted to a temperature. It is a passive analog sensor. The temperature sensor is calibrated from -20° Celsius to +50° Celsius. The RCX can read and display the temperature in either Fahrenheit or Celsius.

Light sensor

The light sensor is an active sensor used to detect the amount of lightness and darkness. When the sensor is pointed at a surface, it reads the amount of reflected light. A light surface or a bright light results in a higher value than a black surface or shadowed object. It can also respond to blinking objects. The light sensor both emits and detects light. Therefore it can measure the amount of light in a room or the reflected amount of light from a surface. The light sensor can be used for line detection, edge detection or light/dark seeking purposes. In this course the light sensor will be used for edge detection.

Rotation sensor

The rotation sensor measures rotation with a resolution of 16 increments per revolution. The sensor uses two light diodes and an encoder disc with 4 slots which results in a quadrature signal with the mentioned resolution of 16 inc/rev. The resolution can be altered by applying a transmission between the motor and the rotation sensor. The maximum working speed of the rotation sensor equals 500 RPM. Note that at very low or very high speeds it is possible that counts are missed.

Motor

The motor has an internal five-stages gear reduction to increase the torque and a weight of 28 g. If no load is attached to the motor, the rotational speed equals 340 RPM and the no-load current equals 3.5 mA [citation needed]. The rotation speed of the motor is proportional to the voltage applied to it. The stall torque (locked motor axle shaft) of the motor equals 5.5 Ncm, the stall current equals 340 mA. Despite of the presence of an internal thermistor, avoid long stall periods in order to prevent overheating of the motor [citation needed].

USB IR tower

The RCX communicates to a computer through IR light. To receive the signals from the RCX, the USB IR tower can be used. For computers which already have an IR port, still the tower has to be used. Most standard IR ports use IrDA for communication, while the RCX uses a simpler proprietary protocol. The IR tower programs can be used to download control programs to the RCX and to upload data to the computer. The IR tower and the RCX must face each other to establish communication.

Connecting wire

The connecting wire can be used to connect the motor to the RCX or to extend the connection wires of the various LEGO parts. No specific orientation of the connectors is required.


Installation

Embedded_Motion_Control/Lego_Mindstorms_Installation

Libraries

In this chapter the libraries processing of the vision information are described and needed for communication. The startup procedure of the earth computer is also included in this chapter.

Video processing on the earth station

To navigate through the unknown mars landscape, vision information plays an important role. By using vision information, the positions of the lakes are determined which are in the field of view. This information can be used as input to determine the trajectory of the mars-lander. Due to the limited onboard computational power of the Mars-lander, the main part of localizing the lakes is done by video processing on the earth-computer. The video processing is based on both color and dimensions of the lakes in the captured images. The centers of the lakes is determined in terms of pixels and linked to the sender which communicates with the Mars-rover. Fig. 5.1 roughly represents the structure of the image processing. Especially if unexpected output is given by the vision system, it can be useful to roughly understand the main steps of the vision module.

The main steps will be described shortly in the remainder of this section.

  1. Acquisition: The image is acquired by the standard acquisition block of Matlab which can run at several sample frequencies. The output of the camera is given as three matrices: Red, Green and Blue, where each matrix exists of 240 × 320 pixels. It has to be emphasized that the pixels are numbered starting in the left-upper corner as indicated in Fig. 5.2.
  2. Color segmentation: Due to the distinct colors of the mars landscape, the objects in the mars environment can be separated based on color information. Every pixel has three [R,G,B] color values between 0 and 255 (short int). This could be interpreted as a location in the 3-D RGB color space. By defining bounds in the color-space, one is able to test for a certain color. To be robust for lightning conditions, these bound are chosen rather loosely. One should keep in mind that all objects in the background which appear more or less blue could disturb the image processing as they may appear as possible lakes.
  3. Blob-analysis and selection: Blob-analysis is used to search for regions of dense blue pixels. The outer bounding box of the blobs and its center are given as output. Since a high number of candidate blobs can be given as output, also a geometric check is performed based on the relation between the height and the length of the blob in relation to the distance. This check is based on geometric relations where the dimensions of the lakes are transformed into a height and width in the image of the camera. The angle of the camera with respect to the ground is one of the key parameters in this relation. In order to perform well, the angle of the camera with respect to the ground should be set properly. Fig. 5.3 depicts how the angle of the camera should be set. The candidate blobs that fulfil the conditions are given as output for the positions of the lakes and are given to the infrared sender. The structure is as follows: [math]\displaystyle{ \begin{bmatrix} \text{row } i \text{ of first lake}, & \text{row } i \text{ of second lake}, & \text{row } i \text{ of third lake} \\ \text{column } j \text{ of first lake}, & \text{column } j \text{ of second lake}, & \text{column } j \text{ of third lake} \end{bmatrix}. }[/math]
Most of the time only one lake is found, or two in rare cases. If the corresponding lake is not found, zero is given as output for the second and for the third lake respectively.

Starting the earth computer

The earth computer can be started in the following steps.

  1. Convince yourself from the fact that the camera is powered on and the camera receiver is connected to the pc.
  2. Start the program GrandTec Walkguard from the start menu. If the camera is connected properly, the camera image appears. Since the color segmentation proces depends heavily on the settings of the camera, these parameters have to be set. In the program GrandTec Walkguard, go to the Tab: Video. Set the following values:
    Brightness: 149
    Contrast: 174
    Saturation: 191
    Hue: 143
    Note that these values are a guideline. Since the values depend on lighting conditions some can deviate from these values. It is possible that the setting of the camera parameters has to be repeated if the camera has been disconnected from the power-plug.
  3. In order to properly check the geometry of the lakes, the camera should have the right angle with respect to the underground (see Fig. 5.1). Adjust the angle of the camera according to this figure. Exit the program GrandTec Walkguard.
  4. Color calibration (not needed, or done by tutors).
  5. Start Matlab and go to the directory D:\MC\vision. Open the Simulink model file communication_and_vision_with_viewers.mdl . In order to guarantee best performance, the priority of Matlab can be increased. Press: Ctrl+Alt+Del, go to Task Manager, processes, right-click matlab.exe. Go to Set Priority and set Real-time. Note that several Simulink schemes are available. If problems occur which could be due to the vision processing: one could chose to run the program: vision_with_viewer to get

more info about the color-classification. Start the Simulink scheme.

Communication

LegOS Network Protocol (LNP), which is included in the BrickOS Kernel, allows for communication between BrickOS powered robots and host computers. The communication is realized by the infrared ports. Therefore, first of all make sure that there are no obstacles between two communicating RCX bricks to prevent communication errors. For the purpose of this course there have been made adjustments and modifications in order to make the communication between RCX bricks and between RCX bricks and the host computer a lot easier.

A possible configuration of a communication setup is depicted in Fig. 5.4. It contains two RCX bricks and one host computer equipped with the Lego USB Tower. Each client has its own iden- tification number. The host computer is identified by ID = 0. The two RCX bricks are identified by ID = 1 and ID = 2. In the main C-file this ID should be defined, for example

#define ID 1

for RCX brick one. Next, the C-file com.c should be included using

#include "com.c".

Make sure that you first define the ID before you include com.c. The C-file com.c is makes it possible to send and receive integers or arrays of integers. The main functions in this file are called com_send and read_from_ir. The source code of the C-file com.c can be found on the CD by choosing Source Code Communication.

com_send

The main function to send integers is com_send.

Syntax

int com_send(int IDs, int IDr, int message_type, int *message)

Arguments

IDs: The ID of the sender
IDr: The ID of the receiver
message_type: The message type
message: Pointer to an integer or an array of integers

Description

Call com_send to send an integer from the sender with ID = IDs to the receiver with ID = IDr. The message that has been send has a message type. There are seven message types: 1 to 7. Each message type is coupled to a global variable:

  • Message type 1: TRIGGER1 (integer)
  • Message type 2: TRIGGER2 (integer)
  • Message type 3: TRIGGER3 (integer)
  • Message type 4: TRIGGER4 (integer)
  • Message type 5: TRIGGER5 (integer)
  • Message type 6: TEMPERATURE (integer)
  • Message type 7: COORDINATES (array of 6 integers)

These global variables can be read in all your functions, for example by calling TRIGGER1. Sending an integer with message type 1 will result in the adjustment of the global variable TRIGGER1 at the receiver side.

Examples

/* declare and initalize a */
int a = 1;
/* examples of sending messages */
com_send(1,0,7,&a);
com_send(2,0,7,&a);
com_send(1,2,1,&a);
com_send(2,1,1,&a);

The communication in the example correspond with line 1,3, 5 and 6 respectively. A description of the communication lines is shown in Fig. 5.4. At communication line 1, the RCX with ID = 1 asks the coordinates from ”earth”. The coordinates are returned at communication line 2 and are stored in the variable COORDINATES. At communication line 3 RCX with ID = 2 asks the coordinates from ”earth”. The coordinates are returned at communication line 4 and are stored in the variable COORDINATES. The coordinates correspond to the pixel numbering of Fig. 5.2. To read the coordinates simple call COORDINATES[0] for the first coordinate, which is the i-coordinate of the lake that is most nearby. An i-coordinates of 0 means that the center of this lake is seen at the top of screen of the camera. An i-coordinate of 240 means that the center of this lake is seen at the bottom of the screen of the camera. COORDINATES[1] is the j-coordinate of the lake that is most nearby. An j-coordinate of 0 means that the center of this lake is seen at outer left side of the screen of the camera. An j-coordinate of 320 means that the lake is seen at the outer right side of the screen of camera. So the screen can be compared with a matrix with a size of 240 × 320. The element (0,0) is the upper left element of the screen / matrix. The element (240,320) is the bottom right element. A lake is found when the following relations are satisfies 0 < i-coordinate < 240 and 0 < j-coordinate < 320. COORDINATES[2] and COORDINATES[3] represent the i- and j-coordinates of the second lake. Finally COORDINATES[4] and COORDINATES[5] represent the i- and j-coordinates of the lake that is located most far away. At communication line 5, the RCX with ID = 1 sends TRIGGER1=1 to RCX with ID = 2. The opposite is the case at communication line 6.


read_from_ir

To use the function read_from_ir, a thread (see [1, page 169]) should be started. The task of this thread is to constantly detect whether or not a message is received at the infrared port. If a message is received, the variables TRIGGER1, TRIGGER2, TRIGGER3, TRIGGER4, TRIGGER5, TEMPERATURE and COORDINATES are adjusted depending on the message type. To start the thread, first define the thread identification like

/* declare thread id for read_from_ir_thread */
tid_t read_from_ir_thread;

To start the thread your main file should look like:

/* begin main */
int main(int argc, char *argv[]) {
	/* initialize communication port */
	lnp_integrity_set_handler(port_handler);
	/* set ir range to "far" */
	lnp_logical_range(1);
	/* initialize semaphore for communication */
	sem_init(sem_com, 0, 1);
	/* start read_from_ir thread */
	read_from_ir_thread = execi(&read_from_ir,0,0,PRIO_NORMAL,DEFAULT_STACK_SIZE);
	/* return 0 */
	return 0;
/* end main */
}

In the function lnp_integrity_set_handler the porthandler is defined. If a message is received, the porthandler defines what to do with this message. The function lnp_logical_range is used to set the infrared range of the RCX brick to ”far” in order to communicate over a long range (± 5 m). To prevent that two or more threads are writing the variables TRIGGER1, TRIGGER2, TRIGGER3, TRIGGER4, TRIGGER5, TEMPERATURE, COORDINATES at the same time, semaphores are used (see [7, chapter 6]). For example, if another RCX brick is sending a message to adjust the variable TRIGGER1 and a thread running on this RCX brick is adjusting the variable TRIGGER1 at the same time. The function sem_init(sem_com) initializes the semaphore sem_com to one. So if you want to change one of the variables TRIGGER1, TRIGGER2, TRIGGER3, TRIGGER4, TRIGGER5, TEMPERATURE, COORDINATES, semaphores should used. Therefore you cannot simply write

TRIGGER=0;

but instead it should be

sem_wait(sem_com);
TRIGGER=0;
sem_post(sem_com);

Additional information