View Single Post
  #12   Spotlight this post!  
Unread 31-03-2004, 02:00
Tom Saxton's Avatar
Tom Saxton Tom Saxton is offline
Registered User
no team (Issaquah Robotics Society)
Team Role: Mentor
 
Join Date: Dec 2003
Rookie Year: 2003
Location: Sammamish, WA
Posts: 98
Tom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud of
Re: More automonous help:ending stuff

OK, here's my take on what's been said, with some minor refinements and details. I took the original code, re-arranged a bit to put it into a state machine (and fix the problem where sensor readings could lock out the code that does the end game), then plopped it all into the User_Autonomous_Code function from the default FIRST code in user_routines_fast.c.

I also added in the loop counter in the right spot and used the constants to give the transitions at 12 and 14 seconds. Since autonomous mode just spins in the one function, there's no reason to mess with global (or static) variables.

Code:
enum
{
	stateFollowLine,
	stateRaiseArm,
	stateDone
};

void User_Autonomous_Code(void)
{
	int count; /* number of times through the "slow" loop */
	int state; /* current state */

	/* Initialize all PWMs and Relays when entering Autonomous mode, or else it
	 will be stuck with the last values mapped from the joysticks.  Remember, 
	 even when Disabled it is reading inputs from the Operator Interface. 
	*/
	pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
	pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;
	relay1_fwd = relay1_rev = relay2_fwd = relay2_rev = 0;
	relay3_fwd = relay3_rev = relay4_fwd = relay4_rev = 0;
	relay5_fwd = relay5_rev = relay6_fwd = relay6_rev = 0;
	relay7_fwd = relay7_rev = relay8_fwd = relay8_rev = 0;
	
	count = 0;
	state = stateFollowLine;
	
	while (autonomous_mode)   /* DO NOT CHANGE! */
	{
		if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
		{
			Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */
			
			/* Add your own autonomous code here. */
			switch (state)
			{
			case stateFollowLine:
				/* we're trying to follow the line */
				if (rc_dig_in01 == 0 && rc_dig_in02 == 0 && rc_dig_in03 == 0)
				{
					pwm13 = 127;
					pwm15 = 127;
				}
				else if (rc_dig_in01 == 0 && rc_dig_in02 == 0 && rc_dig_in03 == 1)
				{
					pwm13 = 139;
					pwm15 = 175;
				}
				else if (rc_dig_in01 == 1 && rc_dig_in02 == 0 && rc_dig_in03 == 0)
				{
					pwm13 = 175;
					pwm15 = 139;
				}
				else if (rc_dig_in01 == 0 && rc_dig_in02 == 1 && rc_dig_in03 == 0)
				{
					pwm13 = 249;
					pwm15 = 249;
				}
				
				/* time to advance the next state? */
				if (count > 457)
					state = stateRaiseArm;
				break;
			
			case stateRaiseArm:
				/* now stop the robit, raise the arm */
				pwm13 = 127;
				pwm15 = 127;
				pwm3 = 175;

				/* time to advance the next state? */
				if (count > 534)
					state = stateDone;
				break;
			
			case stateDone:
				/* all stop */
				pwm13 = 127;
				pwm15 = 127;
				pwm3 = 127;
				break;
			}
			
			Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
			
			Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
			
			++count; // increment once every 26.3 milliseconds
		}
	}
}
In our code, we raised the arm at the beginning of autonomous, so if we got to the right spot (by dead reckoning, using encoders), the ball would drop. In case we were a little off, at the end we wiggled back and forth a little, enough to knock our ball off if we were close, but hopefully not enough to knock the opposing ball.

To do that, just add a few more states to turn left and right a couple of times.

Enjoy.
__________________
Tom Saxton
http://www.idleloop.com/