Go to Post Everyone has regrets in robotics- it's how you learn from them that makes all the difference. - Kevin Leonard [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 30-11-2009, 20:25
Straberrie's Avatar
Straberrie Straberrie is offline
The Plague
AKA: Rebecca
FRC #0375 (Robotic Plague)
Team Role: Programmer
 
Join Date: Feb 2008
Rookie Year: 2007
Location: New York
Posts: 59
Straberrie will become famous soon enough
Gyro Programming

Hi, how are you?

I am trying to get gyros to work and I never programmed the sensor before, so I made use of the FIRST programming guide to implement gyros in the autonomous period.

Quote:
Gyro *gyro;
gyro = new Gyro (1);

gyro->Reset();
gyro->SetSensitivity(.005);

float angle = gyro->GetAngle();

myRobot->Drive(-1.0, -angle / 30);
Wait(4.0);
According to the guide, the above should have corrected the robot's path and set it to match the heading of the original angle. Since the original angle was 0, it should have went straight.

However, when we tested it on the robot, it immediately made a sharp turn.

In order to see what is happening with the angle values, I created an if statement

Quote:
float angle = gyro->GetAngle();

if (angle<0.5)
{
myRobot->Drive(1.0, 0.0);
Wait(0.0);
}
else
{
myRobot->Drive(0.0, 0.0);
Wait(0.0);
}
And it stood, I switched the statements around, and the robot didnt move either. So, I am wondering what I did wrong and how I can make the robot follow a straight path.

Any help would be appreciated,

Thank you!

__________________
Team 375: The Robotic Plague
Current Robot: I-Chihuahua
Last Event: Big Apple Breakaway
  #2   Spotlight this post!  
Unread 30-11-2009, 22:20
biojae's Avatar
biojae biojae is offline
Likes Omni drives :)
AKA: Justin Stocking
FTC #5011 (BOT SQUAD) && FTC#72(Garage bots)&& FRC#0399 (Eagle Robotics)
Team Role: College Student
 
Join Date: Oct 2008
Rookie Year: 2008
Location: Lancaster
Posts: 276
biojae is a jewel in the roughbiojae is a jewel in the roughbiojae is a jewel in the rough
Re: Gyro Programming

Code:
if (angle<0.5)
{
myRobot->Drive(1.0, 0.0);
Wait(0.0);
}
else
{
myRobot->Drive(0.0, 0.0);
Wait(0.0);
}
if there is any sort of noise, or movement of the robot,
then the angle will be larger then 0.5,
when that happens, the robot will just sit where it is without moving
( like you said)

What I would do is make a PID controller (I don't know how to use WPI's)
sortof like this:
Code:
float desiredHeading = 0;
float speed = 0.5;

const float P = .5; // You will need to tune these values 
const float I  = 0.0; // as they are just made up
const float D = 0.0;

float headingIntegral = 0.0;
float prevHeadingError = 0.0;

void autonomousPeriodic()
{
    float heading = fmod(gyro->GetHeading(), 360.0); // limit to + - 360 // EDIT: forgot the denominator
    float headingError = (desiredHeading - heading);
    headingIntegral += headingError;
    float headPID = (P * headingError) +
                              (I * headingIntegral) +
                                  (D * (headingError - prevHeadingError));
    prevHeadingError = headingError;
    myRobot->TankDrive(speed + headPID, speed - headPID);
}
The speed variable is the forward movement that you want

The real advantage of this method as opposed to the wpi example is that you can set any heading you want
(At least within the range of - 360 to 360)

Just remember to tune the PID
__________________
FTC Team 72 - No site
FRC Team 399 - http://www.team399.org
2010 Rockwell Collins Innovation in Control Award - (Use of the CAN bus, among other reasons) Phoenix, Arizona!

Last edited by biojae : 01-12-2009 at 22:07.
  #3   Spotlight this post!  
Unread 01-12-2009, 04:56
Straberrie's Avatar
Straberrie Straberrie is offline
The Plague
AKA: Rebecca
FRC #0375 (Robotic Plague)
Team Role: Programmer
 
Join Date: Feb 2008
Rookie Year: 2007
Location: New York
Posts: 59
Straberrie will become famous soon enough
Re: Gyro Programming

oh wow O.O XD Thank you so much!!!
__________________
Team 375: The Robotic Plague
Current Robot: I-Chihuahua
Last Event: Big Apple Breakaway
  #4   Spotlight this post!  
Unread 01-12-2009, 22:15
biojae's Avatar
biojae biojae is offline
Likes Omni drives :)
AKA: Justin Stocking
FTC #5011 (BOT SQUAD) && FTC#72(Garage bots)&& FRC#0399 (Eagle Robotics)
Team Role: College Student
 
Join Date: Oct 2008
Rookie Year: 2008
Location: Lancaster
Posts: 276
biojae is a jewel in the roughbiojae is a jewel in the roughbiojae is a jewel in the rough
Re: Gyro Programming

Quote:
Originally Posted by Straberrie View Post
oh wow O.O XD Thank you so much!!!
You are quite welcome.

I fixed a small error in the code, i forgot the denominator in the fmod operator.
(360, by the way)
__________________
FTC Team 72 - No site
FRC Team 399 - http://www.team399.org
2010 Rockwell Collins Innovation in Control Award - (Use of the CAN bus, among other reasons) Phoenix, Arizona!
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
gyro captainking General Forum 4 03-02-2008 22:25
Programming in Python and Explaination of Programming roboxking Programming 22 07-01-2008 16:08
programming motors with programming kit BorisTheBlade FIRST Tech Challenge 4 01-11-2005 19:03
Gyro magical hands Programming 2 14-01-2005 20:57
gyro odin892 Programming 0 08-04-2003 09:59


All times are GMT -5. The time now is 01:09.

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