mirror of
https://github.com/BroncBotz3481/YAGSL
synced 2026-06-19 06:21:40 +00:00
Added Tuner X reccommendation if compatible config is used. Added QOL improvment functions
This commit is contained in:
@@ -28,11 +28,16 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import swervelib.encoders.CANCoderSwerve;
|
||||
import swervelib.imu.Pigeon2Swerve;
|
||||
import swervelib.imu.SwerveIMU;
|
||||
import swervelib.math.SwerveMath;
|
||||
import swervelib.motors.TalonFXSwerve;
|
||||
import swervelib.parser.SwerveControllerConfiguration;
|
||||
import swervelib.parser.SwerveDriveConfiguration;
|
||||
import swervelib.simulation.SwerveIMUSimulation;
|
||||
import swervelib.telemetry.Alert;
|
||||
import swervelib.telemetry.Alert.AlertType;
|
||||
import swervelib.telemetry.SwerveDriveTelemetry;
|
||||
import swervelib.telemetry.SwerveDriveTelemetry.TelemetryVerbosity;
|
||||
|
||||
@@ -139,6 +144,13 @@ public class SwerveDrive
|
||||
* Maximum speed of the robot in meters per second.
|
||||
*/
|
||||
private double maxSpeedMPS;
|
||||
/**
|
||||
* Alert to recommend Tuner X if the configuration is compatible.
|
||||
*/
|
||||
private final Alert tunerXRecommendation = new Alert("Swerve Drive",
|
||||
"Your Swerve Drive is compatible with Tuner X swerve generator, please consider using that instead of YAGSL. More information here!\n" +
|
||||
"https://pro.docs.ctr-electronics.com/en/latest/docs/tuner/tuner-swerve/index.html",
|
||||
AlertType.WARNING);
|
||||
|
||||
/**
|
||||
* Creates a new swerve drivebase subsystem. Robot is controlled via the {@link SwerveDrive#drive} method, or via the
|
||||
@@ -224,6 +236,29 @@ public class SwerveDrive
|
||||
odometryThread.startPeriodic(SwerveDriveTelemetry.isSimulation ? 0.01 : 0.02);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all components to ensure that Tuner X Swerve Generator is recommended instead.
|
||||
*/
|
||||
private void checkIfTunerXCompatible()
|
||||
{
|
||||
boolean compatible = imu instanceof Pigeon2Swerve;
|
||||
for (SwerveModule module : swerveModules)
|
||||
{
|
||||
compatible = compatible && module.getDriveMotor() instanceof TalonFXSwerve &&
|
||||
module.getAngleMotor() instanceof TalonFXSwerve &&
|
||||
module.getAbsoluteEncoder() instanceof CANCoderSwerve;
|
||||
if (!compatible)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (compatible)
|
||||
{
|
||||
tunerXRecommendation.set(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the odometry update period in seconds.
|
||||
*
|
||||
@@ -465,6 +500,29 @@ public class SwerveDrive
|
||||
setMaximumSpeed(attainableMaxModuleSpeedMetersPerSecond);
|
||||
this.attainableMaxTranslationalSpeedMetersPerSecond = attainableMaxTranslationalSpeedMetersPerSecond;
|
||||
this.attainableMaxRotationalVelocityRadiansPerSecond = attainableMaxRotationalVelocityRadiansPerSecond;
|
||||
this.swerveController.config.maxAngularVelocity = attainableMaxRotationalVelocityRadiansPerSecond;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum velocity from {@link SwerveDrive#attainableMaxTranslationalSpeedMetersPerSecond} or
|
||||
* {@link SwerveDrive#maxSpeedMPS} whichever is higher.
|
||||
*
|
||||
* @return Maximum speed in meters/second.
|
||||
*/
|
||||
public double getMaximumVelocity()
|
||||
{
|
||||
return Math.max(this.attainableMaxTranslationalSpeedMetersPerSecond, maxSpeedMPS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum angular velocity, either {@link SwerveDrive#attainableMaxRotationalVelocityRadiansPerSecond} or
|
||||
* {@link SwerveControllerConfiguration#maxAngularVelocity}.
|
||||
*
|
||||
* @return Maximum angular velocity in radians per second.
|
||||
*/
|
||||
public double getMaximumAngularVelocity()
|
||||
{
|
||||
return Math.max(this.attainableMaxRotationalVelocityRadiansPerSecond, swerveController.config.maxAngularVelocity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -394,6 +394,16 @@ public class SwerveModule
|
||||
return driveMotor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link SwerveAbsoluteEncoder} for the {@link SwerveModule}.
|
||||
*
|
||||
* @return {@link SwerveAbsoluteEncoder} for the swerve module.
|
||||
*/
|
||||
public SwerveAbsoluteEncoder getAbsoluteEncoder()
|
||||
{
|
||||
return absoluteEncoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the {@link SwerveModuleConfiguration} for the {@link SwerveModule} with the parsed configurations.
|
||||
*
|
||||
|
||||
@@ -46,11 +46,25 @@ import java.util.function.Predicate;
|
||||
public class Alert
|
||||
{
|
||||
|
||||
/**
|
||||
* Group of the alert.
|
||||
*/
|
||||
private static Map<String, SendableAlerts> groups = new HashMap<String, SendableAlerts>();
|
||||
|
||||
/**
|
||||
* Type of the Alert to raise.
|
||||
*/
|
||||
private final AlertType type;
|
||||
/**
|
||||
* Activation state of alert.
|
||||
*/
|
||||
private boolean active = false;
|
||||
/**
|
||||
* When the alert was raised.
|
||||
*/
|
||||
private double activeStartTime = 0.0;
|
||||
/**
|
||||
* Text of the alert.
|
||||
*/
|
||||
private String text;
|
||||
|
||||
/**
|
||||
@@ -89,6 +103,8 @@ public class Alert
|
||||
/**
|
||||
* Sets whether the alert should currently be displayed. When activated, the alert text will also be sent to the
|
||||
* console.
|
||||
*
|
||||
* @param active Set the alert as active and report it to the driver station.
|
||||
*/
|
||||
public void set(boolean active)
|
||||
{
|
||||
@@ -119,6 +135,8 @@ public class Alert
|
||||
|
||||
/**
|
||||
* Updates current alert text.
|
||||
*
|
||||
* @param text The text for the alert.
|
||||
*/
|
||||
public void setText(String text)
|
||||
{
|
||||
@@ -182,11 +200,22 @@ public class Alert
|
||||
INFO
|
||||
}
|
||||
|
||||
/**
|
||||
* Sendable alert for advantage scope.
|
||||
*/
|
||||
private static class SendableAlerts implements Sendable
|
||||
{
|
||||
|
||||
/**
|
||||
* Alert list for sendable.
|
||||
*/
|
||||
public final List<Alert> alerts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Get alerts based off of type.
|
||||
* @param type Type of alert to fetch.
|
||||
* @return Active alert strings.
|
||||
*/
|
||||
public String[] getStrings(AlertType type)
|
||||
{
|
||||
Predicate<Alert> activeFilter = (Alert x) -> x.type == type && x.active;
|
||||
|
||||
Reference in New Issue
Block a user