Need help Urgently (NXT COLOR SENSOR)

Discussion specific to projects ideas and support.
phoenixdancer
Posts: 6
Joined: 10 Nov 2011, 13:35

Need help Urgently (NXT COLOR SENSOR)

Post by phoenixdancer »

Hello Fellow NXT lovers.

I have an issue i am unable to solve on my own, I have tried many times but each time failed.
I have come to a stage where im actually dreaming up code to fix it in my sleep! (allways fails mind you)

Here is my issue: (im sorry if i do not make sence)

I wish to use the NXT color sensor (3 led RGB) to do the following task:
Constantly read in RGB and Ambiant light values and place into an array as follows:

int global_color[INPUT_NO_OF_COLORS];

task color_read_task()
{
TextOut(20, LCD_LINE1, "Start");
int rgb[INPUT_NO_OF_COLORS];
int normed[INPUT_NO_OF_COLORS];
int scaled[INPUT_NO_OF_COLORS];
}
}

Ok this works fine (i think) It has placed the 4 values read from the Sensor into the int global_color[] array. Perfect!

Now here is the bit im stuck on..
I want to be able to "create" two new colors seperate from the standerd 6 NXT sensors read (red, blue, black, yellow, green, white), I wish to see "Turquoise" and one called "carpet".
So i have written the following to set the RGBL values for turquoise:

bool isTerquoise()
{
int turquoise[INPUT_NO_OF_COLORS];
turquoise[INPUT_RED] = 490;
turquoise[INPUT_GREEN] = 533;
turquoise[INPUT_BLUE] = 540;
turquoise[INPUT_BLANK] = 900;

}

Now then, I know the above works and tells the robot (when its called as below) when its hit the carpet or a turquoise block...
task block_search()
{
TextOut(20, LCD_LINE2, "Block Search");
}
}

the MAJOR problem here is that the Values:
turquoise[INPUT_RED] = 490;
turquoise[INPUT_GREEN] = 533;
turquoise[INPUT_BLUE] = 540;
turquoise[INPUT_BLANK] = 900;

Are every so close to the white values:
R: 610
G: 550
B: 550
N: 110 && 990

For some odd reason the Robot says it has seen the Turquoise color when its actually still on the white mat!


I have a feeling that the values are riseing up and down all the time and in sence hit the values i dont want them to hit untill its over the block...

is there any way what so ever to fix it so that the robot can distinguish White from turquoise?

Any help is greatly appreciated.

many thanks
PD
Last edited by phoenixdancer on 16 Nov 2011, 02:09, edited 1 time in total.
hassenplug
Posts: 346
Joined: 27 Sep 2010, 03:05
Contact:

Re: Need help Urgently (NXT COLOR SENSOR)

Post by hassenplug »

I'm not sure this line is actually correct...

Code: Select all

if (((input[i] < (turquoise[i] + 30)) && (input[i] > (turquoise[i] - 30))))
won't this return true if a value IS within the range?

I think you want something like this:

Code: Select all

if (((input[i] < (turquoise[i] - 30)) || (input[i] > (turquoise[i] + 30))))
(three changes)

So the above will evaluate to true, causing the isTerquoise (isTurquoise) function to return false, if the value is NOT in the range.

I could be wrong, but that's what I think you want.

Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
phoenixdancer
Posts: 6
Joined: 10 Nov 2011, 13:35

Re: Need help Urgently (NXT COLOR SENSOR)

Post by phoenixdancer »

Hello Steve!

Many thanks for your reponse.

i think i know what you are trying to tell me here, and thanks!

I tried it and unfortunatly it started the Line follow code even when on white serface again.

I have a feeling i need to do something tottaly mad to get a correct value read and presented to my line follow task :(

If anyone else has any input im sitting here waiting :)

Best regards to all!
loopymech
Posts: 35
Joined: 30 Sep 2010, 15:35

Re: Need help Urgently (NXT COLOR SENSOR)

Post by loopymech »

Did you get this solved? If not, can you post pseudo-code for what you are trying to do?

-Loopy
phoenixdancer
Posts: 6
Joined: 10 Nov 2011, 13:35

Re: Need help Urgently (NXT COLOR SENSOR)

Post by phoenixdancer »

I don't get what u meen mate.
Do you wish to view the entire program?
im still just as stuck as i was when i made my first post.
Have tried multiple ways but i am coming to the inclusion that its not do able without that new senseor that can do 16 colours.
loopymech
Posts: 35
Joined: 30 Sep 2010, 15:35

Re: Need help Urgently (NXT COLOR SENSOR)

Post by loopymech »

Out of interest in the project you are doing, I was just wondering if you could list the steps/goals of the program in simple terms that are not language/syntax specific.

Just to confirm, you are using the Lego Color Sensor (the one that comes in the NXT 2.0 kit), right? I think you're right - the values may be jumping around a bit while you are on the white mat. And, it's possible you may have to (re)calibrate the readings according to lighting conditions, since the readings may be affected by ambient light.

It might help to grab some samples from the sensor while static (not moving) and see if the numbers are stable over time. Another test would be to see if there is noise from the motors or power variations that 'bleed' into your sensor readings (perhaps power the motors with the tires lifted off the floor).

-Loopy



p.s. just noticed...not sure it matters, but NXC seems to want the raw and normalized to be 'unsigned int'.

Code: Select all

int ReadSensorColorEx  ( const byte &  port,  
  int &  colorval,  
  unsigned int &  raw[],  
  unsigned int &  norm[],  
  int &  scaled[]   
 )   [inline] 
phoenixdancer
Posts: 6
Joined: 10 Nov 2011, 13:35

Re: Need help Urgently (NXT COLOR SENSOR)

Post by phoenixdancer »

Hi there.

I have a list of tasks that the robot is set to do :

Placed anywhere on the mat, it should wander / move around looking for the start of the track
(indicated by the Turquoise block). It must avoid going off the mat onto the carpet.
• During the search it must ignore the track and any other coloured blocks.
• If an obstacle is detected off the line, the robot must move backwards a little, turn away from
the obstacle and start to search again for the start of the track.
• Once the start is found, it should follow the track till the end.
• If an obstacle is detected while following the line, the robot must move backwards a little,
and try to go around the obstacle to continue following the line.

I have managed to have most of the requirements under wraps Apart from the Obstacle avoidance (not to hard) and useing more colors that are pre-set.

I am indeed useing the colour sensor that comes with the NXT 2 kit as seen here: http://botbench.com/blog/wp-content/upl ... .jpg?w=250

My understanding when it comes to reading in values it gives: Red, Green, Blue, Value
"Value" is what im presumeing to be light values, i have tried adding them into the array and to be compared yet still it detects turquiose when on a white surface.

I have taken most of my readings when the robot is static and the values can jump around in a range for example:
Red: 287-328
Green: 323-349
blue: 492 - 541
Light: 110-990

Those are real reading, i cannot tell u for which colour they were taken but they did bounce around when on a single colour.

The Robot travels on tracks, causes it to vibrate much more then if it was on a set of wheels i may try altering the robot for a much smoother ride.

hmm im not sure if it does matter about the unsigned int, i would have expected it to behave the same with a bool value.

Just to say this, Im new to programing, this is my first real project with an NXT and so far causeing a headache.

Im very close to just buying the new color sensor and useing that in my project, and setting its values to the colors i want (if that possible, sure i read online that is it..).

thanks again for your help
hassenplug
Posts: 346
Joined: 27 Sep 2010, 03:05
Contact:

Re: Need help Urgently (NXT COLOR SENSOR)

Post by hassenplug »

I would suggest you create a simple program to display True or False from the IsTurquoise function. Don't have the robot move, just display if it matches the values you have listed.

That should help you debug the problem.

At the same time, I would have it display the actual values it's getting.

The bottom line is that you should be able to use the "red" value to tell if it's turquoise or white (looking at the numbers you have). If that's not working, there's something still wrong with the code.

If the bouncing of the robot is causing a problem, I'd have the robot move until it thinks it's on turquoise, then stop, wait a short amount of time (1/2 sec), and check again.

Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Need help Urgently (NXT COLOR SENSOR)

Post by h-g-t »

Have you tried looking at code examples in techbriks, nxtlog, etc to see how these compare with yours?

I have never used the colour sensor but believe that you should 'initialise' it before taking readings - have you done that?

It would help if you post your actual code here so that the experts can examine it.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
phoenixdancer
Posts: 6
Joined: 10 Nov 2011, 13:35

Re: Need help Urgently (NXT COLOR SENSOR)

Post by phoenixdancer »

Im will do what hassenplug suggested tomorrow.

I should have created such a debug program from the start -.- how simple minded of me!
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests