Difference between revisions of "Zoom Radar"
(Created page with 'Zoom radar is a precise lock radar with a minimum cost feature for melee. Created by Frolicking Zombie. <TABLE BORDER="1"> <TR> <TH>Mathematics</TH> <TH ROWSPAN="2">E…') |
m (Reduced code size by optimizing layout.) |
||
Line 185: | Line 185: | ||
// Should have scanned target by now. Resume in opposite direction | // Should have scanned target by now. Resume in opposite direction | ||
scanDirection = 1; | scanDirection = 1; | ||
− | |||
− | |||
} | } | ||
else { | else { | ||
// Continue in the CCW direction. | // Continue in the CCW direction. | ||
scanDirection = -1; | scanDirection = -1; | ||
− | |||
− | |||
} | } | ||
} | } | ||
Line 200: | Line 196: | ||
// Should have scanned target by now. Resume in opposite direction | // Should have scanned target by now. Resume in opposite direction | ||
scanDirection = -1; | scanDirection = -1; | ||
− | |||
− | |||
} | } | ||
else { | else { | ||
// Continue in the CW direction. | // Continue in the CW direction. | ||
scanDirection = 1; | scanDirection = 1; | ||
− | |||
− | |||
} | } | ||
} | } | ||
Line 215: | Line 207: | ||
if(radarBearing >= -thetaBounding && radarBearing <= thetaBounding) { | if(radarBearing >= -thetaBounding && radarBearing <= thetaBounding) { | ||
// Start scanning in the opposite direction to ensure that we scan the target on this turn. | // Start scanning in the opposite direction to ensure that we scan the target on this turn. | ||
− | + | scanDirection = lastScanDirection * -1; | |
− | |||
− | |||
} | } | ||
// Check to see if the CW bound is closer. | // Check to see if the CW bound is closer. | ||
Line 223: | Line 213: | ||
// Scan in the CCW direction ending at the CCW bound. | // Scan in the CCW direction ending at the CCW bound. | ||
scanDirection = -1; | scanDirection = -1; | ||
− | |||
− | |||
} | } | ||
// Check to see if the CCW bound is closer. | // Check to see if the CCW bound is closer. | ||
Line 230: | Line 218: | ||
// Scan in the CW direction ending at the CW bound. | // Scan in the CW direction ending at the CW bound. | ||
scanDirection = 1; | scanDirection = 1; | ||
− | |||
− | |||
} | } | ||
// Both bounds are equal. | // Both bounds are equal. | ||
Line 239: | Line 225: | ||
if(targetsCW >= targetsCCW) { | if(targetsCW >= targetsCCW) { | ||
scanDirection = 1; | scanDirection = 1; | ||
− | |||
− | |||
} | } | ||
else { | else { | ||
scanDirection = -1; | scanDirection = -1; | ||
− | |||
− | |||
} | } | ||
} | } | ||
+ | } | ||
+ | |||
+ | setTurnRadarRightRadians((scanDirection * thetaFinal) – radarBearing); | ||
+ | lastScanDirection = scanDirection; | ||
+ | |||
+ | </PRE> | ||
+ | |||
+ | If <MATH>2 \times \text{targetDistanceFinal} < \text{targetErrorFinal}</MATH> then it will be impossible to resolve bearings that the target may not be at. It is best to continue scanning in the same direction as previous, but with no bounds. | ||
+ | |||
+ | <PRE> | ||
+ | if(2 * targetDistanceFinal < targetErrorFinal) { | ||
+ | scanDirection = lastScanDirection; | ||
+ | setTurnRadarRightRadians(scanDirection * 2* Math.PI); | ||
} | } | ||
</PRE> | </PRE> |
Revision as of 18:50, 26 February 2010
Zoom radar is a precise lock radar with a minimum cost feature for melee. Created by Frolicking Zombie.
When the radar's bearing is between the thetaBounding and thetaFinal bearings, this signals the completion of the scan in the corresponding direction. The scan direction should be reversed to (re)cover the target area. When a target has been scanned, the radar must reverse direction to ensure a scan on the next subsequent turn. This enables a precision lock on the target. The variable lastScanDirection should be initialized with the value that corresponds to the direction (1 = CW, -1 = CCW) of the scan used to find all targets. The variable scanDirection should be initialized with 0 to force a new search. When initiating a new search, if it is determined that the CW and CCW scans will be equal, the direction of search should be the one that will scan the most targets along the path to the desired target.
// Bearings are negative in the CCW direction. if(scanDirection == -1) { // Check to see if we have completed our move. if(radarBearing >= -thetaFinal && radarBearing <= -thetaBounding) { // Should have scanned target by now. Resume in opposite direction scanDirection = 1; } else { // Continue in the CCW direction. scanDirection = -1; } } else if(scanDirection == 1) { // Check to see if we have completed our move. if(radarBearing <= thetaFinal && radarBearing >= thetaBounding) { // Should have scanned target by now. Resume in opposite direction scanDirection = -1; } else { // Continue in the CW direction. scanDirection = 1; } } // Set scanDirection = 0 if we just scanned the target we were looking for so that we can continue scanning in the most manner. else { // Check to see if we are within bounds. if(radarBearing >= -thetaBounding && radarBearing <= thetaBounding) { // Start scanning in the opposite direction to ensure that we scan the target on this turn. scanDirection = lastScanDirection * -1; } // Check to see if the CW bound is closer. else if(Math.abs(thetaFinal - radarBearing) < Math.abs((-thetaFinal) - radarBearing)) { // Scan in the CCW direction ending at the CCW bound. scanDirection = -1; } // Check to see if the CCW bound is closer. else if(Math.abs(thetaFinal - radarBearing) > Math.abs((-thetaFinal) - radarBearing)) { // Scan in the CW direction ending at the CW bound. scanDirection = 1; } // Both bounds are equal. else { // Add code here.... // Just count the number of targets you expect to scan along the CW and CCW directions and start scanning in the most advantageous direction. if(targetsCW >= targetsCCW) { scanDirection = 1; } else { scanDirection = -1; } } } setTurnRadarRightRadians((scanDirection * thetaFinal) – radarBearing); lastScanDirection = scanDirection;
If <MATH>2 \times \text{targetDistanceFinal} < \text{targetErrorFinal}</MATH> then it will be impossible to resolve bearings that the target may not be at. It is best to continue scanning in the same direction as previous, but with no bounds.
if(2 * targetDistanceFinal < targetErrorFinal) { scanDirection = lastScanDirection; setTurnRadarRightRadians(scanDirection * 2* Math.PI); }