Go to Post Break Robot. Re-engineer. Repeat! - Mr MOE [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #16   Spotlight this post!  
Unread 30-03-2004, 23:21
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: More automonous help:ending stuff

Try this. In user_routines_fast.c replace the User_Autonomous_Code function with the function below. It's not a state machine, but it incorporates elements that you probably understand better.

All: Please check this for bugs!

Code:
void User_Autonomous_Code( void )
{
  static unsigned int Old_Clock = 0;

  static unsigned int time = 0;  // cycle counter
  
  while (autonomous_mode)
  {
    if (statusflag.NEW_SPI_DATA)
    {
      Getdata(&rxdata);   // bad things will happen if you move or delete this
      
      // Autonomous code goes here.
      
      if (Clock > Old_Clock) // stay synchronized to beacon data updates (this is important)
      {
        /////////////////////// CUSTOM CODE /////////////////////////
        if ( time < 456 )  // still less than 12 seconds have elapsed
        {

          // LINE FOLLOWING
          // there are 3 bits which means 8 combinations.  
          // only 4 are tested here. ??
          if (rc_dig_in01 == 0 && rc_dig_in02 == 0 && rc_dig_in03 == 0)
          {
            pwm13 = 127;  // stop
            pwm15 = 127;
          }
          else if (rc_dig_in01 == 0 && rc_dig_in02 == 0 && rc_dig_in03 == 1)
          {
            pwm13 = 139;  // turn one way
            pwm15 = 175;
          }
          else if (rc_dig_in01 == 1 && rc_dig_in02 == 0 && rc_dig_in03 == 0)
          {
            pwm13 = 175;  // turn the other way
            pwm15 = 139;
          }
          else if (rc_dig_in01 == 0 && rc_dig_in02 == 1 && rc_dig_in03 == 0)
          {
            pwm13 = 249;  // go straight and fast
            pwm15 = 249;
          } 
          
        }
        else if ( time < 532 )  // 12 seconds have gone by, but less than 14
        {
          // stop wheels
          pwm13 = 127;
          pwm15 = 127;
          
          // raise arm
          pwm03 = 175; 
        }
        else  // more than 14 seconds have gone by
        {
          // stop raising arm
          pwm03 = 127; 
        }
        
        time++;  //  count another cycle

        /////////////////////// END OF CUSTOM CODE /////////////////////////
        
        Old_Clock = Clock; // take a snapshot of the clock
        
      } // clock > oldclock
      
      Generate_Pwms( pwm13, pwm14, pwm15, pwm16 );
      
      Putdata(&txdata);   // even more bad things will happen if you mess with this
      
    } //  statusflag.NEW_SPI_DATA
  }  // while (auotnomous) 
}
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #17   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/
  #18   Spotlight this post!  
Unread 31-03-2004, 09:41
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: More automonous help:ending stuff

Quote:
Originally Posted by Tom Saxton
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.
I think this code is cleaner than mine -- I prefer state machines. Barry, if you can wrap your head around the state machine idea, that's the better way to go.

And Tom, thanks for pointing out that 'static' is unneccesary since it all happens in one loop for 15 seconds. It's just a habit to use a static when I want to see what the value was at the end of the previous pass.

Good luck, Barry!
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #19   Spotlight this post!  
Unread 01-04-2004, 21:29
Robohawk-master's Avatar
Robohawk-master Robohawk-master is offline
Registered User
AKA: Barry
#1109 (Robohawks)
Team Role: Operator
 
Join Date: Mar 2004
Rookie Year: 2003
Location: Lively, Ontario
Posts: 21
Robohawk-master is on a distinguished road
Wink Re: More automonous help:ending stuff

Hey Hey Hey!
I have to hand it to ya, the code did good, but it was our robot who screwed up...

I got a big tip that the line sensors power supply does NOT come from the PWM... it comes directly from the breaker. So the sensers don't have the juice to pick up anything... so useless. I found that out just before we left.

Another thing is the arm which is now removed... is useless to the winch... so no code for that useless device.
off topic but I noticed a lot of teams going for the 'fishingrod' style. I think our robot should have done that, less weight overall. So we play defence and offense.
So our now automonous code is drive like hell with our power window motors (I hate them) and plow the goal to the other end...look for my reason on this in strategy.

MY team and I reall yappreciate all the work you guys did. I wish I could have seen it in action, but if we switch back at least we can say were 'multi automonistic'
Barry

PS: I'm in the hilton business/comp. room. I've met one the official/judges (he didn't tell me) and the DIRECTOR of the whole deal. His wive is photocopying using all the complimentary stuff they have
__________________
- Barry -
-2004 Canadian Regional Semi-Finalists
-2004 Bruce Power Safety Award
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please - stop posting needless stuff! Andy Baker Announcements 0 13-01-2004 09:13
Free stuff at FIRST Not2B General Forum 7 30-09-2003 21:23
What does everyone like to do besides FIRST stuff?? Katie_269 Chit-Chat 45 17-07-2002 17:01
who can we buy stuff from?!?! archiver 2001 7 23-06-2002 23:04
How much robotics stuff is on your resumes??? Robby O Career 14 03-08-2001 19:51


All times are GMT -5. The time now is 03:09.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi