Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   More automonous help:ending stuff (http://www.chiefdelphi.com/forums/showthread.php?t=27129)

gnormhurst 30-03-2004 23:21

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)
}


Tom Saxton 31-03-2004 02:00

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.

gnormhurst 31-03-2004 09:41

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!

Robohawk-master 01-04-2004 21:29

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


All times are GMT -5. The time now is 22:26.

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