in my autonomous program I am using the color sensor in hue mode to sense the green cube and set the cubes on the base. sometimes it over-shoots sometimes under-shoots or gets it. but once it just kept turning and sensed my jeans and then finished the program. would this be because of lighting and the LED needs to be on or something else. how can I fix this?
What do you mean when you say it overshoots? I associate this term with motors, not sensors.
Have you included a color/light sensor calibration at the start of your program?
I mean it turns to far to the side for over-shooting and not turning enough for under-shooting.
And no I have not calibrated the color sensor. how can I do that?
ehhm, sensors don’t move… mostly…
Configuration depends on your programming language, but what I’d do is something like
Start program
Provide sample of colour/hue
Press button to store value
Use value for rest of program.
That way you take into account the specific lighting of the location (and hour) you use the robot.
Some programming languages have specific calibration routines…
And make sure you are using an upper and lower value for each colour and use this as a threshold that the colour must be in, i.e. the upper limit of red is x and the lower limit is y, anything in between these two values is red.
Blue and green are probably harder to tell apart than red and the other two colours.
Perhaps consider adding a distance sensor as well - the distance sensor is there purely to detect an object regardless of colour. Once detected and in position, you can use the colour sensor to read the colour. With the robot stationary, you can take a number of colour readings in a couple of seconds and compare the data to reduce errors - i.e. if you read the data 6 times in quick succession, 2 were blue and 4 were green, let’s assume the block is green based on the average.
How do i make the upper and lower value in text based robotC?
One way to do this is to use a multi-conditional statement (usually used within an if/else statement or a while loop). In the example below, the “if” statement will only execute its code if the color sensor reads a value greater than 190 AND less than 260. If the color sensor’s value is outside of that range, the if statement’s code will not execute.
Note the boolean operator AND (&&); this is used to tell the if statement to check both the left and the right side of the condition (greater than 190 AND less than 260) and only run the code if both sides are true. If either side is false, the code will not run.
//Sets a minimum (190) and maximum (260) range of color values
//If the sensor sees an object within this range of color...
if(getColorValue(colorDetector) > 190 && getColorValue(colorDetector) < 260)
{
//..this code will run.
}