Advanced Light/Color sensors calibration for more than one sensor Pro Preview

In the course section for Advance Sensor Calibration we previously showed you how to find the minimum and maximum value for a single LEGO Mindstorms Color Sensor and to store this value in an array. The program was implemented with the EV3-G software. In this tutorial we are going to find the Min and Max for all the four sensors and to store all the 8 values in an array.

  • #635
  • 04 Oct 2017
  • 7:39


What we could just do is copy/paste the logic for a single sensor and in this way have it for many sensors. Copy/pasting is a possible solution and we are using it in this specific program. A much more beautiful and smart solution would be to extract the logic in a single block and to do some calculation on the indexes, but this will be shown in some of the next tutorials. For now, just copy paste and blocks for the second sensor and have the logic repeated four times for sensors 1,2,3,4. The min and max values should be stored in the following way

Sensor 1 Min -> Array Cell 0

Sensor 1 Max -> Array Cell 1

Sensor 2 Min -> Array Cell 2

Sensor 2 Max -> Array Cell 3

Sensor 3 Min -> Array Cell 4

Sensor 3 Max -> Array Cell 5

Sensor 4 Min -> Array Cell 6

Sensor 4 Max -> Array Cell 7

Do you already see the formula ? :)


Our next step is to detect the minimum and maximum values for more than one sensor. We have 3 sensors connected on port 2, 3 and 4 because on port 1 we have the gyro sensor and we want to detect the minimum values and the maximum values for each of the sensors and store these values in an array. This here is the program that we've developed so far and in this program we have our loop and this loop runs for about a second and in this loop we set the minimum and maximum values for sensor 2. And now we must do exactly the same but for the other sensors. And with different array values. Now, there are different options to do it. We'll do it in the most, not beautiful, but simple way - just copy paste them.

I'll just select all the blocks here, copy part of the blocks, paste them again inside of the loop

and attach them to the front. And now we must change. First, we detect the value for sensor 1. Then we store the minimum in the cell with index 0.

We continue.

And here we store the maximum for port 1 in the cell with index 1.

And here again in the cell with index 1.

As something you can do is to extract this behavior in a new block but currently we are not doing it. We want to have the blocks like this. And now I'll just paste again at the end.

Now we detect the raw sensor value for port 3

and we store this value, not in the cell with index 0, not in the cell with index 2, but in the cell with index 4. This is the minimum value for sensor 3. We continue, minimum value again and the maximum value will be in the cell with index 5. And this is a nice exercise for using arrays. A simple array with just 8 different values - min and max for the 4 sensors and with the different operations it's actually a perfect example for using arrays.

And finally, as we are at the end of the loop, zoom out again.

And I'll just copy-paste again at the end of the loop for sensor 4.

Here I would like to read the value for sensor 4 and the minimum value for sensor 4 will be stored in the array in the cell with index 6. The minimum is in 6 and the maximum is in 7.

Now, that's not a beautiful way to implement it and that's not a very good way but we want to show it because when we read the values after a few tutorials and we'll read them with a formula so you'll have two ways for implementing such logic when you need to access the array. So, to have as a formula that calculates depending on the sensor which is the index or to hardcode these values. So, these are two different approaches and I would like to show you both of these approaches. So, that's why here we are using just hardcoded values and in the next tutorial we'll use the values that are not hardcoded but we calculate them. And then you can actually decide depending in your circumstances how you would like to implement this. At the end we would like to display these values on the screen and the values that we want to display on the screen are all the values.

Let's just arrange these blocks -

something that happens most of the time with the EV3 blocks so, I'll just rearrange them.

Now, we have a display that displays the minimum value for sensor 2 and just as an exercise I'll display the minimum value for sensor 4 which is stored in 6 and the maximum value is stored in 7. Okay, download and run the program and we'll have a program that sets the minimum and finds the minimum and maximum value detected by all the sensors.

The robot moves back, detects the minimum and maximum for all the 3 sensors but displays just the minimum and maximum for the sensor connected on port 4. And these are 4 and 75. In the next program I would like to show you how to display all the values of the array.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for FIRST LEGO League Competition. Constructing and Programming a Robot Base
  • 42
  • 249:53
  • 10
Image for Advanced Light/Color Sensor Calibration
  • 15
  • 0
  • 4
  • 3d_rotation 0