I'll post the entire file.. but there's a new problem. I'm not sure anymore what to call a "line" of code, seeing as a friend of mine pointed out to me that, when counting code lines, I should ignore the comments, just as the compiler does. So I went back to count comment lines, and lo and behold... there weren't enough lines (the way I counted them) to justify a 'line 111'. *hangs head in shame* and now we see the depth of her ignorance. *sigh* anywho. If anyone could clarify just
what constitutes a line of code, it'd be much appreciated.
So... onto business. Here's the entire code:
Code:
/*******************************************************************************
* FILE NAME: user_routines_fast.c <FRC VERSION>
*
* DESCRIPTION:
* This file is where the user can add their custom code within the framework
* of the routines below.
*
* USAGE:
* You can either modify this file to fit your needs, or remove it from your
* project and replace it with a modified copy.
*
* OPTIONS: Interrupts are disabled and not used by default.
*
*******************************************************************************/
#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
/*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/
/*******************************************************************************
* FUNCTION NAME: InterruptVectorLow
* PURPOSE: Low priority interrupt vector
* CALLED FROM: nowhere by default
* ARGUMENTS: none
* RETURNS: void
* DO NOT MODIFY OR DELETE THIS FUNCTION
*******************************************************************************/
#pragma code InterruptVectorLow = LOW_INT_VECTOR
void InterruptVectorLow (void)
{
_asm
goto InterruptHandlerLow /*jump to interrupt routine*/
_endasm
}
/*******************************************************************************
* FUNCTION NAME: InterruptHandlerLow
* PURPOSE: Low priority interrupt handler
* If you want to use these external low priority interrupts or any of the
* peripheral interrupts then you must enable them in your initialization
* routine. Innovation First, Inc. will not provide support for using these
* interrupts, so be careful. There is great potential for glitchy code if good
* interrupt programming practices are not followed. Especially read p. 28 of
* the "MPLAB(R) C18 C Compiler User's Guide" for information on context saving.
* CALLED FROM: this file, InterruptVectorLow routine
* ARGUMENTS: none
* RETURNS: void
*******************************************************************************/
#pragma code
#pragma interruptlow InterruptHandlerLow save=PROD /* You may want to save additional symbols. */
void InterruptHandlerLow ()
{
unsigned char int_byte;
if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) /* The INT2 pin is RB2/DIG I/O 1. */
{
INTCON3bits.INT2IF = 0;
}
else if (INTCON3bits.INT3IF && INTCON3bits.INT3IE) /* The INT3 pin is RB3/DIG I/O 2. */
{
INTCON3bits.INT3IF = 0;
}
else if (INTCONbits.RBIF && INTCONbits.RBIE) /* DIG I/O 3-6 (RB4, RB5, RB6, or RB7) changed. */
{
int_byte = PORTB; /* You must read or write to PORTB */
INTCONbits.RBIF = 0; /* and clear the interrupt flag */
} /* to clear the interrupt condition. */
}
/*******************************************************************************
* FUNCTION NAME: User_Autonomous_Code
* PURPOSE: Execute user's code during autonomous robot operation.
* You should modify this routine by adding code which you wish to run in
* autonomous mode. It will be executed every program loop, and not
* wait for or use any data from the Operator Interface.
* CALLED FROM: main.c file, main() routine when in Autonomous mode
* ARGUMENTS: none
* RETURNS: void
*******************************************************************************/
int counter = 0;
short end_program = 0;
void User_Autonomous_Code(void)
{
/* 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;
/* program note: pwm01 and pwm02 are the WHEEL MOTORS. pwm03 and pwm04 are the ARM MOTORS.
there is no piston used on the robot. */
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! */
if(end_program ! = 1) /* if program has not ended */
{
counter++; /* increment counter approx. 60 times per second */
if(counter < 121) /* if less than 2 seconds have passed */
{
pwm01=pwm02=pwm03=pwm04=127; /* stop */
}
else if(counter > 120 && counter < 240) /* if 2-4 seconds have passed */
{
pwm01=155; /* right motor forward */
pwm02=27; /* left motor backward */
pwm03=pwm04=127; /*arm motors off */
}
else if(counter > 240 && counter < 360) /* if 4-6 seconds have passed */
{
pwm01=pwm02=pwm03=127; /* stop */
pwm04=200; /* upper arm joint raises */
}
else if(counter > 360 && counter < 480) /* if 6-8 seconds have passed */
{
pwm01=pwm02=pwm03=127; /* stop */
pwm04=0; /* upper arm joint lowers */
}
else if(counter > 480 && counter < 600) /* if 8-10 seconds have passed */
{
pwm01=27; /* right motor backward */
pwm02=155; /* left motor forward */
pwm03=pwm04=127; /* stop */
}
else if(counter > 600 && counter < 720) /* if 10-12 seconds have passed */
{
pwm01=pwm02=155; /* both wheel motors forward */
pwm03=pwm04=127; /* stop */
}
else if(counter > 720 && counter < 780) /* if 12-13 seconds have passed */
{
pwm01=155; /* right motor forward */
pwm02=27; /* left motor backward */
pwm03=pwm04=127; /* stop */
}
else if(counter > 780 && counter < 900) /* if 13-15 seconds have passed */
{
pwm01=pwm02=155; /* wheels forward */
pwm03=pwm04=127; /* stop */
}
else /* if more than 15 seconds have passed */
{
pwm01=pwm02=pwm03=pwm04=127; /* stop */
end_program = 1; /* end program */
}
}
Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}
/*******************************************************************************
* FUNCTION NAME: Process_Data_From_Local_IO
* PURPOSE: Execute user's realtime code.
* You should modify this routine by adding code which you wish to run fast.
* It will be executed every program loop, and not wait for fresh data
* from the Operator Interface.
* CALLED FROM: main.c
* ARGUMENTS: none
* RETURNS: void
*******************************************************************************/
void Process_Data_From_Local_IO(void)
{
/* Add code here that you want to be executed every program loop. */
}
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/