Thread: Random behavior
View Single Post
  #1   Spotlight this post!  
Unread 25-02-2006, 01:57
RedBarons RedBarons is offline
Registered User
no team
 
Join Date: Feb 2006
Location: ERIE PA
Posts: 7
RedBarons is on a distinguished road
Random behavior

I am experience some seriously "out there" behavior. I am essentially trying to get the robot into autonomous mode, drive for XXs, and shoot balls.

When I turn on the robot, nothing happens. If I hit 'reset', then the motors start spinning for XXs, and then stop (which makes me really happy: that's what I want to do ). However, if I reset the robot again, only one of the left or right drive motors may start, sometimes the robot starts shooting balls for no reason, sometimes the motors start spinning but never stop, etc. It's just driving me insane.... It seems completely undeterministic.

If you guys have any idea what's going on, let me know...

1. I use a interrupt based timer to know when to stop driving. The interrupt is handled as follows:

void Timer_1_Int_Handler()
{

static unsigned int timer1_count = 0; // initialized at compile time

// Make sure we still enforce a 50ms loop
TMR1L = 0xF4;
TMR1H = 0x24;

if (timer1_count < TIMER_1_CNT)
{
timer1_count++; // Timer1 counter incremented every 50ms
drive_period_expired = false;
}
else
{
drive_period_expired = true;
T1CONbits.TMR1ON = 0; // stop timer
PIE1bits.TMR1IE = 0; // disable interrupt
}

}


drive_period_expired is an unsigned char global variable that is initialized to false.

The timer is initialized in user_routines.c, in the user_initialization() function.

2. I am essentially trying to jumper out into autonomatic mode right off the bat in main.c:


if (statusflag.NEW_SPI_DATA)
{
Process_Data_From_Master_uP();

// ####################
// Kick start autonomous mode
// ####################
autonomous_mode = 1;

if (autonomous_mode)
{
User_Autonomous_Code();
}
}


3. In user_routines_fast, I initiate the timer (Autonom_Code_Init()) and then call a state machine (Autonom_Code_Handler())

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;

/* Initialize autonomous code */
Autonom_Code_Init();

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. */
Autonom_Code_Handler();

Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

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


Autonom_Mode_Init():
void Autonom_Code_Init()
{
T1CONbits.TMR1ON = 1; // enable timer
}


Autonom_Mode_Handler():
Essentially, if drive_period_enabled == FALSE (see step 1), then the pwms for the drive motors are set to 127, else, they are set 254.

void Autonom_Code_Handler()
{

static unsigned char autonom_state = AUTONOM_STATE_DRIVE;

switch(autonom_state)
{
case(AUTONOM_STATE_DRIVE):
pwm01 = 254; // left motor
pwm02 = 254; // right motor

// Next state
if (drive_period_expired == true)
{
autonom_state = AUTONOM_STATE_SHOOT;
}

break;

case(AUTONOM_STATE_SHOOT):
pwm01 = 127;
pwm02 = 127;

default:


break;
}

}