Skip to content

Commit fcf3ef3

Browse files
committed
fix broken aim on red
1 parent ec46415 commit fcf3ef3

27 files changed

+80
-24
lines changed
-180 Bytes
Binary file not shown.
-180 Bytes
Binary file not shown.
-180 Bytes
Binary file not shown.

sim_logs/Log_177dd034386b90b9.wpilog

-87 Bytes
Binary file not shown.

sim_logs/Log_24-03-22_11-06-26.wpilog

-915 KB
Binary file not shown.

sim_logs/Log_24-03-22_11-22-21.wpilog

-811 KB
Binary file not shown.

sim_logs/Log_24-03-22_11-23-07.wpilog

-27 MB
Binary file not shown.

sim_logs/Log_24-03-22_12-07-00.wpilog

-170 KB
Binary file not shown.

sim_logs/Log_24-03-22_12-07-29.wpilog

-4.36 MB
Binary file not shown.

sim_logs/Log_24-03-24_23-04-25.wpilog

-605 KB
Binary file not shown.

sim_logs/Log_24-03-26_16-40-15.wpilog

-6.06 MB
Binary file not shown.

sim_logs/Log_24-03-26_16-53-41.wpilog

-10.7 MB
Binary file not shown.

sim_logs/Log_24-03-26_17-02-18.wpilog

-2.33 MB
Binary file not shown.

sim_logs/Log_24-03-26_17-03-13.wpilog

-2.77 MB
Binary file not shown.

sim_logs/Log_24-03-26_17-04-32.wpilog

-530 KB
Binary file not shown.

sim_logs/Log_24-03-26_17-06-37.wpilog

-1.24 MB
Binary file not shown.

sim_logs/Log_24-03-26_17-08-13.wpilog

-177 KB
Binary file not shown.

sim_logs/Log_3d6856de97fcdd78.wpilog

-87 Bytes
Binary file not shown.

sim_logs/Log_83507f982185395e.wpilog

-87 Bytes
Binary file not shown.

sim_logs/Log_91d5eeb224f9d4f0.wpilog

-87 Bytes
Binary file not shown.

sim_logs/Log_940c1027443a1052.wpilog

-87 Bytes
Binary file not shown.

sim_logs/Log_b794d6b437744c25.wpilog

-87 Bytes
Binary file not shown.

simgui.json

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"/SmartDashboard/NoteTwo": "String Chooser",
3737
"/SmartDashboard/NoteTwoShot": "String Chooser",
3838
"/SmartDashboard/Pathfind to Pickup Pos": "Command",
39+
"/SmartDashboard/Pivot Sysid": "Command",
3940
"/SmartDashboard/PivotArm": "Subsystem",
4041
"/SmartDashboard/Start": "String Chooser",
4142
"/SmartDashboard/Sysid Dynamic Drive Backward": "Command",
@@ -78,6 +79,11 @@
7879
"window": {
7980
"visible": true
8081
}
82+
},
83+
"/SmartDashboard/Pivot Sysid": {
84+
"window": {
85+
"visible": true
86+
}
8187
}
8288
}
8389
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ public void disabledPeriodic() {
574574

575575
setPivotPose3d();
576576
field.setRobotPose(drive.getPose());
577+
Logger.recordOutput("DriveAimed", DriveCommands.pointedAtSpeaker(drive));
578+
Logger.recordOutput("PivotAimed", pivot.atSetpoint());
577579
}
578580

579581
public Command intakeUntilIntaked(){

src/main/java/frc/robot/commands/DriveCommands.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public static Command joystickDrive(
8585
.getTranslation();
8686

8787
// Convert to field relative speeds & send command
88-
boolean isFlipped = DriverStation.getAlliance().isPresent()
89-
&& DriverStation.getAlliance().get() == Alliance.Red;
88+
boolean isFlipped = getIsFlipped();
9089
drive.runVelocity(
9190
ChassisSpeeds.fromFieldRelativeSpeeds(
9291
linearVelocity.getX() * drive.getMaxLinearSpeedMetersPerSec(),
@@ -138,6 +137,11 @@ public static Command joystickDriveRobotRelative(
138137
drive);
139138
}
140139

140+
private static boolean getIsFlipped() {
141+
return DriverStation.getAlliance().isPresent()
142+
&& DriverStation.getAlliance().get() == Alliance.Red;
143+
}
144+
141145
/**
142146
* Drive robot while pointing at a specific point on the field.
143147
*/
@@ -153,6 +157,8 @@ public static Command joystickSpeakerPoint(
153157
// should use field
154158
// constants
155159

160+
161+
156162

157163
// Apply deadband
158164
double linearMagnitude = MathUtil.applyDeadband(
@@ -161,9 +167,12 @@ public static Command joystickSpeakerPoint(
161167
Rotation2d linearDirection = new Rotation2d(xSupplier.getAsDouble() * slowMode,
162168
ySupplier.getAsDouble() * slowMode);
163169
Transform2d targetTransform = drive.getPose().minus(speakerPose);
164-
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY());
170+
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY())
171+
.plus(new Rotation2d(getIsFlipped() ? Math.PI : 0));
165172
// Rotation2d deltaDirection = drive.getRotation().minus(targetDirection);
166173

174+
Logger.recordOutput("AimAngle", targetDirection);
175+
167176
double omega = angleController.calculate(drive.getRotation().getRadians(),
168177
targetDirection.getRadians());
169178

@@ -210,7 +219,7 @@ public static Command joystickPasserPoint(
210219
Rotation2d linearDirection = new Rotation2d(xSupplier.getAsDouble() * slowMode,
211220
ySupplier.getAsDouble() * slowMode);
212221
Transform2d targetTransform = drive.getPose().minus(passerPosition);
213-
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY());
222+
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY()).plus(new Rotation2d(getIsFlipped() ? Math.PI : 0));;
214223
// Rotation2d deltaDirection = drive.getRotation().minus(targetDirection);
215224

216225
double omega = angleController.calculate(drive.getRotation().getRadians(),
@@ -283,13 +292,13 @@ public static Command turnSpeakerAngle(Drive drive) {
283292
return new FunctionalCommand(
284293
() -> {
285294
Transform2d targetTransform = drive.getPose().minus(speakerPose);
286-
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY());
295+
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY()).plus(new Rotation2d(getIsFlipped() ? Math.PI : 0));;
287296
angleController.setSetpoint(targetDirection.getRadians());
288297
},
289298
() -> {
290299
// defines distance from speaker
291300
Transform2d targetTransform = drive.getPose().minus(speakerPose);
292-
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY());
301+
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY()).plus(new Rotation2d(getIsFlipped() ? Math.PI : 0));;
293302
double omega = angleController.calculate(drive.getRotation().getRadians(),
294303
targetDirection.getRadians());
295304
omega = Math.copySign(omega * omega, omega); // no idea why squared
@@ -322,7 +331,7 @@ public static void toggleSlowMode() {
322331
public static boolean pointedAtSpeaker(Drive drive) {
323332
Pose2d speakerPose = FieldConstants.speakerPosition();
324333
Transform2d targetTransform = drive.getPose().minus(speakerPose);
325-
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY());
334+
Rotation2d targetDirection = new Rotation2d(targetTransform.getX(), targetTransform.getY()).plus(new Rotation2d(getIsFlipped() ? Math.PI : 0));;
326335

327336
// Convert to robot relative speeds and send command
328337
if (Math.abs(drive.getRotation().getDegrees() - targetDirection.getDegrees()) < 1) {

src/main/java/frc/robot/subsystems/pivotArm/PivotArm.java

+38-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import static edu.wpi.first.units.Units.Second;
44
import static edu.wpi.first.units.Units.Seconds;
55
import static edu.wpi.first.units.Units.Volts;
6+
import static edu.wpi.first.units.MutableMeasure.mutable;
7+
import static edu.wpi.first.units.Units.Rotations;
8+
import static edu.wpi.first.units.Units.RotationsPerSecond;
69

710
import java.util.function.DoubleSupplier;
811

@@ -12,12 +15,18 @@
1215
import edu.wpi.first.math.MathUtil;
1316
import edu.wpi.first.math.geometry.Rotation2d;
1417
import edu.wpi.first.math.util.Units;
18+
import edu.wpi.first.units.Angle;
19+
import edu.wpi.first.units.MutableMeasure;
20+
import edu.wpi.first.units.Velocity;
21+
import edu.wpi.first.units.Voltage;
22+
import edu.wpi.first.wpilibj.RobotController;
1523
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
1624
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1725
import edu.wpi.first.wpilibj.util.Color;
1826
import edu.wpi.first.wpilibj.util.Color8Bit;
1927
import edu.wpi.first.wpilibj2.command.Command;
2028
import edu.wpi.first.wpilibj2.command.FunctionalCommand;
29+
import edu.wpi.first.wpilibj2.command.InstantCommand;
2130
import edu.wpi.first.wpilibj2.command.SubsystemBase;
2231
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
2332
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction;
@@ -35,6 +44,13 @@ public class PivotArm extends SubsystemBase {
3544
private LoggedDashboardNumber logkV;
3645
private LoggedDashboardNumber logkA;
3746

47+
// Mutable holder for unit-safe voltage values, persisted to avoid reallocation.
48+
private final MutableMeasure<Voltage> m_appliedVoltage = mutable(Volts.of(0));
49+
// Mutable holder for unit-safe linear distance values, persisted to avoid reallocation.
50+
private final MutableMeasure<Angle> m_angle = mutable(Rotations.of(0));
51+
// Mutable holder for unit-safe linear velocity values, persisted to avoid reallocation.
52+
private final MutableMeasure<Velocity<Angle>> m_velocity = mutable(RotationsPerSecond.of(0));
53+
3854

3955
private double setpoint = 0;
4056

@@ -61,8 +77,18 @@ public PivotArm(PivotArmIO io) {
6177
logkA = new LoggedDashboardNumber("PivotArm/kG", io.getkA());
6278

6379
SysId = new SysIdRoutine(
64-
new SysIdRoutine.Config(Volts.per(Second).of(PivotArmConstants.RAMP_RATE), Volts.of(PivotArmConstants.STEP_VOLTAGE), Seconds.of(6)),
65-
new SysIdRoutine.Mechanism(v -> io.setVoltage(v.in(Volts)), null, this));
80+
new SysIdRoutine.Config(Volts.per(Second).of(PivotArmConstants.RAMP_RATE), Volts.of(PivotArmConstants.STEP_VOLTAGE), null),
81+
new SysIdRoutine.Mechanism(v -> io.setVoltage(v.in(Volts)),
82+
(sysidLog) -> {
83+
sysidLog.motor("pivot")
84+
.voltage(
85+
m_appliedVoltage.mut_replace(inputs.appliedVolts, Volts))
86+
.angularPosition(m_angle.mut_replace(inputs.angleRads, Rotations))
87+
.angularVelocity(
88+
m_velocity.mut_replace(inputs.angVelocityRadsPerSec, RotationsPerSecond));
89+
90+
},
91+
this));
6692

6793
}
6894

@@ -251,38 +277,43 @@ public Command bringDownCommand() {
251277
() -> {},
252278
() -> {
253279
move(-1);
280+
setpoint = 0;
254281
},
255282
(interrupted) -> {
256283
move(0);
257284
},
258285
() -> {
259-
return io.getAngle() < 0.15;
286+
return io.getAngle() < 0.1;
260287
},
261288
this);
262289
}
263290

264291
public Command quasistaticForward() {
265292
return SysId
266293
.quasistatic(Direction.kForward)
267-
.until(() -> getAngle().getRadians() > PivotArmConstants.PIVOT_ARM_MAX_ANGLE);
294+
.until(() -> getAngle().getRadians() > PivotArmConstants.PIVOT_ARM_MAX_ANGLE)
295+
.alongWith(new InstantCommand(() -> Logger.recordOutput("PivotArm/sysid-test-state-", "quasistatic-forward")));
268296
}
269297

270298
public Command quasistaticBack() {
271299
return SysId
272300
.quasistatic(Direction.kReverse)
273-
.until(() -> getAngle().getRadians() < PivotArmConstants.PIVOT_ARM_MIN_ANGLE);
301+
.until(() -> getAngle().getRadians() < PivotArmConstants.PIVOT_ARM_MIN_ANGLE)
302+
.alongWith(new InstantCommand(() -> Logger.recordOutput("PivotArm/sysid-test-state-", "quasistatic-reverse")));
274303
}
275304

276305
public Command dynamicForward() {
277306
return SysId
278307
.dynamic(Direction.kForward)
279-
.until(() -> getAngle().getRadians() > PivotArmConstants.PIVOT_ARM_MAX_ANGLE);
308+
.until(() -> getAngle().getRadians() > PivotArmConstants.PIVOT_ARM_MAX_ANGLE)
309+
.alongWith(new InstantCommand(() -> Logger.recordOutput("PivotArm/sysid-test-state-", "dynamic-forward")));
280310
}
281311

282312
public Command dynamicBack() {
283313
return SysId
284314
.dynamic(Direction.kReverse)
285-
.until(() -> getAngle().getRadians() < PivotArmConstants.PIVOT_ARM_MIN_ANGLE);
315+
.until(() -> getAngle().getRadians() < PivotArmConstants.PIVOT_ARM_MIN_ANGLE)
316+
.alongWith(new InstantCommand(() -> Logger.recordOutput("PivotArm/sysid-test-state-", "dynamic-reverse")));
286317
}
287318

288319
}

src/main/java/frc/robot/util/drive/DriveControls.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,26 @@ public static void configureControls() {
9191
break;
9292
case PROGRAMMERS:
9393
default:
94-
DRIVE_FORWARD = () -> -driver.getLeftY();
95-
DRIVE_STRAFE = () -> -driver.getLeftX();
96-
DRIVE_ROTATE = driver::getRightX;
97-
DRIVE_SLOW = driver.x();
98-
DRIVE_SPEAKER_AIM = driver.b();
99-
100-
DRIVE_STOP = driver.rightBumper();
94+
// Driver controls
95+
DRIVE_FORWARD = () -> (-driver.getLeftY());
96+
DRIVE_STRAFE = ()->(-driver.getLeftX());
97+
DRIVE_ROTATE = () -> (-driver.getRightX());
10198

102-
LOCK_PASS = driver.a();
99+
// Driver Settings
100+
DRIVE_SLOW = driver.start();
101+
DRIVE_STOP = driver.x();
103102

104-
DRIVE_AMP = driver.leftBumper();
105-
break;
103+
// Driver Modes
104+
DRIVE_ROBOT_RELATIVE = driver.y();
105+
DRIVE_SPEAKER_AIM = driver.b(); // uses vision
106+
107+
// Driver Angle Locks
108+
LOCK_BACK = driver.getDPad(DPad.DOWN);
109+
LOCK_PICKUP = driver.getDPad(DPad.RIGHT);
110+
LOCK_ON_AMP = driver.rightBumper();
111+
LOCK_PASS = driver.getDPad(DPad.LEFT); // uses vision
112+
113+
DRIVE_AMP = EMPTY_TRIGGER; // uses vision
106114
}
107115

108116
switch (Constants.operator) {

0 commit comments

Comments
 (0)