Ev3+Info

http://www.ev-3.net/en/archives/850 http://www.lego.com/en-us/mindstorms/downloads/software/ddsoftwaredownload/

Getting a NXT light sensor to work on an EV3: “Any sensor can be read using the raw sensor block. Using a raw sensor block for an NXT light sensor appears to be the same as reading the raw values from an NXT Light Sensor block (on an NXT running a NXT-G program). This is a good thing, because most teams that rolled their own calibration based everything off raw sensor data. Raw sensor data is a better choice because it it has a wider range.

Calibration

If you want the NXT light sensor to provide a reading from 0 (dark) to 100 (bright) you need to convert the slope and offset. This is often done using the following equation:

Calibrated Reading = (Raw Reading - Dark Reading) * 100 / (Bright Reading - Dark Reading)

The (Raw Reading - Dark Reading) is the offset. Place the NXT light sensor over a dark color and you will see readings around 1400. We want these to be zero. If I subtract 1400 (or whatever the raw reading was) from every raw reading I will get "calibrated" sensor reading near zero when we put the sensor over the dark color.

Now I place the light sensor over a bright color. The raw sensor reads 600, and my "calibrated" reading is -800. I don't want the range to be 0 to -800, I want it to be 0 to 100. That is what the 100 / (Bright Reading - Dark Reading) is for, it adjusts the slope. The numerator is the desired sensor range (think of this as 100 - 0 if that helps) and the denominator is the measured range. Look what happens when I put 600(or whatever the raw reading was) in for "Bright Reading")

Calibrated = (Raw Reading - 1400) * 100 / (600 - 1400)

Place the sensor over the dark area and the raw reading is 1400.

Calibrated = (1400 - 1400) * 100 / (-800) = 0 / (-800) = 0.

Place the sensor over the bright area and the raw reading is 600.

Calibrated = (600 - 1400) * 100 / (-800) = -80,000 / (-800) = 100.

The "Bright Reading" and "Dark Reading" are called "The Calibration". When you calibrated the NXT light sensor you were collecting raw sensor data to assign values to the bright and dark fields of "The Calibration". NXT stored this information in a file and it was used whenever you read the light sensor. If NXT couldn't find the calibraton file it used default values, but the equation was exactly the same.

Modes

A color sensor can be used as a color sensor, or a reflected light sensor, or an ambient light sensor. A NXT light sensor can be used as a reflected or ambient light sensor. The raw sensor block doesn't have any modes, it just reads the raw sensor value. EV3 doesn't have an NXT light sensor block. If you want to use a NXT light sensor in an EV3 program you have to use the EV3 color sensor block to set the mode. If your NXT light sensor is plugged into port 3, add a EV3 color sensor block to your program and set the port to 3. Set the sensor block to measure ambient light and the NXT light sensor LED turns off. Set the sensor block to measure reflected light and the LED turns on.

Saving Calibration

Saving calibration is the biggest challenge in writing your own light sensor block(s). NXT saved calibrations as files on the NXT. Some teams with home grown calibrations do the same thing. When the program starts they read the calibration values from a file and store them in variables. When they read the light sensor they used the variables to get the bright and dark values for the calibration equation.

Some teams collected calibration values on the fly. As they drove about the mat they would collect calibration values when they knew the robot was position over a bright or dark portion of the mat. Some teams would use a default dark calibration and collect the bright calibration value as soon as the program started (making sure the sensor was over a white portion of the mat.)

A third choice is to use a default calibration. Sample raw readings for bright and dark and hardcode the numbers into you light sensor block. The values won't always be 0 and 100 for black and white, but they will be close, and with good ambient light shielding an uncalibrated light sensor can be pretty robust.”

http://forums.usfirst.org/showthread.php?20685-Older-light-sensors-on-new-EV3