예제 #1
0
 private Vector3D?getCurrentObjective()
 {
     if (this.Objective == null)
     {
         List <MyWaypointInfo> route = new List <MyWaypointInfo>();
         remotePilot.GetWaypointInfo(route);
         if (route.Count > 0)
         {
             MyWaypointInfo nextWaypoint = route.First();
             return(nextWaypoint.Coords);
         }
     }
     return(this.Objective);
 }
            public void Tick()
            {
                p.Echo(new Vector3D(0, 0, 0).ToString());
                Controller.GetWaypointInfo(Waypoints);
                var pos = Controller.GetPosition();

                //var target = Vector3D.TransformNormal(new Vector3D(10, 0, 0), MatrixD.Transpose(Controller.WorldMatrix));
                p.Echo("Pos: " + pos.ToString());
                if (Waypoints.Any())
                {
                    var point = Waypoints.First();

                    p.Echo("Distance to waypoint: " + Vector3D.Distance(pos, point.Coords).ToString());
                }

                //p.Echo("test: " + Vector3D.Add(pos, target));
            }
예제 #3
0
        public void Main(string argument, UpdateType updateSource)
        {
            IMyTextPanel lcdWriteScreen = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(lcdName);


            IMyRemoteControl remoteControl = (IMyRemoteControl)GridTerminalSystem.GetBlockWithName(remoteControllerName);

            List <MyWaypointInfo> mywaypoint = new List <MyWaypointInfo>();

            remoteControl.GetWaypointInfo(mywaypoint);

            foreach (MyWaypointInfo item in mywaypoint)
            {
                Echo(item.Coords.ToString());
            }
            wayPoint = mywaypoint[0];

            Echo(wayPoint.ToString());

            // If setupcomplete is false, run Setup method.
            if (!setupcomplete)
            {
                Echo("Running setup.");
                Setup();
            }
            else
            {
                // Create our message. We first make it a string, and then we "box" it as an object type.
                string sendCords = lcdWriteScreen.GetText();

                // Through the IGC variable we issue the broadcast method. IGC is "pre-made",
                // so we don't have to declare it ourselves, just go ahead and use it.
                if (sendCords.ToLower() == "send" && wayPoint.Coords != null)
                {
                    IGC.SendBroadcastMessage(broadcastChannel, wayPoint.ToString(), TransmissionDistance.TransmissionDistanceMax);
                }
                else
                {
                    Echo("Broadcasting failed.");
                }
                // To create a listener, we use IGC to access the relevant method.
                // We pass the same tag argument we used for our message.
                IGC.RegisterBroadcastListener(broadcastChannel);
            }
        }
예제 #4
0
        void CloneWaypoints()
        {
            if (_patrolEnabled)
            {
                if (_patrolRoute == null)
                {
                    _patrolRoute = new List <MyWaypointInfo>();
                    if (_controllerBlock == null)
                    {
                        _remoteBlock.GetWaypointInfo(_patrolRoute);
                    }
                    else
                    {
                        _controllerBlock.GetWaypointInfo(_patrolRoute);
                    }
                }

                if (_controllerBlock != null)
                {
                    _remoteBlock.ClearWaypoints();
                    foreach (var item in _patrolRoute)
                    {
                        _remoteBlock.AddWaypoint(item);
                    }
                }

                if (_controllerBlock != null)
                {
                    _opMode = OperationMode.RemoteCtrl;
                }
                else
                {
                    _opMode = OperationMode.SingleCtrl;
                }
            }
            else
            {
                _opMode = OperationMode.Stationary;
            }
        }
예제 #5
0
        public void InitializationCheck()
        {
            CustomData();
            error = false;
            Echo(errors);
            errors = "ERROR\n";

            //LCDs
            GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(LCDs, filterThis);
            if (LCDs.Count > 0)
            {
                for (int i = 0; i < LCDs.Count; i++)
                {
                    if (LCDs[i].CustomName.IndexOf(mainLCDname) > -1)
                    {
                        mainLCD = LCDs[i];
                    }
                    if (LCDs[i].CustomName.IndexOf(statusLCDname) > -1)
                    {
                        statusLCD = LCDs[i];
                    }
                }
                if (mainLCD == null)
                {
                    Echo("no LCD blocks with name including [" + mainLCDname + "]\n");
                    error = true;
                }
                if (statusLCD == null)
                {
                    Echo("no LCD blocks with name including [" + statusLCDname + "]\n");
                    error = true;
                }
            }
            else
            {
                errors += "no LCD blocks found\n";
                error   = true;
            }
            //Cockpit
            GridTerminalSystem.GetBlocksOfType <IMyCockpit>(Cockpits, filterThis);
            if (Cockpits.Count > 0)
            {
                for (int i = 0; i < Cockpits.Count; i++)
                {
                    if (Cockpits[i].CustomName.IndexOf(cockpitName) > -1)
                    {
                        cockpit = Cockpits[i];
                    }
                }
                if (cockpit == null)
                {
                    errors += "no Cockpit blocks with name including [" + cockpitName + "]\n";
                    error   = true;
                }
            }
            else
            {
                errors += "no Cockpit blocks found\n";
                error   = true;
            }
            //Jump drives
            GridTerminalSystem.GetBlocksOfType <IMyJumpDrive>(Jumpers, filterThis);
            if (Jumpers.Count > 0)
            {
                for (int i = 0; i < Jumpers.Count; i++)
                {
                    if (Jumpers[i].CustomName.IndexOf(jumperName) > -1)
                    {
                        jumper = Jumpers[i];
                    }
                }
                if (jumper == null)
                {
                    errors += "no Jump drive blocks with name including [" + jumperName + "]\n";
                    error   = true;
                }
            }
            else
            {
                errors += "no Jump drive blocks found\n";
                error   = true;
            }
            //Remote
            GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(Remotes, filterThis);
            if (Remotes.Count > 0)
            {
                for (int i = 0; i < Remotes.Count; i++)
                {
                    if (Remotes[i].CustomName.IndexOf(remoteName) > -1)
                    {
                        remote = Remotes[i];
                    }
                }
                if (remote == null)
                {
                    errors += "no Remote Control blocks with name including [" + remoteName + "]\n";
                    error   = true;
                }
            }
            else
            {
                errors += "no Remote Control blocks found\n";
                error   = true;
            }
            //Gyros
            GridTerminalSystem.GetBlocksOfType <IMyGyro>(Allgyros, filterThis);
            if (Allgyros.Count > 0)
            {
                for (int i = 0; i < Allgyros.Count; i++)
                {
                    if (Allgyros[i].CustomName.IndexOf(gyroName) > -1)
                    {
                        gyros.Add(Allgyros[i]);
                    }
                }
                if (Allgyros.Count == 0)
                {
                    errors += "no Gyroscope blocks with name including [" + gyroName + "]\n";
                    error   = true;
                }
            }
            else
            {
                errors += "no Gyroscope blocks found\n";
                error   = true;
            }

            statusLCD.Alignment       = TextAlignment.CENTER;
            statusLCD.ContentType     = ContentType.TEXT_AND_IMAGE;
            statusLCD.FontColor       = Color.Gray;
            statusLCD.BackgroundColor = Color.Black;
            remote.GetWaypointInfo(waypoints);

            if (error && (GridTerminalSystem.GetBlockWithName(mainLCDname) as IMyTextPanel != null) && (GridTerminalSystem.GetBlockWithName(statusLCDname) as IMyTextPanel != null))
            {
                mainLCD.WriteText(errors);
                systemStatus = "ERROR";
                Echo(errors);
                statusLCD.WriteText(systemStatus);
                statusLCD.BackgroundColor = Color.Red;
            }
        }
예제 #6
0
        public void Main(string argument)
        {
            if (!started)
            {
                //initialize
                control = GetBlockOfType <IMyRemoteControl>();
                timer   = GetBlockOfType <IMyTimerBlock>();

                string[] parse = argument.Split(':');   // two GPS points

                target   = new Vector3(float.Parse(parse[2]), float.Parse(parse[3]), float.Parse(parse[4]));
                approach = new Vector3(float.Parse(parse[7]), float.Parse(parse[8]), float.Parse(parse[9]));
                CreateCoordSystem();
                started = true;

                mode    = 0; //approach
                lastPos = Me.CubeGrid.GridIntegerToWorld(control.Position);
                speed   = new Vector3(0, 0, 0);
            }
            else
            {
                Vector3 pos = Me.CubeGrid.GridIntegerToWorld(control.Position);
                speed = ((pos - lastPos) / Runtime.TimeSinceLastRun.Milliseconds) * 1000;
            }

            if (mode == 0)  //approach mode
            {
                Echo("approach");
                if (Vector3.Distance(Me.CubeGrid.GridIntegerToWorld(control.Position), approach) > 0.1)
                {
                    List <MyWaypointInfo> waypoints = new List <MyWaypointInfo>();
                    control.GetWaypointInfo(waypoints);
                    if (waypoints.Count != 1 || !waypoints[0].Coords.Equals(approach))
                    {
                        Echo("clearing approach " + approach);
                        control.ClearWaypoints();
                        control.AddWaypoint(approach, "[AUTO]approach");
                    }
                    SwitchFlyMode(true);
                    if (!control.IsAutoPilotEnabled)
                    {
                        control.SetAutoPilotEnabled(true);
                    }
                }
                else
                {
                    mode = 1;
                }
            }

            if (mode == 1)  //find column
            {
                Random rnd = new Random();
                column = new Vector2I(rnd.Next(-5, 5), rnd.Next(-5, 5));
                mode   = 2;
            }
            if (mode == 2)  //initalize mining
            {
                if (TurnForward())
                {
                    if (MoveTo(approach + column.X * left + column.Y * up))
                    {
                        mode = 3;
                    }
                }
            }
            if (mode == 3)  //run the column
            {
                if (TurnForward())
                {
                    Vector3 currentPos        = Me.CubeGrid.GridIntegerToWorld(control.Position);
                    float   progressAlongLine = Vector3.Dot(currentPos - approach, forward);
                    if (progressAlongLine < 200)
                    {
                        MoveTo(approach + column.X * left + column.Y * up + (progressAlongLine + 2) * forward);
                    }
                    else
                    {
                        mode = 4;
                    }
                }
            }

            if (mode == 4)  //back out
            {
                Vector3 currentPos        = Me.CubeGrid.GridIntegerToWorld(control.Position);
                float   progressAlongLine = Vector3.Dot(currentPos - approach, forward);
                if (progressAlongLine > 0)
                {
                    MoveTo(approach + column.X * left + column.Y * up + (progressAlongLine - 2) * forward);
                }
                else
                {
                    mode = 5;
                }
            }

            if (mode == 5)  //return home

            {
            }

            timer.ApplyAction("Start");
        }
예제 #7
0
        public void Main(string args)
        {
            // Get Text Panels
            IMyTextPanel panel1 = GridTerminalSystem.GetBlockWithName("Donkey Panel Front 1") as IMyTextPanel;
            IMyTextPanel panel2 = GridTerminalSystem.GetBlockWithName("Donkey Panel Front 2") as IMyTextPanel;
            IMyTextPanel panel3 = GridTerminalSystem.GetBlockWithName("Donkey Panel Front 3") as IMyTextPanel;

            Echo("Screen connected: " + panel1.CustomName);
            Echo("Screen connected: " + panel2.CustomName);
            Echo("Screen connected: " + panel3.CustomName);

            // Get Sensor [0]
            List <IMySensorBlock> sensors = new List <IMySensorBlock>();

            GridTerminalSystem.GetBlocksOfType <IMySensorBlock>(sensors);
            IMySensorBlock sensor = sensors[0];

            Echo("Sensor: " + sensor.CustomName);

            // Get Remote Control [0]
            List <IMyRemoteControl> remotes = new List <IMyRemoteControl>();

            GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(remotes);
            IMyRemoteControl remote = remotes[0];

            Echo("Remote: " + remote.CustomName);


            // Main

            // Write Detection to Panel 1
            panel1.WriteText("Last detected:");
            panel1.WriteText("\n" + sensor.LastDetectedEntity.Name);
            panel1.WriteText("\n" + sensor.LastDetectedEntity.TimeStamp.ToString(), true);
            panel1.WriteText("\n" + sensor.LastDetectedEntity.Relationship.ToString(), true);
            panel1.WriteText("\n" + sensor.LastDetectedEntity.Position.ToString(), true);

            // Write Remote to Panel 2
            panel2.WriteText("Flight mode: " + remote.FlightMode);
            // Get properties
            List <ITerminalProperty> remote_props = new List <ITerminalProperty>();

            remote.GetProperties(remote_props);
            foreach (ITerminalProperty property in remote_props)
            {
                panel2.WriteText("\n" + property.Id + " : " + property.TypeName, true);
            }

            // Write Waypoints to Panel 3
            List <MyWaypointInfo> waypoints = new List <MyWaypointInfo>();

            remote.GetWaypointInfo(waypoints);
            foreach (MyWaypointInfo waypoint in waypoints)
            {
                panel2.WriteText(waypoint.Name + " - " + waypoint.Coords);
            }

            // Add waypoint
            remote.ClearWaypoints();
            remote.AddWaypoint(sensor.LastDetectedEntity.Position, sensor.LastDetectedEntity.Name + " " + sensor.LastDetectedEntity.TimeStamp);
        }