CSE 4051: Project #8

Due: Friday, 29 February 2008

The Task

Your task is to write the software to safely land a spaceship on another world. You must write a real-time Java program that controls the spaceship's rocket engines given the velocity of the spaceship and its distance from the surface of the planet. Only the vertical descent is modeled (horizontal motion is ignored completely).

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:

f (t) = 0.5 · a · t2 + v · t + x
where a is the acceleration, v is the (initial) velocity, and x is the (initial) distance.

Take a look at the following Java applet that has a nice animation of the physical situation.

A Lunar Lander Applet

The following is a lunar lander applet written by Rick Wagner in Java. It has nothing to do specifically with this project. The up and down arrow keys change the throttle.

The Spaceship

The spaceship is modeled by a Java class called Lander which is provided. This class has one, no-argument constructor.
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.

Example

The following program is a solution for a one test case (seed=91484). The program may fail to land the ship safely some of the time due to the unpredictable nature of Java execution.
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);
   }
}

Turning it in

The name of the file with the main program must be Control.java. The program must take one command-line argument which is the seed to be passed to the random number generator in Lander. The program must call the print() method as described above. Be sure your name is in comments at the beginning of your program as required in the standard header for this class. Turn in the Java source code for the program using the submission server. The project tag for this project is proj08.

File 1
Control code:
Course=cse4051
Project=proj08


Ryan Stansifer <ryan@cs.fit.edu>
Last modified: Mon Feb 25 17:51:58 EST 2008