LEGO Formula — Normalizing Data

Converting Data to Use The Same Range — Episode #14

J3
KidsTronics
6 min readJun 8, 2019

--

Did you hear about Normalization? No, Here’s the scoop: when you normalize a set of data, you map the original data range into another scale. videos? Click here now!

I’m going to be showing you how to convert information read from the IR Sensor into normalized data set to turn your data into a percentage scale and make your line follower program adaptable to any track!

In the end, we implement a code that joins both the calibration and the navigation functionality using the EV3 programming environment’s built-in Image Editor to make the menu graphics — a follower line custom GUI.

Motivation

Let’s say I run the 13_BlackLineReading_v1 code, from Episode #13, on my test line and get Min and Max values of 5 and 65, and let’s suppose that you run the same program on your line and get values of 15 and 55 with your own paraphernalia.

Fig 1. My measure and your measure

The midpoint of both sets of values is 35, but the program 12_Proportional_Controller_v1 really should react differently for each line because the range of values is different.

How to implement a code that works for both (or any) test tracks? or how to configure according to the maximum and minimum restraints?

The solution would be to turn all scales into a percentage and this is called normalizing for a percentage scale (in fact you can normalize to any scale).

Fig 2. Transforming all scale in percentage; But how?

Let`s just create some intuition about normalization:

Suppose you are reading a sensor in the Arduino’s analog pin A1.

The analog-to-digital converter of ATMega328p (the chip that comes in the Arduino board) has a 10-bits resolution; this means that it can spit out values from 0 to 1023 (2¹⁰).

All you want is to put all values in percentage :).

So far so good!

To get the percentage scale you can do like this:

Fig 3. Transforming all the extremes to percentual value scale

From the calculation above, you can see that it is enough to divide the reading taken from the sensor by the original scale (removing so this scale from the result) and multiply the equation by the new max scale value (adopting this new scale).

Back to LEGO:)

The steps for normalizing a data set are described here.

1° Step

Calculate the normalized value of every number x in the original data set using this equation (scientific formula):

Fig 4. Simplified equation incorporated into the program below.

2° Step

Identify the Maximum and Minimum values numbers in the original data set and save them in the variables max and min, respectively, saving the data set to a file called File3.

Fig 5. The code 14_Calibration_FollowerLine_v1 that collects the Color Sensors' minimum and maximum reading and saves the two values to a file called File3. PLEASE, DOWNLOAD THE CODE AND OPEN IT AT LEGO® MINDSTORMS® EV3 Software
Video 1. Make the test with the new GUI (normalizing data)

3° Step

Now, join the follower line, calibration, and data normalizer in one program with a custom GUI, saving the min and max values to a File named File4 and retrieving them internally to calibrate the Tribot v1:

Fig 6. Code 14_GUI_Cal_FollowerLine_v2; PLEASE, DOWNLOAD THE CODE AND OPEN IT AT LEGO® MINDSTORMS® EV3 Software

This GUI, follower line’s Graphical User Interface, allows the user to select one of the two operating modes (or more) within the same program. After selecting an operating mode, the user can exit and return to this menu screen to select a new operating mode.

Fig 7. Making GUI with Tool > Image Editor

A GUI has additional applications within the realm of LEGO robotics — many First Lego League (FLL) teams have decided to use custom GUI’s and/or program sequencers to make changing programs quicker and easier, saving precious time on the competition field.

Video 2. Presenting LEGO on the two rounds training circuit!

And that’s all folks!

For the next episode, we will use finally PID controller.

The ideas behind the Proportional-integral-derivative controller are about 100 years old and are used to control all kinds of mechanisms in everything from ship navigation and printers to musical instruments.

Bye!

Download All Files For This Project

Related Posts:

01º Lego Episode — Our Startup’s Journey — Invaders and Invasions?

02º Lego Episode — Timmyton Lego-Learning-By-Playing — L2BP Series

04º Lego Episode — Lego MotionsTribot v 1.0Seeing Your Creation Move — Move Steering Block

05º Lego Episode — Lego Motions Move Tribot Around — And Backward…Five Programs Files

06º Lego Episode — Lego SensorsTouch N Color — Two out of five human senses — Touch N Sight

07º Lego Episode — Lego Sensor LineFollower — Line Follower Tribot v1.0

08º Lego Episode — Maze Solving Robot v1 — Lego Solution Right-Wall-Follower-Robot

09° Lego Episode — Gettle_&_Sound_Bots — How gentle can a robot be? What is the audible range of the human ear? How deep can we dive?

10° Lego Episode — Data Logging — Data Collection and the EV3

11º Lego Episode — Binning the LineFollower Code — Binning: Arithmetic To Map Sensor Reading

12º Lego Episode — A Proportional LineFollower Robot — Advanced Math To Improve Your Robot’s Steering

8th KidSeries — J3 Follower Line Robot v1.0 — The Simplest Follower Line Robot

13º LEGO Theory — Multitasking — A very Useful Programming Technique

14º LEGO formula — Normalizing Data — Converting Data to Use The Same Range

15º Lego Episode — PID — The Ultimate Line Follower — Algorithm for your EV3 PID Line Follower Robot

16° Lego Meets Pixy Episode — How to Connect Your Inexpensive Camera Module to Lego

18° Lego Episode — GEARS & WORMS — Geartrains & Worm & Clutch Gears

23° Lego Episode — Differential Explained — How Differential Works?

24° Lego Episode — PitBot — A Star Is Born — Working at The First Structure in Our Sparring Robot

25° Lego Episode — PitBot Is Agressive? Well, No Worries! — Making PitBot bite!

26° Lego Episode — Dancing Good w/ PitBot — All The Secret for Replicate This Awesome Robot

27 ° LEGO Episode — Sumo Arena is Ready! — Here is the playing arena for Arduino x Lego

28 ° LEGO Episode — Pick Pitbot Up! — Our Robot Are Leaving Body & Paint Shop

28 ° LEGO — B — Episode — Pitbot Battery & Sensor Setup — Preparing The infrastructure for running Arduino code

29 ° LEGO Episode — Bridging All Sensors Together — Pitbot — Collecting All Codes for the Final Act of Giving Behaviors to Robot

Credits & References

Book: The Art of Lego Mindstorms EV3 Programming by Terry Griffin

EV3 Large and NXT Motors — The Differences Explained

Building Instructions & Program Descriptions

LEGO® 9V Technic Motors compared characteristics

Robotics for Children (& Parents (& Grandparents))

Tribot v 1.0 .pdf File

Introducing LEGO Digital Designer

--

--

J3
KidsTronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!