Due: Friday, 29 February 2008
You write only the controller; the software modeling the lander is given to you: lander.jar. So you can compile and run your program this way:
javac -classpath lander.jar:. Control.java java -classpath lander.jar:. Control
The software faithfully models the physics of an object in freefall. Namely, the distance from the surface of the planet is a function of time:
Take a look at the following Java applet that has a nice animation of the physical situation.
final Lander ship = new Lander ();This constructor immediately creates the spaceship at the time it approaches the surface of the planet. Each scenario is different. In order to facilitate debugging, the Lander class has a constructor which takes the seed for the random number generator as an argument.
final long seed = Long.parseLong (args[0]); final Lander ship = new Lander (seed);The scenario will be the same for the same seed.
A landing scenario is governed by the following parameters.
The landing is successful if the velocity of the spaceship upon contact with the surface is between -2 m/s and 0 m/s.
It is possible to control the spaceship by increasing or decreasing the thrust by one step. There are are eleven steps numbered 0-10.
void throttleUp(); // increase throttle (no more than 10) void throttleDown(); // decrease throttle (no less than 0)Calling the method means the throttle is changed at that moment in time (when Java gets around to executing it).
It is possible to monitor the distance and velocity of the spaceship using another method of the Lander class.
Telemetry query()The Telemetry class is a triple:
public class Telemetry {
public final long time_stamp; // milliseconds since Unix epoch
public final double distance, velocity;
}
The object will be null if x<0 or x> 1,000km.
(Be sure to avoid NullPointerException.)
The lander provides one other method:
void print (int interval)This methods prints to the standard output the position of the spacecraft throughout the simulation. It should be called once after the end of the simulation. Each line corresponds to one point in time and you can vary the interval via the integer argument to the function. The interval is in milliseconds, so print(1000) prints a line for every second. You must land the spacecraft within 30 minutes. Be sure to call this method once; the last line should indicated whether the control software successfully landed the spaceship or not.
The goal is to write robust control software that will land the spaceship under different circumstances. One limitation is the precision of Thread.sleep(). Since it does not work with millisecond precision, it is best to develop a landing strategy that does not depend on executing changes in the throttle at precise times. It is possible to overcome the lack of precision by other means or by busy-waiting. However, a secondary subgoal should be to use as little CPU cycles as possible.
The current version of the simulation does not take fuel into account. Though clearly, it would be a desirable subgoal to use as little fuel as possible.
public class Control {
public static void main (String[] args) throws InterruptedException {
final long seed = args.length>0 ? Long.parseLong(args[0]) : 91484;
final Lander ship = new Lander (seed);
Thread.sleep (80000); // wait 80 seconds
ship.throttleUp ();
Thread.sleep (9722);
System.err.println (ship.query());
ship.throttleUp ();
ship.print (10000);
}
}
|
Course=cse4051 Project=proj08 |