Using msleep to pause execution of the code

4 replies [Last post]
Millburn1
Title: NooBot
Joined: 02/04/2013
Posts:
BotPoints: 22
User offline. Last seen 10 years 6 weeks ago.

Hello:

For some reason, the msleep(int) function isn't working in the install of Kiss IDE.

IDE version 4.0.4, with a 2D simulator built in on Windows 7.

Our code (in C):


#ifndef _test1_H_
#define _test1_H_

int main()
{
printf("started");
motor(0,50);
motor(2,50);
msleep(5000);
printf("about to return 0");
return 0;
}

#endif

What happens in the simulator is that it prints out started, the robot turns on for barely a moment, stops, and then prints out about to return 0. Everything is almost instantaneous.
What we want is the robot to move forward at 50% power for 5 seconds, then stop. It works with a loop when a variable is incremented up to a maximum, but that doesn't run in a specified unit of time, rather a specified unit of number.

Is there an import we're missing or something?

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

First why do you have your main in a header, and if its not a header why does it have a shield (#ifndef) at the top?

I'm not sure about your problem with msleep though. I have a team meeting later today and I'll see if its working for me then.

Millburn1
Title: NooBot
Joined: 02/04/2013
Posts:
BotPoints: 22
User offline. Last seen 10 years 6 weeks ago.

Actually, even if we remove the header, and cut the code down to this:

int main()
{
printf("started");
motor(0,0);
motor(2,0);
msleep(4000);
return 0;
}

it still won't work on Windows.
Surprisingly on the Mac OSX Kiss IDE v 4.0.4, the same exact code functions properly.

Beta
Beta's picture
Title: The Magnificent
Joined: 02/24/2012
Posts:
BotPoints: 266
User offline. Last seen 9 years 16 weeks ago.

This issue has been corrected in KISS Platform 4.0.5. We will be releasing KISS 4.0.5 on Wednesday night. As a workaround:


void fixed_msleep(unsigned long msecs)
{
while(msecs) {
const unsigned long current = msecs > 999UL ? 999UL : msecs;
msleep(current);
msecs -= current;
}
}
.......
fixed_msleep(5000);

Braden McDorman

Developer of the KIPR Link, KISS IDE, KIPR's 2D Simulator, and CBCJVM.

Reach me at bmcdorman(cat)kipr(dog)org where (cat)=@ and (dog)=. if you need assistance of any kind.

ted90
Title: NooBot
Joined: 04/07/2016
Posts:
BotPoints: 12
User offline. Last seen 7 years 8 weeks ago.

Thanks guys, helped found what he was looking!