@@ -16,10 +16,10 @@ public class localizationSubsystem extends SubsystemBase {
1616 private static final double TARGET_DISTANCE_FEET = 2.0 ;
1717 private static final double ANGLE_TOLERANCE_DEGREES = 2.0 ;
1818 private static final double DISTANCE_TOLERANCE_FEET = 0.3 ;
19-
20- private static final double CAMERA_MOUNT_ANGLE_DEGREES = 0 .0 ;
21- private static final double CAMERA_HEIGHT_INCHES = 24 .0 ;
22- private static final double TAG_HEIGHT_INCHES = 6 .0 ;
19+
20+ private static final double CAMERA_MOUNT_ANGLE_DEGREES = 30 .0 ;
21+ private static final double CAMERA_HEIGHT_INCHES = 6 .0 ;
22+ private static final double TAG_HEIGHT_INCHES = 10 .0 ;
2323
2424 private double lastUpdate = 0.0 ;
2525
@@ -92,13 +92,16 @@ private void updateFromLimelight() {
9292
9393 /** Checks whether corner data is valid (not all zeros and length = 8) */
9494 private boolean isCornersValid () {
95- if (tcornxy == null || tcornxy .length < 8 )
96- return false ;
97- for (double v : tcornxy ) {
98- if (Math .abs (v ) > 1e-3 )
99- return true ;
100- }
101- return false ;
95+ /**
96+ * if (tcornxy == null || tcornxy.length < 8)
97+ * return false;
98+ * for (double v : tcornxy) {
99+ * if (Math.abs(v) > 1e-3)
100+ * return true;
101+ * }
102+ * return false;
103+ */
104+ return true ;
102105 }
103106
104107 /** Vertical & horizontal side lengths */
@@ -161,80 +164,81 @@ private void calculateDiagonalsAndMidpoint() {
161164 private void calculateOptimalMovement () {
162165 double realTimeTA = calculateTagArea ();
163166 double currentDistance = calculateDistanceFromArea (realTimeTA );
164-
165- Logger .recordOutput ("Movement/CurrentDistance_Feet" , currentDistance );
167+ // currentDistance -= 1;
168+
169+ Logger .recordOutput ("Movement/CurrentDistance_Feet" , currentDistance + 1 );
166170 Logger .recordOutput ("Movement/TargetDistance_Feet" , TARGET_DISTANCE_FEET );
167-
171+
168172 double horizontalAngleError = tx ;
169173 Logger .recordOutput ("Movement/HorizontalAngleError_Degrees" , horizontalAngleError );
170-
174+
171175 double forwardMovement = currentDistance - TARGET_DISTANCE_FEET ;
172176 Logger .recordOutput ("Movement/RequiredForward_Feet" , forwardMovement );
173-
177+
174178 double strafeMovement = currentDistance * Math .tan (Math .toRadians (horizontalAngleError ));
175179 Logger .recordOutput ("Movement/RequiredStrafe_Feet" , strafeMovement );
176-
180+
177181 double rotationRequired = horizontalAngleError ;
178182 Logger .recordOutput ("Movement/RequiredRotation_Degrees" , rotationRequired );
179-
183+
180184 String movementCommand = generateMovementCommand (forwardMovement , strafeMovement , rotationRequired );
181185 Logger .recordOutput ("Movement/Command" , movementCommand );
182-
186+
183187 boolean isAligned = checkAlignment (forwardMovement , rotationRequired );
184188 Logger .recordOutput ("Movement/IsAligned" , isAligned );
185-
189+
186190 logMovementBreakdown (forwardMovement , strafeMovement , rotationRequired );
187191 }
188192
189193 private String generateMovementCommand (double forward , double strafe , double rotation ) {
190194 StringBuilder command = new StringBuilder ();
191-
192- if (Math .abs (forward ) < DISTANCE_TOLERANCE_FEET &&
193- Math .abs (rotation ) < ANGLE_TOLERANCE_DEGREES ) {
195+
196+ if (Math .abs (forward ) < DISTANCE_TOLERANCE_FEET &&
197+ Math .abs (rotation ) < ANGLE_TOLERANCE_DEGREES ) {
194198 return "ALIGNED - Hold position" ;
195199 }
196-
200+
197201 if (Math .abs (rotation ) > ANGLE_TOLERANCE_DEGREES ) {
198- command .append (String .format ("ROTATE %.1f° %s" ,
199- Math .abs (rotation ),
200- rotation > 0 ? "RIGHT" : "LEFT" ));
202+ command .append (String .format ("ROTATE %.1f° %s" ,
203+ Math .abs (rotation ),
204+ rotation > 0 ? "RIGHT" : "LEFT" ));
201205 command .append (" → THEN → " );
202206 }
203-
207+
204208 if (Math .abs (forward ) > DISTANCE_TOLERANCE_FEET ) {
205- command .append (String .format ("DRIVE %.2f ft %s" ,
206- Math .abs (forward ),
207- forward > 0 ? "BACKWARD" : "FORWARD" ));
209+ command .append (String .format ("DRIVE %.2f ft %s" ,
210+ Math .abs (forward ),
211+ forward > 0 ? "BACKWARD" : "FORWARD" ));
208212 } else {
209213 command .append ("HOLD DISTANCE" );
210214 }
211-
215+
212216 if (Math .abs (strafe ) > 0.1 ) {
213- command .append (String .format (" + STRAFE %.2f ft %s" ,
214- Math .abs (strafe ),
215- strafe > 0 ? "RIGHT" : "LEFT" ));
217+ command .append (String .format (" + STRAFE %.2f ft %s" ,
218+ Math .abs (strafe ),
219+ strafe > 0 ? "RIGHT" : "LEFT" ));
216220 }
217-
221+
218222 return command .toString ();
219223 }
220224
221225 private boolean checkAlignment (double forwardError , double rotationError ) {
222- return Math .abs (forwardError ) < DISTANCE_TOLERANCE_FEET &&
223- Math .abs (rotationError ) < ANGLE_TOLERANCE_DEGREES ;
226+ return Math .abs (forwardError ) < DISTANCE_TOLERANCE_FEET &&
227+ Math .abs (rotationError ) < ANGLE_TOLERANCE_DEGREES ;
224228 }
225229
226230 private void logMovementBreakdown (double forward , double strafe , double rotation ) {
227231 Logger .recordOutput ("Movement/Phase1_RotationNeeded" , Math .abs (rotation ) > ANGLE_TOLERANCE_DEGREES );
228232 Logger .recordOutput ("Movement/Phase2_ForwardNeeded" , Math .abs (forward ) > DISTANCE_TOLERANCE_FEET );
229233 Logger .recordOutput ("Movement/Phase3_StrafeNeeded" , Math .abs (strafe ) > 0.1 );
230-
234+
231235 Logger .recordOutput ("Movement/Direction_Forward" , forward < 0 );
232236 Logger .recordOutput ("Movement/Direction_Backward" , forward > 0 );
233237 Logger .recordOutput ("Movement/Direction_StrafeLeft" , strafe < 0 );
234238 Logger .recordOutput ("Movement/Direction_StrafeRight" , strafe > 0 );
235239 Logger .recordOutput ("Movement/Direction_RotateLeft" , rotation < 0 );
236240 Logger .recordOutput ("Movement/Direction_RotateRight" , rotation > 0 );
237-
241+
238242 Logger .recordOutput ("Movement/ForwardError_Inches" , forward * 12 );
239243 Logger .recordOutput ("Movement/StrafeError_Inches" , strafe * 12 );
240244 Logger .recordOutput ("Movement/RotationError_Degrees" , rotation );
@@ -260,21 +264,22 @@ public double getTa() {
260264 public double [] getTcornxy () {
261265 return tcornxy ;
262266 }
263-
267+
264268 public double getCurrentDistance () {
265269 if (isCornersValid ()) {
266270 return calculateDistanceFromArea (calculateTagArea ());
267271 }
268272 return -1.0 ;
269273 }
270-
274+
271275 public boolean isAligned () {
272- if (!isCornersValid ()) return false ;
273-
276+ if (!isCornersValid ())
277+ return false ;
278+
274279 double currentDistance = getCurrentDistance ();
275280 double forwardError = currentDistance - TARGET_DISTANCE_FEET ;
276281 double rotationError = tx ;
277-
282+
278283 return checkAlignment (forwardError , rotationError );
279284 }
280285}
0 commit comments