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); }
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(); }
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); }