Compare commits
4 Commits
coaching
...
098f16665a
| Author | SHA1 | Date | |
|---|---|---|---|
| 098f16665a | |||
| 1240160ed7 | |||
| 4068016d36 | |||
|
|
6afc342006 |
@@ -40,6 +40,7 @@ public class Lancer extends Command {
|
|||||||
if(limeLight3G.getV()){}
|
if(limeLight3G.getV()){}
|
||||||
pidController = new PIDController(0.0007, 0,0, 0.001);
|
pidController = new PIDController(0.0007, 0,0, 0.001);
|
||||||
timer.reset();
|
timer.reset();
|
||||||
|
alliance = DriverStation.getAlliance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every time the scheduler runs while the command is scheduled.
|
// Called every time the scheduler runs while the command is scheduled.
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -42,7 +43,9 @@ public class Limelighter extends Command {
|
|||||||
|
|
||||||
// Called when the command is initially scheduled.
|
// Called when the command is initially scheduled.
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {}
|
public void initialize() {
|
||||||
|
alliance = DriverStation.getAlliance();
|
||||||
|
}
|
||||||
|
|
||||||
// Called every time the scheduler runs while the command is scheduled.
|
// Called every time the scheduler runs while the command is scheduled.
|
||||||
@Override
|
@Override
|
||||||
@@ -50,38 +53,63 @@ public class Limelighter 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()) {
|
||||||
|
// BotPose = limelight3g.getBotPoseBlue();
|
||||||
|
if (!alliance.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (alliance.get() == Alliance.Blue) {
|
||||||
|
x = 4.6;
|
||||||
BotPose = limelight3g.getBotPoseBlue();
|
BotPose = limelight3g.getBotPoseBlue();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x = 11.915394;
|
||||||
|
BotPose = limelight3g.getBotPoseRed();
|
||||||
|
}
|
||||||
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(angle > 180){
|
||||||
|
angle -= 360;
|
||||||
|
}
|
||||||
|
if(calcul > -5 && calcul < 5){
|
||||||
|
drivetrain.setControl(
|
||||||
|
drive.withRotationalRate(0));
|
||||||
|
}
|
||||||
|
else if(calcul > 5){
|
||||||
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){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(-0.5*180/Math.PI));
|
drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
}
|
|
||||||
else if(calcul >= 180){
|
|
||||||
drivetrain.setControl(
|
|
||||||
drive.withRotationalRate(-0.5*180/Math.PI));
|
|
||||||
}
|
|
||||||
else if(calcul <= -180){
|
|
||||||
drivetrain.setControl(
|
|
||||||
drive.withRotationalRate(0.5*180/Math.PI));
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
drivetrain.setControl(
|
|
||||||
drive.withRotationalRate(0));
|
|
||||||
}
|
|
||||||
drivetrain.setControl(
|
|
||||||
drive.withVelocityX(0).withVelocityY(0).withRotationalRate(calcul));
|
|
||||||
System.out.println(angle);
|
|
||||||
if (calcul < 0.2 && calcul > -0.2) {
|
|
||||||
drivetrain.setControl(drive.withRotationalRate(0));
|
|
||||||
}
|
}
|
||||||
|
// if(calcul < -5 && calcul > -180){
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(0.5*(2*Math.PI)));
|
||||||
|
// }
|
||||||
|
// else if(calcul > 5 && calcul < 180){
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
|
// }
|
||||||
|
// else if(calcul >= 180){
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
|
// }
|
||||||
|
// else if(calcul <= -180){
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(0.5*(2*Math.PI)));
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(0));
|
||||||
|
// }
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withVelocityX(0).withVelocityY(0).withRotationalRate(calcul));
|
||||||
|
// System.out.println(angle);
|
||||||
|
// if (calcul < 0.2 && calcul > -0.2) {
|
||||||
|
// drivetrain.setControl(drive.withRotationalRate(0));
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
drivetrain.setControl(drive.withRotationalRate(0));
|
drivetrain.setControl(drive.withRotationalRate(0));
|
||||||
|
|||||||
@@ -47,7 +47,9 @@ public class GrimperMur extends Command {
|
|||||||
|
|
||||||
// Called when the command is initially scheduled.
|
// Called when the command is initially scheduled.
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {}
|
public void initialize() {
|
||||||
|
alliance = DriverStation.getAlliance();
|
||||||
|
}
|
||||||
|
|
||||||
// Called every time the scheduler runs while the command is scheduled.
|
// Called every time the scheduler runs while the command is scheduled.
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -47,7 +47,9 @@ public class GrimperReservoir extends Command {
|
|||||||
|
|
||||||
// Called when the command is initially scheduled.
|
// Called when the command is initially scheduled.
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {}
|
public void initialize() {
|
||||||
|
alliance = DriverStation.getAlliance();
|
||||||
|
}
|
||||||
|
|
||||||
// Called every time the scheduler runs while the command is scheduled.
|
// Called every time the scheduler runs while the command is scheduled.
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class LancerAuto extends Command {
|
|||||||
public void initialize() {
|
public void initialize() {
|
||||||
pidController = new PIDController(0.0007, 0, 0, 0.001);
|
pidController = new PIDController(0.0007, 0, 0, 0.001);
|
||||||
timer.reset();
|
timer.reset();
|
||||||
|
alliance = DriverStation.getAlliance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every time the scheduler runs while the command is scheduled.
|
// Called every time the scheduler runs while the command is scheduled.
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -42,7 +43,9 @@ public class LimelighterAuto extends Command {
|
|||||||
|
|
||||||
// Called when the command is initially scheduled.
|
// Called when the command is initially scheduled.
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {}
|
public void initialize() {
|
||||||
|
alliance = DriverStation.getAlliance();
|
||||||
|
}
|
||||||
|
|
||||||
// Called every time the scheduler runs while the command is scheduled.
|
// Called every time the scheduler runs while the command is scheduled.
|
||||||
@Override
|
@Override
|
||||||
@@ -50,38 +53,63 @@ 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()) {
|
||||||
|
// BotPose = limelight3g.getBotPoseBlue();
|
||||||
|
if (!alliance.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (alliance.get() == Alliance.Blue) {
|
||||||
|
x = 4.6;
|
||||||
BotPose = limelight3g.getBotPoseBlue();
|
BotPose = limelight3g.getBotPoseBlue();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x = 11.915394;
|
||||||
|
BotPose = limelight3g.getBotPoseRed();
|
||||||
|
}
|
||||||
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(angle > 180){
|
||||||
|
angle -= 360;
|
||||||
|
}
|
||||||
|
if(calcul > -5 && calcul < 5){
|
||||||
|
drivetrain.setControl(
|
||||||
|
drive.withRotationalRate(0));
|
||||||
|
}
|
||||||
|
else if(calcul > 5){
|
||||||
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){
|
||||||
drivetrain.setControl(
|
drivetrain.setControl(
|
||||||
drive.withRotationalRate(-0.5*180/Math.PI));
|
drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
}
|
|
||||||
else if(calcul >= 180){
|
|
||||||
drivetrain.setControl(
|
|
||||||
drive.withRotationalRate(-0.5*180/Math.PI));
|
|
||||||
}
|
|
||||||
else if(calcul <= -180){
|
|
||||||
drivetrain.setControl(
|
|
||||||
drive.withRotationalRate(0.5*180/Math.PI));
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
drivetrain.setControl(
|
|
||||||
drive.withRotationalRate(0));
|
|
||||||
}
|
|
||||||
drivetrain.setControl(
|
|
||||||
drive.withVelocityX(0).withVelocityY(0).withRotationalRate(calcul));
|
|
||||||
System.out.println(angle);
|
|
||||||
if (calcul < 0.2 && calcul > -0.2) {
|
|
||||||
drivetrain.setControl(drive.withRotationalRate(0));
|
|
||||||
}
|
}
|
||||||
|
// if(calcul < -5 && calcul > -180){
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(0.5*(2*Math.PI)));
|
||||||
|
// }
|
||||||
|
// else if(calcul > 5 && calcul < 180){
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
|
// }
|
||||||
|
// else if(calcul >= 180){
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(-0.5*(2*Math.PI)));
|
||||||
|
// }
|
||||||
|
// else if(calcul <= -180){
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(0.5*(2*Math.PI)));
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withRotationalRate(0));
|
||||||
|
// }
|
||||||
|
// drivetrain.setControl(
|
||||||
|
// drive.withVelocityX(0).withVelocityY(0).withRotationalRate(calcul));
|
||||||
|
// System.out.println(angle);
|
||||||
|
// if (calcul < 0.2 && calcul > -0.2) {
|
||||||
|
// drivetrain.setControl(drive.withRotationalRate(0));
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
drivetrain.setControl(drive.withRotationalRate(0));
|
drivetrain.setControl(drive.withRotationalRate(0));
|
||||||
@@ -98,7 +126,6 @@ public class LimelighterAuto extends Command {
|
|||||||
// Returns true when the command should end.
|
// Returns true when the command should end.
|
||||||
@Override
|
@Override
|
||||||
public boolean isFinished() {
|
public boolean isFinished() {
|
||||||
return calcul < 5 && calcul > -5;
|
return calcul > -5 && calcul < 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ public class TournerVersMur extends Command {
|
|||||||
|
|
||||||
// Called when the command is initially scheduled.
|
// Called when the command is initially scheduled.
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {}
|
public void initialize() {
|
||||||
|
alliance = DriverStation.getAlliance();
|
||||||
|
}
|
||||||
|
|
||||||
// Called every time the scheduler runs while the command is scheduled.
|
// Called every time the scheduler runs while the command is scheduled.
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ public class TournerVersReservoir extends Command {
|
|||||||
|
|
||||||
// Called when the command is initially scheduled.
|
// Called when the command is initially scheduled.
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {}
|
public void initialize() {
|
||||||
|
alliance = DriverStation.getAlliance();
|
||||||
|
}
|
||||||
|
|
||||||
// Called every time the scheduler runs while the command is scheduled.
|
// Called every time the scheduler runs while the command is scheduled.
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -52,22 +52,28 @@ NetworkTable table = NetworkTableInstance.getDefault().getTable("limelight-tag")
|
|||||||
}
|
}
|
||||||
public double Calcule(double x1, double x2, double y1, double y2, double angle)
|
public double Calcule(double x1, double x2, double y1, double y2, double angle)
|
||||||
{
|
{
|
||||||
if(x1 > x2){
|
// if(x1 > x2){
|
||||||
if(y1 > y2){
|
// if(y1 > y2){
|
||||||
return Math.atan(90-((x2 - x1) / (y2 - y1))) * (180 / Math.PI) - angle;
|
// return Math.atan(90-((x2 - x1) / (y2 - y1))) * (180 / Math.PI) - angle;
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// return Math.atan((x2 - x1) / (y2 - y1)) * (180 / Math.PI)+90 - angle;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// if(y1 > y2){
|
||||||
|
// return Math.atan((x2 - x1) / (y2 - y1))* (180 / Math.PI)+270 - angle;
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// return Math.atan(90-((x2 - x1) / (y2 - y1))) * (180 / Math.PI)+180 - angle;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
if(y1 > y2){
|
||||||
|
return Math.atan((x2 - x1) / (y2 - y1)) * (180 / Math.PI) - angle;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return Math.atan((x2 - x1) / (y2 - y1)) * (180 / Math.PI)+90 - angle;
|
return Math.atan((x2 - x1) / (y2 - y1)) * (180 / Math.PI)-360 - angle;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(y1 > y2){
|
|
||||||
return Math.atan(90-((x2 - x1) / (y2 - y1)))* (180 / Math.PI)+270 - angle;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return Math.atan((x2 - x1) / (y2 - y1)) * (180 / Math.PI)+180 - angle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void periodic() {
|
public void periodic() {
|
||||||
|
|||||||
Reference in New Issue
Block a user