generated from DeepBlueRobotics/EmptyProject2024
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from DeepBlueRobotics/limelight-megatag2
Limelight megatag2
- Loading branch information
Showing
8 changed files
with
186 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/carlmontrobotics/commands/AimArmSpeakerMT2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package org.carlmontrobotics.commands; | ||
|
||
import org.carlmontrobotics.subsystems.Arm; | ||
import org.carlmontrobotics.subsystems.Limelight; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
|
||
public class AimArmSpeakerMT2 extends Command { | ||
private final Arm arm; | ||
private final Limelight ll; | ||
|
||
/** Creates a new AimOuttakeSpeaker. */ | ||
public AimArmSpeakerMT2(Arm arm, Limelight ll) { | ||
// Use addRequirements() here to declare subsystem dependencies. | ||
addRequirements(this.arm = arm); | ||
this.ll = ll; | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() { | ||
double goal = ll.getOptimizedArmAngleRadsMT2(); | ||
arm.setArmTarget(goal); | ||
} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() { | ||
} | ||
|
||
// Called once the command ends or is interrupted. | ||
@Override | ||
public void end(boolean interrupted) { | ||
} | ||
|
||
// Returns true when the command should end. | ||
@Override | ||
public boolean isFinished() { | ||
return arm.armAtSetpoint(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/org/carlmontrobotics/commands/AlignToApriltagMegatag2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package org.carlmontrobotics.commands; | ||
|
||
import static org.carlmontrobotics.Constants.Drivetrainc.*; | ||
|
||
import org.carlmontrobotics.subsystems.Drivetrain; | ||
import org.carlmontrobotics.subsystems.Limelight; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.util.sendable.SendableRegistry; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
|
||
public class AlignToApriltagMegatag2 extends Command { | ||
|
||
public final TeleopDrive teleopDrive; | ||
public final Drivetrain drivetrain; | ||
private Limelight limelight; | ||
|
||
public final PIDController rotationPID = new PIDController(thetaPIDController[0], thetaPIDController[1], | ||
thetaPIDController[2]); | ||
|
||
public AlignToApriltagMegatag2(Drivetrain drivetrain, Limelight limelight) { | ||
this.limelight = limelight; | ||
this.drivetrain = drivetrain; | ||
this.teleopDrive = (TeleopDrive) drivetrain.getDefaultCommand(); | ||
|
||
rotationPID.enableContinuousInput(-180, 180); | ||
Rotation2d targetAngle = Rotation2d.fromDegrees(drivetrain.getHeading()) | ||
.plus(Rotation2d.fromRadians(limelight.getRotateAngleRadMT2())); | ||
rotationPID.setSetpoint(MathUtil.inputModulus(targetAngle.getDegrees(), -180, 180)); | ||
rotationPID.setTolerance(positionTolerance[2], velocityTolerance[2]); | ||
SendableRegistry.addChild(this, rotationPID); | ||
addRequirements(drivetrain); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
Rotation2d targetAngle = Rotation2d.fromDegrees(drivetrain.getHeading()) | ||
.plus(Rotation2d.fromRadians(limelight.getRotateAngleRadMT2())); | ||
rotationPID.setSetpoint(MathUtil.inputModulus(targetAngle.getDegrees(), -180, 180)); | ||
if (teleopDrive == null) | ||
drivetrain.drive(0, 0, rotationPID.calculate(drivetrain.getHeading())); | ||
else { | ||
double[] driverRequestedSpeeds = teleopDrive.getRequestedSpeeds(); | ||
drivetrain.drive(driverRequestedSpeeds[0], driverRequestedSpeeds[1], | ||
rotationPID.calculate(drivetrain.getHeading())); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
// SmartDashboard.putBoolean("At Setpoint", rotationPID.atSetpoint()); | ||
// SmartDashboard.putNumber("Error", rotationPID.getPositionError()); | ||
// return rotationPID.atSetpoint(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters