Skip to content

Commit 9eee946

Browse files
Aligns Drivetrain based on calculations
1 parent 06c5fb8 commit 9eee946

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/main/java/org/carlmontrobotics/RobotContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private void registerAutoCommands() {
361361
NamedCommands.registerCommand("AlignToAprilTagMegaTag2",
362362
new AlignToApriltag(drivetrain, limelight));
363363
NamedCommands.registerCommand("Shoot", new SequentialCommandGroup(
364-
new ParallelCommandGroup(new AlignToApriltag(drivetrain, limelight),
364+
new ParallelCommandGroup(new AlignDrivetrain(drivetrain),
365365
new AimArmSpeaker(arm, limelight),
366366
new RampRPMAuton(intakeShooter)),
367367
new PassToOuttake(intakeShooter),
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) FIRST and other WPILib contributors.
2+
// Open Source Software; you can modify and/or share it under the terms of
3+
// the WPILib BSD license file in the root directory of this project.
4+
5+
package org.carlmontrobotics.commands;
6+
7+
import java.util.Optional;
8+
9+
import org.carlmontrobotics.subsystems.Drivetrain;
10+
11+
import edu.wpi.first.math.geometry.Rotation2d;
12+
import edu.wpi.first.wpilibj.DriverStation.Alliance;
13+
import edu.wpi.first.wpilibj2.command.InstantCommand;
14+
import edu.wpi.first.wpilibj2.command.ProxyCommand;
15+
import edu.wpi.first.wpilibj.DriverStation;
16+
17+
/** Add your docs here. */
18+
public class AlignDrivetrain extends ProxyCommand {
19+
static double blueSpeakerX = 0.14;
20+
static double blueSpeakerY = 5.54;
21+
22+
static double redSpeakerX = 16.36;
23+
static double redSpeakerY = 5.51;
24+
25+
public AlignDrivetrain(Drivetrain dt) {
26+
super(() -> {
27+
Optional<Alliance> allianceSide = DriverStation.getAlliance();
28+
if (allianceSide.get() == Alliance.Red) {
29+
// double redAngle = Math.atan2(redSpeakerY-dt.getPose().getY(),
30+
// dt.getPose().getX());
31+
return new RotateToFieldRelativeAngle(
32+
new Rotation2d(dt.getPose().getX(),
33+
blueSpeakerY - dt.getPose().getY()),
34+
dt);
35+
36+
} else if (allianceSide.get() == Alliance.Blue) {
37+
// double blueAngle = Math.atan2(blueSpeakerY-dt.getPose().getY(),
38+
// dt.getPose().getX());
39+
return new RotateToFieldRelativeAngle(
40+
new Rotation2d(redSpeakerX - dt.getPose().getX(),
41+
redSpeakerY - dt.getPose().getY()),
42+
dt);
43+
44+
}
45+
// create an if statement based on alliance side
46+
return new InstantCommand();
47+
});
48+
}
49+
}

0 commit comments

Comments
 (0)