View Full Version : Large amounts of gyro drift
I'm trying to use the KOP Gyro to control our orientation during auton, but the angle is drifting a lot without the robot moving.
This makes our robot drive in curves, and not in straight lines.
We're not doing anything funky programming-wise, the drift is observable with barebones code
from wpilib import SampleRobot, run, Gyro, Timer, SmartDashboard
class GyroTest(SampleRobot):
def robotInit(self):
self.gyro = Gyro(0)
def disabled(self):
while self.isDisabled():
SmartDashboard.putNumber('Gyro', self.gyro.getAngle())
Timer.delay(0.01)
if __name__ == "__main__":
run(GyroTest)
The gyro starts at 0 (as it should) and without the robot moving, slowly starts creeping at a rate of about -1 degree / 5 seconds.
Any ideas? We've already checked our gyro's pwm cable.
Ben Wolsieffer
18-03-2015, 09:02
Are you letting the gyro calibrate correctly? You need to make sure the robot does not move at all during the calibration process, which occurs when you construct the gyro object and takes 5 seconds.
Yep, robot is totally still for calibration.
we had some really bad problems with this. Turned out that the signal wire to the gyro was going right by a cim, and speed controller. The RF noise was just enough to get the gyro to drift. We replaced the signal cable with a shielded one and all our problems were gone.
Hope this helps
:)
SousVide
18-03-2015, 10:37
Gyros drift naturally overtime. Numerous ways to deal with this: You can re-zero constantly; you can assume drift overtime and compensate in your code; you can combine data with an accelerometer and/or magnet heading.
See "Drift" here:
http://www.phidgets.com/docs/Gyroscope_Primer
and here:
http://www.instructables.com/id/Guide-to-gyro-and-accelerometer-with-Arduino-inclu/
Joe Johnson
18-03-2015, 10:46
I have no financial interest in AndyMark or Kauai Labs (http://www.kauailabs.com/store/) but we are using the navX MXP Robotics Navigation Sensor (http://www.andymark.com/product-p/am-3060.htm) and we LOVE it.
I was a complete skeptic when the coding team insisted that we could do Field Centric driving using our Wild Swerve modules. But after looking into it, asking a real roboticist that I am lucky enough to work with (http://www.shamlian.net/), and, most importantly, after seeing it work on Rover (Overclocked's fall "Practice Project") (http://www.chiefdelphi.com/forums/showthread.php?t=131704), I am a complete and total fanboy.
The navX MXP is amazing. If you are not using it, you should be.
It takes the literal "rocket science" technology from InvenSence IMU (http://www.invensense.com/mems/gyro/mpu9250.html) and puts it in an beautiful and well behaved (and Open Source/Open Hardware) wrapper.
IT IS AMAZING.
If you are using a gyro and you're not using a navX, I think you're missing the boat.
Free advice, worth every penny.
Dr. Joe J.
P.S. They claim 1 degree per minute drift. Again, I was skeptical but I think actually, in most cases, they do better than that. We will often practice for 20 minutes and stop because the motors are hot or the battery is dead not because we need to rezero the gyro. YMMV but that is our experience.
virtuald
18-03-2015, 11:50
We're using python + KOP gyro, and it works fine for me.
I've had issues with gyros in past years drifting too much... I think it's just something that's particular to some gyros.
Make sure you're actually using the same gyro that the WPILib is expecting you to use. If the volts per g parameter is wrong, then you'll get behavior similar to what you're describing.
Here is some calibration code I found here on Chielf Delphi. It basically involves adjusting the sensitivity with the gyro sitting still so that it doesn't change. It seems to help, although I don't know how accurate it was after changing the sensitivity.
void CalibrateGyro()
{
// gyro should be out of cal mode by now,
// try to find and set best sensitivity
float fAngle;
for(int uLoop = 0; uLoop < 10; uLoop++)
{
float fAngleSensitivity = Gyro::kDefaultVoltsPerDegreePerSecond;
bool bLastAdjustmentWasIncrease;
// reset the accumulator, stop a while and see if we drifted
gyro.Reset();
// taskDelay(sysClkRateGet() / 4);
Wait(.001);
fAngle = gyro.GetAngle();
if(fAngle > 0.0)
{
fAngleSensitivity -= 0.0001;
bLastAdjustmentWasIncrease = false;
}
else
{
fAngleSensitivity += 0.0001;
bLastAdjustmentWasIncrease = true;
}
gyro.SetSensitivity(fAngleSensitivity);
if((fAngleSensitivity > 0.0) && (bLastAdjustmentWasIncrease == false))
{
// we were adjusting up then went down a step - good enough
break;
}
else if ((fAngleSensitivity < 0.0) && (bLastAdjustmentWasIncrease == true))
{
// we were adjusting down then went up a step - good enough
break;
}
if((fAngleSensitivity >= (Gyro::kDefaultVoltsPerDegreePerSecond + 0.0008)) ||
(fAngleSensitivity <= (Gyro::kDefaultVoltsPerDegreePerSecond - 0.0008)))
{
// the next number would be outside any reasonable value according to the datasheet
break;
}
}
gyro.Reset();
}
We will often practice for 20 minutes and stop because ... the battery is dead.
How "dead" do you let the batteries get during practice?
We had similar drift issues and the most important things to do are:
1) ensuring a stable, secure, level mounting of the gyro
2) making certain that the gyro is perfectly still when it's being calibrated (as was already mentioned).
We were drifting around 1-3 degrees per second before mounting the gyro properly. Afterward, we had a drift of maybe 5 degrees after driving for a couple of minutes.
Joe Johnson
18-03-2015, 18:06
How "dead" do you let the batteries get during practice?
How dead do our batteries get? I'm sure to be honest. The Coding Team has figured out a way to have our laptop play a sound "Low Power" sound when our battery voltage gets too low and then we change our battery. It seems to be working so I haven't looked into the voltage that they've picked.
Our robot for this year's game is not a huge current hog. We have 14 motors yes, but the Gripper & Pusher motors are off literally 95% of the time, the three arm motors and the lift motor are nearly perfectly counter balanced and the three wheels are never scrubbing because they are always pointed in the direction of travel with respect to the ground (thanks to the awesome programming of Paul, Michael, & Owen -- you guys are rock stars!). The motors that get hottest, believe it or not, are the three swerve motors.
Don't know if that answers your question, but that's all I've got...
Dr. Joe J.
...our laptop play a sound "Low Power" sound when our battery voltage gets too low and then we change our battery.
Thanks for that clarification Joe.
I didn't want rookie readers to be left with the impression that you drain the batteries until the robot stops working.
Deep discharging is enemy #1 of lead acid batteries.
... P.S. They claim 1 degree per minute drift. Again, I was skeptical but I think actually, in most cases, they do better than that. We will often practice for 20 minutes and stop because the motors are hot or the battery is dead not because we need to rezero the gyro. YMMV but that is our experience.
The navX MXP static yaw drift (e.g., when the navX MXP is still, and the ambient temperature is constant) averages just below 0.25 degrees/hour. This yields a very respectable 15 degrees of drift/hour when not moving - comparable to the ADXRS453. Our goal is to under-promise and over-deliver. :)
Bacon8er
18-03-2015, 18:23
Triple check that the analog port you are plugged into matches what port the software is looking at. A slowly changing input value is exactly what you would see on an open-circuited analog input channel.
Jean Tenca
18-03-2015, 19:33
...we are using the navX MXP Robotics Navigation Sensor (http://www.andymark.com/product-p/am-3060.htm) and we LOVE it.
I honestly wish this had been our experience. We bought two and have been experiencing problems with them across both competition and practice robots all season (it appears that the something gets hosed and the gyro only sends 0's instead of actual values). We've gone back to the KOP gyro while we investigate the problem. :(
fovea1959
19-03-2015, 08:18
@lark95: where do you get *shielded* PWMs? or do you make your own?
BradFerg
19-03-2015, 12:25
We improved out gyro performance doing two things:
1. We re-run the calibration code from the gyro constructor at the beginning of autonomous:
m_analog->InitAccumulator();
Wait(kCalibrationSampleTime);
INT64 value;
UINT32 count;
m_analog->GetAccumulatorOutput(&value, &count);
UINT32 center = (UINT32)((float)value / (float)count + .5);
m_offset = ((float)value / (float)count) - (float)center;
m_analog->SetAccumulatorCenter(center);
m_analog->SetAccumulatorDeadband(0); ///< TODO: compute / parameterize this
m_analog->ResetAccumulator();
2. We allow the driver to re-run this during play if the drift has gotten too bad. Even a 500ms calibration seems to give good results.
I think the culprit is lack of temperature compensation. The gyro specifically has a temperature output to allow compensation and that has not been implemented.
By delaying the calibration until the start of autonomous, we are allowing the gyro temperature to stabilize in the operating environment.
Note: we are actually programming in LabVIEW but the calibration code is basically the same and it's easier to post the C++ version.
Brad
I honestly wish this had been our experience. We bought two and have been experiencing problems with them across both competition and practice robots all season (it appears that the something gets hosed and the gyro only sends 0's instead of actual values). We've gone back to the KOP gyro while we investigate the problem. :(
We were experiencing similar problems whenever the robot experienced a brownout. Try hooking your NavX up to the USB port on the roboRIO in addition to the MXP port. USB is immune to brownouts.*
*Well, unless you get down to crazy low voltages, which you never should be able to.
How dead do our batteries get? I'm sure to be honest. The Coding Team has figured out a way to have our laptop play a sound "Low Power" sound when our battery voltage gets too low and then we change our battery. It seems to be working so I haven't looked into the voltage that they've picked.
We picked 6.8V, the same voltage as a Stage 1 brownout.
@lark95: where do you get *shielded* PWMs? or do you make your own?
Sorry it took awhile to respond. We were at a regional. I don't know were you can get in from. But it will be 3 wires inside of a metal mesh which is then all in insulation. To make it shielded solder the wire mesh to any other grount cable, preferably not the ground in in the actual shielded cable. (We did it antway and it turned out just fine
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.