track object using icreate robot

4 replies [Last post]
egyptian00
Title: NooBot
Joined: 03/31/2014
Posts:
BotPoints: 5
User offline. Last seen 8 years 27 weeks ago.

Dear botballers..

I am new here and i will be happy if you heled me in this issue:

i have to use a vision camera fixed on my icreate robot i tried to use the demo bot robot the following program worked perfectly.

/* 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
msleep(5000);
}
while(side_button() == 0) { // stop if button is pressed
camera_update();
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;
}

but when i used the programe on my icreate robot .. it doesn't work..

i changed motor(#port,speed) to work on create program using create_drive_direct( # , # )

can anyone help me or give me a programe that can let my icreate robot track an object

regards

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

Try this code

  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) { // wait for button press
  10. msleep(15);
  11. }
  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); motor(rghtmtr,high); // arc left
  17. printf("It is to the left\n");
  18. }
  19. else if(get_object_center_column(ch,0) > 95) {// if object is on right...
  20. motor(rghtmtr,low); motor(leftmtr,high); // arc right
  21. printf("It is to the right\n");
  22. }
  23. else {
  24. motor(rghtmtr,high); motor(leftmtr,high); //go straight
  25. printf("It is directly ahead\n");
  26. }
  27. }
  28. else {
  29. msleep(15);
  30. printf("We can't see it\n");
  31. }
  32. }
  33. ao(); // stop because button pressed
  34. printf("done\n"); return 0;
  35. }

It is basically the same as yours just slightly polished(and it'll keep moving if it loses the object). I'm not sure how your motor commands are working though could you explain what you mean by "i changed motor(#port,speed) to work on create program using create_drive_direct( # , # )" preferably with code as well as explaining what it is/does.

Try running this code and tell us what the output is so we can better address whatever problem is coming up.

egyptian00
Title: NooBot
Joined: 03/31/2014
Posts:
BotPoints: 5
User offline. Last seen 8 years 27 weeks ago.

thank you for your reply ... i mean that how i can use this program to work on my icreate robot .. not the demo bot robot

regards

Aly

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

everywhere you see motor(lmotor,#a);motor(rmotor,#b); change that into create_drive_direct(#a,#b); and change ao(); to create_stop(); I'm not sure on that last one I don't remember the create functions that well.

peterstrong
peterstrong's picture
Title: NooBot
Joined: 07/05/2016
Posts:
BotPoints: 12
User offline. Last seen 5 years 5 weeks ago.

if(get_object_center_column(ch,0) > 95) {// if object is on right...
motor(rghtmtr,low); motor(leftmtr,high); // arc right