1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- // INFO: See below.
-
- public class TutorialController extends Controller {
-
- public SpringObject object;
-
- ComposedSpringObject cso;
-
- /* These are the agents senses (inputs) */
- DoubleFeature x; /* Positions */
- DoubleFeature y;
- DoubleFeature vx; /* Velocities */
- DoubleFeature vy;
- DoubleFeature angle; /* Angle */
-
- /* Example:
- * x.getValue() returns the vertical position of the rocket
- */
-
- /* These are the agents actuators (outputs)*/
- RocketEngine leftRocket;
- RocketEngine middleRocket;
- RocketEngine rightRocket;
-
- /* Example:
- * leftRocket.setBursting(true) turns on the left rocket
- */
-
- public void init() {
- cso = (ComposedSpringObject) object;
- x = (DoubleFeature) cso.getObjectById("x");
- y = (DoubleFeature) cso.getObjectById("y");
- vx = (DoubleFeature) cso.getObjectById("vx");
- vy = (DoubleFeature) cso.getObjectById("vy");
- angle = (DoubleFeature) cso.getObjectById("angle");
-
- leftRocket = (RocketEngine) cso.getObjectById("rocket_engine_left");
- rightRocket = (RocketEngine) cso.getObjectById("rocket_engine_right");
- middleRocket = (RocketEngine) cso.getObjectById("rocket_engine_middle");
- }
-
- public void tick(int currentTime) {
-
- // TDDC17
- // Part1: Print useful informations and use
- // threshold to guide the vessel
-
- System.out.println("Tick: " + currentTime + ". Angle: " + angle.getValue() + ", vx: " + vx.getValue() + ", vy: " + vy.getValue());
-
-
- System.out.print("Vessel state: ");
- if (angle.getValue() > 0.01) {
- rightRocket.setBursting(true);
- System.out.print("ENG_RGT ON; ");
- }
- else {
- rightRocket.setBursting(false);
- System.out.print("ENG_RGT OFF; ");
- }
- if (angle.getValue() < -0.01) {
- leftRocket.setBursting(true);
- System.out.print("ENG_LFT ON; ");
- }
- else {
- leftRocket.setBursting(false);
- System.out.print("ENG_LFT OFF; ");
- }
- if (vy.getValue() > 0.05) {
- middleRocket.setBursting(true);
- System.out.print("ENG_MDL ON; ");
- }
- else {
- middleRocket.setBursting(false);
- System.out.print("ENG_MDL OFF; ");
- }
-
- System.out.println("");
- }
-
- }
|