|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Use Gyro to turn 90 Degrees
What are the values of the gyro. Is it 0 - 359 or what?
|
|
#2
|
||||
|
||||
|
Re: Use Gyro to turn 90 Degrees
The gyro actually gives you angular velocity (turn rate), but the FPGA is doing integration for you. If you are calling the GetAngle() method, I believe you will get the accumulated angle. So if you turn several rounds, for example, you could get angle values > 360 or < -360. Remember, it is not a compass. It doesn't give you absolute heading. If only gives you current angle relative to your starting angle.
|
|
#3
|
|||
|
|||
|
Re: Use Gyro to turn 90 Degrees
So another words, if you were heading a direction recording 0. Then you used "GetAngle() + 90" when the drive is correcting itself it will think the robot turned 90 degrees to the right and will try to correct itself by turning 90 degrees to the left?
(Assuming a positive value turns the robot right and a negative value turns the robot left). I am trying to accomplish this program without using the Reset() because that causes unpredictable angles at which it reset itself. |
|
#4
|
||||
|
||||
|
Re: Use Gyro to turn 90 Degrees
Yes, you can do the following, for eample:
Code:
float targetHeading = gyro->GetAngle() + 90.0;
while (gyro->GetAngle() < targetHeading)
{
drive->ArcadeDrive(0.0, 0.5);
}
|
|
#5
|
|||
|
|||
|
Re: Use Gyro to turn 90 Degrees
Alright I will be testing that tomorrow. I was curious about the value range because we had the bot set up with the following code:
Code:
float angle = gyro.GetAngle() + 90; myRobot.Drive(-0.2, -angle / 30); The result when running this was that the robot would turn right at a medium rate and continue turning after passing 90 degrees. The other result that seemed odd was that changing "/ 30" to "/ 1" caused a slower turn rate while changing it to "/ 60" caused a faster turn rate. |
|
#6
|
||||
|
||||
|
Re: Use Gyro to turn 90 Degrees
If you just want a simple turn, don't use myRobot.Drive, just use ArcadeDrive, like this:
Code:
#define TURN_TOLERANCE 0.5
void Turn(float angle)
{
float targetHeading = gyro.GetAngle() + angle;
while (fabs(targetHeading - gyro.GetAngle()) > TURN_TOLERANCE)
{
myRobot.ArcadeDrive(0.0, (angle < 0.0)? -0.5: 0.5);
}
}
BTW, you should really fix your signs by calling myRobot->SetInvertedMotor(), you will benefit from it in the long run. Last edited by mikets : 28-02-2012 at 21:46. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|