Can motors be efficeint without sleep?

4 replies [Last post]
firetiger5
firetiger5's picture
Title: NooBot
Joined: 05/03/2012
Posts:
BotPoints: 23
User offline. Last seen 10 years 18 weeks ago.

I recently learned that you can programe the CBC to run motors without a sleep but I was wondering if it was more efficeint and time-saving with or without sleep after it?

~ARIGATO
-From firetiger5

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.

I'm not sure I understand your question, can you provide a code example of what you're talking about?

-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

firetiger5
firetiger5's picture
Title: NooBot
Joined: 05/03/2012
Posts:
BotPoints: 23
User offline. Last seen 10 years 18 weeks ago.

alright, i was wondering if the motors would be faster and more efficient if there was a sleep or no sleep

int main()
{
mrp(1,500,2500);
mrp(3,500,2500);
bmd(1);
bmd(3);
}

or,

int main()
{
mrp(1,500,2500);
mrp(3,500,2500);
sleep(1);
bmd(1);
bmd(3);
}

would they be the same or is one of them more efficient and faster then the other?

~ARIGATO
-From firetiger5

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.

The first method is preferable. bmd is defined as follows:

  1. void block_motor_done(int motor)
  2. {
  3. if(motor < 0 || motor > 3) {
  4. printf("Motor must be 0..3\n");
  5. return;
  6. }
  7. msleep(10);
  8. //loop doing nothing while motor position move is in progress
  9. while(!get_motor_done(motor)){msleep(10);}
  10. }

As you can see, bmd already calls msleep, so there is no reason to sleep in your own code. Also, if you sleep in your own code, you might sleep longer than the motors take to move, which would delay your robot's next command.

-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

firetiger5
firetiger5's picture
Title: NooBot
Joined: 05/03/2012
Posts:
BotPoints: 23
User offline. Last seen 10 years 18 weeks ago.

Sweet, thank you so much that really helps when it comes to the whole under two minutes restriction, so thank you!

~ARIGATO
-From firetiger5