Color Tracking Issue

11 replies [Last post]
TheClaymore
Title: NooBot
Joined: 12/06/2013
Posts:
BotPoints: 26
User offline. Last seen 7 years 28 weeks ago.

So I used the the code from the workshop and I can't get it to run. It prints about 10 lines of "VIDIOC_QUERYMENU: Invalid argument", and then prints the "Press B button when ready." Pressing the B button doesn't have any effect. Any help would be appreciated.


/* Move the robot towards the largest object on channel 0.
Robots stops if no object is detected*/
int main()
{
int ch = 0, leftmtr = 0, rghtmtr = 3; // identify channel and motors
int high = 100, low = -10; // set wheel powers for arc radius
camera_open();
printf("Move towards object on channel 0\n");
printf("Press B button when ready\n\nPress side button to stop\n");
while(b_button() == 0) { // wait for button press
}
while(side_button() == 0) { // stop if button is pressed
if(get_object_count(ch) > 0) { // if object is seen...
if(get_object_center_column(ch,0) < 65) { // if object is on left...
motor(leftmtr,low); motor(rghtmtr,high); // arc left
}
else {
if(get_object_center_column(ch,0) > 95) {// if object is on right...
motor(rghtmtr,low); motor(leftmtr,high); // arc right
}
else {
motor(rghtmtr,high); motor(leftmtr,high); //go straight
}
}
}
else {
ao();
}
}
ao(); // stop because button pressed
printf("done\n"); return 0;
}

nzaman
Title: Software Engineer @ KIPR
Joined: 02/12/2014
Posts:
BotPoints: 12
User offline. Last seen 8 years 24 weeks ago.

Don't worry about the "VIDIOC_QUERYMENU: Invalid argument" messages, as long as it stops printing eventually.

Your program never calls camera_update(), so camera functions like get_object_count(ch) have no image to work with. You should update anytime you want a new image from the camera.

Nafis Zaman

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

First you have some pretty terrible formatting of your code that makes it hard to check.
I'm not sure if it helps, but I added an msleep(5) to the loop so that there is some processing time.
You are also missing camera_update() in your while loop.

  1. /* Move the robot towards the largest object on channel 0.
  2. Robots stops if no object is detected*/
  3. int main(){
  4. int ch = 0, leftmtr = 0, rghtmtr = 3; // identify channel and motors
  5. int high = 100, low = -10; // set wheel powers for arc radius
  6. camera_open();
  7. printf("Move towards object on channel 0\n");
  8. printf("Press B button when ready\n\nPress side button to stop\n");
  9. while(b_button() == 0){
  10. msleep(5);
  11. }// wait for button press
  12. while(side_button() == 0) { // stop if button is pressed
  13. camera_update();
  14. if(get_object_count(ch) > 0) { // if object is seen...
  15. if(get_object_center_column(ch,0) < 65) { // if object is on left...
  16. motor(leftmtr,low);
  17. motor(rghtmtr,high); // arc left
  18. }
  19. else if(get_object_center_column(ch,0) > 95) {// if object is on right...
  20. motor(rghtmtr,low);
  21. motor(leftmtr,high); // arc right
  22. }
  23. else {
  24. motor(rghtmtr,high);
  25. motor(leftmtr,high); //go straight
  26. }
  27. }
  28. else {
  29. ao();
  30. }
  31. }
  32. ao(); // stop because button pressed
  33. printf("done\n"); return 0;
  34. }

That is your formatted code with the change I suggested

TheClaymore
Title: NooBot
Joined: 12/06/2013
Posts:
BotPoints: 26
User offline. Last seen 7 years 28 weeks ago.

Thanks for the replies, the code is copied and pasted directly from the 2014 workshop slides, and I'm not sure how to keep the formatting. (Though I did use code HTML tag). I tried adding the "camera_update();" command, and even tried copying the code you gave me with no different results.

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

Are you certain left and right motor is plugged in correctly? look at the code for the port numbers they should be plugged into.

EDIT: If that doesn't work try commenting out the while loop for the b_button and just see if the movement code works.

TheClaymore
Title: NooBot
Joined: 12/06/2013
Posts:
BotPoints: 26
User offline. Last seen 7 years 28 weeks ago.

The motors are plugged correctly, and we tried commenting out the b_button loop, and it had the same result except without printing the line about the b_button (of course). We also tried using the Rumba as well as the Link just in case, and neither worked.

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

Does it just sit there doing nothing or does the program end right away?

TheClaymore
Title: NooBot
Joined: 12/06/2013
Posts:
BotPoints: 26
User offline. Last seen 7 years 28 weeks ago.

Without the B Button loop it just prints about 10 lines of "VIDIOC_QUERYMENU: Invalid argument", and then does nothing. So it must not be reaching the "printf("done\n");" part of the code.

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

try changing ao(); to msleep(5); and are you certain the camera is calibrated to the right color?

EDIT: Here is some code that will give us more information on what is going wrong.

  1. /* Move the robot towards the largest object on channel 0.
  2. Robots doesn't change movement if it loses the object*/
  3. int main(){
  4. int ch = 0, leftmtr = 0, rghtmtr = 3; // identify channel and motors
  5. int high = 100, low = -10; // set wheel powers for arc radius
  6. camera_open();
  7. printf("Move towards object on channel 0\n");
  8. printf("Press B button when ready\n\nPress side button to stop\n");
  9. while(b_button() == 0){
  10. msleep(5);
  11. }// wait for button press
  12. while(side_button() == 0) { // stop if button is pressed
  13. camera_update();
  14. if(get_object_count(ch) > 0) { // if object is seen...
  15. if(get_object_center_column(ch,0) < 65) { // if object is on left...
  16. motor(leftmtr,low);
  17. motor(rghtmtr,high); // arc left
  18. printf("Object to the left\n");
  19. }
  20. else if(get_object_center_column(ch,0) > 95) {// if object is on right...
  21. motor(rghtmtr,low);
  22. motor(leftmtr,high); // arc right
  23. printf("Object to the right\n");
  24. }
  25. else {
  26. motor(rghtmtr,high);
  27. motor(leftmtr,high); //go straight
  28. printf("Object dead ahead!\n");
  29. }
  30. }
  31. else {
  32. printf("No object found\n");
  33. }
  34. }
  35. ao(); // stop because button pressed
  36. printf("done\n"); return 0;
  37. }

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 7 years 18 weeks ago.

@TheClaymore: Just for reference, enclose C code in < c > rather than < code > (without spaces), so that it displays properly. It's a quirk in the forum software.

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

TheClaymore
Title: NooBot
Joined: 12/06/2013
Posts:
BotPoints: 26
User offline. Last seen 7 years 28 weeks ago.

That code works fine, thanks so much! :)