MechJeb#

Provides functionality to interact with the MechJeb mod. Tested with MechJeb 2.15.4.0. Originally written by Genhis. The service acts on the MechJeb of the active vessel, which needs a part with MechJeb. Its classes follow MechJeb’s windows: a setting is found under the window that shows it.

Example#

The following example launches the active vessel into a 100 km orbit, inclined at 6 degrees, with Ascent Guidance, and waits for the ascent to finish:

import krpc.client.Connection;
import krpc.client.Event;
import krpc.client.services.KRPC.Expression;
import krpc.client.services.MechJeb;
import krpc.client.services.MechJeb.AscentGuidance;
import krpc.client.services.SpaceCenter;
import krpc.client.services.SpaceCenter.Vessel;
import krpc.schema.KRPC.ProcedureCall;

public class MechJebExample {
    public static void main(String[] args) {
        Connection connection = Connection.newInstance("MechJeb Example");
        Vessel vessel =
            SpaceCenter.newInstance(connection).getActiveVessel();
        AscentGuidance ascent =
            MechJeb.newInstance(connection).getAscentGuidance();

        ascent.setDesiredOrbitAltitude(100000);
        ascent.setDesiredInclination(6);
        ascent.getSettings().setAutostage(true);
        ascent.setEnabled(true);

        vessel.getControl().activateNextStage();

        ProcedureCall enabled = connection.getCall(ascent, "getEnabled");
        Expression.Bound e = Expression.bind(connection);
        Expression expr = e.equal(e.call(enabled), e.constantBool(false));
        Event event = connection.addEvent(expr);
        synchronized (event.getCondition()) {
            event.waitFor();
        }

        System.out.println("Launch complete");
        connection.close();
    }
}