Investigating control using the Lego Mindstorms EV3

[From Bruce Abbott (2018.02.14.1200 EST)]

Happy Valentine’s Day!

Bill Powers relied on computer simulations to develop and test PCT, and to teach its principles. It is important to understand that the control systems implemented in such simulations are real control systems, not simulations of them. Consider, for example, the control-system models that are fit to a participant’s data from a tracking task. Those models typically control the position of a cursor relative to a target better than the participant does – and the participant is exerting real control of the cursor via mouse movements.

In contrast, computer simulations do simulate what the designer believes to be the relevant aspects of the environment with which the control system interacts. The inverted pendulum demo, for example, specifies parameters such as the mass of the cart, mass of the bob, compressibility of the pendulum shaft, force of gravity, and the geometry of the cart and pendulum. The cart’s control system generates a simulated horizontal force that accelerates the cart left or right, and these accelerations, together with the simulated inertia of the pendulum bob and the slightly compressible rod linking the bob to the cart via a pivot on the cart, generate forces normal to the rod, etc. However, to keep things simple the simulation assumes an ideal case; it does not take into account energy losses due to friction or wind resistance (although it could in a more realistic version). Much of the effort that goes into writing a computer simulation involves getting these properties of the environment right. A control system that functions well in such a simulated environment may not do so if implemented in a real device; it all depends on whether the simulation properly captured the important determining environmental factors. Thus, it is important to demonstrate that what works in a simulated environment also performs well in the physical environment. Working with physical systems also eliminates having to create a user interface to display the simulated entities (e.g., the inverted pendulum, cart, and “road”). Rendering these usually requires considerable coding.

It was with these in mind that I purchased the Lego Mindstorms EV3 robotics kits that I’ve been using to build the various robotics demos I’ve been posting on YouTube. Building and testing those examples has been instructive, and in what follows I’ll share some of what I’ve learned. In this post I share some general information about the EV3 kit.

The EV3 “brick” is a small computer in a brick-shaped plastic housing, The brick includes on its face a gray LCD display screen and a few buttons, and four ports on each end into which one can plug up to four sensors (on one end) and up to four motors (on the other end). The “home” and “education” versions differ in the sensors provided in the kit: the home edition includes a “color sensor,” an infrared beam sensor, and a push-button switch. For the education edition an ultrasonic sensor is substituted for the infrared sensor and you also get gyro sensor to detect rotation about a single axis in addition to the color sensor and switch. Both kits come with two “large” motors and one “medium” motor.

Although you can program the EV3 via the pushbuttons on its face, it is much easier to program it using the free Mindstorms software. The brick has a USB port and includes a USB cable with which you can connect the EV3 to your computer. The software is based on National Instruments’ LabVIEW product. To create a program you drag “blocks” from a menu at the bottom of the screen onto the program area and connect their inputs and outputs via “wires.” For example, you could drag a “loop” block onto the program area, then grab a “large motor” block and place it inside the loop. Each block typically has parameters you can set; in the case of the large motor block you can set the motor’s power level (rotation speed) and mode. If the power (range -100 to 100) is set to a negative value the motor runs in reverse. Each motor includes a digital rotation sensor that reads the motor’s rotations (positive = clockwise, negative = counterclockwise), and you can set the mode value to cause the motor to rotate a certain number of degrees, a certain number of rotations, continuous rotation, or off. You can also set whether the motor will brake at the end of its movements of coast to a stop.

The EV3 runs a version of the Linux operating system. It is possible to override the block-based programming software inside the EV3 by installing an alternative on a micro SD card that fits into a slot the brick. For example, one option, called leJOS, makes it possible to program the brick in JAVA. Rupert Young is using leJOS in his Lego bricks. I have installed leJOS on an SD card but for now I’m still using the Mindstorms software.

To create a robotic system, you connect various physical components via pins – a difference between the Lego Technic system on which the Mindstorms kit is based and the more familiar press-together Lego bricks. The Education version of the Mindstorms programming environment provides instructions for assembling various examples, including what is referred to as the “Driving Base” – a two-wheeled vehicle in which each wheel is powered by a separate large motor. (the rear end rides on a ball bearing in a cup.) The small motor is mounted between the wheels and is geared to operate a rectangular bar that can be raised or lowered so as to capture, drag, and release objects that fit inside its perimeter. A color sensor can be mounted to one side, facing down, to provide input for a line follower, and an area in front can serve to mount either the infrared or ultrasound sensor.

Below is a screen shot of the Mindstorms programming environment showing a simple infrared beam-follower program:

image001194.jpgThe green triangle represents the start of the program. This is followed by a loop block that is set to continue endlessly (note the infinity symbol at the right end). Inside the loop are three bricks. The first represents the infrared sensor, which includes an output tab that provides a “heading” signal. This indicates the position of an infrared transmitter beam relative to the sensor, with 0 indicating straight ahead, negative numbers positions to the left, and positive numbers positions to the right. The heading signal is “wired” to a “math” block. This is set to multiply input “a” (set to a value of 4) times input “b,” the heading signal. The output of the math block is wired to the direction input of a “steering” block. The steering block assumes that there are two large motors, one connected to port B and the other to port C of the EV3 brick (note the letters at top right of the block). The number received by the steering input determines the relative speeds of the two motors, with negative numbers producing turns to the left (the more negative the sharper) and positive numbers producing turns to the right. The second input, set to 30, determines the motors’ speeds during straight-ahead movement; turning reduces the speed of one motor and even reverses it for sharp turns, while the other maintains the set speed.

The blocks are selected from the panel at bottom: currently the tab is selected showing the available “data operations” blocks. To the right is a display showing readings coming from the medium and two large motors (top row) and the infrared sensor (bottom row). By clicking on the little arrow, center extreme right of this display, you download the program into the brick and start it running. Alternatively you can click on the down-arrow to just download the program. You can then start it by pressing the proper buttons on the EV3 face.

Simple as it is, this program functions as a control system. It works quite well: the Driving Base will track the transmitter beam as the transmitter is moved around in front of the infrared sensor, turning left or right as necessary to move the sensed direction toward zero (straight ahead). Reality provides the physics and the physical object to observe, so there is no need to represent these within the program.

That’s a brief introduction of the EV3 and its programming. Next time I’ll describe some experiments I’ve done to test the EV3’s capabilities as a test bed for investigating control.

Bruce

image00297.jpg