Color Tracking Problems

12 replies [Last post]
NoahZinn
NoahZinn's picture
Title: NooBot
Joined: 03/11/2013
Posts:
BotPoints: 9
User offline. Last seen 4 years 41 weeks ago.

I am working on a color tracking program but i am having some difficulties. It might be something really obvious, but i just can't seem to find it. When i run the program i don't get anything on the screen.
I would like to know what is wrong.

AttachmentSize
ColorTracking.c1.31 KB

Noah Zinn

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 3 years 31 weeks ago.

First you have way too many blank lines separating things. It makes your code quite hard to read.
You also seem to have very strange indentation where some lines are randomly indented or less indented than those around them

You need to have #include at the top of your file if you want to use printf
You should use if{} else if{} else{} not if{} if{} else{} The way you currently have it when the blob is to the right it print out that it is to the right and that it is not in the frame.
You do not handle the case of x=80 and instead assume the object is out of the frame.

  1. // Created by noah zinn on Tue December3 2013
  2.  
  3. int main()
  4.  
  5. int x, y, color=0; //sets all variables to 0
  6. camera_open(LOW_RES);
  7. while(side_button()==0) //while the a button isn't pressed
  8. {
  9. if(get_object_count(color) > 0) // If the right color is detected, run this code
  10. {
  11. x = get_object_center(color,0).x;
  12. y = get_object_center(color,0).y; //x and y variables now represent x and y coordinates of the biggest color blob
  13.  
  14. if(x>80) //if the x coordinate is on the right
  15. {
  16. printf("The biggest blob is on the right and the coordinates are (%d,%d)", x ,y); //prints the words
  17. }
  18. else if(x<80) //if x is on th left
  19. {
  20. printf("The biggest blob is on the left and the coordinates are (%d,%d)" , x ,y); //print the words
  21. }
  22. else
  23. {
  24. printf("no object in sight");
  25. }
  26. camera_update();
  27. }
  28. }
  29. }

There is your code with my suggested fixes. I do not have a robot so cannot test if it works.

NoahZinn
NoahZinn's picture
Title: NooBot
Joined: 03/11/2013
Posts:
BotPoints: 9
User offline. Last seen 4 years 41 weeks ago.

Thank you. I will see if it works.

Noah Zinn

NoahZinn
NoahZinn's picture
Title: NooBot
Joined: 03/11/2013
Posts:
BotPoints: 9
User offline. Last seen 4 years 41 weeks ago.

After i made the changes and compiled it, i ran the program. But it says VIDIOC_QUERYMENU: Invalid argument.
it still runs but it says that for several lines.

Noah Zinn

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 3 years 31 weeks ago.

I remember last year when I worked with the robots they did that when you initialized the camera(I couldn't find a way around it, but I didn't look to hard). As long as your program runs fine after it you're good.

ahfagg
Title: NooBot
Joined: 01/16/2013
Posts:
BotPoints: 13
User offline. Last seen 4 years 43 weeks ago.

We are seeing the same error message (printed many times), but things are otherwise working.

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 3 years 31 weeks ago.

Yeah the error doesn't affect anything with the botball color tracking library.

NoahZinn
NoahZinn's picture
Title: NooBot
Joined: 03/11/2013
Posts:
BotPoints: 9
User offline. Last seen 4 years 41 weeks ago.

The program still says "No object in sight" even when i put the object right in front of the camera and move it around to various positions.

Noah Zinn

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 3 years 31 weeks ago.

Have you checked that you calibrated the color correctly on the robot?

amoriarty
Title: NooBot
Joined: 02/22/2014
Posts:
BotPoints: 5
User offline. Last seen 3 years 42 weeks ago.

I have the latest botball software for everything. My configurations are correct in that they correctly show the object in question. Also the configuration that I am using is default. I think my coding is right but I still get this problem of "No such object 0" If you could tell me what the possible problems are that would be really helpful.

Marty Rand
Marty Rand's picture
Title: Botball Youth Advisory Council
Joined: 07/04/2009
Posts:
BotPoints: 253
User offline. Last seen 4 years 17 weeks ago.

Call camera_update() before assigning x and y.

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}