Hello. Our team (and many others at the St. Lous regional) are having a puzzling dilemma. Our robot suddenly decided to scale the speeds differently between autonomous and teleoperated periods. For example, the robot, when set to 255 on all drive pwms will go like a bat out of heck during the driver period. But, during the first 15 seconds, the robot does not go near as fast, where 255 on all drive pwms only makes the robot go to a turtle’s pace.
When we test the robot in the pits, the code works great. It seems only to happen during the competion :(.
The lapcounter putting out interfering IR has been disproved because I tried setting the code to ignore IR imput. It didn’t change anything.
There could be a myriad of things wrong, but it seems like it would be a code problem. Not to sound pessimistic, but I don’t know if anyone knows the solution. However, a suggestion of what might be wrong , or at least a place to look for the problem, is appreciated.
Here is my user_routines_fast.c:
/*******************************************************************************
* 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"
#include "user_Serialdrv.h"
#include "reflex.h"
/*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/
int recti9[2] = {0,0};
int recti10[2] = {0,0};
int recti11[2] = {0,0};
int recti12[2] = {0,0};
int count = 0;
int start = 1;
unsigned int second = 0;
int pushed = 0;
/*******************************************************************************
* 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. */
else
{
CheckUartInts(); /* For Dynamic Debug Tool or buffered printf features. */
}
}
/*******************************************************************************
* 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
*******************************************************************************/
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;
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. */
//pwm01 = left
//pwm02 = right
printf("notsafe.hex\r");
switch (second)
{
case 0:
pwm01 = 255 - 255;
pwm02 = 255;
UP;
break;
case 1:
pwm01 = 255 - 220;
pwm02 = 220;
break;
/* case 2:
pwm01 = 255 - 176;
pwm02 = 197;
break;
case 3:
//pwm01 = 255 - 170;
//pwm02 = 150;
pwm01 = 255- 136;
pwm02 = 156;
break;
case 4:
pwm01 = 255 - 136;
pwm02 = 156;
// pwm01 = 255 - 176;
// pwm02 = 197;
break;
case 5:
printf("\r commencing auto turn\r");
pwm01 = 255 - 200;
pwm02 = 150;
break;
case 6:
//I am not sure what should happen now.
//should it be turning, or should it stop now?
if (count <= 19)
{
pwm01 = 255 - 176;
pwm02 = 197;
relay1_fwd=1;
relay1_rev=0;
}
else
{
pwm01 = 127;
pwm02 = 127;
}
break;
case 7:
if(count <= 22)
{
pwm01 = 255 -210;
pwm02 = 160;
break;
}
else
{
pwm01 = 127;
pwm02 = 127;
}
case 8:
pwm01 = 255 - 200;
pwm02 = 160;
break;
case 9:
pwm01 = 255-200;
pwm02 = 160;
break;
*/
default:
pwm01 = 127;
pwm02 = 127;
break;
}
if (rectify(rc_dig_in09, &recti9[0], &recti9[1], SENSI) == 1 )
{
//enter
pushed = 1;
}
else if((rectify(rc_dig_in12, &recti10[0], &recti10[1], SENSI) == 1) || (pushed == 2))
{
//left
pushed = 2;
}
else if((rectify(rc_dig_in11, &recti11[0], &recti11[1], SENSI) == 1) || (pushed == 3))
{
//right
pushed = 3;
}
else if((rectify(rc_dig_in10, &recti12[0], &recti12[1], SENSI) == 1) || (pushed == 4))
{
pushed = 4;
//forward, reverse the robot
}
else if((rc_dig_in09 + rc_dig_in10 + rc_dig_in11 + rc_dig_in12) >= 2)
{
printf("The rc board is broken");
pwm01 = 127;
pwm02 = 127;
}
//makes the input constant until changed.
if(pushed == 1)
{
pwm01 =255 - 255;
pwm02 = 255;
}
else if( pushed == 2)
{
pwm01 = 255 - 200;
pwm02 = 60;
}
else if(pushed == 3)
{
pwm01 = 255 - 60;
pwm02 = 200;
}
else if(pushed == 4)
{
pwm01 = 255 - 60;
pwm02 = 80;
}
else
{
pwm01 = 127;
pwm02 = 127;
}
if ((count/36) == 1)
{
count = 0;
second = second + 1;
}
count = count + 1;
printf("count = %d, second = %d\r pwm01 = %d, pwm02 = %d", count, second, pwm01, pwm02);
/* if((count/36) >= DELAY && pushed == 0)
{
pwm01 = 127;
pwm02 = 127;
}
*/
// printf("end pwm01 (left) = %d, pwm02 (right) = %d\r, count = %d, case = %d", pwm01, pwm02, count, count/36);
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. */
}
/*******************************************************************************
* FUNCTION NAME: Serial_Char_Callback
* PURPOSE: Interrupt handler for the TTL_PORT.
* CALLED FROM: user_SerialDrv.c
* ARGUMENTS:
* Argument Type IO Description
* -------- ---- -- -----------
* data unsigned char I Data received from the TTL_PORT
* RETURNS: void
*******************************************************************************/
void Serial_Char_Callback(unsigned char data)
{
/* Add code to handle incomming data (remember, interrupts are still active) */
}
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
rectify() takes a pulsing signal and returns a constant (rectified) one.
It is in reflex.c.
I will post it if asked.
On behalf of the St. Louis regional teams and 1208, thanks.