3pi turns off too fast to program

Hello,
I’m just starting to play around with program the motors of the 3pi, and had input the following sketch, very simply to move the robot forward a tiny amount.

#include <OrangutanMotors.h>
OrangutanMotors motors;
unsigned long prevMillis = 0;
int Beatlength=250;
int Speed = 128;

void frontStep(int beats)
{
  motors.setSpeeds(Speed,Speed);
  delay(beats*Beatlength);
}

void setup()               // run once, when the sketch starts
{
}

void loop()                // run over and over again
{
frontStep(4);
}

I compiled using the Arduino software version 0012, having made the modifications necessary to use it to program the Orangutang as suggested, and uploaded using the Orangutang programmer. I should add, I have been able to upload numerous other example sketches multiple times with no problem.

And this one, too, loaded just fine. The problem now is that when I power up the 3Pi, the motors move forward for a tiny bit of time, then the robot powers down. This does not give me enough time to reprogram with the next iteration of the sketch, no matter how closely I try to time the upload/turn-on sequence. Any way I can regain control of the robot? Also, by the way, why isn’t the frontStep command repeated over and over again?

Thanks,
Rich

Hello,
The only way that your 3pi should be powering down is if you are low on batteries. Have you checked the battery voltage?
-Paul

Aha! Nice fresh set of batteries, problem solved!

Thanks!
- Rich

Hello, Rich.

I’m glad to hear you got the problem solved.

As a word of warning, if you notice that your 3pi is turning off unexpectedly, do not attempt to program it until you have recharged the batteries or replaced them with a fresh set. If the power cuts out in the middle of programming, there is a chance that the microcontroller will get its fuses misconfigured and will become unresponsive. This isn’t a common problem, but it has happened before.

- Ben