Page 1 of 1

Color sensor issues

Posted: 22 May 2012, 02:42
by everst
I could use some help. I am an elementary teacher and currently am teaching a robotics unit to 4th and 5th graders. We have used the RCX kits for years and within the last couple years we have been migrating to NXT. Programming seems to be a nightmare in NXT, more so when we get to using the color and light sensors. I am not a NXT guru so I am going to ask some questions that may seem basic. Just letting you know that ahead of time.

I am really having troubles in NXT 2.0 in writing a simple training program involving a color sensor where the robot goes fwd until it finds a black line, then backs up for about 1-2 sec, then turns and goes fwd again. I am wondering if anyone can help me with this?

Also, we have a few kits with a light sensor? Ideas how to properly program using this sensor?


Later , We have a competition called the Can-Do where the robot is in a ring and knocks out cans while staying inside the ring boundaries. This was pretty easy to write in RCX, but it just isn't coming together this year in NXT.

Thanks. Any help would be appreciated.

Re: Color sensor issues

Posted: 22 May 2012, 02:56
by inxt-generation
You are using NXT-G (the software it came with), right? I know how it is. When I first started with NXT, the language seemed like a nightmare. I was used to RCX code, and a bit of NQC. But slowly (kinda) I learned it, mastered it, and have now moved on to RobotC.

Anyway, back to your question.

NXT-G has many more capabilities than RCX code, which may seem intimidating at first, but aren't that hard to get. You might want to check out one of the NXT-G programming books. I can give you a couple of sample programs to do what you mentioned if you want.

What exactly do you not understand? What's not working? Can you give some examples of what you've tried? It's easier to give help if you explain your problem better.

Re: Color sensor issues

Posted: 22 May 2012, 03:16
by everst
Thanks for the quick reply. While I don't have all the mindstorms kit with me, I have attached the simple program I wrote just to intro the sensor to my students. No loops yet introduced. Seems like it should work, but won't just want it to go fwd, sense black line, back away and turn. Take a look and see what you think. Thanks again.

Re: Color sensor issues

Posted: 22 May 2012, 03:28
by inxt-generation
Actually, you do have it in a loop, but that should just make it repeat the action "go forward till black, back up, and turn". This code is fine except for one thing: You color sensor block. I assume you want it in Light Sensor mode, right? Cause' that's how it is now. Now, here's your problem: The color sensor block you had is meant for reading the sensor. It has "plugs" that extend from the bottom that pass the readings on to other "plugs" via "wires" on other blocks. But, we needn't go in to that now. Anyway, your problem should be fixed by replacing the previous sensor block with a "wait until" block set to color sensor, and lower than 50. The attached program should be fixed.

Re: Color sensor issues

Posted: 22 May 2012, 03:35
by everst
I really appreciate your help. I definitely learned something new. I won't be able to test it until I get back to class tomorrow, but am anxious to give it a whirl. I may be back on here with a few more questions in the near future. Thanks again.

Re: Color sensor issues

Posted: 22 May 2012, 03:43
by cpapple123
Try This. I just added a step before the Loop to turn on the Light. I'm new the the whole Mindstorm community so I Have no prior habits to break. I have seen on some Follow the line sample people state that the light sensor takes some time to turn on. Also put the sensor in light sense mode using red light.

Re: Color sensor issues

Posted: 22 May 2012, 03:53
by everst
Thanks! Now I can sleep tonight a bit knowing I have some solutions to try out tomorrow with my students.

Re: Color sensor issues

Posted: 22 May 2012, 14:47
by everst
Got it to work! At first it didn't. I swapped out the color sensor for another, and then it worked fine.

Another question, for kits with just the light sensor (instead of color sensor) how would I configure my program? See attached files. Thanks.

Re: Color sensor issues

Posted: 22 May 2012, 19:39
by tabbycatrobots
I found several good ideas for using the light and color sensors at <http://www.nxtprograms.com/>, "Fun
Projects for your LEGO® MINDSTORMS® NXT!". This site has some interesting building ideas, and for some
of the models, there is NXT-G code. The building ideas are listed by NXT kit type, 1.0, 2.0, or 9797
(Educational Kit), and the NXT 1.0 has the light sensor and the NXT 2.0 has the color, so this may help.
The "Line Follower" for NXT 1.0 uses the light sensor. I found the LineFollowPro program and the light
sensor calibration program to be helpful. Although I normally program in NXC, I found the ideas in these
programs to be helpful, and translated parts of the NXT-G code to NXC. In the NXT 2.0 section , the
ColorRace program, for the race car, may have some ideas you can use for your robot - seeing colored lines
on the floor and reacting. And this is a paragraph from the instructions for the race car:
"You may also need to change the colors used in the program to adjust for the color of your floor and
markers used. To test which color the car sees over various surfaces, use the View -> Color feature
in the NXT brick menu and roll the car over various surfaces."
I found this to be very true. The light sensor on a robot may react differently to black tape vs. black
paint vs. black marker, depending on the lighting in the room, or if sunlight is coming through the
windows. This isn't a big problem, if you are aware of it, and do a little testing with different colors
and lighting, i.e. 20 minutes of testing prevents a failure in front of 20 3rd graders. (I'm a reading
volunteer in an elementary school, and sometimes take my robots in for demos.) Off on a tangent,
the book "Robo World the story of robot designer Cynthia Breazeal" by Jordan D. Brown may be of interest
to your 5th graders.

Re: Color sensor issues

Posted: 22 May 2012, 23:05
by everst
Thanks for the great info. I will take a look!