Hi, I'm trying to get two Lego color sensors to proportionally follow a line, AND tell me what color it is seeing. I remember in ROBOTC 2.16.1, (the first version supporting the color sensor) there was a sample program that demonstrated this. It showed what color the sensor was seeing , plus it showed the raw peg counts the sensor was reading. Now that I have upgraded to 3.05, the sample program is VERY simple, just showing the color it is seeing.

Can anybody either give me the old sample code, or explain to me how to use the raw peg counts. (I can find no documentation on it) Any help will be greatly appreciated, THANKS!

--mr64bit

EDIT: sorry, my bad. They're not peg counts, it's the AtoD values. I am not sure what that stands for though, but I know it works!

_________________--mr64bit

Last edited by mr64bit on Tue Jan 31, 2012 1:15 pm, edited 1 time in total.

Wow, thanks a million! (now, if I can figure out how it works!)Just a little background, I am doing this for ION's Mini Urban Challenge. http://www.ion.org/outreach/muc/ I am part of a four man team from my local Christian school. I wanted the peg count ability so that I could use a proportional line follower, AND tell which color the line is. That matters, because while most lines are white, there are some yellow lines, (meaning your robot has to go slower) and blue lines. (parking spots) Thanks again for the help, this will be invaluable!

Well, here is my code so far. I got the light sensors working perfectly now, THANKS! I am a somewhat new programmer, so any tips/advice/ constructive criticism on compacting code, optimizing and combining and the like would be most appreciated.

Here are some tips:Use a lot more comments than you do now. Don't comment the obvious like "button 2 pressed", rather explain what the function is doing. If a particularly tricky piece of code requires a little explanation, you can add some text there, too.Below the pragmas, add a bit of text to tell the reader what your program is doing, I usually put something like this in my test programs:

/** * MSTMUX-driver.h provides an API for the Mindsensors Touch Sensor MUX. This program * demonstrates how to use that API. * * Changelog: * - 0.1: Initial release * * Credits: * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this. * * License: You may use this code as you wish, provided you give credit where it's due. * * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 2.00 AND HIGHER. * Xander Soldaat (mightor_at_gmail.com) * 11-May-2010 * version 0.1 */

You may not have credits or a license, but you get the idea.Don't use tasks unless you really, really need them. Your task sensors and motors are not necessary. A single task should be more than enough for your line follower:

Yeah, the while(true) was for debugging, as was several other lines that were commented out. Got those out now. (variable mix up) Yeah, I know I should be commenting more, but I find it easier to do after I finish at least a piece of code. I am doing the line by line commenting some places, because I am also teaching three even newer programmers. The motor task will have much more in it, for controlling the motor speeds using inputs from the speed limit and US sensor. How is the sensor task not necessary? The task Main is not repeating all of itself continually, so I either have it as a task, of put it in more than once. Or is there some other way?

The sensor task is not necessary because you can just read the sensors at the top of your loop and use those values. It takes less than a few ms to go through your entire loop, so you're not going to miss valuable information unless you're going at 1m/s.

You need to rework your program. You need a single while loop that does the things I put in my previous post. Trying to teach tasks to new programmers is not recommended as it's a very advanced topic and takes quite a bit of work to do correctly. So for now, keep your program simple and use a single task to do everything.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum