jaywion
19-03-2004, 09:51
[/FONT][/SIZE][/COLOR]I need help with my code, its not working so far in Autonomous mode. We didn't have one at Reginals and want one for nationals please tell me whats wrong with my code.
void User_Autonomous_Code(void)
{
//A handy-dandy macro to convert a number of seconds into a number of 26.2ms ticks
#define SECS_TO_TICKS(a) ( ((long)(a)) * (long)10000 / (long)262 )
//And milliseconds too:
#define MSECS_TO_TICKS(a) ( ((long)(a)) * (long)10 / (long)262 )
/* 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;
tickCount=0;
AUTO_STATE = AUTO_FIRST_STATE;
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. */
printf("In auto mode ");
tickCount++; //tickCount contains the number of 26.2ms "ticks" since the start of the current step
switch (AUTO_STATE)
{
case AUTO_FIRST_STATE:
printf ("First, we go forward for 3 secz %d", (int)tickCount);
pwm13 = 127+100;
pwm15 = 127+100;
printf ("in auto first state pmw13= %d\n",(int)pwm13);
if(tickCount >= SECS_TO_TICKS(1))
{
AUTO_STATE = AUTO_FINISHED; //AUTO_SECOND_STATE;
tickCount = 0;
}
break;
case AUTO_SECOND_STATE:
pwm13 = 127 + 50; pwm15 = 127;
if(tickCount >= SECS_TO_TICKS(3))
{
AUTO_STATE = AUTO_THIRD_STATE;
tickCount = 0;
}
break;
case AUTO_THIRD_STATE:
relay3_fwd=1;
pwm01 = 127; pwm02 = 127;
if(tickCount >= SECS_TO_TICKS(3))
{
AUTO_STATE = AUTO_FOURTH_STATE;
tickCount = 0;
}
break;
case AUTO_FINISHED:
pwm13 = pwm15 = 127;
tickCount=0;
break;
default:
pwm01 = pwm02 = 127;
tickCount=0;
}// end switch
printf("READY to Put Data pwm13 = %d pwm 15=%d/n",(int)pwm13, (int)pwm15);
DisplayBufr( &rxdata ); // Print the 26 bytes received from the Master processor.
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}// end if
}// end while
}// end User_Autonomous_Code
void User_Autonomous_Code(void)
{
//A handy-dandy macro to convert a number of seconds into a number of 26.2ms ticks
#define SECS_TO_TICKS(a) ( ((long)(a)) * (long)10000 / (long)262 )
//And milliseconds too:
#define MSECS_TO_TICKS(a) ( ((long)(a)) * (long)10 / (long)262 )
/* 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;
tickCount=0;
AUTO_STATE = AUTO_FIRST_STATE;
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. */
printf("In auto mode ");
tickCount++; //tickCount contains the number of 26.2ms "ticks" since the start of the current step
switch (AUTO_STATE)
{
case AUTO_FIRST_STATE:
printf ("First, we go forward for 3 secz %d", (int)tickCount);
pwm13 = 127+100;
pwm15 = 127+100;
printf ("in auto first state pmw13= %d\n",(int)pwm13);
if(tickCount >= SECS_TO_TICKS(1))
{
AUTO_STATE = AUTO_FINISHED; //AUTO_SECOND_STATE;
tickCount = 0;
}
break;
case AUTO_SECOND_STATE:
pwm13 = 127 + 50; pwm15 = 127;
if(tickCount >= SECS_TO_TICKS(3))
{
AUTO_STATE = AUTO_THIRD_STATE;
tickCount = 0;
}
break;
case AUTO_THIRD_STATE:
relay3_fwd=1;
pwm01 = 127; pwm02 = 127;
if(tickCount >= SECS_TO_TICKS(3))
{
AUTO_STATE = AUTO_FOURTH_STATE;
tickCount = 0;
}
break;
case AUTO_FINISHED:
pwm13 = pwm15 = 127;
tickCount=0;
break;
default:
pwm01 = pwm02 = 127;
tickCount=0;
}// end switch
printf("READY to Put Data pwm13 = %d pwm 15=%d/n",(int)pwm13, (int)pwm15);
DisplayBufr( &rxdata ); // Print the 26 bytes received from the Master processor.
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}// end if
}// end while
}// end User_Autonomous_Code