Go to Post math can actually be fun! - Karthik [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 11-03-2007, 15:26
magical hands magical hands is offline
Jigar Patel
AKA: Jigar Patel
FRC #2185 (Etobicoke CI)
Team Role: Mentor
 
Join Date: Dec 2003
Rookie Year: 2004
Location: TORONTO
Posts: 93
magical hands is on a distinguished road
Need help with gyro turn

I have gyro onto the robot. As soon as i get the angle from the cam. I want my gyro to turn exactly at that angle. so for e.g. my pan angle is 34 degrees than i want my robot to turn 34 degree. However, my Gyro just can't do that. Can someone help me how can i code it so it turns the angle i want it to turn? this is what i have.

/********VARIABLE*******/
int unit_speed = 50;
/*********************/

angle = ((((int)PAN_SERVO - 124) * 65)/124); /* +/- 65 degree [0 to 148] */
error_angle = (angle - (int)temp_gyro_angle); /*Check the angle difference between camera and Gyro*/
printf("Error_angle=%d\r\n", error_angle); /*Print Error Angle*/

if (error_angle < -5) /*If Error angle is less than 5 degrees*/
{
speed = ((error_angle * unit_speed)/100); /*PID Forumula to control the speed as we move close to target*/
printf("Target is to the left\r\n"); /*Prints if target is to left*/

while(speed > 5)
{
pwm13 = pwm14= 127; /*Turning Left and the turn is controlled, see below comment*/
pwm15 = pwm16 = 127 + speed; /*The motor movements are controlled by the PID Speed Calculated*/

printf("PWM 13=%d pwm14=%d pwm14=%d pwm15=%d\r\n", (int)pwm13, (int) pwm14, (int) pwm15, (int) pwm15); /*Printing motor values for Debugging*/
printf("Speed=%d\r\n", speed); /*Tells us what is the value of speed according to PID Calculation*/
}
}


if (error_angle > 5) /*If Error angle is greater than 5 degrees*/
{
speed = ((error_angle * unit_speed)/100); /*PID Formula to control the speed as we move close to the target*/
printf("Target is to the right\n"); /*Prints that the target is to right*/

while(speed > 5)
{
pwm13 = pwm14 = 127 + speed; /*Turning Right and the turn is controlled, see below comment*/
pwm15 = pwm16 = 127; /*The motor movements are controlled by the PID Speed Calculated*/

printf("PWM 13=%d pwm14=%d pwm14=%d pwm15=%d\r\n", (int)pwm13, (int) pwm14, (int) pwm15, (int) pwm15); /*Printing motor values for Debugging*/
printf("Speed=%d\r\n", speed); /*Tells us what is the value of speed according to PID Calculation*/
}
}

if (error_angle > -5 && error_angle < 5) /*If the error angle is between -5 degree and + 5 degree*/
{
printf("Target is straight on"); /*Prints that we are right on target*/
pwm13 = pwm14= pwm15 = pwm16 = 127; /*Stops our motor for a while*/
printf("PWM 13=%d pwm14=%d pwm15=%d pwm16=%d \r\n", (int)pwm13, (int) pwm14, (int) pwm15, (int) pwm16); /*Printing motor values for Debugging*/
printf("Speed=%d \r\n", speed); /*Tells us what is the value of speed according to PID Calculation*/

Last edited by magical hands : 11-03-2007 at 15:34.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
KOP Gyro seems to run-on after turn stops PhilBot Control System 8 05-03-2007 12:43
Need help with Gyro = Analog Devices ADXRS150EB Jack Jones Technical Discussion 9 18-07-2005 07:00
With gyro need to access ADC for poteniometer mrozek Programming 0 21-02-2005 13:39
hey need some help with writing a code please help me here magical hands Programming 9 01-01-2004 21:46
Help with the gyro chip Team852 Electrical 1 10-01-2003 22:31


All times are GMT -5. The time now is 00:20.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi