Beispiel #1
0
        public Status ApproachFindDockingPort(double distance)
        {
            if (approach_target_stage_ != ApproachTargetStage.SHIP)
            {
                return(Status.FINISHED);
            }

            if (distance > TARGET_HAS_DETAILS_DISTANCE_THRESHOLD)
            {
                return(Status.UNFINISHED);
            }

            var ports = approach_vessel_.Parts.DockingPorts.Where(p => p.Part.Tag == approach_dock_tag_);

            if (ports.Count() == 0)
            {
                return(Status.UNFINISHED);
            }
            DockingPort port = ports.First();

            approach_tar_pos_stream_.Remove();
            approach_tar_vel_stream_.Remove();
            SpaceCenter.TargetDockingPort = port;
            approach_tar_pos_stream_      = Conn.AddStream(() => port.Position(OrbitBodyFrame));
            approach_tar_vel_stream_      = Conn.AddStream(() => port.Part.Velocity(OrbitBodyFrame));
            approach_tar_dir_stream_      = Conn.AddStream(() => port.Direction(OrbitBodyFrame));
            approach_target_stage_        = ApproachTargetStage.PORT;
            return(Status.SUCCESS);
        }
Beispiel #2
0
        public Status ApproachInit(
            string ship_name,
            string dock_tag         = null,
            string control_node_tag = null,
            double distance         = 50d)
        {
            approach_dock_tag_         = dock_tag;
            approach_control_node_tag_ = control_node_tag;
            approach_distance_max_     = distance;

            IEnumerable <Vessel> vessels = SpaceCenter.Vessels.Where(v => v.Name == ship_name);

            if (vessels.Count() == 0)
            {
                return(Status.FAIL);
            }
            approach_vessel_         = vessels.First();
            SpaceCenter.TargetVessel = approach_vessel_;
            approach_tar_pos_stream_ = Conn.AddStream(() => approach_vessel_.Position(OrbitBodyFrame));
            approach_tar_vel_stream_ = Conn.AddStream(() => approach_vessel_.Velocity(OrbitBodyFrame));
            approach_tar_dir_stream_ = null;

            Vector3d tar_pos      = new Vector3d(approach_tar_pos_stream_.Get());
            Vector3d tar_vel      = new Vector3d(approach_tar_vel_stream_.Get());
            double   tar_distance = (tar_pos - State.Vessel.Position).Length();
            double   tar_rel_vel  = (tar_vel - State.Vessel.Velocity).Length();

            if (tar_distance < 1000d && tar_rel_vel < Math.Max(10d, Math.Sqrt(tar_distance)))
            {
                approach_stage_ = ApproachStage.DOCKING;
            }
            else
            {
                approach_stage_ = ApproachStage.ENGINE;
            }
            if (string.IsNullOrEmpty(dock_tag))
            {
                approach_target_stage_ = ApproachTargetStage.PORT;
            }
            else
            {
                approach_target_stage_ = ApproachTargetStage.SHIP;
            }

            return(Status.SUCCESS);
        }