@@ -40,8 +40,8 @@ public class Targeting extends SubsystemBase {
40
40
private final static double FOV_CAMERA_IN_DEGREES = 78.0 ;
41
41
private double m_bestY = 0.0 ;
42
42
private double m_bestX = 0.0 ;
43
- private double tilt = 0.0 ;
44
- private double area = 0.0 ;
43
+ private double m_tilt = 0.0 ;
44
+ private double m_area = 0.0 ;
45
45
46
46
public enum TargetPosition {
47
47
LEFT_MOST , CENTER_MOST , RIGHT_MOST , CENTER_OF_RIGHT_CARGO_SHIP , CENTER_OF_LEFT_CARGO_SHIP
@@ -51,17 +51,12 @@ public enum TargetHeight {
51
51
CARGO , HATCH
52
52
};
53
53
54
- private TargetPosition m_mode = TargetPosition .CENTER_MOST ;
55
- // Mode for target height
56
- private TargetHeight m_TargetHeightMode = TargetHeight .HATCH ;
57
-
58
54
@ Override
59
55
public void periodic () {
60
56
update ();
61
57
}
62
58
63
59
// TODO: make an updateSmartDashboard() method in Targeting for optimization
64
- // TODO: clean up the content in Targeting.update() -- just too long!
65
60
public void update () {
66
61
// perform periodic update functions for the targeting capability
67
62
int latestFrameCount = (int ) SmartDashboard .getNumber ("frameCount" , -1.0 /* default to -1 */ );
@@ -86,14 +81,11 @@ public void update() {
86
81
SmartDashboard .putString ("visionOkDebug" , "Good Data" );
87
82
}
88
83
89
- double [] centerMostTargetArray ;
90
84
// Update all of the targeting information, as follows:
91
85
// 1 - Determine if we have any valid data in the array.
92
86
// If not, set the "error" to zero, so that the robot thinks
93
87
// it is on target.
94
- // 2 - Look through the valid data in the array to find the
95
- // target closest to the "trueCenter"
96
- // 3 - Use the selected target to compute the needed information
88
+ // 2 - Use the target to compute the needed information
97
89
98
90
// get the latest output from the targeting camera
99
91
m_target_array = SmartDashboard .getNumberArray ("target" , ARRAY_OF_NEG_ONE );
@@ -102,15 +94,15 @@ public void update() {
102
94
// this means the key is found, but is empty
103
95
m_bestX = 0.0 ;
104
96
m_bestY = 0.0 ;
105
- tilt = 0.0 ;
106
- area = 0.0 ;
97
+ m_tilt = 0.0 ;
98
+ m_area = 0.0 ;
107
99
m_desiredAzimuth = RobotContainer .shooter .getAzimuthForCapturedImage ();
108
100
} else if (m_target_array [0 ] < 0.0 ) {
109
101
// this means the array has no valid data. Set m_xError = 0.0
110
102
m_bestX = 0.0 ;
111
103
m_bestY = 0.0 ;
112
- tilt = 0.0 ;
113
- area = 0.0 ;
104
+ m_tilt = 0.0 ;
105
+ m_area = 0.0 ;
114
106
m_desiredAzimuth = RobotContainer .shooter .getAzimuthForCapturedImage ();
115
107
} else {
116
108
// We have a valid data array.
@@ -123,17 +115,17 @@ public void update() {
123
115
// we need the results in "bestXError" and "bestY"
124
116
m_bestX = m_target_array [0 ]; // get the x-value
125
117
m_bestY = m_target_array [1 ]; // get the y-value
126
- tilt = m_target_array [2 ];
127
- area = m_target_array [3 ];
118
+ m_tilt = m_target_array [2 ];
119
+ m_area = m_target_array [3 ];
128
120
129
- m_desiredAzimuth = findDesiredAzimuth (m_bestX , m_bestY , tilt , area );
121
+ m_desiredAzimuth = findDesiredAzimuth (m_bestX , m_bestY , m_tilt , m_area );
130
122
}
131
123
132
124
// at this point in the code, the "selected" target should be in the "best"
133
125
SmartDashboard .putNumber ("m_bestX" , m_bestX );
134
126
SmartDashboard .putNumber ("m_bestY" , m_bestY );
135
- SmartDashboard .putNumber ("tilt " , tilt );
136
- SmartDashboard .putNumber ("area " , area );
127
+ SmartDashboard .putNumber ("m_tilt " , m_tilt );
128
+ SmartDashboard .putNumber ("m_area " , m_area );
137
129
}
138
130
139
131
public double getDesiredAzimuth () {
@@ -163,30 +155,8 @@ public double getRecommendedSpeed() {
163
155
return speed ;
164
156
}
165
157
166
- // public boolean atWall(Autonomous.RocketHeight desiredHeight) {
167
- // // we are at the wall when the target is lower in the field of view (bigger
168
- // Y)
169
- // // than the "at the wall" threshold
170
- // switch (desiredHeight) {
171
- // case HIGH:
172
- // return (m_bestY >= Y_WHEN_HATCH_HIGH_AT_WALL);
173
- // case MID:
174
- // return (m_bestY >= Y_WHEN_HATCH_MID_AT_WALL);
175
- // case LOW:
176
- // return (m_bestY >= Y_WHEN_HATCH_LOW_AT_WALL);
177
- // default:
178
- // return (m_bestY >= Y_WHEN_HATCH_LOW_AT_WALL);
179
- // }
180
- // }
181
-
182
- public void setMode (TargetPosition modeToSet ) {
183
- // Set the mode e.g. LEFT_MOST, CENTER_MOST, RIGHT_MOST,
184
- // CENTER_OF_RIGHT_CARGO_SHIP, CENTER_OF_LEFT_CARGO_SHIP
185
- m_mode = modeToSet ;
186
- }
187
-
188
- private final double CenterOfTarget_X = 0.5 ;
189
- private final double TICK_PER_DEGREE = (6300.0 / 45.0 );
158
+ private final double CENTER_OF_TARGET_X = 0.5 ;
159
+ private final double TICKS_PER_DEGREE = (6300.0 / 45.0 );
190
160
191
161
/**
192
162
* Return the desired turrent encoder ticks in the turret for the center of the
@@ -200,28 +170,24 @@ public void setMode(TargetPosition modeToSet) {
200
170
*/
201
171
public double findDesiredAzimuth (double X , double Y , double tilt , double area ) {
202
172
// Calulate angle error based on an X,Y
203
- double AngleError ;
173
+ double angleError ;
204
174
double ticksError ;
205
- // double TrueCenter;
206
- double XError ;
175
+ double xError ;
207
176
double desiredAzimuth ;
208
177
209
- // compute the "x error" based upon the trueCenter
210
- XError = X - CenterOfTarget_X ;
178
+ // compute the "x error" based upon the center for shooting
179
+ xError = X - CENTER_OF_TARGET_X ;
211
180
// Find the angle error
212
- AngleError = FOV_CAMERA_IN_DEGREES * XError ;
213
- ticksError = AngleError * TICK_PER_DEGREE ;
181
+ angleError = FOV_CAMERA_IN_DEGREES * xError ;
182
+ // convert the angle error into ticks
183
+ ticksError = angleError * TICKS_PER_DEGREE ;
214
184
215
- // Convert angleError into a desired heading , using the heading history
185
+ // Convert angleError into a desired azimuth , using the azimuth history
216
186
desiredAzimuth = ticksError + RobotContainer .shooter .getAzimuthForCapturedImage ();
217
187
// Update SmartDashboard
218
- SmartDashboard .putNumber ("True Angle Error" , AngleError );
188
+ SmartDashboard .putNumber ("Vision Angle Error" , angleError );
219
189
SmartDashboard .putNumber ("Vision Desired Azimuth" , desiredAzimuth );
220
190
return desiredAzimuth ;
221
191
}
222
192
223
- public void setTargetHeight (TargetHeight target ) {
224
- m_TargetHeightMode = target ;
225
- }
226
-
227
193
}
0 commit comments