View Single Post
  #30   Spotlight this post!  
Unread 03-05-2010, 10:44
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,926
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

Sorry, I just guessed wrong about how you've put your code together looking over your virtual shoulder...
The error you got meant the compiler couldn't find your Autonomous routine-"void Autonomous(void) {".
It'll be something simple, like my leaving out the keyword "void".

There are lots of different ways to do this, so here's a template for one way.
I assume you are doing all your work in the file user_routines.c
This is only one way to integrate the code from posts 20 and 14.

Code:
/*******************************************************************************
* FILE NAME: user_routines.c <FRC VERSION>
*
* DESCRIPTION:
*  This file contains the default mappings of inputs  
*  (like switches, joysticks, and buttons) to outputs on the RC.  
*
* USAGE:
*  You can either modify this file to fit your needs, or remove it from your 
*  project and replace it with a modified copy. 
*
*******************************************************************************/
#include <stdio.h>
#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
#include "user_Serialdrv.h"
 
extern unsigned char aBreakerWasTripped;
 
// Drive forward, turn, return, and stop
 
void Autonomous(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
 
  switch (autostate)
  {
      case 1:   // Drive forward
                   pwm01 = 200;
                   pwm02 = 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 = 200;
                   pwm02 = 200;  //motor is reversed
                   if (counter>76)  //2 seconds
                   {  
                       autostate = 3;
                       counter = 0;
                   }
                   break;
 
 
      case 3:   // Drive forward (returning now)
                   pwm01 = 200;
                   pwm02 = 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 = 127;   // Make sure the last thing you do is always stop
  }
   counter++;
}
 
/*******************************************************************************
* FUNCTION NAME: Limit_Switch_Max
* PURPOSE:       Sets a PWM value...
 
... (etc)
 
void Process_Data_From_Master_uP(void)
{
  static unsigned char i;
 
  Getdata(&rxdata);   /* Get fresh data from the master microprocessor. */
 
    if (p1_sw_trig == 1)
   {
      Autonomous();
   }
   else 
        Default_Routine();  /* Optional.  See below. */
 
... (etc.)
You can also put the Autonomous routine way down at the bottom of the user_routines.c file, and then you'd need that prototype statement up at the top to warn and prepare the compiler about what any calls must look like (if the call comes before the compiler has seen the routine) .
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 03-05-2010 at 14:05.