Lego Mindstorms & the IGSS Scada System
I have for many years now been working on the IGSS scada system that is sold by Schneider-Electric in Denmark.
IGSS comes in a free edition, the "FREE50", that allows for up to 50 objects in the configuration and a single driver.
One of the drivers available, I have written to communicate with the RCX of Lego's Mindstorms set, first generation.
The RCX can be equipped with 3 sensors chosen from a number of sensors, like touch sensors, light sensors, rotation sensors, and even a temperature sensor.
It can also control 3 motors.
All this allows for anyone to set up a "real" scada system for no other cost than the price of a Lego Mindstorms set - and a PC to run the software.
This page will take you through the steps one by one to set it all up, and complete a simple project involving a "luggage conveyor belt".
The project description involves a few more components, but they are optional, and with a little innovation, you can easily replace them with something else.
Please be aware that this article is NOT a tutorial into the IGSS system.
If you are not already familiar with IGSS, you HAVE to study the IGSS system by reading the accompanying tutorials and documents.
This is strictly intentional as this article is meant as an inspiration to combine IGSS and Lego Mindstorms, if you have an interest in both fields.
If you are only interested in Lego Mindstorms, and not in Scada systems in general or IGSS in particular, you will be better off chosing a different approach for your project.
IGSS will prove to be far too complex, as it is indeed a huge industrial grade system.
If you are still game for IGSS, read on!
Download and install IGSS.
When asked to choose a license, choose "FREE50".
The documentation includes a "Getting Started" among other things, be sure to read this, if you are not familiar with IGSS already.
A FREE50 license does not include the right to support.
However, if you have a question or a comment, feel free to mail me, my email address is legoscada and my domain is mdjnet.dk.
I cannot guarantee that I have the time to answer you, but maybe I do.
3. The PLC
In the real world, a scada system is not communicating directly with the sensors and motors.
Instead, the scada system is communicating with a "PLC" (Programmable Logic Controller), that knows how to communicate with the sensors, and the PLC is also responsible for some of the logic controlling how to react to events detected by the sensors.
The drivers in IGSS are each designed to communicate with a PLC type chosen from a wide range of PLCs on the market.
To stay in this architecture, I have also written a "PLC program", that the driver is talking to, and this program is in turn talking to the Lego RCX.
The accompanying project file is a Visual Studio 2012 project file.
It is a console program, but can also be installed to run as a service.
Type "legorcxplc -?" to get a full list of arguments.
The program requires some DLL's, which was released by Lego as part of the LegoMindstorms SDK.
Install this SDK, and if you are going to compile the PLC yourself, make sure Visual Studio can find the DLL's and the include files required.
It will once per second poll the RCX to get the complete status of the sensors, and the IGSS driver will poll the PLC program with the frequency configured in IGSS.
Note that the RCX requires new firmware to be installed, the PLC program will automatically detect this and install the firmware.
Place the firmware file in the folder C:\Lego, or change the location in the Firmware.cpp file of the PLC.
The PLC program also has some other duties, that need to be changed depending on the project.
This logic can be found in the Plc.cpp file.
The design of having the PLC do the actual logic of the project is in fact the usual scenario, as it allows the installation to continue functioning independantly of the scada system, which can be down for various reasons due to for instance maintenance or PC failure, and it can even easily be replaced with another scada system.
The scada system is among other things left with the responsibilities of logging the history of events occuring in the installation, and allowing for manual manipulation of the installation through sending commands to the PLC.
Further discussion of the PLC program later.
4. The RCX Tower
The RCX unit of the Mindstorms set needs a tower connected to the PC running the PLC program.
(The red and blue wires are my own invention, see later.)
If you have version 1.0 of the Mindstorms set, the tower has a serial connector, and you might need a USB-serial converter, if your PC does not have a serial connector.
The PC needs to be installed with the tower driver (this driver is newer than the one from the SDK) to be able to communicate with the tower.
(A USB-serial converter may need it's own driver as well.)
While both types of towers can communicate with all versions of the RCX, the PLC program needs to know the type of tower used.
See the Init() function in the file Rcx.cpp.
5. Power Supply (Optional)
If you don't want to use regular batteries for the RCX (and serial tower), it is possible to build your own power supply.
I have built a simple one that takes 12V from my PC's power supply.
The little light emitting diode is optional, it just shows when the power supply is on.
A schematic diagram of my power supply is shown below, but you can build it in many different ways.
You might need to add a capacitor between the diodes and the voltage regulator to smooth out the voltage level, if the power source is indeed an AC power source, but if you use your PC's power supply or another stable DC power supply, no capacitor is required.
I have added some extra wires to the inside of the RCX to allow for easy connection of the power supply.
Now all there is left to do is to close the RCX brick again, and connect it to the 9V power supply, observing polarity.
The same thing can be done with the serial version of the tower, which requires a 9V battery.
The USB version of the tower is powered by the USB link.
6. The Model
The Lego model I have chosen for this project is modelling a luggage conveyor belt, like the ones you will find in airports.
They stand still, until ground crew start placing luggage on the belt, then it will start transporting the luggage to the waiting passengers.
It is a very simple model with a small conveyor belt, a rotation sensor attached to it to measure the speed, a photocell to automatically start the belt, when a piece of luggage is placed on it - and a temperature sensor measuring the room temperature, starting and stopping the fan, when the threshold is crossed.
You can find instructions for the model here.
I have used MLCad from the LDraw all-in-one package for these instructions.
Note that MLCad does not support drawing the wires, so you will have to do this using these instructions:
Connect the light sensor to the Sensor 1 connector on the RCX, connect the rotation sensor to the Sensor 2 connector, and connect the temperature sensor to the Sensor 3 connector.
Connect the motor next to the light emitting diode to the opposite corner using a short wire and another short wire from there to the Motor A connector of the RCX - or use a longer wire to go all the way.
Finaly, connect the fan motor to the Motor C connector using 2 short wires, going beneath the belt, another continuing all the way up to the RCX - or use a longer wire to go all the way around (sometimes the wire going below the belt is rubbing against the belt, so you might prefer to have the wire go another way).
I have used the Lego bricks from a Mindstorms set 9747/3804 plus a few extras.
It can be easily improved upon, if you don't have the extra pieces that I have used, or if you have better ideas, like more support under the belt at the middle or a touch sensor to start and stop the fan.
7. The Photocell
To detect when a piece of luggage is put on the belt, I am using a standard light sensor placed opposite a little light emitting diode that almost accurately fits in the hole of a lego technic brick.
I have added a 690Ω resistor to it, so that it can be connected directly to the 9V power supply, observing polarity.
An alternative is to use one of Lego's own light bricks as a light source.
That way the light itself can also be controlled from the PLC through the RCX and ultimately the IGSS system.
The actual amount of light measured by the light sensor when the diode is on and off must be determined, so the logic in the PLC can be correctly calibrated. More on that later.
8. IGSS Configuration basics
You will need to get familiar with how to configure IGSS to communicate through the driver.
When you create a new configuration, during the project wizard, or later using IGSS' System Configuration program, you can choose the communication driver to use.
Choose the "7TLEGO" driver, and make sure it has Node 0 (the only node number available for now).
You can just leave all other settings with their default values, until you understand how they work.
Now, in IGSS' Definition program, you can create templates and objects, and have them connect to the 7TLego driver on the "Edit Mapping" page:
Note all the various values available.
A PLC is usually exposing it's internal state as a memory map, where the driver on behalf of an object can query a certain value given by the word offset.
The Lego PLC and the 7TLEGO driver are no different, but to ease the configuration the possible values are shown as in the dropdown above.
To understand the meaning of these parameters, you will need the "RCX2 LASM byte codes.pdf" document, which is part of the documentation for the LegoMindstorms SDK.
You can also have a look inside the files Rcx.cpp and Rcx.h of the PLC program, specifically the functions plcdata() and plccommand().
I have created a simple test configuration for the conveyor project, which you can study, and use as a basis for your own configuration as it has all the required templates.
Unzip the configuration in a folder called "C:\IGSS Configs", or be sure to enter the System Configuration program afterwards to change the path of the report folder to your preference.
Take a look at the "Main" diagram for an (almost) complete collection of the possible objects, to see how they are configured.
Here, you can also read the values for the light sensor when the light is on and off, and make sure that the threshold value used by the PLC program is correct.
Same calibration should be done for the temperature sensor, or you risc that the fan is always or never on.
- Word offset 1(0x01) = Battery level (in)
- Word offset 17-19(0x11-0x13) = Type for sensor 1-3 (in/out)
- Word offset 33-35(0x21-0x23) = Mode for sensor 1-3 (in/out)
- Word offset 49-51(0x31-0x33) = Slope for sensor 1-3 (in/out)
- Word offset 65-67(0x41-0x43) = Value of sensor 1-3 (in/out)
- Word offset 81-83(0x51-0x53) = Raw value of sensor 1-3 (in)
- Word offset 129-131(0x81-0x83) = Status of motor A-C (in/out)
- Word offset 145-147(0x91-0x93) = Direction of motor A-C (in/out)
- Word offset 161-163(0xA1-0xA3) = Power of motor A-C (in/out)
The RCX does not by default know the type of sensors connected, so it must be instructed.
This can be done through objects using the "Sensor type" values for the command atom, and then sending the appropriate "command".
The downside is that you will have to do this every time you turn on the RCX as it "forgets" the configuration when the power is cut.
Instead, the PLC program should be compiled with a proper set of defaults for type and mode in the "conf" variable near the top of Rcx.cpp.
These defaults are written to the RCX every time the program starts, so simply restarting the service will be sufficient to reset the types to the desired defaults.
The values in the Rcx.cpp file is matching the requirements for the luggage conveyor belt, but can be easily changed to match your project.
Here you will find the complete list of links and downloads used in this article:
The official LEGO website
IGSS Test configuration
The PLC program source code
MLCad (LDraw all-in-one)
LEGO® is a registered trademark of The LEGO Group, which is not in any way affiliated with this site.
The LegoMindstorms SDK, the tower driver, firmware, and related DLL's presented for download on this page are all Copyright© The LEGO Group.
The LegoRcxPlc Software is Copyright© myself, but you may use it as basis for your own projects, and you may freely distribute it and derived works, as long as it is done without any charge or fee.
Last revised: 2016-05-05