View Single Post
  #7   Spotlight this post!  
Unread 09-02-2005, 20:30
ak_Knight ak_Knight is offline
Gee
#1219 (Iron Eagles)
 
Join Date: Jan 2004
Location: Toronto
Posts: 5
ak_Knight is on a distinguished road
Re: Example gyro code released.

Hi,
i used your gyro code with a ADXRS300. The user_routines.c executes pretty good, the gyro bias is mostly stable there is almost no change in angle. But the autonomous mode is giving us a lot of trouble. I am trying to accomplish two tasks, one give robot an angle and have to turn, like turn(90) and it should turn 90 degree, The other thing is being able to go in a straight line with out drifting. But after about 2-3 seconds in the autonomous i encounter an runtime error( the program state starts blinking red). Here is my user_routines_fast.c please take a look and help me out.

Quote:
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. */

if (counter < sec(2) )
{
move_Forward();
}
else if( counter < sec(4) )
{
pause();
}
else
{
turn_Right(200);
}

counter++;

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) */
}



/************************************************** ****************************
/USER FUNCTIONS/
************************************************** ****************************/


/************************************************** ****************************
* FUNCTION NAME: move_Forward, move_Backward, pause
* PURPOSE: Routine handling (name speaks for it self)
* CALLED FROM: user_routines_fast.c
* ARGUMENTS: none
* RETURNS: none
************************************************** ****************************/
void move_Forward(void)
{
set_Right(160);
set_Left(94);
}

void move_Backward(void)
{
set_Right(94);
set_Left(160);
}

void pause(void)
{
set_Right(127);
set_Left(127);
}

void set_Right(int value)
{
pwm13=value;
pwm14=value;
}

void set_Left(int value)
{
pwm15=value;
pwm16=value;
}

/************************************************** ****************************
* FUNCTION NAME: sec
* PURPOSE: Handles the program loop so that we work in terms of seconds.
* CALLED FROM: user_routines_fast.c
* ARGUMENTS:
* Argument Type Description
* -------- ---- -----------
* number_of_seconds int The amount of seconds to be converted
* RETURNS: INT
************************************************** ****************************/
int sec( int number_of_seconds)
{
return number_of_seconds*38;
}




void turn_Right(int angle)
{

int temp_gyro_rate= Get_Gyro_Rate();
int temp_gyro_bias= Get_Gyro_Bias();
int temp_gyro_angle = (int)Get_Gyro_Angle();

if ( ((int)Get_Gyro_Rate) > angle)
{
Reset_Gyro_Angle();
}

while( temp_gyro_angle < angle )
{
set_Right(160);
set_Left(127);

temp_gyro_rate= Get_Gyro_Rate();
temp_gyro_bias= Get_Gyro_Bias();
temp_gyro_angle = (int)Get_Gyro_Angle();

printf("Gyro Bias=%d\r", temp_gyro_bias);
printf("Gyro Rate=%d\r", temp_gyro_rate);
printf("Gyro Angle=%d\r", temp_gyro_angle);
printf("Gyro Required Angle=%d\r", angle);
printf("--------------%d\r");

}
}
__________________
<--Gee-->
Emery Robotics