|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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:
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:
Any help would be appreciated, Thank you! ![]() |
|
#2
|
|
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);
}
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 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 ![]() Last edited by biojae : 01-12-2009 at 22:07. |
|
#3
|
||||
|
||||
|
Re: Gyro Programming
oh wow O.O XD Thank you so much!!!
|
|
#4
|
|
Re: Gyro Programming
You are quite welcome.
I fixed a small error in the code, i forgot the denominator in the fmod operator. (360, by the way) |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |