Skip to content

Commit

Permalink
Auto position testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelLesirge committed Mar 1, 2024
1 parent c505222 commit 55c74e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static class AutoConstants {

public static class VisionConstants {

public static final Transform3d CAMERA_POSE = new Transform3d(0.5, 0, 0.25, new Rotation3d());
public static final Transform3d CAMERA_POSE = new Transform3d(0, 0, 0, new Rotation3d());
public static final String CAMERA_NAME = "Arducam_OV9281_USB_Camera";
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import edu.wpi.first.net.PortForwarder;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.button.CommandJoystick;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;

Expand Down Expand Up @@ -163,12 +164,15 @@ public void setUpDriveController() {
// xbox.povLeft().whileTrue(Commands.run(drivetrain::toDefaultStates,
// drivetrain));

xbox.b().onTrue(Commands.runOnce(inputs::decreaseSpeedLevel));
// xbox.b().onTrue(Commands.runOnce(inputs::decreaseSpeedLevel));
xbox.povDown().onTrue(Commands.runOnce(inputs::decreaseSpeedLevel));

xbox.povUp().onTrue(Commands.runOnce(inputs::increaseSpeedLevel));

xbox.a().whileTrue(new AutoPosition(drivetrain, vision));
var autoPosition = new AutoPosition(drivetrain, vision);
xbox.a().onTrue(autoPosition);
// xbox.a().onTrue(autoPosition);
xbox.b().onTrue(new InstantCommand(() -> drivetrain.getCurrentCommand().cancel(), drivetrain));

drivetrain.setDefaultCommand(new ChassisRemoteControl(drivetrain, inputs));
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/frc/robot/commands/AutoPosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,16 @@ public void initialize() {
if (dist3d == null) {
return;
}

double angle = dist3d.getRotation().getZ();
Translation2d trans = new Translation2d(dist3d.getY() - AutoConstants.PREFERRED_TAG_DISTANCE * Math.cos(angle),
dist3d.getX() - AutoConstants.PREFERRED_TAG_DISTANCE * Math.sin(angle));
Translation2d trans = new Translation2d(
dist3d.getX() - 0.5, dist3d.getY());
SmartDashboard.putNumber("ANGLE", angle);
SmartDashboard.putNumber("Y", trans.getY());
SmartDashboard.putNumber("X", trans.getX());
Rotation2d rot = new Rotation2d(-(Math.PI-angle));
SmartDashboard.putNumber("tr X", trans.getX());
SmartDashboard.putNumber("tr Y", trans.getY());
Rotation2d rot = new Rotation2d(-(Math.PI - angle));
Commands.sequence(
new AutoRotateTo(drivetrain, rot, false)
,new AutoDriveTo(drivetrain, trans)
).schedule();
new AutoRotateTo(drivetrain, rot, false), new AutoDriveTo(drivetrain, trans)).schedule();
;

}
Expand Down

0 comments on commit 55c74e2

Please sign in to comment.