Get robot to move for certain amount of time

7 replies [Last post]
Owl
Title: NooBot
Joined: 01/22/2012
Posts:
BotPoints: 13
User offline. Last seen 10 years 33 weeks ago.

Hello there I'm new to Botball and C programming in general, and I can't seem to get the robot to move for a certain amount of time. I tried this in the simulator, but the robot doesn't move at all. Any help would be appreciated.

int main()
{
while (get_motor_position_counter(0) < 300);
{
mav(3,100);
mav(0,100);
}
return 0;
}

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.

300 ticks isn't very far... could it be that the robot moves but you just don't see it move the small distance? Any chance you could try this code on a CBC with 2 motors plugged in?

-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

amehta
Title: NooBot
Joined: 07/18/2011
Posts:
BotPoints: 136
User offline. Last seen 5 years 32 weeks ago.

Try getting rid of the semicolon on the "while" line... I tried your code out in the simulator (IDE 3.0.0) and it seemed to work. Your new code should look like this:

int main()
{
while (get_motor_position_counter(0) < 300)
{
mav(3,100);
mav(0,100);
}
return 0;
}

Hope it helps!

-amehta (Andrew Mehta)

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.

Andrew is correct, that is definitely the problem. Not sure how I missed that....

-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

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

All you're doing is equivalent to mrp. You could just put:

  1. int main()
  2. {
  3. mrp(0,1000,300);
  4. mrp(3,1000,300);
  5. bmd(0);
  6. bmd(3);
  7. return 0;
  8. }

where mrp moves motors 0 and 3 at full speed (out of 1000) for 300 ticks

bmd waits for the program to finish moving the motors before going to the next line of code

There are about 1100 ticks in a wheel rotation (not exact)

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}

Owl
Title: NooBot
Joined: 01/22/2012
Posts:
BotPoints: 13
User offline. Last seen 10 years 33 weeks ago.

Thanks MarsEdge. I've found your technique to be more useful and efficient than clearing the motor positions everytime I want to move. Thank you.

Owl
Title: NooBot
Joined: 01/22/2012
Posts:
BotPoints: 13
User offline. Last seen 10 years 33 weeks ago.

Thanks MarsEdge. I've found your technique to be more useful and efficient than clearing the motor positions everytime I want to move. Thank you.

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

Sure thing!

FYI: I forgot to mention that if you want the motor to go backward, make the distance negative.

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}