Fixed NetworkAlerts

This commit is contained in:
thenetworkgrinch
2024-01-17 09:17:39 -06:00
parent f16ca43981
commit 1ca3db242c
19 changed files with 510 additions and 108 deletions

View File

@@ -1,15 +1,14 @@
package swervelib.imu;
import com.kauailabs.navx.frc.AHRS;
import edu.wpi.first.math.geometry.Quaternion;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.geometry.Translation3d;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.SPI;
import edu.wpi.first.wpilibj.SerialPort;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import java.util.Optional;
import swervelib.telemetry.Alert;
/**
* Communicates with the NavX as the IMU.
@@ -25,6 +24,10 @@ public class NavXSwerve extends SwerveIMU
* Offset for the NavX.
*/
private Rotation3d offset = new Rotation3d();
/**
* An {@link Alert} for if there is an error instantiating the NavX.
*/
private Alert navXError;
/**
* Constructor for the NavX swerve.
@@ -33,6 +36,7 @@ public class NavXSwerve extends SwerveIMU
*/
public NavXSwerve(SerialPort.Port port)
{
navXError = new Alert("IMU", "Error instantiating NavX.", Alert.AlertType.ERROR_TRACE);
try
{
/* Communicate w/navX-MXP via the MXP SPI Bus. */
@@ -43,7 +47,8 @@ public class NavXSwerve extends SwerveIMU
SmartDashboard.putData(gyro);
} catch (RuntimeException ex)
{
DriverStation.reportError("Error instantiating navX: " + ex.getMessage(), true);
navXError.setText("Error instantiating NavX: " + ex.getMessage());
navXError.set(true);
}
}
@@ -64,7 +69,8 @@ public class NavXSwerve extends SwerveIMU
SmartDashboard.putData(gyro);
} catch (RuntimeException ex)
{
DriverStation.reportError("Error instantiating navX: " + ex.getMessage(), true);
navXError.setText("Error instantiating NavX: " + ex.getMessage());
navXError.set(true);
}
}
@@ -85,7 +91,8 @@ public class NavXSwerve extends SwerveIMU
SmartDashboard.putData(gyro);
} catch (RuntimeException ex)
{
DriverStation.reportError("Error instantiating navX: " + ex.getMessage(), true);
navXError.setText("Error instantiating NavX: " + ex.getMessage());
navXError.set(true);
}
}