X2 is resetting itself

I am using the servo.h and servo.c files to run servos from the X2. I was successful getting my servo to turn clockwise and counter-clockwise separately, however, when I tried to get the servo to turn one way for a period of time and then the opposite direction, the X2 appears to reset itself without allowing the second turn to execute. Why is this? And how do I fix it?

while ( !checkForButton() )
		{
	unsigned char broom;

	// Some loop variables
	unsigned char i;

	// Initialize the servo system
	servo_init();

	// Define our servos to use DC6 and DC7, respectively
	broom  = servo_define(_SFR_IO_ADDR(DDRC), _SFR_IO_ADDR(PORTD), 7);
	servo_active(broom);
	servo_set(broom, 1200);		//Sweep block in
		for(i = 0; i < 5; i++)
			{
				delay_ms(400);
			}
//X2 RESETS ITSELF RIGHT HERE!!!
	servo_set(broom, 1600);		//Replace broom properly
		for(i = 0; i < 5; i++)
			{
				delay_ms(400);
			}

Hello.

Can you describe how you are connecting your servos to your Orangutan X2, how you are powering them, and how are you powering your X2?

The servo.c/h files were not created by Pololu, so I’m not all that familiar with them. Still, at first glance, it seems to me that you have a mistake in your servo_define call when you send it DDRC and PORTD. I expect that the DDR and PORT should be for the same I/O bank (i.e. change your first argument to _SFR_IO_ADDR(DDRD)).

Lastly, if you want to, you can simplify your code slightly by replacing

for(i = 0; i < 5; i++)
{
delay_ms(400);
}

with

delay_ms(2000);

delay_ms() takes an unsigned integer as an argument, so the number you provide must be non-negative and no greater than 65,535.

- Ben