In episode 11 we looked at one of the most important topics for the competition - calibrating the light sensors. In this video I would like to show you how to use a more programmatic approach. This means letting the robot do the calibration on its own. Automatically.
- 10 Apr 2013
Program for displaying the value of the sensor on the screen
Program for calibrating including the DisplayLightSensor block
0 In episode 11 we looked at one of the most important topics for the competition - calibrating the light sensors.
In this video I would like to show you how to use a more programmatic approach. This means letting the robot do the calibration on its own. Automatically.
I am going to use the Calibrate block from the Advanced section in NXT-G.
1 - software
First I would like to display the value of the sensors on the brick. This is achieved with the Light sensor block. You should convert the value returned from the block to a text using the Number to Text block. Our sensor is attached on port 1. And after we have converted the value we can display it on the brick. We select Text. Finally after displaying the value, I would like to leave the robot working for 5 seconds just to make sure we can see the displayed value. Time. Five seconds. OK.
2 - robot
Let’s start the robot. As you can see we currently get a value of 53 for the brightest part of the field and a value of 31 for the darkest part of the field, this black line here.
3. - software
Next we move the four blocks in a new block and call it DisplayLightSensor. DisplayLightSensor. Finish. In this way, we could use this block many times in our program without repeating ourselves.
After we see the value on the screen, we should calibrate this value. Calibrate. As the robot will first be on the brightest part of the field, we set the calibrated value to a maximum, so we would like to calibrate the maximum of the sensor. Just to make sure that the calibration is successful, I will put a sound after the calibration and select the Click sound. After calibrating, we again show the value of the light sensor on the screen. We take the MyBlock DisplayLightSensor.
4. - robot
Now, as I start the robot, it shows the value of the sensor, again 53, we calibrate it, to make the brightest object with a value around 100, and after the calibration the new value was a 100.
5. - software
As we have calibrated the maximum value of the sensor, we should now calibrate for the minimum. Let’s move the robot about 1 rotation forward and calibrate for the Minimum Value. Calibrate on port 1 but this time for the minimum. Again with an appropriate sound at the end. The sound is “Click”. I will add a few comments to make the program easier to understand. You have this comment tool so here we are “calibrating maximum” and here we are “calibrating minimum”. And now we download the program. Um.. no. We should first add one more block to see the value of the sensor, and take the DisplayLightSensor. Download.
6. - robot
Again we start the robot. First it shows the non-calibrated value of the brightest object. The calibration is done. Then we show the new value for bright object. Now the robot moves automatically about 1 rotation, it calibrates for the minimum value, which, in this case, it was 0.
7. - software
One more important thing about calibration is to always reset the calibrated value before doing new calibration. You can do this again with the Calibration block, but this time for Action you chose “Delete” instead of Calibrate.
8. - robot
As a result, we have a robot that can automatically calibrate itself with just a push of a button.