public void StartClient(string fileName)
    {
        this.fileName     = fileName;
        bridgeActive      = false;
        transmittingFloat = 1;
        APImanager        = gameObject.AddComponent(typeof(APIManager)) as APIManager;
        APImanager.CustomAwake(this);
        Debug.Log("API Built");

        floatFile = gameObject.AddComponent(typeof(FloatFile)) as FloatFile;
        floatFile.ConnectToServer(this);
        cameraFeeds = new List <CameraFeed>();

        vesselControl = gameObject.GetComponent <VesselControl>();
        vesselControl.ControlAwake(this);
        //  Debug.Log("Vessel Control Initialized");

        roboticController = gameObject.GetComponent <RoboticController>();
        if (roboticController)
        {
            roboticController.CustomAwake(this);
            Debug.Log("Robotics Configured");
        }


        // debugWriteToSelf = GetComponent<KSPMechs.MechManager>().debugWriteToSelf;

        // SetFloat("TestFromClient" + fileName, 4);
        SetBool("ClientTransmitting" + fileName, true);

        //for (int i = 0; i < 1000; i++)
        //{
        //    SetFloat("test" + i.ToString(), i);
        //}
    }
Beispiel #2
0
    public virtual void CustomAwake(MemoryBridge memoryBridge, string limbName, VesselControl vesselControl)
    {
        Debug.Log("Custom Awake Limb : " + limbName);
        this.memoryBridge  = memoryBridge;
        this.vesselControl = vesselControl;
        limbFile           = MemoryMappedFile.Open(MapAccess.FileMapAllAccess, limbName);
        float byteCount;
        float servoCount;

        using (Stream mapStream = limbFile.MapView(MapAccess.FileMapAllAccess, 0, 16))
        {
            var floatBuffer = new byte[4];
            mapStream.Read(floatBuffer, 0, 4);
            byteCount = BitConverter.ToSingle(floatBuffer, 0);
            mapStream.Read(floatBuffer, 0, 4);
            servoCount = BitConverter.ToSingle(floatBuffer, 0);
        }
        var servosMirror = new List <RoboticServoMirror>();

        ground = Instantiate(GameObject.Find("Ground")).transform;

        using (Stream mapStream = limbFile.MapView(MapAccess.FileMapAllAccess, 0, (int)byteCount))
        {
            mapStream.Position = 16;

            for (int i = 0; i < servoCount; i++)
            {
                //servo name
                var floatBuffer = new byte[4];
                mapStream.Read(floatBuffer, 0, 4);
                var stringByteLength = BitConverter.ToSingle(floatBuffer, 0);

                var stringBuffer = new byte[(int)stringByteLength];
                mapStream.Read(stringBuffer, 0, stringBuffer.Length);
                string servoName = ASCIIEncoding.ASCII.GetString(stringBuffer);

                //servo parent id
                mapStream.Read(floatBuffer, 0, 4);
                var partID = BitConverter.ToSingle(floatBuffer, 0);
                mapStream.Read(floatBuffer, 0, 4);
                var parentID = BitConverter.ToSingle(floatBuffer, 0);

                foreach (var part in vesselControl.vessel.parts)
                {
                    if (part.ID == partID)
                    {
                        var newServo = part.gameObject.AddComponent(typeof(RoboticServoMirror)) as RoboticServoMirror;
                        newServo.CustomStart(servoName, memoryBridge, this, (int)parentID);
                        servosMirror.Add(newServo);
                    }
                }
            }
        }

        foreach (var servo in servosMirror)
        {
            servo.CreateBaseAnchor();
        }
        CreateRoboticLegs(servosMirror);
    }
Beispiel #3
0
 private bool LaunchAndDocking(out Thread launch_thread)
 {
     engine_main.ThrustLimit = 0.6f;
     //engine_main.GimbalLimit = 0.1f;
     engine_north.GimbalLimit = 0.1f;
     engine_south.GimbalLimit = 0.1f;
     launch_thread            = new Thread(() => VesselControl.LaunchAndDocking(
                                               "LOAD", common_data, conn, sc, vessel, 80000,
                                               "Kerbin空间站", "docking_port_2", "docking_port",
                                               ref force_docking));
     launch_thread.Start();
     new Thread(() =>
     {
         Thread.Sleep(2000);
         vessel.Control.ActivateNextStage();
         Thread.Sleep(2000);
         vessel.Control.ActivateNextStage();
     }).Start();
     return(true);
 }
Beispiel #4
0
    // List<LimbControllersIK> IKlimbs;

    public void CustomAwake(MemoryBridge memoryBridge, VesselControl vesselControl, ref List <LimbController> limbs)
    {
        IRFile = MemoryMappedFile.Open(MapAccess.FileMapAllAccess, "IRFile" + memoryBridge.fileName);
        limbs  = new List <LimbController>();
        float byteCount;
        float limbCount;

        using (Stream mapStream = IRFile.MapView(MapAccess.FileMapAllAccess, 0, 16))
        {
            var floatBuffer = new byte[4];

            mapStream.Read(floatBuffer, 0, 4);
            byteCount = BitConverter.ToInt32(floatBuffer, 0);
            mapStream.Read(floatBuffer, 0, 4);
            limbCount = BitConverter.ToInt32(floatBuffer, 0);
        }
        Debug.Log("vessel has limbs " + limbCount);
        using (Stream mapStream = IRFile.MapView(MapAccess.FileMapAllAccess, 0, (int)byteCount))
        {
            mapStream.Position = 16;

            for (int i = 0; i < limbCount; i++)
            {
                var floatBuffer = new byte[4];
                mapStream.Read(floatBuffer, 0, 4);
                var stringByteLength = BitConverter.ToSingle(floatBuffer, 0);

                var stringBuffer = new byte[(int)stringByteLength];
                mapStream.Read(stringBuffer, 0, stringBuffer.Length);
                string limbName = ASCIIEncoding.ASCII.GetString(stringBuffer);

                var newLimbObject = new GameObject();
                newLimbObject.name = limbName;
                newLimbObject.transform.SetParent(vesselControl.vessel.transform);
                var newLimb = newLimbObject.AddComponent(typeof(LimbController)) as LimbController;
                newLimb.CustomAwake(memoryBridge, limbName, vesselControl);
                limbs.Add(newLimb);
                //  Debug.Log("Add limb " + limbName);
            }
        }
    }
Beispiel #5
0
 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);
 }
Beispiel #6
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();
    }
Beispiel #7
0
    //public AnimationCurve myCurve;

    public void CustomAwake(MemoryBridge memoryBridge)
    {
        this.memoryBridge = memoryBridge;
        vesselControl     = memoryBridge.vesselControl;

        IRmanager = gameObject.GetComponent <IR_Manager>();
        //convert IR parts on this vessel to robotic servos and create limbcontroller/limbs
        IRmanager.CustomAwake(memoryBridge, memoryBridge.vesselControl, ref limbs);

        steeringPID          = new PidController(1, 0, .3f, .3, -.3f);
        steeringPID.SetPoint = 0;

        Debug.Log("IR Manager Enabled, Limb Count : " + limbs.Count);

        if (limbs.Count == 6)
        {
            Debug.Log("robot is a hexapod");
            groupLeft        = new HexapodLimbGroup();
            groupLeft.limbs  = new List <LimbController>();
            groupRight       = new HexapodLimbGroup();
            groupRight.limbs = new List <LimbController>();

            group0       = new HexapodLimbGroup();
            group0.limbs = new List <LimbController>();
            group1       = new HexapodLimbGroup();
            group1.limbs = new List <LimbController>();


            foreach (var limb in limbs)
            {
                limb.roboticController = this;
                var offset = memoryBridge.vesselControl.vessel.transform.InverseTransformPoint(limb.transform.position);
                Debug.Log(limb.name);
                var group = groupRight;
                if (offset.x < 0)
                {
                    Debug.Log("left leg found");
                    group = groupLeft;
                }

                group.limbs.Add(limb);
                if (limb.name.Contains("1"))
                {
                    Debug.Log("limb one found");
                    group.limb0 = limb;
                }
                if (limb.name.Contains("2"))
                {
                    Debug.Log("limb two found");
                    group.limb1 = limb;
                }
                if (limb.name.Contains("3"))
                {
                    Debug.Log("limb three found");
                    group.limb2 = limb;
                }

                if (offset.x < 0)
                {
                    groupLeft = group;
                }
                else
                {
                    groupRight = group;
                }
            }

            foreach (var item in groupRight.limbs)
            {
                Debug.Log(item.name);
            }

            group0.limbs.Add(groupLeft.limb0);
            group0.limbs.Add(groupLeft.limb2);
            group0.limbs.Add(groupRight.limb1);

            group1.limbs.Add(groupRight.limb0);
            group1.limbs.Add(groupRight.limb2);
            group1.limbs.Add(groupLeft.limb1);

            foreach (var limb in groupLeft.limbs)
            {
                Debug.Log("Group Left Limb : " + limb.name);
            }
            foreach (var limb in groupRight.limbs)
            {
                Debug.Log("Group Right Limb : " + limb.name);
            }
        }
    }
Beispiel #8
0
    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);
    }