|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Re: Programming SPI Gyro
We considered doing this immediately following bag-and-tag when our next-to-last analog gyro died. We had hoped to extend the AnalogChannel class and get the integration done for us by using the Gyro(AnalogChannel) constructor. We learned that the integration was done in hardware, so we would have to do it manually. A gyroscope gives you a rotation rate-of-change, so the computer must integrate that rate to determine the actual orientation. At that point, we switched to encoders instead, and trusted that the wheels didn't slip. For more info, see this thread on usfirst. We may tackle this as an off-season project, or get one of those integrated solutions (e.g. the AndyMark NavX MXP board) that are out of stock for next year.
Last edited by GeeTwo : 13-04-2015 at 23:05. |
|
#2
|
|||
|
|||
|
Re: Programming SPI Gyro
Quote:
On the navX MXP wiki in the Application Example section, there are several robot examples for features including Field-centric drive, auto-balancing, motion detection and auto-rotate to angle. Team 2465's mecanum drive featured field-centric drive and auto-rotate to angle based on the navX MXP and it worked very well - and you can find the open-source code for this here. Last edited by slibert : 14-04-2015 at 02:12. |
|
#3
|
||||
|
||||
|
Re: Programming SPI Gyro
We used the gyro you mentioned in the original post all season with good results. The other programming mentor on our team (kevin[at]team2168.org) spent time getting this class up and running.
Our source code to interface with this sensor is available here: https://gist.github.com/jcorcoran/6d721cf6570f772b51f8 Once the sensor is wired up, the code is pretty easy to use. We instantiate it in our drivetrain susbsystem: Code:
public ADXRS453Gyro gyroSPI; gyroSPI = new ADXRS453Gyro(); gyroSPI.startThread(); There's also a feature built in which allows you to recalibrate the gyro. Calibration will occur automatically on startup. It's a 10 second calibration sequence, and should only be called when you expect the robot to be stationary for this duration of time (disabled before a match). This feature is there to allow the robot to re-calibrate itself before a match if the robot was say, turned on while it was being placed on the field, or moved around while it was calibrating. This affects the static drift rate, so it will throw off all subsequent calculations. Our recalibration code looks something like this in our disabledPeriodic method: Code:
//Check to see if the gyro is drifting, if it is re-initialize it.
//Thanks FRC254 for orig. idea.
curAngle = drivetrain.getHeading();
gyroCalibrating = drivetrain.isGyroCalibrating(); //this is a call into ADXRS453Gyro.isCalibrating();
if (lastGyroCalibrating && !gyroCalibrating) {
//if we've just finished calibrating the gyro, reset
gyroDriftDetector.reset();
curAngle = drivetrain.getHeading();
System.out.println("Finished auto-reinit gyro");
} else if (gyroDriftDetector.update(Math.abs(curAngle - lastAngle) > (0.75 / 50.0))
&& !matchStarted && !gyroCalibrating) {
//&& gyroReinits < 3) {
gyroReinits++;
System.out.println("!!! Sensed drift, about to auto-reinit gyro ("+ gyroReinits + ")");
drivetrain.calibrateGyro();
}
lastAngle = curAngle;
lastGyroCalibrating = gyroCalibrating;
It's possible that a match will start while the gyro is calibrating. So if you're going to use the recalibration code, you should ensure that you add a call to ADXRS453Gyro.stopCalibrating() inside your autonomousInit() method, so that the gyro completes its calibration sequence prior to match start. For your information, if you call stopCalibrating, while a calibration sequence is active, it will fail gracefully with a partial calibrated zero drift value. See implementation at line 325 of ADXRS453Gyro.java. In the above code gyroDriftDetector is an instance of the Debouncer class. If you have any questions please shoot an e-mail to kevin[at]team2168.org or myself james[at]team2168.org Last edited by otherguy : 14-04-2015 at 08:22. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|