Difference between revisions of "Radar"
Jump to navigation
Jump to search
(New page: The Radar is perhaps the most vital parts of your robot. Without it targeting effectively is impossible, and movement is purely random. Just like movement and targting there are ma...) |
(Cleanup, adding some example code) |
||
Line 1: | Line 1: | ||
− | The | + | The radar is one of the most vital components of your robot. Without it [[targeting]] is effectively impossible, and [[movement]] is purely random. Just as with movement and targeting, there are many simple and complex algorithms for radar control. In most robots the radar takes up the smallest portion of code. |
+ | |||
+ | == Example code == | ||
+ | '''NOTE:''' for most of these radar locks, you will need to add one of the following to your <code>run()</code> method: | ||
+ | |||
+ | <pre> | ||
+ | setAdjustRadarForRobotTurn(true); | ||
+ | </pre> | ||
+ | |||
+ | <pre> | ||
+ | setAdjustGunForRobotTurn(true); | ||
+ | setAdjustRadarForGunTurn(true); | ||
+ | </pre> | ||
+ | |||
+ | === Spinning radar === | ||
+ | To just spin the radar, add this to your <code>run()</code> method: | ||
+ | |||
+ | <pre> | ||
+ | setTurnRadarRightRadians(Double.POSITIVE_INFINITY); | ||
+ | </pre> | ||
+ | |||
+ | === The infinity lock === | ||
+ | The infinity lock is the simplest radar lock, and is used frequently in [[Nano bots]]. It has the disadvantage of "slipping" and losing its lock frequently. | ||
+ | |||
+ | <pre> | ||
+ | public void run() { | ||
+ | // ... | ||
+ | setTurnRadarRightRadians(Double.POSITIVE_INFINITY); | ||
+ | } | ||
+ | |||
+ | public void onScannedRobot(ScannedRobotEvent e) { | ||
+ | // ... | ||
+ | setTurnRadarLeftRadians(getRadarTurnRemainingRadians()); | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | === Perfect radar locks === | ||
+ | There are several "perfect" radar locks that will not slip once they have a lock. Here is one: | ||
+ | |||
+ | <pre> | ||
+ | import robocode.util.Utils; | ||
+ | |||
+ | public void run() { | ||
+ | // ... | ||
+ | turnRadarRight(Double.POSITIVE_INFINITY); | ||
+ | do { | ||
+ | scan(); | ||
+ | } while (true); | ||
+ | } | ||
+ | |||
+ | public void onScannedRobot(ScannedRobotEvent e) { | ||
+ | // ... | ||
+ | double absoluteBearing = getHeadingRadians() + e.getBearingRadians(); | ||
+ | double radarTurn = absoluteBearing - getRadarHeadingRadians(); | ||
+ | setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn)); | ||
+ | } | ||
+ | </pre> |
Revision as of 08:19, 12 November 2007
The radar is one of the most vital components of your robot. Without it targeting is effectively impossible, and movement is purely random. Just as with movement and targeting, there are many simple and complex algorithms for radar control. In most robots the radar takes up the smallest portion of code.
Example code
NOTE: for most of these radar locks, you will need to add one of the following to your run()
method:
setAdjustRadarForRobotTurn(true);
setAdjustGunForRobotTurn(true); setAdjustRadarForGunTurn(true);
Spinning radar
To just spin the radar, add this to your run()
method:
setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
The infinity lock
The infinity lock is the simplest radar lock, and is used frequently in Nano bots. It has the disadvantage of "slipping" and losing its lock frequently.
public void run() { // ... setTurnRadarRightRadians(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e) { // ... setTurnRadarLeftRadians(getRadarTurnRemainingRadians()); }
Perfect radar locks
There are several "perfect" radar locks that will not slip once they have a lock. Here is one:
import robocode.util.Utils; public void run() { // ... turnRadarRight(Double.POSITIVE_INFINITY); do { scan(); } while (true); } public void onScannedRobot(ScannedRobotEvent e) { // ... double absoluteBearing = getHeadingRadians() + e.getBearingRadians(); double radarTurn = absoluteBearing - getRadarHeadingRadians(); setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn)); }