Skip to content

Commit a8c6c28

Browse files
committed
Testing
1 parent 3224b64 commit a8c6c28

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

src/main/java/frc/robot/Robot.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public void autonomousInit() {
172172
if (m_autonomousCommand != null) {
173173
m_autonomousCommand.schedule();
174174
}
175+
mRobotContainer.enableLights();
175176
}
176177

177178
/** This function is called periodically during autonomous. */

src/main/java/frc/robot/RobotContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ public Command getAutonomousCommand() {
163163
*/
164164
}
165165
// return autoCommand;
166-
return new NewAuto(mDrive, mShooter, mIntake);
166+
return new NewAuto(mDrive, mShooter, mIntake, mLimelight, joysticks
167+
);
167168
}
168169

169170
public void displaySwitch() {

src/main/java/frc/robot/auto/groups/NewAuto.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup;
1111
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
1212
import edu.wpi.first.wpilibj2.command.WaitCommand;
13+
import frc.lib.HelixJoysticks;
1314
import frc.paths.NewAutoPartFour;
1415
import frc.paths.NewAutoPartOne;
1516
import frc.paths.NewAutoPartThree;
@@ -18,6 +19,7 @@
1819
import frc.robot.drive.Drivetrain;
1920
import frc.robot.drive.commands.ResetOdometry;
2021
import frc.robot.drive.commands.TrajectoryFollower;
22+
import frc.robot.drive.commands.TurnToAngle;
2123
import frc.robot.intake.Intake;
2224
import frc.robot.intake.commands.FastIntake;
2325
import frc.robot.intake.commands.RetractIntake;
@@ -29,19 +31,20 @@
2931
import frc.robot.shooter.commands.StopTrigger;
3032
import frc.robot.status.actions.ImageAction;
3133
import frc.robot.status.commands.ActionCommand;
34+
import frc.robot.vision.Limelight;
3235

3336
// NOTE: Consider using this command inline, rather than writing a subclass. For more
3437
// information, see:
3538
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
3639
public class NewAuto extends SequentialCommandGroup {
3740
/** Creates a new NewAuto. */
38-
public NewAuto(Drivetrain drive, Shooter shooter, Intake intake) {
41+
public NewAuto(Drivetrain drive, Shooter shooter, Intake intake, Limelight limelight, HelixJoysticks joysticks) {
3942
addCommands(
4043
new ResetOdometry(drive, new Pose2d(new Translation2d(0,0), new Rotation2d(-2.35))),
4144
new ResetEncoder(shooter),
4245
new ParallelDeadlineGroup(
4346
new WaitCommand(2.9),
44-
new ActionCommand(new ImageAction(Robot.fiveBallAutoImage, 0.02, ImageAction.FOREVER).brightness(0.7).oscillate()),
47+
// new ActionCommand(new ImageAction(Robot.fiveBallAutoImage, 0.02, ImageAction.FOREVER).brightness(0.7).oscillate()),
4548
new TrajectoryFollower(drive, new NewAutoPartOne()),
4649
new FastIntake(intake),
4750
new SequentialCommandGroup(
@@ -56,17 +59,24 @@ public NewAuto(Drivetrain drive, Shooter shooter, Intake intake) {
5659
),
5760
new WaitCommand(0.35),
5861
new ParallelDeadlineGroup(
59-
new WaitCommand(3.9),
60-
new TrajectoryFollower(drive, new NewAutoPartThree()),
62+
new WaitCommand(4.5),
6163
new SequentialCommandGroup(
62-
new WaitCommand(1.25),
64+
new WaitCommand(1.75),
6365
new FlywheelController(shooter, 1795, 76.0)
6466
),
6567
new SequentialCommandGroup(
66-
new WaitCommand(2.9),
68+
new TrajectoryFollower(drive, new NewAutoPartThree()),
69+
new TurnToAngle(drive, limelight, joysticks)
70+
),
71+
new SequentialCommandGroup(
72+
new WaitCommand(3.4),
6773
new PullTrigger(shooter)
6874
),
69-
new RetractIntake(intake)),
75+
new SequentialCommandGroup(
76+
new WaitCommand(0.25),
77+
new RetractIntake(intake)
78+
)
79+
),
7080
new ParallelDeadlineGroup(
7181
new WaitCommand(3.0),
7282
new TrajectoryFollower(drive, new NewAutoPartFour()),

src/main/java/frc/robot/drive/commands/MotionProfileTurn.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public class MotionProfileTurn extends CommandBase {
1616
Drivetrain drive;
1717
double offset;
1818
double target;
19+
double velocity;
20+
double dt;
21+
double maxAcceleration, maxVelocity;
1922
ProfiledPIDController controller;
2023

2124
public MotionProfileTurn(Drivetrain drive, double offset) {
@@ -28,22 +31,42 @@ public MotionProfileTurn(Drivetrain drive, double offset) {
2831
public void initialize() {
2932
// target = offset + drive.getPose().getRotation().getRadians();
3033
SmartDashboard.putString("Turning", "Enabled");
31-
target = 0;
32-
controller = new ProfiledPIDController(0.35, 0.0, 0.0, new TrapezoidProfile.Constraints(10, 10), 0.02);
33-
controller.enableContinuousInput(-Math.PI, Math.PI);
34+
controller = new ProfiledPIDController(0.35, 0.0, 0.0, new TrapezoidProfile.Constraints(1, 1), 0.02);
35+
// controller.enableContinuousInput(-Math.PI, Math.PI);
36+
velocity = 0;
37+
maxAcceleration = 0.5;
38+
maxVelocity = 1;
39+
dt = 0.02;
3440
}
3541

3642
@Override
3743
public void execute() {
3844
double theta = drive.getPose().getRotation().getRadians();
39-
double feedback = controller.calculate(theta, 1);
40-
double feedforward = controller.getSetpoint().velocity;
41-
SmartDashboard.putNumber("Theta Angle", theta);
42-
SmartDashboard.putNumber("Turning Feedforward", feedforward);
45+
double error = shortAngle(0, theta);
46+
double feedback = controller.calculate(0, shortAngle(0, theta));
47+
double feedforward = solveVelocity(maxVelocity, maxAcceleration, error, dt);
48+
SmartDashboard.putNumber("Error", error);
49+
SmartDashboard.putNumber("Velocity", feedforward);
4350
drive.drive(new ChassisSpeeds(0, 0, feedforward), false);
44-
target++;
45-
SmartDashboard.putNumber("Loops", target);
46-
// drive.drive(new ChassisSpeeds(0, 0, 1), false);
51+
}
52+
53+
public double solveVelocity(double maxVelocity, double maxAcceleration, double error, double dt) {
54+
double accel = 0;
55+
if (Math.sqrt(2*maxAcceleration*Math.abs(error)) > Math.abs(velocity)) {
56+
accel = -maxAcceleration * Math.signum(error);
57+
} else {
58+
accel = maxAcceleration * Math.signum(error);
59+
}
60+
SmartDashboard.putNumber("Accel", accel);
61+
velocity = Math.min(maxVelocity, Math.max(-maxVelocity, velocity + accel * dt));
62+
// velocity += accel * dt;
63+
return velocity;
64+
}
65+
66+
public double shortAngle(double targetAngle, double currentAngle) {
67+
double diff = (targetAngle - currentAngle + Math.PI) % (2* Math.PI) - Math.PI;
68+
diff = diff < -Math.PI ? diff + 2 * Math.PI : diff;
69+
return diff;
4770
}
4871

4972
// Called once the command ends or is interrupted.

0 commit comments

Comments
 (0)