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;
}
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 likeget_object_count(ch)
have no image to work with. You should update anytime you want a new image from the camera.Nafis Zaman
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.
That is your formatted code with the change I suggested
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.
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.
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.
Does it just sit there doing nothing or does the program end right away?
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.
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.
@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
That code works fine, thanks so much! :)