Go to Post Glad to see the CIMulators aren't vaporware after all. - thefro526 [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #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.
  #2   Spotlight this post!  
Unread 11-03-2007, 15:33
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
Re: Need help with gyro turn

int unit_speed = 50;
  #3   Spotlight this post!  
Unread 11-03-2007, 21:53
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: Need help with gyro turn

...hmmmm
Why don't you, first, try something a bit easier. Let your value of angle be the error term for your P controller. As long as your camera holds its tracking, you should see your robot turn to align to the camera and the value of angle will drive to 0. 0 error, 0 angle Then keep an eye on the value you are getting from your gyro calculations (I am assuming that by gyro, you mean yaw rate sensor, and you are integrating yaw rate to calculate an angle) There could be error creeping into your gyro calculations that is causing problems with your controller.
__________________

Don't PANIC!
S. P. A. M.
Closed Thread


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 09:31.

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