View Single Post
  #15   Spotlight this post!  
Unread 30-04-2010, 15:28
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,801
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Older FRC autonomous code

Quote:
Originally Posted by johncap100 View Post
by the way i am opening up the user-routine_fast.c to modify the autonomous code is that correct?
That means you're using the IFI default code rather than the Watson default code.

You'll need slightly different handling for that just because the framework structure is different. In user_routines_fast.c in the Autonomous() routine already there you'll want to keep some of the default code it uses. Below the lines in black are what you should already see in that default routine, and the lines in red are what need to be added. Really the critical part that's missing is the Getdata that tells the robot when autonomous mode is over and Putdata that sends your motor settings out to be used. Without that nothing would ever happen.

Code:
void User_Autonomous_Code(void)
{
 static int counter=0; //keep track of loops to use as a crude timer - static keeps it around from call to call
 static int autostate=1;   //keep track of what step we're supposed to be doing

  /* 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;

  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! */
 
        // Drive forward, turn, return, and stop

        switch (autostate)
        {
    case 1:   // Drive forward
       pwm01 = pwm02 = 200;
        pwm03 = pwm04 = 54;  //motor is reversed
       if (counter>38)  //1 second
        {  
           autostate = 2;  // move on to the next step
           counter = 0;    // reset our timer for the next step
        }
        break;
 
    case 2:   // Turnaround
        pwm01 = pwm02 = 200;
        pwm03 = pwm04 = 200;  //motor is reversed
        if (counter>76)  //2 seconds
        {  
           autostate = 3;
           counter = 0;
        }
        break;

 
    case 3:   // Drive forward (returning now)
        pwm01 = pwm02 = 200;
        pwm03 = pwm04 = 54;  //motor is reversed
        if (counter>38)  //1 second
        {  
           autostate = 4;
           counter = 0;
       }
       break;

 
     case 4:   // Stop - What to do when everything else is done
     default:  // also what to do if an invalid autostate occurs
 
       pwm01 = pwm02 = pwm03 = pwm04 = 127;   // Make sure the last thing you do is always stop
  }
  counter++;

        Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  }
}

__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 30-04-2010 at 15:36.