コード例 #1
0
ファイル: FH.cs プロジェクト: jpxthu/ksp_krpc_autopilot
 private bool RecycleFirstStage(out Thread recycle_main_thread)
 {
     recycle_main_thread = new Thread(() =>
     {
         LandingAdjustBurnStatus landingAdjustBurnStatusMain = LandingAdjustBurnStatus.UNAVAILABEL;
         bool landingAdjustBurnMain = true;
         VesselControl.Recycle(
             vessel_name: "MAIN",
             common_data: common_data,
             connection: conn,
             space_center: sc,
             vessel: vessel_main,
             rcs_layout: KrpcAutoPilot.Control.RcsLayout.TOP,
             tar_pos: new Vector3d(sc.Vessels.Where(v => v.Name == "landing_ship").First().Position(body.ReferenceFrame)),
             tar_altitude: LANDING_FIRST_STAGE_ALTITUDE,
             landing_min_velocity: LANDING_MIN_VELOCITY,
             heading: 0d,
             landing_adjust_burn_status: ref landingAdjustBurnStatusMain,
             landing_adjust_could_burn: ref landingAdjustBurnMain);
     });
     recycle_main_thread.Start();
     return(true);
 }
コード例 #2
0
    public void Start(
        double tar_altitude,
        double landing_min_velocity)
    {
        bool running = true;

        Connection conn = new Connection(
            name: "My Example Program",
            address: IPAddress.Parse("127.0.0.1"),
            rpcPort: 50000,
            streamPort: 50001);
        Service       sc     = conn.SpaceCenter();
        Vessel        vessel = sc.ActiveVessel;
        Orbit         orbit  = vessel.Orbit;
        CelestialBody body   = orbit.Body;

        KrpcAutoPilot.CommonData common_data = new KrpcAutoPilot.CommonData(conn, sc, body);
        Thread common_data_thread            = new Thread(() =>
        {
            while (running)
            {
                if (!common_data.Update())
                {
                    break;
                }
                Thread.Sleep(100);
            }
            common_data.Dispose();
        });

        common_data_thread.Start();

        KrpcAutoPilot.Control control = new KrpcAutoPilot.Control("1", common_data, conn, sc, vessel);
        Thread recycle_thread         = new Thread(() =>
        {
            LandingAdjustBurnStatus landingAdjustBurnStatusMain = LandingAdjustBurnStatus.UNAVAILABEL;
            bool landingAdjustBurnMain = true;
            VesselControl.Recycle(
                vessel_name: "MAIN",
                common_data: common_data,
                connection: conn,
                space_center: sc,
                vessel: vessel,
                rcs_layout: KrpcAutoPilot.Control.RcsLayout.SYMMETRICAL,
                tar_pos: new Vector3d(body.PositionAtAltitude(
                                          KrpcAutoPilot.Constants.Position.KERBAL_CENTER_LAUNCH_PAD.Lat,
                                          KrpcAutoPilot.Constants.Position.KERBAL_CENTER_LAUNCH_PAD.Lng,
                                          tar_altitude, body.ReferenceFrame)),
                tar_altitude: tar_altitude,
                landing_min_velocity: landing_min_velocity,
                heading: 0d,
                landing_adjust_burn_status: ref landingAdjustBurnStatusMain,
                landing_adjust_could_burn: ref landingAdjustBurnMain);
        });

        recycle_thread.Start();
        recycle_thread.Join();

        running = false;
        common_data_thread.Join();

        conn.Dispose();
    }
コード例 #3
0
ファイル: FH.cs プロジェクト: jpxthu/ksp_krpc_autopilot
    private bool RecycleBoosters(
        out Thread recycle_north_thread,
        out Thread recycle_south_thread)
    {
        LandingAdjustBurnStatus landingAdjustBurnStatusNorth = LandingAdjustBurnStatus.UNAVAILABEL;
        LandingAdjustBurnStatus landingAdjustBurnStatusSouth = LandingAdjustBurnStatus.UNAVAILABEL;
        bool landingAdjustBurn = false;

        recycle_north_thread = new Thread(() => VesselControl.Recycle(
                                              vessel_name: "NORTH",
                                              common_data: common_data,
                                              connection: conn,
                                              space_center: sc,
                                              vessel: vessel_north,
                                              rcs_layout: KrpcAutoPilot.Control.RcsLayout.TOP,
                                              tar_pos: new Vector3d(body.PositionAtAltitude(
                                                                        KrpcAutoPilot.Constants.Position.VAB_TOP_EAST.Lat,
                                                                        KrpcAutoPilot.Constants.Position.VAB_TOP_EAST.Lng,
                                                                        LANDING_BOOSTERS_ALTITUDE, body.ReferenceFrame)),
                                              tar_altitude: LANDING_BOOSTERS_ALTITUDE,
                                              landing_min_velocity: LANDING_MIN_VELOCITY,
                                              heading: 0d,
                                              landing_adjust_burn_status: ref landingAdjustBurnStatusNorth,
                                              landing_adjust_could_burn: ref landingAdjustBurn));
        recycle_south_thread = new Thread(() => VesselControl.Recycle(
                                              vessel_name: "SOUTH",
                                              common_data: common_data,
                                              connection: conn,
                                              space_center: sc,
                                              vessel: vessel_south,
                                              rcs_layout: KrpcAutoPilot.Control.RcsLayout.TOP,
                                              tar_pos: new Vector3d(body.PositionAtAltitude(
                                                                        KrpcAutoPilot.Constants.Position.VAB_TOP_WEST.Lat,
                                                                        KrpcAutoPilot.Constants.Position.VAB_TOP_WEST.Lng,
                                                                        LANDING_BOOSTERS_ALTITUDE, body.ReferenceFrame)),
                                              tar_altitude: LANDING_BOOSTERS_ALTITUDE,
                                              landing_min_velocity: LANDING_MIN_VELOCITY,
                                              heading: Math.PI,
                                              landing_adjust_burn_status: ref landingAdjustBurnStatusSouth,
                                              landing_adjust_could_burn: ref landingAdjustBurn));
        recycle_north_thread.Start();
        recycle_south_thread.Start();

        new Thread(o =>
        {
            while (true)
            {
                Thread.Sleep(100);
                if (landingAdjustBurnStatusNorth == LandingAdjustBurnStatus.ABANDON ||
                    landingAdjustBurnStatusSouth == LandingAdjustBurnStatus.ABANDON)
                {
                    return;
                }
                if (landingAdjustBurnStatusNorth == LandingAdjustBurnStatus.WAITING &&
                    landingAdjustBurnStatusSouth == LandingAdjustBurnStatus.WAITING)
                {
                    break;
                }
            }
            landingAdjustBurn = true;
        }).Start();

        return(true);
    }
コード例 #4
0
        public static void Recycle(
            string vessel_name,
            CommonData common_data,
            Connection connection,
            Service space_center,
            Vessel vessel,
            KrpcAutoPilot.Control.RcsLayout rcs_layout,
            Vector3d tar_pos, double tar_altitude, double landing_min_velocity, double heading,
            ref KrpcAutoPilot.Control.LandingAdjustBurnStatus landing_adjust_burn_status,
            ref bool landing_adjust_could_burn)
        {
            KrpcAutoPilot.Control control = new KrpcAutoPilot.Control(vessel_name, common_data, connection, space_center, vessel);
            control.UpdateData();
            control.Command.SetHeadingAngle(Math.PI);

            control.Engage();

            SwitchRcsEngines(vessel, true);
            vessel.Control.RCS = true;

            vessel.Control.Brakes = true;
            SwitchEngineMode(vessel);
            Thread.Sleep(1000);
            control.Trajectory.ReCacheAvailableThrust();
            SwitchEngineMode(vessel);

            Console.WriteLine("Landing init");
            control.LandingInit(tar_altitude, landing_min_velocity);

            Console.WriteLine("Adjust landing position");
            while (true)
            {
                if (!control.UpdateData())
                {
                    break;
                }
                landing_adjust_burn_status = control.AdjustLandingPosition(tar_pos, tar_altitude, landing_adjust_could_burn);
                if (landing_adjust_burn_status == KrpcAutoPilot.Control.LandingAdjustBurnStatus.FINISHED)
                {
                    break;
                }
                if (control.Execute() == KrpcAutoPilot.Control.Status.FAIL)
                {
                    break;
                }
                Thread.Sleep(100);
            }

            SwitchEngineMode(vessel);

            while (true)
            {
                if (!control.UpdateData())
                {
                    break;
                }
                if (control.Landing(tar_pos, tar_altitude, rcs_layout, 5d, heading))
                {
                    break;
                }
                if (control.Execute() == KrpcAutoPilot.Control.Status.FAIL)
                {
                    break;
                }
                Thread.Sleep(100);
            }

            control.DisEngage();
            control.Dispose();
            vessel.Control.Brakes      = false;
            landing_adjust_burn_status = KrpcAutoPilot.Control.LandingAdjustBurnStatus.ABANDON;
        }