|
20 | 20 | import edu.wpi.first.util.sendable.SendableBuilder; |
21 | 21 | import edu.wpi.first.wpilibj2.command.Command; |
22 | 22 |
|
| 23 | +import java.util.List; |
23 | 24 | import java.util.function.Supplier; |
24 | 25 |
|
25 | 26 |
|
@@ -84,8 +85,10 @@ public ExampleShooter() { |
84 | 85 | solver = new TrajectorySolver(gamePiece, solverConfig); |
85 | 86 |
|
86 | 87 | shooterSystem = new ShooterSystem(config, table, solver); |
87 | | - shooterSystem.setMode(ShotMode.LOOKUP_WITH_SOLVER_FALLBACK); |
| 88 | + shooterSystem.setMode(ShotMode.SOLVER_ONLY); |
88 | 89 | shooterSystem.setFallbackShot(60.0, 3000); |
| 90 | + |
| 91 | + solver.setDebugEnabled(true); |
89 | 92 | } |
90 | 93 |
|
91 | 94 | public void setPoseSupplier(Supplier<Pose2d> supplier) { this.poseSupplier = supplier; } |
@@ -138,6 +141,100 @@ public void periodic() { |
138 | 141 | Pose3d goalPose = new Pose3d(targetPosition, new Rotation3d()); |
139 | 142 | Logger.recordOutput("ExampleShooter/GoalPose3d", goalPose); |
140 | 143 | Logger.recordOutput("ExampleShooter/GoalPose3dArray", new Pose3d[] { goalPose }); |
| 144 | + |
| 145 | + recordOutput("TargetX", targetPosition.getX()); |
| 146 | + recordOutput("TargetY", targetPosition.getY()); |
| 147 | + recordOutput("TargetZ", targetPosition.getZ()); |
| 148 | + recordOutput("ShooterHeight", shooterHeightMeters); |
| 149 | + recordOutput("ExitVelocity", currentShot.exitVelocityMps); |
| 150 | + |
| 151 | + logTrajectoryDebug(); |
| 152 | + } |
| 153 | + |
| 154 | + private void logTrajectoryDebug() { |
| 155 | + TrajectoryResult trajResult = shooterSystem.getLastTrajectoryResult(); |
| 156 | + if (trajResult == null) return; |
| 157 | + |
| 158 | + recordOutput("Trajectory/Status", trajResult.getStatus().name()); |
| 159 | + recordOutput("Trajectory/StatusMessage", trajResult.getStatusMessage()); |
| 160 | + recordOutput("Trajectory/Confidence", trajResult.getConfidenceScore()); |
| 161 | + |
| 162 | + if (trajResult.isSuccess()) { |
| 163 | + recordOutput("Trajectory/PitchDeg", trajResult.getPitchAngleDegrees()); |
| 164 | + recordOutput("Trajectory/YawAdjustDeg", trajResult.getYawAdjustmentDegrees()); |
| 165 | + recordOutput("Trajectory/Velocity", trajResult.getRequiredVelocityMps()); |
| 166 | + recordOutput("Trajectory/TimeOfFlight", trajResult.getTimeOfFlightSeconds()); |
| 167 | + recordOutput("Trajectory/MaxHeight", trajResult.getMaxHeightMeters()); |
| 168 | + recordOutput("Trajectory/Margin", trajResult.getMarginOfErrorMeters()); |
| 169 | + recordOutput("Trajectory/RPM", trajResult.getRecommendedRpm()); |
| 170 | + |
| 171 | + List<Pose3d> flightPath = trajResult.getFlightPath(); |
| 172 | + if (!flightPath.isEmpty()) { |
| 173 | + Logger.recordOutput("ExampleShooter/Trajectory/FlightPath", |
| 174 | + flightPath.toArray(new Pose3d[0])); |
| 175 | + |
| 176 | + double[] pathX = new double[flightPath.size()]; |
| 177 | + double[] pathY = new double[flightPath.size()]; |
| 178 | + double[] pathZ = new double[flightPath.size()]; |
| 179 | + for (int i = 0; i < flightPath.size(); i++) { |
| 180 | + pathX[i] = flightPath.get(i).getX(); |
| 181 | + pathY[i] = flightPath.get(i).getY(); |
| 182 | + pathZ[i] = flightPath.get(i).getZ(); |
| 183 | + } |
| 184 | + recordOutput("Trajectory/PathX", pathX); |
| 185 | + recordOutput("Trajectory/PathY", pathY); |
| 186 | + recordOutput("Trajectory/PathZ", pathZ); |
| 187 | + recordOutput("Trajectory/PathLength", flightPath.size()); |
| 188 | + } |
| 189 | + } |
| 190 | + |
| 191 | + SolveDebugInfo debug = trajResult.getDebugInfo(); |
| 192 | + if (debug != null) { |
| 193 | + recordOutput("Debug/Enabled", true); |
| 194 | + recordOutput("Debug/TotalTested", debug.getTotalTested()); |
| 195 | + recordOutput("Debug/Accepted", debug.getAcceptedCount()); |
| 196 | + recordOutput("Debug/TotalRejected", debug.getTotalRejected()); |
| 197 | + recordOutput("Debug/RejectedCollision", debug.getRejectedCollisionCount()); |
| 198 | + recordOutput("Debug/RejectedArcTooLow", debug.getRejectedArcTooLowCount()); |
| 199 | + recordOutput("Debug/RejectedClearance", debug.getRejectedClearanceCount()); |
| 200 | + recordOutput("Debug/RejectedMiss", debug.getRejectedMissCount()); |
| 201 | + recordOutput("Debug/RejectedFlyover", debug.getRejectedFlyoverCount()); |
| 202 | + recordOutput("Debug/BestScore", debug.getBestScore()); |
| 203 | + recordOutput("Debug/BestPitchDeg", debug.getBestPitchDegrees()); |
| 204 | + recordOutput("Debug/Summary", debug.getSummary()); |
| 205 | + recordOutput("Debug/DetailedTable", debug.getDetailedTable()); |
| 206 | + |
| 207 | + List<SolveDebugInfo.CandidateInfo> accepted = debug.getAcceptedCandidates(); |
| 208 | + double[] accPitch = new double[accepted.size()]; |
| 209 | + double[] accScore = new double[accepted.size()]; |
| 210 | + double[] accTOF = new double[accepted.size()]; |
| 211 | + double[] accMaxH = new double[accepted.size()]; |
| 212 | + for (int i = 0; i < accepted.size(); i++) { |
| 213 | + accPitch[i] = accepted.get(i).getPitchDegrees(); |
| 214 | + accScore[i] = accepted.get(i).getScore(); |
| 215 | + accTOF[i] = accepted.get(i).getTimeOfFlight(); |
| 216 | + accMaxH[i] = accepted.get(i).getMaxHeight(); |
| 217 | + } |
| 218 | + recordOutput("Debug/AcceptedPitches", accPitch); |
| 219 | + recordOutput("Debug/AcceptedScores", accScore); |
| 220 | + recordOutput("Debug/AcceptedTOF", accTOF); |
| 221 | + recordOutput("Debug/AcceptedMaxHeight", accMaxH); |
| 222 | + |
| 223 | + List<SolveDebugInfo.CandidateInfo> all = debug.getCandidates(); |
| 224 | + double[] allPitch = new double[all.size()]; |
| 225 | + double[] allClosest = new double[all.size()]; |
| 226 | + String[] allStatus = new String[all.size()]; |
| 227 | + for (int i = 0; i < all.size(); i++) { |
| 228 | + allPitch[i] = all.get(i).getPitchDegrees(); |
| 229 | + allClosest[i] = all.get(i).getClosestApproach(); |
| 230 | + allStatus[i] = all.get(i).getRejection().name(); |
| 231 | + } |
| 232 | + recordOutput("Debug/AllPitches", allPitch); |
| 233 | + recordOutput("Debug/AllClosest", allClosest); |
| 234 | + recordOutput("Debug/AllStatus", allStatus); |
| 235 | + } else { |
| 236 | + recordOutput("Debug/Enabled", false); |
| 237 | + } |
141 | 238 | } |
142 | 239 |
|
143 | 240 | /** |
@@ -168,10 +265,22 @@ private void updateShot() { |
168 | 265 |
|
169 | 266 | double measuredRpm = currentRpmSupplier != null ? currentRpmSupplier.get() : 0; |
170 | 267 |
|
| 268 | + shooterSystem.setSolverInputTemplate( |
| 269 | + ShotInput.builder() |
| 270 | + .shooterPositionMeters(shooterX, shooterY, shooterHeightMeters) |
| 271 | + .shooterYawRadians(yawRad) |
| 272 | + .targetPositionMeters(targetPosition.getX(), targetPosition.getY(), targetPosition.getZ()) |
| 273 | + .targetRadiusMeters(0.53) |
| 274 | + .includeAirResistance(true) |
| 275 | + .robotVelocity(vx, vy) |
| 276 | + ); |
| 277 | + |
171 | 278 | currentShot = shooterSystem.calculate(lastDistanceMeters, measuredRpm, vx, vy, yawRad); |
172 | 279 |
|
173 | 280 | recordOutput("RobotX", pose.getX()); |
174 | 281 | recordOutput("RobotY", pose.getY()); |
| 282 | + recordOutput("ShooterX", shooterX); |
| 283 | + recordOutput("ShooterY", shooterY); |
175 | 284 | } |
176 | 285 |
|
177 | 286 | /** |
|
0 commit comments