Bricxcc, NXC, Color Sensor, NXT 2.0
Bricxcc, NXC, Color Sensor, NXT 2.0
Hi,
I am trying to get the code from Mr Hansen's book for the line follower to work with the new color sensor in NXT 2.0. Has anyone been able to make the new robot follow the black line using the new color sensor instead of the old light sensor? Is there any NXC sample code to do this. My robot follows the line a little then it just does other things.
Thanks for the help,
I am trying to get the code from Mr Hansen's book for the line follower to work with the new color sensor in NXT 2.0. Has anyone been able to make the new robot follow the black line using the new color sensor instead of the old light sensor? Is there any NXC sample code to do this. My robot follows the line a little then it just does other things.
Thanks for the help,
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bricxcc, NXC, Color Sensor, NXT 2.0
Please post a code snippet of your usage of the color sensor. Although it took me some time to determine how to use it properly in NXC, it is actually quite simple.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Re: Bricxcc, NXC, Color Sensor, NXT 2.0
Here is a code snippet of where I make the motors do something depending on the color value.
switch (SV){
case INPUT_BLACKCOLOR: // 1
OnFwd(OUT_A, FAST_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_BLUECOLOR: // 2
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_GREENCOLOR: // 3
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_YELLOWCOLOR: // 4
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_REDCOLOR: // 5
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_WHITECOLOR: // 6
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, FAST_SPEED);
break;
default : write = "unknown: ";
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
}
switch (SV){
case INPUT_BLACKCOLOR: // 1
OnFwd(OUT_A, FAST_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_BLUECOLOR: // 2
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_GREENCOLOR: // 3
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_YELLOWCOLOR: // 4
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_REDCOLOR: // 5
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
break;
case INPUT_WHITECOLOR: // 6
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, FAST_SPEED);
break;
default : write = "unknown: ";
OnFwd(OUT_A, SLOW_SPEED);
OnFwd(OUT_C, SLOW_SPEED);
}
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: Bricxcc, NXC, Color Sensor, NXT 2.0
a) You really ought to use the "code" control when you are posting here.
b) What is the definition of "sv"? That is, how did you set up the sensor?
b) What is the definition of "sv"? That is, how did you set up the sensor?
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
Re: Bricxcc, NXC, Color Sensor, NXT 2.0
To use the color sensor like the NXT 1.0 light sensor you configure it using SetSensorColorRed(port) and then read its value using SENSOR_n where "n" is 1..4 depending on which port you have the sensor attached to. In this case you would get a value from 0 to 100 which you can use after calibrating what value is returned directly over white and what value is returned directly over black. You could also use the raw value in this mode by calling SensorRaw(port). Using the color sensor for line following like you might have previously used the NXT 1.0 light sensor works best when you configure the sensor in this manner. If you configure the color sensor as a full color sensor using SetSensorColorFull(port) then you would get a color number back by reading its value using SENSOR_n (as before) but I think you will have a much harder time trying to use the sensor in this mode as a line following sensor. The device is slower in full color mode and when you deviate off of the black line you would get a shade of grey rather than true black or true white which could cause you all sorts of trouble in your code.
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: Bricxcc, NXC, Color Sensor, NXT 2.0
Thank you so much Mr. Hansen. This is very helpful. I will try this and will let you know if I have further questions. Your book has been very helpful, by the way. I also found your Bricxcc tool very helpful.
Cheers
Cheers
Re: Bricxcc, NXC, Color Sensor, NXT 2.0
I am interested in this thread since, as a very new user, I have been having similar problems (challenges!).
I found that if I use SetSensorColorFull(S3); then I can read the light value with code like
On the other hand, if I use SetSensorColorRed(S3); then to get a meaningful light value, I need to use light = SensorRaw(S3); and I don't get any meaningful values from ReadSensorColorRaw.
Are there some examples of code for using this sensor anywhere around please?
I found that if I use SetSensorColorFull(S3); then I can read the light value with code like
- int light, RawColor[];
ReadSensorColorRaw(S3, RawColor);
light = RawColor[3];
On the other hand, if I use SetSensorColorRed(S3); then to get a meaningful light value, I need to use light = SensorRaw(S3); and I don't get any meaningful values from ReadSensorColorRaw.
Are there some examples of code for using this sensor anywhere around please?
Re: Bricxcc, NXC, Color Sensor, NXT 2.0
I am still working through the old line-follower code. It is very tricky. I did find this sample code. I believe that it is NXC but have not tried it yet. I also do not know if it applies to the default color sensor. Try it at your own risk, of course.
http://www.techbricks.nl/downloads/line ... 20NXT2.nxc
http://www.techbricks.nl/downloads/line ... 20NXT2.nxc
Re: Bricxcc, NXC, Color Sensor, NXT 2.0
Does anyone know if it matters which way the color sensor is facing? Does it matter if it is put at the front of the robot versus the rear of the robot?
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Bricxcc, NXC, Color Sensor, NXT 2.0
SensorRaw returns the RAW ADC value of the sensor port (of pin 1). AFAIK, the color sensor doesn't even have connection to that pin. With a color sensor, the value should always be 1023.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Who is online
Users browsing this forum: Semrush [Bot] and 0 guests