|
| 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