Ejemplo n.º 1
0
        IEnumerable <string> MoveToGrind()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update1;
            Message("Start grinding on " + GrinderGroup);
            Vector3D target = GrinderLocation + GrinderApproach * Clamp.WorldMatrix.Scale.Y / 2;
            var      task   = new AimedFlightStrategy(target, Clamp, Base6Directions.Direction.Down, Base6Directions.Direction.Forward);

            task.MaxLinearSpeed    = 0.5;
            task.DampenersOverride = true;
            Pilot.Tasks.Add(task);
            while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
            {
                if (Clamp.LockMode != LandingGearMode.Locked)
                {
                    Message("Lost contact with the object.");
                    yield return("BackOffFromGrinders");
                }
                else if (HasToAbort())
                {
                    break;
                }
                else
                {
                    yield return(null);
                }
            }
            yield return("BackOffFromGrinders");
        }
Ejemplo n.º 2
0
 IEnumerable <string> LeaveDockForGrinders()
 {
     Message("Leaving dock via route " + ChosenApproach);
     while (ApproachIndex >= 0)
     {
         var task = new AimedFlightStrategy(Approaches[ChosenApproach][ApproachIndex], Pilot.Controller);
         task.MaxLinearSpeed = MaxSpeed;
         Pilot.Tasks.Add(task);
         while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
         {
             if (HasToAbort())
             {
                 yield return("ReturnHome");
             }
             else
             {
                 yield return(null);
             }
         }
         ApproachIndex--;
     }
     ChosenApproach = "";
     ApproachIndex  = -1;
     yield return("GoToGrinderApproachVector");
 }
Ejemplo n.º 3
0
        IEnumerable <string> ReachTargetArea()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10;
            Waypoint wp = new Waypoint(TargetLocation.CurrentPosition, TargetLocation.Velocity, TargetLocation.Name);

            wp.TargetDistance = ScanningDistance;
            if ((TargetLocation.CurrentPosition - Pilot.Controller.GetPosition()).LengthSquared() < (wp.TargetDistance * wp.TargetDistance))
            {
                yield return("FindTarget");
            }
            Message("Proceeding to target area.");

            double rotangle     = 0;
            double scandistance = 190.0;
            MyDetectedEntityInfo obstacle;

            var task = new AimedFlightStrategy(wp, Pilot.Controller);

            task.MaxLinearSpeed = MaxSpeed;
            Pilot.Tasks.Add(task);
            while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
            {
                if (HasToAbort())
                {
                    yield return("ReturnHome");
                }
                else
                {
                    Vector3D scanvector =
                        Clamp.GetPosition() +
                        Clamp.WorldMatrix.Forward * 1.5 * Me.CubeGrid.WorldVolume.Radius * Math.Sin(rotangle) +
                        Clamp.WorldMatrix.Left * 1.5 * Me.CubeGrid.WorldVolume.Radius * Math.Cos(rotangle) +
                        Clamp.WorldMatrix.Down * scandistance;
                    foreach (var cam in Cameras)
                    {
                        if (cam.CanScan(scanvector))
                        {
                            rotangle += 0.8;
                            if (rotangle > 2 * Math.PI)
                            {
                                rotangle -= 2 * Math.PI;
                            }
                            obstacle = cam.Raycast(scanvector);
                            if (!obstacle.IsEmpty() && (!TargetSelector(obstacle) || (obstacle.HitPosition.Value - TargetLocation.CurrentPosition).LengthSquared() > ScanningDistance * ScanningDistance))
                            {
                                Message($"Obstacle detected, aborting. {obstacle.Name} @ {obstacle.Position}");
                                yield return("FullStop");
                            }
                        }
                    }
                }
                yield return(null);
            }
            yield return("FindTarget");
        }
Ejemplo n.º 4
0
        IEnumerable <string> FindTarget()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10;
            foreach (IMySensorBlock sensor in Sensors)
            {
                sensor.Enabled = true;
            }
            yield return(null);

            foreach (IMySensorBlock sensor in Sensors)
            {
                sensor.DetectedEntities(Entities);
                foreach (MyDetectedEntityInfo ent in Entities)
                {
                    if (ent.Type == MyDetectedEntityType.SmallGrid ||
                        ent.Type == MyDetectedEntityType.LargeGrid)
                    {
                        TargetEntityID = ent.EntityId;
                        Message($"Target: {ent.Name} #{ent.EntityId}");
                        yield return("CaptureTarget");
                    }
                }
            }
            var strategy = new AimedFlightStrategy(TargetLocation, Pilot.Controller);

            strategy.MaxLinearSpeed = MaxSpeed / 10;
            Pilot.Tasks.Add(strategy);
            while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
            {
                foreach (IMySensorBlock sensor in Sensors)
                {
                    sensor.DetectedEntities(Entities);
                    foreach (MyDetectedEntityInfo ent in Entities)
                    {
                        if (TargetSelector(ent))
                        {
                            TargetEntityID = ent.EntityId;
                            Message($"Target: {ent.Name} #{ent.EntityId}");
                            yield return("CaptureTarget");
                        }
                    }
                }
                if (HasToAbort())
                {
                    yield return("ReturnHome");
                }
                else
                {
                    yield return(null);
                }
            }
            //we didn't find the target - abort mission
            Message("Aborting: no targets found.");
            yield return("ReturnHome");
        }
Ejemplo n.º 5
0
 IEnumerable <string> ReturnHome()
 {
     Runtime.UpdateFrequency = UpdateFrequency.Update10;
     Pilot.Tasks.Clear();
     foreach (IMySensorBlock sensor in Sensors)
     {
         sensor.Enabled = false;
     }
     foreach (IMyThrust thruster in Thrusters)
     {
         thruster.Enabled = true;
     }
     if (ApproachIndex < 0)
     {
         var minkv = Approaches.MinBy((kv) => (float)(Pilot.Controller.GetPosition() - kv.Value[0]).Length());
         ChosenApproach = minkv.Key;
         ApproachIndex  = 0;
     }
     Message("Returning to base via route " + ChosenApproach);
     while (ApproachIndex < Approaches[ChosenApproach].Count)
     {
         Timeout = ActionTimeout;
         var strategy = new AimedFlightStrategy(Approaches[ChosenApproach][ApproachIndex], Pilot.Controller);
         strategy.PositionEpsilon = 1.0;
         Pilot.Tasks.Add(strategy);
         while (!Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds))
         {
             if (ActionTimeout > 0)
             {
                 Timeout -= Runtime.TimeSinceLastRun.TotalSeconds;
             }
             if (TooFar() || (Timeout <= 0 && ActionTimeout > 0))
             {
                 Clamp.Unlock();
             }
             yield return(null);
         }
         ApproachIndex++;
     }
     Timeout        = ActionTimeout;
     ChosenApproach = "";
     ApproachIndex  = -1;
     yield return("Dock");
 }