limelight
This commit is contained in:
@@ -27,6 +27,7 @@ public class Limelighter extends Command {
|
|||||||
double boty;
|
double boty;
|
||||||
double angle;
|
double angle;
|
||||||
double calcul;
|
double calcul;
|
||||||
|
double x;
|
||||||
Optional<Alliance> alliance = DriverStation.getAlliance();
|
Optional<Alliance> alliance = DriverStation.getAlliance();
|
||||||
private final SwerveRequest.FieldCentric drive = new SwerveRequest.FieldCentric()
|
private final SwerveRequest.FieldCentric drive = new SwerveRequest.FieldCentric()
|
||||||
.withDeadband(MaxSpeed * 0.1).withRotationalDeadband(MaxAngularRate * 0.1)
|
.withDeadband(MaxSpeed * 0.1).withRotationalDeadband(MaxAngularRate * 0.1)
|
||||||
@@ -51,26 +52,34 @@ public class Limelighter extends Command {
|
|||||||
System.out.println("e");
|
System.out.println("e");
|
||||||
if (limelight3g.getV()) {
|
if (limelight3g.getV()) {
|
||||||
BotPose = limelight3g.getBotPoseBlue();
|
BotPose = limelight3g.getBotPoseBlue();
|
||||||
|
if (!alliance.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (alliance.get() == Alliance.Blue) {
|
||||||
|
x = 4.6;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x = 11.915394;
|
||||||
|
}
|
||||||
botx = BotPose[1];
|
botx = BotPose[1];
|
||||||
boty = BotPose[0];
|
boty = BotPose[0];
|
||||||
angle = drivetrain.getPigeon2().getYaw().getValueAsDouble();
|
angle = drivetrain.getPigeon2().getYaw().getValueAsDouble();
|
||||||
calcul = limelight3g.Calcule(botx, 4, boty, 4.6, angle);
|
calcul = limelight3g.Calcule(botx, x, boty, 4, angle);
|
||||||
if(calcul < -5 && calcul > -180){
|
if(calcul < -5 && calcul > -180){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(0.5*180/Math.PI));
|
drive.withRotationalRate(0.5*(2*Math.PI)));
|
||||||
}
|
}
|
||||||
else if(calcul > 5 && calcul < 180){
|
else if(calcul > 5 && calcul < 180){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(-0.5*180/Math.PI));
|
drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
}
|
}
|
||||||
else if(calcul >= 180){
|
else if(calcul >= 180){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(-0.5*180/Math.PI));
|
drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
}
|
}
|
||||||
else if(calcul <= -180){
|
else if(calcul <= -180){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(0.5*180/Math.PI));
|
drive.withRotationalRate(0.5*(2*Math.PI)));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class LimelighterAuto extends Command {
|
|||||||
double boty;
|
double boty;
|
||||||
double angle;
|
double angle;
|
||||||
double calcul;
|
double calcul;
|
||||||
|
double x;
|
||||||
Optional<Alliance> alliance = DriverStation.getAlliance();
|
Optional<Alliance> alliance = DriverStation.getAlliance();
|
||||||
private final SwerveRequest.FieldCentric drive = new SwerveRequest.FieldCentric()
|
private final SwerveRequest.FieldCentric drive = new SwerveRequest.FieldCentric()
|
||||||
.withDeadband(MaxSpeed * 0.1).withRotationalDeadband(MaxAngularRate * 0.1)
|
.withDeadband(MaxSpeed * 0.1).withRotationalDeadband(MaxAngularRate * 0.1)
|
||||||
@@ -50,27 +51,35 @@ public class LimelighterAuto extends Command {
|
|||||||
double[] BotPose = new double[6];
|
double[] BotPose = new double[6];
|
||||||
System.out.println("e");
|
System.out.println("e");
|
||||||
if (limelight3g.getV()) {
|
if (limelight3g.getV()) {
|
||||||
|
if (!alliance.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (alliance.get() == Alliance.Blue) {
|
||||||
|
x = 4.6;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x = 11.915394;
|
||||||
|
}
|
||||||
BotPose = limelight3g.getBotPoseBlue();
|
BotPose = limelight3g.getBotPoseBlue();
|
||||||
|
|
||||||
botx = BotPose[1];
|
botx = BotPose[1];
|
||||||
boty = BotPose[0];
|
boty = BotPose[0];
|
||||||
angle = drivetrain.getPigeon2().getYaw().getValueAsDouble();
|
angle = drivetrain.getPigeon2().getYaw().getValueAsDouble();
|
||||||
calcul = limelight3g.Calcule(botx, 4, boty, 4.6, angle);
|
calcul = limelight3g.Calcule(botx, x, boty, 4, angle);
|
||||||
if(calcul < -5 && calcul > -180){
|
if(calcul < -5 && calcul > -180){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(0.5*180/Math.PI));
|
drive.withRotationalRate(0.5*(2*Math.PI)));
|
||||||
}
|
}
|
||||||
else if(calcul > 5 && calcul < 180){
|
else if(calcul > 5 && calcul < 180){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(-0.5*180/Math.PI));
|
drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
}
|
}
|
||||||
else if(calcul >= 180){
|
else if(calcul >= 180){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(-0.5*180/Math.PI));
|
drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
}
|
}
|
||||||
else if(calcul <= -180){
|
else if(calcul <= -180){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(0.5*180/Math.PI));
|
drive.withRotationalRate(0.5*(2*Math.PI)));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
|
|||||||
@@ -62,10 +62,10 @@ NetworkTable table = NetworkTableInstance.getDefault().getTable("limelight-tag")
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(y1 > y2){
|
if(y1 > y2){
|
||||||
return Math.atan(90-((x2 - x1) / (y2 - y1)))* (180 / Math.PI)+270 - angle;
|
return Math.atan((x2 - x1) / (y2 - y1))* (180 / Math.PI)+270 - angle;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return Math.atan((x2 - x1) / (y2 - y1)) * (180 / Math.PI)+180 - angle;
|
return Math.atan(90-((x2 - x1) / (y2 - y1))) * (180 / Math.PI)+180 - angle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user