@@ -68,39 +68,24 @@ public class AlignWithNearest extends Command {
6868
6969 // add vision as a requirement to run
7070 public AlignWithNearest () {
71- this .xLimiter = new SlewRateLimiter (4 );
72- this .yLimiter = new SlewRateLimiter (4 );
73- this .giroLimiter = new SlewRateLimiter (Units .degreesToRadians (720 ));
74-
75- /**
76- * PID Controllers for the align
77- */
78- this .drivePID = new PIDController (
79- 0.00023 ,
80- 0.0000002 ,
81- 2 );
82-
83- this .strafePID = new PIDController (
84- 0.00023 ,
85- 0.0000002 ,
86- 2 );
87-
88- this .rotationPID = new PIDController (
89- 0.0020645 ,
90- 0 ,
91- 0 );
92- /**
93- * Boolean for what target to search
94- */
95-
96- /**
97- * Offsets for the limelight
98- */
99- //this.offsets = limelight.getOffsets(alingToAprilTag);
100-
101- this .driveOffset = 2.1 ;
102- this .strafeOffset = -0.2 ;
103- this .rotationOffset = 10.2 ;
71+ this .xLimiter = new SlewRateLimiter (4 );
72+ this .yLimiter = new SlewRateLimiter (4 );
73+ this .giroLimiter = new SlewRateLimiter (Units .degreesToRadians (720 ));
74+
75+ /** PID Controllers for the align */
76+ this .drivePID = new PIDController (0.00023 , 0.0000002 , 2 );
77+
78+ this .strafePID = new PIDController (0.00023 , 0.0000002 , 2 );
79+
80+ this .rotationPID = new PIDController (0.0020645 , 0 , 0 );
81+ /** Boolean for what target to search */
82+
83+ /** Offsets for the limelight */
84+ // this.offsets = limelight.getOffsets(alingToAprilTag);
85+
86+ this .driveOffset = 2.1 ;
87+ this .strafeOffset = -0.2 ;
88+ this .rotationOffset = 10.2 ;
10489 }
10590
10691 @ Override
@@ -115,40 +100,42 @@ public void initialize() {
115100 */
116101 }
117102
118- public void execute (){
103+ public void execute () {
119104 double velForward = 0 ;
120- double velStrafe = 0 ;
121- double velGiro = 0 ;
122-
123- /**
124- * If there is a seen target, calculate the PIDs velocities,
125- * otherwise, rotate so the robot can search the target
126- */
127- if (VisionSubsystem .getTags ().length != 0 ){
128-
129- velForward = drivePID .calculate (VisionSubsystem .getTagArea (), driveOffset );
130- velStrafe = strafePID .calculate (VisionSubsystem .getXDistance (), strafeOffset );
131- velGiro = -rotationPID .calculate (VisionSubsystem .getTagPose2d ().getRotation ().getDegrees (), rotationOffset );
132- } else if (VisionSubsystem .getTags ().length == 0 ){
133- velForward = 0 ;
134- velStrafe = 0 ;
135- velGiro = 0.4 ;
136- } else {
137- velForward = 0 ;
138- velStrafe = 0 ;
139- velGiro = 0 ;
140- }
141-
142- // 3. Make the driving smoother
143- velForward = xLimiter .calculate (velForward ) * 3 ;
144- velStrafe = yLimiter .calculate (velStrafe ) * 3 ;
145- velGiro = giroLimiter .calculate (velGiro ) * 5 ;
146-
147- // 4. Construct desired chassis speeds
148- ChassisSpeeds chassisSpeeds ;
149-
150- //Relative to robot
151- chassisSpeeds = new ChassisSpeeds (velForward , velStrafe , velGiro );
105+ double velStrafe = 0 ;
106+ double velGiro = 0 ;
107+
108+ /**
109+ * If there is a seen target, calculate the PIDs velocities, otherwise, rotate so the robot can
110+ * search the target
111+ */
112+ if (VisionSubsystem .getTags ().length != 0 ) {
113+
114+ velForward = drivePID .calculate (VisionSubsystem .getTagArea (), driveOffset );
115+ velStrafe = strafePID .calculate (VisionSubsystem .getXDistance (), strafeOffset );
116+ velGiro =
117+ -rotationPID .calculate (
118+ VisionSubsystem .getTagPose2d ().getRotation ().getDegrees (), rotationOffset );
119+ } else if (VisionSubsystem .getTags ().length == 0 ) {
120+ velForward = 0 ;
121+ velStrafe = 0 ;
122+ velGiro = 0.4 ;
123+ } else {
124+ velForward = 0 ;
125+ velStrafe = 0 ;
126+ velGiro = 0 ;
127+ }
128+
129+ // 3. Make the driving smoother
130+ velForward = xLimiter .calculate (velForward ) * 3 ;
131+ velStrafe = yLimiter .calculate (velStrafe ) * 3 ;
132+ velGiro = giroLimiter .calculate (velGiro ) * 5 ;
133+
134+ // 4. Construct desired chassis speeds
135+ ChassisSpeeds chassisSpeeds ;
136+
137+ // Relative to robot
138+ chassisSpeeds = new ChassisSpeeds (velForward , velStrafe , velGiro );
152139 }
153140
154141 @ Override
0 commit comments