mirror of
https://github.com/Team4388/2023WayOfTheRobot.git
synced 2026-06-09 00:37:59 -06:00
added pid controller
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
package frc4388.utility;
|
||||
|
||||
import com.ctre.phoenix.sensors.PigeonIMU;
|
||||
import com.ctre.phoenix.sensors.WPI_Pigeon2;
|
||||
import com.ctre.phoenix.sensors.PigeonIMU.CalibrationMode;
|
||||
import com.kauailabs.navx.frc.AHRS;
|
||||
|
||||
@@ -21,14 +22,13 @@ import edu.wpi.first.math.MathUtil;
|
||||
public class RobotGyro implements Gyro {
|
||||
private RobotTime m_robotTime = RobotTime.getInstance();
|
||||
|
||||
private PigeonIMU m_pigeon = null;
|
||||
private WPI_Pigeon2 m_pigeon = null;
|
||||
private AHRS m_navX = null;
|
||||
public boolean m_isGyroAPigeon; //true if pigeon, false if navX
|
||||
|
||||
private double m_lastPigeonAngle;
|
||||
private double m_deltaPigeonAngle;
|
||||
|
||||
private double yawZero = 0;
|
||||
private double pitchZero = 0;
|
||||
private double rollZero = 0;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class RobotGyro implements Gyro {
|
||||
* Creates a Gyro based on a pigeon
|
||||
* @param gyro the gyroscope to use for Gyro
|
||||
*/
|
||||
public RobotGyro(PigeonIMU gyro) {
|
||||
public RobotGyro(WPI_Pigeon2 gyro) {
|
||||
m_pigeon = gyro;
|
||||
m_isGyroAPigeon = true;
|
||||
}
|
||||
@@ -53,10 +53,9 @@ public class RobotGyro implements Gyro {
|
||||
/**
|
||||
* Resets yaw, pitch, and roll.
|
||||
*/
|
||||
public void resetAllAngles() {
|
||||
public void resetZeroValues() {
|
||||
if (!m_isGyroAPigeon) return;
|
||||
|
||||
yawZero = m_pigeon.getYaw();
|
||||
pitchZero = m_pigeon.getPitch();
|
||||
rollZero = m_pigeon.getRoll();
|
||||
}
|
||||
@@ -90,7 +89,7 @@ public class RobotGyro implements Gyro {
|
||||
@Override
|
||||
public void calibrate() {
|
||||
if (m_isGyroAPigeon) {
|
||||
m_pigeon.enterCalibrationMode(CalibrationMode.Temperature);
|
||||
m_pigeon.calibrate();
|
||||
} else {
|
||||
m_navX.calibrate();
|
||||
}
|
||||
@@ -98,6 +97,8 @@ public class RobotGyro implements Gyro {
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
resetZeroValues();
|
||||
|
||||
if (m_isGyroAPigeon) {
|
||||
m_pigeon.setYaw(0);
|
||||
} else {
|
||||
@@ -117,7 +118,7 @@ public class RobotGyro implements Gyro {
|
||||
double[] ypr = new double[3];
|
||||
m_pigeon.getYawPitchRoll(ypr);
|
||||
|
||||
return new double[] {(ypr[0] - yawZero), (ypr[1] - pitchZero), (ypr[2] - rollZero)};
|
||||
return new double[] {ypr[0], (ypr[1] - pitchZero), (ypr[2] - rollZero)};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -182,7 +183,7 @@ public class RobotGyro implements Gyro {
|
||||
}
|
||||
}
|
||||
|
||||
public PigeonIMU getPigeon(){
|
||||
public WPI_Pigeon2 getPigeon(){
|
||||
return m_pigeon;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user