Extremely accurate hitting robot (reposted)
Alisdair Owens (Aw101@ecs.soton.ac.uk) Student, UNIVERSITY OF SOUTHAMPTON (UK) May 2002
After you are aiming at the straight line, the next step is the circumference. The system is slightly highly high to enable you to make a rigid robot that makes a circular motion in an extremely accurate hit, while still retaining the effectiveness of robots against linear motors. Alisdair Owens will show you how to implement this skill and provide an example robot, you can take it out and try again.
This tip will give you an in-depth understanding of the working principle of the circumference. We will begin with the basic skills of discussing basic techniques, then explain a simple iteration, it can significantly improve accuracy. I also provide source code, it is easy to adapt to work in your own robot.
Working principle calculates the Change in x x (X direction in X direction in X) and the pseudo code of the Change in Y (the change in Y direction) is quite simple, assuming that you calculate in an arc:
Change in x = cos (inTIALHEADING) * RADIUS - COS (InitialHeading ChangeinHeading) * RADIUS
Change in y = sin (inTIALHEADING CHANGEINHEADING) * RADIUS - SIN (InitialHeading) * RADIUS
InitialHeading is the direction of the enemy robot in the initial position, and the direction of the bullet is changed to changeinheading, we assume that it moves with RADIUS as a circular radius.
Calculate the necessary data. Figure 1 illustrates most of the data we need: R is a circumferential radius around the robot movement, and the direction varies into A, and V is an immediate speed of the enemy robot movement.
Figure 1. Moving along the circumference
In order to accurately aim at the enemy, we need some specific data: the current direction of the robot, the direction of each revolution, the current speed, our bullets reach the moment. We can use these data to calculate the circular half of the enemy turn circle, and its final direction (ie, our bullets reach the direction of the enemy's instantaneous enemy). The method of calculating the position of the bullet hit is as follows:
Direction of each revolution: We get this value with HeadingChangeperturn = (Heading2 - Heading1) / Time, where time is the interval of measurement twice. You must also standardize the results, as shown in the following code. Bullet Time: We use simple time = getTime () (Range / (20- (3 * firepower)) to meet it. Where Range is the distance between us and the enemy, and FirePower is the firepower we plan to use. When the bullet hits, the target to our distance is unchanged. This assumption is not suitable, but we have developed iteration before the content later in this article, it is enough. Radius: We use radius = velocity / HeadingChangeperturn to get this value.
The code circumference path prediction requires only a list 1. However, please note that if the direction changes in the target, then use a linear aim. Since the radius will cause the Double overflow to store it, we use this way to alleviate this risk. However, the condition is that the direction changes, and we don't have to worry too much.
Listing 1. Wheel targeting code
Public Point2d.double Guesposition (long when) {/ ** Time is When Our Scan Data Was Produced .hen Is The Time
That We think the bullet will reach the target. diff is the Target. Diff is The THE
Difference Between The Two ** /
Double DIFF = WHEN - TIME
Double newx, newy;
/ ** if there is a significant change in heading, use circular
PATH PREDiction ** /
IF (Math.Abs (Changehead)> 0.00001) {
Double Radius = speed / changehead;
Double Tothead = DIFF * CHANGEHEAD;
NEWY = Y (Math.SIN (Heading Tothead) * Radius) -
(Math.sin (Heading) * Radius;
NEWX = X (Math.cos (Heading) * Radius -
(Math.cos (Heading Tothead) * Radius;
}
/ ** if the change in Heading is inSignificant, Use linear
PATH PREDiction ** /
Else {
NEWY = Y Math.cos (Heading) * Speed * DIFF;
NEWX = X Math.sin (Heading) * Speed * DIFF;
}
Return New Point2D.double (newx, newy);
}
Improvement Result If you have tried the code in Listing 1, you will find that the situation dealing with Spinbot is significantly better, but you can also notice that there is still no shells from the robot. There is less hit target. This is not just because it is not aimed. To improve your technology, you can estimate the time by using a very simple iteration, then feed this estimated value into a target system to get a more accurate estimate of the distance between your target when the bullet reaches the target. Effure a few times, you will get a near perfect valuation.
Listing 2. Iterative code
/ ** this function predicts the time of the interSecion BetWeen Thae
Bullet and the target based on a Simple ity. It the moves. IT THEN MOVES
The Gun to the Correct Angle To Fire on The Target. ** /
Void dogun () {
Long Time;
Long nexttime;
Point2d.double p;
P = new point2d.double (target.x, target.y);
For (int i = 0; i <10; i ) {
NextTime =
(INTMATH.ROUND (GetRange (GetX (), get (), P.X, P.Y) / (20- (3 * firepower))));
Time = gettime () nextTIME;
P = target.guessposition (time);
}
/ ** Turn the gun to the correct angle ** / double gunoffset = getGunHeadingradians () -
(Math.pi / 2 - Math.atan2 (p.y - get (), p.x - getx ()));
SetTurngunleftradians (NormaliseBearing (Gunoffset);
}
Double NormaliseBearing (Double Ang) {
IF (Ang> Math.pi)
Ang - = 2 * pi;
IF (ang <-math.pi)
Ang = 2 * math.pi;
Return Ang;
}
Public Double GetRange (Double X1, Double Y1, Double X2, Double Y2) {
Double X = X2-X1;
Double Y = Y2-Y1;
Double h = math.sqrt (x * x y * y);
Return H;
}
Improve the performance of the circumference as aiming system, the circumference is basically shaped; that is, it is not only more further in our ability, and there is not much affairs on this basis. However, there are two places that improve performance.
Average speed: You may be willing to maintain a moving average speed of compensating acceleration effects rather than calculating based on the last speed of the target. The average change in each round direction: Measuring the average value of the target direction in each round can help us deal with those that are not as regular as Spinbot.
Reference
Download the source code used in this example. Please read all the contents of "Secrets from The Robocode Masters". This page will be updated when there is a new trick. Please download the latest version of Robocode from AlphaWorks. Mathew Nelson is the founder of Robocode, and he maintains the official Robocode site. This should be the first stop of all people who care about RoboCode. Here you can also participate in the discussion group hosted by Mathew Nelson, and the administrator is Mathew Nelson. You can also see to-do list, this list is a list of "continuous updates" for request functions. Roboleague is a resident administrator for RoboCode, and is responsible for Robocodeby Christian Schnell. It ensures that all possible groups actually make a game, manage the results and generate HTML status reports. "Rock 'EM, SOCK' EM ROBOCODE" (DEVELOPERWORKS, January 2002) dismantling Robocode, while with you to build your own, customized, small and fine fighter machine. "Rock 'EM, SOCK' EM ROBOCOCOCODE: ROCOPERWORKS, May 2002) Bold participates in the build and team of advanced robots. Just contact Java? Take a look at "Java Language Essentials" (DEVELOPERWORKS, November 2000), this tutorial will teach you step by step to learn the basis of Java language programming. Want to know more about Robocode? Is it a secret of learning a master or from the creator of the download work on IBM AlphaWorks to discover the truth? Now you can subscribe to a print version of IBM DeveloperWorks Journal (2002 No. 5). Please find other reference materials in the DeveloperWorks Java Technology area. About Author Alisdair Owens is an undergraduate student at the University of Computer Science, University. He is engaged in Java programming for two years, and it is particularly interested in Robocode. You can contact AliSDAIR via AWO101@ecs.soton.ac.uk.
Transfer from:
http://www-900.cn.ibm.com/developerWorks/cn/java/j-circular/index.shtml