Zaramel2002
10-02-2004, 12:04
I was wondering how to make the program below count the encoder then go to another step instead of ending.
Im trying to make this code my encoder program for this years robot please help.
int encoder_count = 0;
short start_counting = 0;
short end_program = 0;
void Default_Routine(void) /* default routine */
{
if((end_program != 1) && (encoder_count < 12))
/* if program has not ended
and encoder has registered
less than 20 ticks */
{
pwm01=pwm03=169; /* turn left motors forward slowly */
pwm02=pwm04=86; /* turn right motors forward slowly */
if((end_program != 2) && (encoder_count < 30))
/* if program has not ended
and encoder has registered
less than 20 ticks */
{
pwm01=pwm03=169; /* turn left motors forward slowly */
pwm02=pwm04=86; /* turn right motors forward slowly */
if((start_counting == 1) && (rc_dig_in08 == 0))
/* if sensor has seen light and now sees dark*/
{
encoder_count++; /* increment encoder count */
start_counting = 0; /* set to 0 to prevent program
from counting wedge or spoke more than once. */
}
if(rc_dig_in08 != 0) /* if sensor sees light */
{
start_counting = 1; /* set to 1 to enable program
to count a dark wedge or spoke */
}
}
else
{
pwm01=pwm02=pwm03=pwm04=127; /* stop */
end_program = 1; /* end program */
}
printf("%d\n" , rc_dig_in08 ); /* print IR Reflective Sensor readings */
} /* END Default_Routine(); */
Im trying to make this code my encoder program for this years robot please help.
int encoder_count = 0;
short start_counting = 0;
short end_program = 0;
void Default_Routine(void) /* default routine */
{
if((end_program != 1) && (encoder_count < 12))
/* if program has not ended
and encoder has registered
less than 20 ticks */
{
pwm01=pwm03=169; /* turn left motors forward slowly */
pwm02=pwm04=86; /* turn right motors forward slowly */
if((end_program != 2) && (encoder_count < 30))
/* if program has not ended
and encoder has registered
less than 20 ticks */
{
pwm01=pwm03=169; /* turn left motors forward slowly */
pwm02=pwm04=86; /* turn right motors forward slowly */
if((start_counting == 1) && (rc_dig_in08 == 0))
/* if sensor has seen light and now sees dark*/
{
encoder_count++; /* increment encoder count */
start_counting = 0; /* set to 0 to prevent program
from counting wedge or spoke more than once. */
}
if(rc_dig_in08 != 0) /* if sensor sees light */
{
start_counting = 1; /* set to 1 to enable program
to count a dark wedge or spoke */
}
}
else
{
pwm01=pwm02=pwm03=pwm04=127; /* stop */
end_program = 1; /* end program */
}
printf("%d\n" , rc_dig_in08 ); /* print IR Reflective Sensor readings */
} /* END Default_Routine(); */