NXT Light Sensor intensity Value

Hi All,
Loving my BrickPi so far and have got a few simple projects running including some of the samples and am now moving onto some more complex projects.

I’m currently trying to build a robot that can follow a line as a example to some students that we run a programming challenge for using the NXT bots, as a example to what we have planned for next years challenges.

I’m trying to use the the NXT colour sensor to get the light intensity but I have been unable to get any value out that looks like the intensity value using the TYPE_SENSOR_RAW, TYPE_SENSOR_LIGHT_OFF, TYPE_SENSOR_LIGHT_ON, TYPE_SENSOR_COLOR_FULL or TYPE_SENSOR_RCX_LIGHT sensor modes. The only result I got was from TYPE_SENSOR_COLOR_FULL which gave out the value 1, which from what I understood meant it saw black, this was when I was testing with multiple colours. I have also checked the sensor using the NXT block and it seems to still work on that. Is there something I am missing or is this not yet available in the libraries.

I’m currently programming the BrickPi using the C library as that is the one I’m most comfortable with but I am able to switch to one of the other languages if that is what is needed. It is also being powered by both the Micro USB port on the Pi and the 9V input on the BrickPi using 6x1.5V AA batteries. The Sensors I have attached are:

NXT Light Sensor in port 1
NXT UltraSonic Sensor in port 2
NXT Touch Sensor in port 3

3xNXT Motors attached to Ports A, B and C

The code I have so far is available at http://github.com/jamesptanner/BrickPi-LineFollow/blob/master/LineFollow.c
(its probably a little over engineered for what is needed but I’ve been converting code that I had thrown together in the LEGO block language so it made sense to keep the threads in.)

Nevermind, took another shot in the dark and tried TYPE_SENSOR_COLOR_NONE. I seems to be getting good values out for that, and now only have to debug my own code.

Keep up the good work.

Hey entity8817,
First, thanks for the question. Next, thanks for answering the question!

If you have any thoughts about how to make the C library easier to use, or complaints (but no idea how to address them) please let us know. We would love any feedback on how to make it easier to use.

Double thanks again for your posts!

No problem.

I think the only suggestion that I can make about the library would be to have the #defines documented inside the header with what the value returned is, range, etc, nothing huge, just the basics. It is useful having the examples showing exactly how to use them, but having the basic info in the header as well saves having to search for an example of what you want when all you really want is a memory prod.

On another note how would I get the rotation angle value out of the the motors? its not a massive issue if it isn’t doable, but I haven’t seen any way to use the motors as a rotational sensor like they can be on the NXT.

TYPE_SENSOR_LIGHT_<OFF, ON> is for the NXT light sensor (not the NXT color sensor), in one of two modes (ambient, or reflected).

TYPE_SENSOR_RCX_LIGHT is for using a Lego RCX light sensor (with an NXT <> RCX adapter cable).

TYPE_SENSOR_COLOR_<FULL, RED, GREEN, BLUE, NONE> is for a Lego NXT color sensor, in one of 5 modes.

In mode TYPE_SENSOR_COLOR_FULL, the color number will be stored in BrickPi.Sensor[port] (where port is PORT_<1, 2, 3, 4>), and the raw ADC values for the 4 measurements will be stored in BrickPi.SensorArray[port][index] (where index is INDEX_<RED, GREEN, BLUE, BLANK>.

In modes TYPE_SENSOR_COLOR_<RED, GREEN, BLUE, NONE> (not FULL), the LED will light according to the color specified (red, green, blue, or off), and the raw ADC value of the sensor will be stored in BrickPi.Sensor[port].

For motor encoder values, you can read the variable BrickPi.Encoder[port], where the port is PORT_<A, B, C, D>.

You can add to or subtract from the encoder value using the variable BrickPi.EncoderOffset[port]. If you want to reset the encoder value to 0, you can use something like this BrickPi.EncoderOffset[port] = BrickPi.Encoder[port];

Thanks for that mattallen37. It has certainly cleared up how the light and colour sensor work. My problem seemed to stem from confusing my colour sensor with a light sensor which i hadn’t realised existed. :S
And thanks for explaining the offsets, may have to try something with that soon.