Thank you so much! Mark and Foster ! I seem to get the idea of controlling the timer , but the 18.5 milisecond loop is really an enigma to me, like, how did they come up with the number 18.5ms (in the code that Mark provided me there is also an if loop and it was also stated /* 18.5ms loop area */ how did you know that?)and how will we know that the code that I've written had exceeded 18.5ms
But anyway right now I've moved on, I'm using the sensors! Using Limit Switch Sensors and Bumper Sensors
and here is what I did the first time
Code:
static int counter=0;
static int signal=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 = 127;
pwm05 = pwm06 = pwm07 = pwm08 = 127;
pwm09 = pwm10 = pwm11 = pwm12 = 127;
while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 18.5ms loop area */
{
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */
/* Add your own code here. */
pwm02=100;
pwm03=155;
counter= ++counter ;
if(counter>541){
pwm02=127;
pwm03=127;
}
signal=Get_Analog_Value(rc_ana_in02);
if (signal!=0){
pwm02=127;
pwm03=127;
}
printf("%2x : %2x %2x %2x %2x %2x %2x\n",(int)rxdata.rc_receiver_status_byte.allbits,
(int)PWM_in1,(int)PWM_in2,(int)pwm01,(int)pwm02,(int)pwm03,(int)pwm04);
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}
and here's what happened it was stationed initially, when I press the button the robot moved forward... which I think there is nothing wrong with that but when I tried to do the other way around
Code:
static int counter=0;
static int signal=1;
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 = 127;
pwm05 = pwm06 = pwm07 = pwm08 = 127;
pwm09 = pwm10 = pwm11 = pwm12 = 127;
while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 18.5ms loop area */
{
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */
/* Add your own code here. */
pwm02=100;
pwm03=155;
counter= ++counter ;
if(counter>541){
pwm02=127;
pwm03=127;
}
signal=Get_Analog_Value(rc_ana_in02);
if (signal=0){
pwm02=127;
pwm03=127;
}
printf("%2x : %2x %2x %2x %2x %2x %2x\n",(int)rxdata.rc_receiver_status_byte.allbits,
(int)PWM_in1,(int)PWM_in2,(int)pwm01,(int)pwm02,(int)pwm03,(int)pwm04);
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}
and it completely ignored me pressing button. What I was trying to do is let the robot move forward for 10 seconds and during the period of time I want it to stop when I pressed the botton. I understand that when I press the button it will convert the voltage at the connection point to a 10 bit (0 to 1023) value representing that voltage.And when the button is press it will generate a Electrical gound 0 voltage. I assigned a variable of type
unsigned int it should be used when reading the value. And somehow it was bypassing the the "if" loop I assigned
I've been growing so dependent on you guys...Thank you so much for your help...