@@ -51,7 +51,7 @@ public class Targeting extends SubsystemBase {
51
51
private double [] m_target_array ;
52
52
private int m_priorFrameCount ;
53
53
private double m_priorFrameTime ;
54
- private double [] ARRAY_OF_NEG_ONE = { -1.0 };
54
+ private final double [] ARRAY_OF_NEG_ONE = { -1.0 };
55
55
56
56
private double m_bestY = 0.0 ;
57
57
private double m_bestX = 0.0 ;
@@ -65,65 +65,60 @@ public void periodic() {
65
65
66
66
// TODO: make an updateSmartDashboard() method in Targeting for optimization
67
67
public void update () {
68
- // perform periodic update functions for the targeting capability
69
- int latestFrameCount = (int ) SmartDashboard .getNumber ("frameCount" , -1.0 /* default to -1 */ );
70
- if (latestFrameCount < 0 ) {
71
- // an invalid number for latestFrameCount, display warning light
72
- SmartDashboard .putBoolean ("visionOK" , false );
73
- SmartDashboard .putString ("visionOkDebug" , "No Data" );
74
- } else if (latestFrameCount == m_priorFrameCount ) {
75
- // have not received a new frame. If more than 1 second has elapsed since
76
- // prior new frame, display a warning light on the SmartDashboard
77
- if (Timer .getFPGATimestamp () > m_priorFrameTime + 1.0 ) {
78
- SmartDashboard .putBoolean ("visionOK" , false );
79
- SmartDashboard .putString ("visionOkDebug" , "Stale Data" );
80
- } else {
81
- // else, have an old frame, but it's not too old yet, so do nothing
82
- }
83
- } else {
84
- // have received a new frame, save the time and update m_priorFrameCount
85
- m_priorFrameTime = Timer .getFPGATimestamp ();
86
- m_priorFrameCount = latestFrameCount ;
87
- SmartDashboard .putBoolean ("visionOK" , true );
88
- SmartDashboard .putString ("visionOkDebug" , "Good Data" );
89
- }
68
+ // get the latest output from the targeting camera
69
+ m_target_array = SmartDashboard .getNumberArray ("target" , ARRAY_OF_NEG_ONE );
90
70
91
71
// Update all of the targeting information, as follows:
92
72
// 1 - Determine if we have any valid data in the array.
93
73
// If not, set the "error" to zero, so that the robot thinks
94
74
// it is on target.
95
75
// 2 - Use the target to compute the needed information
96
76
97
- // get the latest output from the targeting camera
98
- m_target_array = SmartDashboard .getNumberArray ("target" , ARRAY_OF_NEG_ONE );
99
-
100
77
if (m_target_array == null || m_target_array .length == 0 ) {
101
- // this means the key is found, but is empty
78
+ // This means that the key was set, but to an empty array
79
+ SmartDashboard .putBoolean ("visionOK" , false );
80
+ SmartDashboard .putString ("visionOkDebug" , "Bad Data" );
102
81
m_bestX = 0.0 ;
103
82
m_bestY = 0.0 ;
104
83
m_tilt = 0.0 ;
105
84
m_area = 0.0 ;
106
85
// m_desiredAzimuth = RobotContainer.turret.getAzimuthForCapturedImage();
107
86
} else if (m_target_array [0 ] < 0.0 ) {
108
- // this means the array has no valid data. Set m_xError = 0.0
87
+ // This means the array was not retrieved (and the default value was returned)
88
+ // Display warning light
89
+ SmartDashboard .putBoolean ("visionOK" , false );
90
+ SmartDashboard .putString ("visionOkDebug" , "No Data" );
109
91
m_bestX = 0.0 ;
110
92
m_bestY = 0.0 ;
111
93
m_tilt = 0.0 ;
112
94
m_area = 0.0 ;
113
95
// m_desiredAzimuth = RobotContainer.turret.getAzimuthForCapturedImage();
114
96
} else {
115
97
// We have a valid data array.
116
- // There are three different situations:
117
- // a - We want the left-most target
118
- // b - We want the "centered" target
119
- // c - We want the right-most target
120
-
121
- // Handle each of them separately;
122
- // we need the results in "bestXError" and "bestY"
123
- m_bestX = m_target_array [0 ]; // get the x-value
124
- m_bestY = m_target_array [1 ]; // get the y-value
125
- m_tilt = m_target_array [2 ];
126
- m_area = m_target_array [3 ];
98
+ final int latestFrameCount = (int ) m_target_array [0 ];
99
+
100
+ // perform periodic update functions for the targeting capability
101
+ if (latestFrameCount == m_priorFrameCount ) {
102
+ // have not received a new frame. If more than 1 second has elapsed since
103
+ // prior new frame, display a warning light on the SmartDashboard
104
+ if (Timer .getFPGATimestamp () > m_priorFrameTime + 1.0 ) {
105
+ SmartDashboard .putBoolean ("visionOK" , false );
106
+ SmartDashboard .putString ("visionOkDebug" , "Stale Data" );
107
+ } else {
108
+ // else, have an old frame, but it's not too old yet, so do nothing
109
+ }
110
+ } else {
111
+ // have received a new frame, save the time and update m_priorFrameCount
112
+ m_priorFrameTime = Timer .getFPGATimestamp ();
113
+ m_priorFrameCount = latestFrameCount ;
114
+ SmartDashboard .putBoolean ("visionOK" , true );
115
+ SmartDashboard .putString ("visionOkDebug" , "Good Data" );
116
+ }
117
+
118
+ m_bestX = m_target_array [1 ]; // get the x-value
119
+ m_bestY = m_target_array [2 ]; // get the y-value
120
+ m_tilt = m_target_array [3 ];
121
+ m_area = m_target_array [4 ];
127
122
128
123
m_desiredAzimuth = findDesiredAzimuth (m_bestX , m_bestY , m_tilt , m_area );
129
124
m_desiredHood = getHoodFromY ();
0 commit comments