public void Main(string _argument, UpdateType updateSource)
        {
            counter++;

            if (updateSource == UpdateType.Terminal || firstRun)
            {
                argument = _argument;
                Initialise();
            }

            if (!test)
            {
                switch (ConnectorFront.Status)
                {
                case MyShipConnectorStatus.Unconnected:
                    ExtendPistons();
                    break;

                case MyShipConnectorStatus.Connectable:
                    if (PistonBack1.Status == PistonStatus.Extended)
                    {
                        ConnectorFront.Connect();
                        ConnectorBack.Disconnect();
                    }
                    break;

                case MyShipConnectorStatus.Connected:

                    break;
                }

                switch (ConnectorBack.Status)
                {
                case MyShipConnectorStatus.Unconnected:
                    RetractPistons();
                    break;

                case MyShipConnectorStatus.Connectable:
                    if (PistonBack1.Status == PistonStatus.Retracted)
                    {
                        ConnectorBack.Connect();
                        ConnectorFront.Disconnect();
                    }
                    break;

                case MyShipConnectorStatus.Connected:
                    if (ConnectorFront.Status == MyShipConnectorStatus.Connected)
                    {
                        ConnectorBack.Disconnect();
                        RetractPistons();
                    }
                    break;
                }
            }

            UpdateAssemblers();

            PrintStatus();
        }
 void CheckOpen()
 {
     openConnector.Connect();
     if (openConnector.Status == MyShipConnectorStatus.Connected)
     {
         state = "OPEN";
     }
 }
 void CheckClosed()
 {
     closeConnector.Connect();
     if (closeConnector.Status == MyShipConnectorStatus.Connected)
     {
         state = "CLOSED";
     }
 }
Beispiel #4
0
 public void MoveX() // step 1, release and move piston
 {
     _PistonX.Enabled = true;
     if (xDir == Dir.forward || xDir == Dir.backward)
     {
         _MoveConX.Connect();
         if (_MoveConX.Status == MyShipConnectorStatus.Connected)
         {
             _ConnectorX.Disconnect();
             _MergeX.Enabled = false;
             if (xPosMerge < xTar)
             {
                 _PistonX.Velocity = -1 * maxMovementSpeed;
                 xDir = Dir.movingForward;
             }
             else if (xPosMerge > xTar)
             {
                 _PistonX.Velocity = maxMovementSpeed;
                 xDir = Dir.movingBackward;
             }
         }
     }
     else if (xDir == Dir.movingForward || xDir == Dir.movingBackward) // step 2, merge and continue
     {
         _MergeX.Enabled = true;
         if (_MergeX.IsConnected)
         {
             moveReady = true;
             _ConnectorX.Connect();
             _MoveConX.Disconnect();
             if (xDir == Dir.movingForward)
             {
                 xDir = Dir.forward;
                 if (autoMode)
                 {
                     _PistonX.Velocity = maxToolSpeed;
                 }
                 else
                 {
                     _PistonX.Velocity = maxMovementSpeed;
                 }
             }
             if (xDir == Dir.movingBackward)
             {
                 xDir = Dir.backward;
                 if (autoMode)
                 {
                     _PistonX.Velocity = -1 * maxToolSpeed;
                 }
                 else
                 {
                     _PistonX.Velocity = -1 * maxMovementSpeed;
                 }
             }
         }
     }
 }
Beispiel #5
0
 static void Connect(IMyShipConnector connector, bool value)
 {
     if (value)
     {
         connector.Connect();
     }
     else
     {
         connector.Disconnect();
     }
 }
Beispiel #6
0
 void ToggleConnector(bool connect = true)
 {
     if (_connectorBlock != null)
     {
         if (connect)
         {
             _connectorBlock.Connect();
         }
         else
         {
             _connectorBlock.Disconnect();
         }
     }
 }
        public void CheckHummingbird()
        {
            status = releaseStage.ToString();
            if (releaseStage == 0)
            {
                // Check for completeness
                if (!Hummingbird.CheckHummingbirdComponents(ChasisMerge, ref hummingbirdConnector, ref turretRotor, ref PartScratchpad, ref status))
                {
                    return;
                }

                if (!Hummingbird.CheckHummingbirdComponents(TurretMerge, ref hummingbirdConnector, ref turretRotor, ref PartScratchpad, ref status))
                {
                    return;
                }

                if (turretRotor == null || hummingbirdConnector == null)
                {
                    return;
                }

                turretRotor.Detach();

                Connector.Connect();

                var inventoryItem = Host.AmmoBox?.GetItemAt(0);
                if (inventoryItem != null)
                {
                    Host.AmmoBox.TransferItemTo(Connector.OtherConnector.GetInventory(0), (MyInventoryItem)inventoryItem);
                }

                Connector.Disconnect();

                releaseStage    = 1;
                Piston.Velocity = -0.2f;
            }
            else if (releaseStage == 1)
            {
                // Move pistons
                if (Piston.CurrentPosition == Piston.MinLimit)
                {
                    releaseStage = 2;
                }
            }
            else if (releaseStage < 0)
            {
                releaseStage++;
            }
        }
Beispiel #8
0
            bool TryLockInConnector(double distance)
            {
                IMyShipConnector clamp = Reference as IMyShipConnector;

                clamp.Enabled = true;
                if (clamp.Status == MyShipConnectorStatus.Connectable)
                {
                    clamp.Connect();
                    return(clamp.Status == MyShipConnectorStatus.Connected);
                }
                else
                {
                    return(false);
                }
            }
Beispiel #9
0
 void CheckConnector()
 {
     if ((flags & SpaceshipFlags.Dock) == SpaceshipFlags.Dock)
     {
         if (connector.Status == MyShipConnectorStatus.Connectable)
         {
             connector.Connect();
         }
     }
     else if ((flags & SpaceshipFlags.Undock) == SpaceshipFlags.Undock)
     {
         if (connector.Status == MyShipConnectorStatus.Connected)
         {
             connector.Disconnect();
         }
     }
 }
        private IEnumerator <object> ConnectorSafetyConnect(IMyShipConnector connector)
        {
            // The connector isn't allowed to connect for some reason.
            // This would be unexpected. Stop the whole process.
            if (connector.Status != MyShipConnectorStatus.Connectable)
            {
                throw new InvalidOperationException(
                          $"{connector.CustomName} is not ready to be connected to the conveyor system");
            }

            // Connect the connector and wait a tiny bit to make sure we aren't checking block status too fast.
            connector.Connect();
            yield return(0.2);

            // If it didn't connect for whatever reason, bail out.
            if (connector.Status != MyShipConnectorStatus.Connected)
            {
                throw new InvalidOperationException(
                          $"{connector.CustomName} was not properly connected");
            }
        }
Beispiel #11
0
        public void Main(string argument, UpdateType updateSource)
        {
            write_settings();

            if (updateSource.Equals(UpdateType.Update100))
            {
                drill_pistons_command("status");

                //pistons at max, connector connected
                condition1 = drill_pistons_group_current_distance == drill_pistons_group_max_distance;
                condition2 = drill_connector_status == "Connected";
                if (condition1 & condition2)
                {
                    drill_status = "wait";
                    drill_drills_command("stop");
                    drill_landing_gears_command("status");
                    if (drill_landing_gears_locked == true)
                    {
                        Runtime.UpdateFrequency = UpdateFrequency.None;
                        drill_connector.Disconnect();
                        drill_connector_status = "Unconnected";
                        drill_pistons_command("retract");
                    }
                    write_settings();
                }

                //drill connected and ready
                condition1 = drill_status == "ready";
                condition2 = drill_connector_status == "Connected";
                if (condition1 & condition2)
                {
                    drill_status = "stopped";
                    drill_drills_command("start");
                    drill_status = "running";
                    write_settings();
                }
            }
            else if (updateSource.Equals(UpdateType.Update1))
            {
                //drill wait but unconnected
                condition1 = drill_status == "wait";
                condition2 = drill_connector_status == "reconnecting";
                if (condition1 & condition2)
                {
                    drill_connector.Connect();
                    if (drill_connector.Status.ToString() == "Connected")
                    {
                        drill_status            = "ready";
                        drill_connector_status  = "Connected";
                        Runtime.UpdateFrequency = UpdateFrequency.Update100;
                        write_settings();
                    }
                }
            }
            else if (updateSource.Equals(UpdateType.Trigger) | updateSource.Equals(UpdateType.Terminal))
            {
                write_settings();

                if (argument != "")
                {
                    drill_status = argument;
                }

                verify_availability();

                //switch running state
                if (drill_status == "running")
                {
                    drill_drills_command("stop");
                    drill_status = "stopped";
                }
                else if (drill_status == "stopped")
                {
                    drill_drills_command("start");
                    drill_status = "running";
                }
                else if (drill_status == "wait")
                {
                    drill_pistons_command("reconnect");
                    drill_connector_status  = "reconnecting";
                    Runtime.UpdateFrequency = UpdateFrequency.Update1;
                }
                else
                {
                    drill_status = "stopped";
                    drill_drills_command("stop");
                    drill_status = "stopped";
                }
            }

            //write settings to Programmable block Custom Data field and LCD
            write_settings();
        }
Beispiel #12
0
            Vector3D dockPos3 = new Vector3D(); //Straight Up And Forward Location
            private void DockingIterator(bool Docking, List <Vector3D> COORDINATES, IMyGyro GYRO, IMyShipConnector CONNECTOR, IMyRemoteControl RC)
            {
                if (COORDINATES.Count < 3)
                {
                    return;
                }

                int TargetID  = 0;
                int CurrentID = 0;
                int iter_er   = 0;

                if (Docking == true)
                {
                    TargetID = 1; CurrentID = 0; iter_er = +1;
                }
                if (Docking == false)
                {
                    TargetID = 0; CurrentID = 1; iter_er = -1;
                }

                if (Docking == true)
                {
                    CONNECTOR.Connect();
                }
                if (Docking == true && CONNECTOR.IsWorking == false)
                {
                    CONNECTOR.Enabled = true;
                }
                if (Docking == false && CONNECTOR.IsWorking == true)
                {
                    CONNECTOR.Disconnect(); CONNECTOR.Enabled = true;
                }
                if (CONNECTOR.Status == MyShipConnectorStatus.Connected && Docking == true)
                {
                    for (int j = 0; j < CAF2_THRUST.Count; j++)
                    {
                        (CAF2_THRUST[j] as IMyThrust).Enabled = false;
                    }
                    GYRO.GyroOverride = false;
                    return;
                }
                Vector3D RollOrienter        = Vector3D.Normalize(COORDINATES[COORDINATES.Count - 1] - COORDINATES[COORDINATES.Count - 2]);
                Vector3D Connector_Direction = -1 * ReturnConnectorDirection(CONNECTOR, RC);
                double   RollReqt            = (float)(0.6 * (Vector3D.Dot(RollOrienter, Connector_Direction)));

                //垂直运动在码头
                if (COORD_ID == COORDINATES.Count - 1)
                {
                    Vector3D DockingHeading = Vector3D.Normalize(COORDINATES[COORDINATES.Count - 3] - COORDINATES[COORDINATES.Count - 2]) * 9000000; //Heading
                    GyroTurn6(DockingHeading, RotationalSensitvity, GYRO, RC, RollReqt, PrecisionMaxAngularVel);                                     //Turn to heading
                    if (Vector3D.Dot(RC.WorldMatrix.Forward, Vector3D.Normalize(DockingHeading)) > 0.98)                                             //Error check for small rotational velocity
                    {
                        Vector_Thrust_Manager(COORDINATES[COORD_ID - TargetID], COORDINATES[COORD_ID - CurrentID], CONNECTOR.GetPosition(), 5, 0.7, RC);
                    }                                                                                                                                     //Thrusts to point
                }

                //在码头上的最后/第一个外部Coord
                else if (COORD_ID == 0)
                {
                    print($"启动自动驾驶\n距离目标:{Vector3D.Distance(COORDINATES[0], RC.GetPosition())}");
                    RC_Manager(COORDINATES[0], RC, false);
                }

                //水平和迭代语句
                else
                {
                    var HEADING = Vector3D.Normalize(COORDINATES[COORD_ID - CurrentID] - COORDINATES[COORD_ID - TargetID]) * 9000000;
                    Vector_Thrust_Manager(COORDINATES[COORD_ID - TargetID], COORDINATES[COORD_ID - CurrentID], CONNECTOR.GetPosition(), 8, 1, RC); //Runs docking sequence
                    GyroTurn6(HEADING, RotationalSensitvity, GYRO, RC, RollReqt, PrecisionMaxAngularVel);
                }

                //逻辑检查和迭代
                if (Docking == false && COORD_ID == 0)
                {
                }
                else if ((CONNECTOR.GetPosition() - COORDINATES[COORD_ID - CurrentID]).Length() < 1 || ((RC.GetPosition() - COORDINATES[COORD_ID - CurrentID]).Length() < 10 && COORD_ID == 0))
                {
                    COORD_ID = COORD_ID + iter_er;
                    if (COORD_ID == COORDINATES.Count)
                    {
                        COORD_ID = COORDINATES.Count - 1;
                    }
                    if (COORD_ID < 0)
                    {
                        COORD_ID = 0;
                    }
                }
            }
        private void Exec_Reload(BuildState NewState)
        {
            _buildState = NewState;

            _timer.Enabled = true;
            _timer.StopCountdown();

            switch (NewState)
            {
            case BuildState.Build:
            {
                if (_piston.Velocity >= 0)
                {
                    _piston.Velocity = -_piston.Velocity;
                    _piston.Enabled  = true;
                }

                _projector.Enabled = true;

                foreach (IMyShipWelder welder in _welders)
                {
                    welder.Enabled = true;
                }

                _timer.TriggerDelay = 30;
                _timer.StartCountdown();
            }
            break;

            case BuildState.Rise:
            {
                _piston.Enabled = true;

                if (_piston.Velocity <= 0)
                {
                    _piston.Velocity = -_piston.Velocity;
                }

                _timer.TriggerDelay = 125;
                _timer.StartCountdown();
            }
            break;

            case BuildState.Cut:
            {
                _torpDock.Enabled = true;

                foreach (IMyThrust cutter in _cutters)
                {
                    cutter.Enabled = true;
                }

                _projector.Enabled = false;

                foreach (IMyShipWelder welder in _welders)
                {
                    welder.Enabled = false;
                }

                _timer.TriggerDelay = 10;
                _timer.StartCountdown();
            }
            break;

            case BuildState.Reset:
            {
                _torpDock.Connect();

                foreach (IMyThrust cutter in _cutters)
                {
                    cutter.Enabled = false;
                }

                _timer.TriggerDelay = 8;
                _timer.StartCountdown();
            }
            break;

            case BuildState.Idle:
            {
            }
            break;

            default:
                return;
            }
        }
Beispiel #14
0
        Boolean Dock3()
        {
            mode = 3;

            foreach (IMyThrust thruster in allThrusters)
            {
                thruster.ThrustOverridePercentage = 0;
            }

            rc.SetAutoPilotEnabled(false);
            foreach (IMyGyro gyro in gyros)
            {
                gyro.ApplyAction("OnOff_On");
            }

            double yaw;
            double pitch;

            Boolean yawLock   = false;
            Boolean pitchLock = false;

            GetRotationAngles(Vector3D.Negate(dockingDir), connector, out yaw, out pitch);
            ApplyGyroOverride(pitch, yaw, 0, gyros, connector);

            if (yaw < 0.01)
            {
                yawLock = true;
            }
            if (pitch < 0.01)
            {
                pitchLock = true;
            }

            Echo("yawLock:" + yawLock);
            Echo("pitchLock" + pitchLock);

            if (pitchLock && yawLock)
            {
                Vector3D closestPoint;
                double   distanceFromDockingVector = DistanceFromVector(dockingConnectorPos, dockingDir, connector.GetPosition(), out closestPoint);

                Echo("Distance from docking vector:" + distanceFromDockingVector);

                if (distanceFromDockingVector > 0.35)
                {
                    NewAdjustTest(closestPoint, connector, distanceFromDockingVector);
                }
                else if (distanceFromDockingVector == -1)
                {
                    Echo("Error in docking vector distance calculation");
                }
                else
                {
                    float shipmass = rc.CalculateShipMass().TotalMass;
                    if (rc.GetShipSpeed() < 1.5)
                    {
                        foreach (IMyThrust thruster in backThrusterGroup)
                        {
                            thruster.ThrustOverride = shipmass;
                        }
                    }
                    else
                    {
                        foreach (IMyThrust thruster in backThrusterGroup)
                        {
                            thruster.ThrustOverridePercentage = 0;
                        }
                    }

                    if (Vector3D.Distance(dockingConnectorPos, rc.GetPosition()) > errorDistance)
                    {
                        Storage             = "";
                        dockingConnectorPos = new Vector3D();
                        dockingDir          = new Vector3D();
                        mode = 0;
                        globalPath.Clear();
                        rc.ClearWaypoints();
                        foreach (IMyThrust thrust in allThrusters)
                        {
                            thrust.ThrustOverridePercentage = 0;
                        }

                        foreach (IMyGyro gyro in gyros)
                        {
                            gyro.GyroOverride = false;
                            gyro.Pitch        = 0;
                            gyro.Yaw          = 0;
                            gyro.Roll         = 0;
                        }

                        Boolean sent = antenna.TransmitMessage("canceldock," + password);
                        if (!sent)
                        {
                            messageQue.Add("canceldock," + password);
                        }
                        antenna.CustomName += " ERROR";
                    }
                }
            }

            if (connector.Status == MyShipConnectorStatus.Connectable)
            {
                connector.Connect(); mode = 5;
                globalPath.Clear();

                foreach (IMyThrust thruster in allThrusters)
                {
                    thruster.ThrustOverridePercentage = 0;
                }

                foreach (IMyGyro gyro in gyros)
                {
                    gyro.Pitch = 0;
                    gyro.Yaw   = 0;
                    gyro.Roll  = 0;
                }
                return(true);
            }
            return(false);
        }
Beispiel #15
0
        public void Main(string argument, UpdateType updateSource)
        {
            Echo(IsPaused ? "System paused" : "System working");
            if (argument == "Pause")
            {
                IsPaused = true;
            }
            else if (argument == "Resume")
            {
                IsPaused = false;
            }
            if (IsPaused)
            {
                return;
            }
            //While connector is connected, move stone while at it
            if (Far_Right_Connector.Status == MyShipConnectorStatus.Connected)
            {
                //Move all stones out of drill
                if (GetAnyCargo())
                {
                    //Move all stone
                    foreach (var drill in Far_Array_Drills)
                    {
                        if (drill.GetInventory(0).ItemCount > 0)
                        {
                            //Move stone
                            var inv = drill.GetInventory(0);
                            List <MyInventoryItem> items = new List <MyInventoryItem>();
                            inv.GetItems(items);
                            foreach (var item in items)
                            {
                                inv.TransferItemTo(AnyCargo.GetInventory(0), item);
                            }
                        }
                    }
                }
            }
            //Check connector can connect now
            bool isAllExtended      = IsAllPistonExtended(Far_Top_Pistons);
            bool isAllRetracted     = IsAllPistonRetracted(Far_Top_Pistons);
            bool isMidPush          = IsPistonMidPush(Far_Top_Pistons);
            bool isPistonMergeOn    = Far_PistonEnd_Merge_Top.GetValueBool("OnOff");
            bool isAnyDrillHasStone = IsAnyDrillHasStone(Far_Array_Drills);

            Echo($"Currently all piston: {(isAllExtended ? "Extended" : "")}{(isAllRetracted ? "Retracted" : "")}");
            //Assuming this already push to it fullest
            if (isAllExtended && !isPistonMergeOn && Far_Right_Connector.Status == MyShipConnectorStatus.Connectable && !isMidPush)
            {
                //If it can connect, connect it and turn on side merge block, and turn off top merge block
                Far_Right_Connector.Connect();
                Far_PistonEnd_Merge_Side.SetValueBool("OnOff", true);
                Far_PistonEnd_Merge_Top.SetValueBool("OnOff", false);
                Echo("Connector connected, turn on side merge block, and turn on top merge block");
            }
            else if (!isAllExtended && isPistonMergeOn)
            {
                //Merge block at the tip of piston is off. Time to pull it up
                foreach (var piston in Far_Top_Pistons)
                {
                    piston.SetValueFloat("Velocity", -0.3f);
                }
            }
            //All piston retracted, turn on projector merge block and all welders
            else if (isAllRetracted && !Far_Projector_Merge.GetValueBool("OnOff"))
            {
                Far_Projector_Merge.SetValueBool("OnOff", true);
                //Turn on all welder
                var welders = Far_Top_Welders.Concat(Far_Left_Welders).Concat(Far_Right_Welders).ToList();
                foreach (var welder in welders)
                {
                    welder.SetValueBool("OnOff", true);
                }
                //Extend a piston to build the other side of crane
                Far_Piston_Side_Welders.SetValueFloat("Velocity", 0.3f);
            }
            //Check projector status
            else if (isAllRetracted && Far_Projector.RemainingBlocks < 1 && !isPistonMergeOn)
            {
                //All done and welded. Turn off all welders and retract side welder
                var welders = Far_Top_Welders.Concat(Far_Left_Welders).Concat(Far_Right_Welders).ToList();
                foreach (var welder in welders)
                {
                    welder.SetValueBool("OnOff", false);
                }
                Far_Piston_Side_Welders.SetValueFloat("Velocity", -0.3f);
                //Then extend top piston!
                foreach (var piston in Far_Top_Pistons)
                {
                    piston.SetValueFloat("Velocity", 0.1f);
                    Far_PistonEnd_Merge_Top.SetValueBool("OnOff", true);
                }
            }
            else if (isPistonMergeOn && Far_PistonEnd_Merge_Top.IsConnected)
            {
                //If top merge block is connected, then disable projector merge block
                //Letting it push down
                //Disable side merger, if it connected
                Far_Projector_Merge.SetValueBool("OnOff", false);
                Far_PistonEnd_Merge_Side.SetValueBool("OnOff", false);
            }
            //After it push down for a while
            else if (isPistonMergeOn && isMidPush)
            {
                //Disconnect connector
                Far_Right_Connector.Disconnect();
            }
        }
Beispiel #16
0
 protected override void OnExecuting(IMyShipConnector connector)
 => connector.Connect();
Beispiel #17
0
        public void CheckLandpedo()
        {
            statusBuilder.Clear();
            if (Landpedo != null)
            {
                return;
            }

            if (Connector != null)
            {
                if (!Connector.IsWorking)
                {
                    return;
                }
                if (Connector.Status == MyShipConnectorStatus.Unconnected)
                {
                    return;
                }
                if (Connector.Status == MyShipConnectorStatus.Connectable)
                {
                    Connector.Connect();
                }

                if (Connector.Status != MyShipConnectorStatus.Connected)
                {
                    return;
                }

                var other = Connector.OtherConnector;
                var lines = other.CustomData.Split('\n');
                // Parts
                // Projector
                // Merge

                IMyProjector      projector = null;
                IMyShipMergeBlock merge     = null;


                if (GridTerminalHelper.Base64BytePosToBlockList(lines[1], other, ref PartScratchpad))
                {
                    projector = PartScratchpad[0] as IMyProjector;
                }

                PartScratchpad.Clear();
                if (GridTerminalHelper.Base64BytePosToBlockList(lines[2], other, ref PartScratchpad))
                {
                    merge = PartScratchpad[0] as IMyShipMergeBlock;
                }

                if (projector != null && merge != null)
                {
                    projector.Enabled = true;
                    merge.Enabled     = false;
                }

                PartScratchpad.Clear();
                if (!GridTerminalHelper.Base64BytePosToBlockList(lines[0], other, ref PartScratchpad))
                {
                    return;
                }

                Landpedo          = Landpedo.GetLandpedo(PartScratchpad);
                projector.Enabled = false;
            }
            else
            {
            }
        }
Beispiel #18
0
        public void Main(string argument)
        {
            //THIS STEP IS IMPORTANT BECAUSE THE TIMER RUNS THE PB WITH DEFAULT PARAMETER, WICH IS EMPTY.
            //IF YOU WERE TO REMOVE THIS, THE FOLLOWING SWITCH WOULDN'T WORK
            if (!String.IsNullOrEmpty(argument))
            {
                timer.CustomData = argument.ToLower() + "1"; //the ToLower method makes argument case not matter
            }
            //DIFFERENT PHASES ARE REGULATED VIA TIMER'S CUSTOM DATA
            //notice that extend and retract processes are not the same in reverse because I found out that it would bump into obstacles
            switch (timer.CustomData)
            {
            case "extend1":
                piston1.Extend();
                piston2.Extend();
                Sleep(1f);
                timer.CustomData = "extend2";     //timer's customData gets updated so next time it runs the PB the next phase gets executed
                break;

            case "extend2":
                if (rotor1.TargetVelocityRPM > 0)     //just to be sure it doesn't reverse in the wrong way
                {
                    rotor1.TargetVelocityRPM *= -1;
                }
                Sleep(2f);
                timer.CustomData = "extend3";
                break;

            case "extend3":
                piston3.Extend();
                if (rotor2.TargetVelocityRPM > 0)
                {
                    rotor2.TargetVelocityRPM *= -1;
                }
                Sleep(2f);
                timer.CustomData = "extend4";
                break;

            case "extend4":
                piston4.Extend();
                Sleep(1.5f);
                timer.CustomData = "extend5";
                break;

            case "extend5":
                connector.Connect();
                timer.CustomData = "";
                break;

            case "retract1":
                connector.Disconnect();
                piston4.Retract();
                if (rotor2.TargetVelocityRPM < 0)
                {
                    rotor2.TargetVelocityRPM *= -1;
                }
                piston3.Retract();
                piston2.Retract();
                if (rotor1.TargetVelocityRPM < 0)
                {
                    rotor1.TargetVelocityRPM *= -1;
                }
                Sleep(1f);
                timer.CustomData = "retract2";
                break;

            case "retract2":
                piston1.Retract();
                timer.CustomData = "";
                break;

            default:
                Echo("unknown timer customdata");
                break;
            }
        }
Beispiel #19
0
            internal void Main()
            {
                ProgramInstance.Echo("Status: " + _status);
                ProgramInstance.Echo("Route length: " + _routeLength);
                ProgramInstance.Echo("Current node: " + _currentNodeNum);

                _gridCenterPosition = _controller.CubeGrid.GetPosition();
                _currentSpeed       = _controller.GetShipSpeed() * 3.7d;

                RadioInput();

                switch (_status)
                {
                case State.STANDBY:
                    if (_commands.Count != 0)
                    {
                        NextCommand();
                    }
                    break;

                case State.MOVE:
                    MovementControl(_route[_currentNodeNum].Direction);
                    break;

                case State.CLEARCOMM:
                    _commands.Clear();
                    _currentNodeNum = 0;
                    NextCommand();
                    break;

                case State.CLEARROUTE: //TODO
                    _currentNodeNum = 0;
                    _route.Clear();
                    NextCommand();
                    break;

                case State.READROUTE:
                    _currentNodeNum = 0;
                    ReadRouteData();
                    NextCommand();
                    break;

                case State.UNDOCKING:
                    if (_connector.Status == MyShipConnectorStatus.Connected)
                    {
                        _connector.Disconnect();
                        _connector.Enabled = false;
                    }
                    else
                    {
                        NextCommand();
                    }
                    break;

                case State.DOCKING:
                    GetForwardAxels();
                    float angle; double distance;
                    CalculatePlanarAngleAndDistanceTo(_route[_currentNodeNum].Position, out angle, out distance);
                    WheelsControl(angle, 1, _route[_currentNodeNum - 1].Speed);


                    if (_currentNodeNum == _routeLength)
                    {
                        if (_connector.Status == MyShipConnectorStatus.Connectable)
                        {
                            _connector.Connect();
                        }
                        if (_connector.Status == MyShipConnectorStatus.Connected)
                        {
                            NextCommand();
                        }
                    }
                    else if (distance < _route[_currentNodeNum].CheckDistance)
                    {
                        _currentNodeNum++;
                        _connector.Enabled = false;
                        if (_currentNodeNum == _routeLength)
                        {
                            _connector.Enabled = true;
                        }
                        WriteData();
                    }

                    break;

                case State.RADIOCALL:
                    ProgramInstance.IGC.SendBroadcastMessage(_radio, "DELIVERY " + _sender + " " + _mode + " " + _recipient);
                    NextCommand();
                    break;
                }
            }
        public void Main(string argument, UpdateType updateSource)
        {
            // SETUP

            craneCabin     = GridTerminalSystem.GetBlockWithName(cabinName) as IMyCockpit;
            craneRotor     = GridTerminalSystem.GetBlockWithName(rotorName) as IMyMotorAdvancedStator;
            craneConnector = GridTerminalSystem.GetBlockWithName(connectorName) as IMyShipConnector;
            cranePiston    = GridTerminalSystem.GetBlockWithName(pistonName) as IMyPistonBase;

            if (callPanels.Count == 0)
            {
                List <IMyButtonPanel> tempPanels = new List <IMyButtonPanel>();
                GridTerminalSystem.GetBlocksOfType(tempPanels, tempPanel => tempPanel.CustomName.Contains(callPanelName));

                for (int key = 0; key < tempPanels.Count; key++)
                {
                    IMyTextSurfaceProvider panelLCD = (IMyTextSurfaceProvider)tempPanels[key];

                    if (panelLCD.GetSurface(0) != null)
                    {
                        callPanels.Add(tempPanels[key]);
                    }
                }
            }

            if (areaStatusPanels.Count == 0)
            {
                GridTerminalSystem.GetBlocksOfType(areaStatusPanels, tempPanel => tempPanel.CustomName.Contains(areaStatusPanelName));
            }

            if (craneCabin != null)
            {
                pistonMonitor    = craneCabin.GetSurface(1);
                connectorMonitor = craneCabin.GetSurface(2);
                rotorMonitor     = craneCabin.GetSurface(3);
            }

            // END SETUP

            if (argument != "" && callOverride == null)
            {
                if (craneConnector == null || cranePiston == null || craneRotor == null)
                {
                    return;
                }

                callOverride = Math.Min(Math.Max((int.Parse(argument) * 45) - 180, -135), 135);
                UpdateCallPanels();
                lastRotorInput  = 0;
                rotorMultiplier = 0;
                craneConnector.Disconnect();

                if (Math.Floor((craneRotor.Angle * (180 / Math.PI)) + 0.5) < callOverride)
                {
                    craneRotor.UpperLimitDeg     = (float)callOverride;
                    craneRotor.TargetVelocityRPM = 1;
                }
                else
                {
                    craneRotor.LowerLimitDeg     = (float)callOverride;
                    craneRotor.TargetVelocityRPM = -1;
                }
            }

            if ((updateSource & UpdateType.Update100) != 0)
            {
                Runtime.UpdateFrequency = craneCabin.IsUnderControl || rotorMultiplier != 0 || callOverride != null ? UpdateFrequency.Update1 | UpdateFrequency.Update100 : UpdateFrequency.Update100;
                UpdateCallPanels();
            }

            if (callOverride == null)
            {
                if ((updateSource & UpdateType.Update1) != 0 && craneCabin != null)
                {
                    pistonOutput.Length    = 0;
                    connectorOutput.Length = 0;
                    rotorOutput.Length     = 0;

                    connectorOutput.Append("\n\n\n\n");

                    if (craneCabin.IsUnderControl)
                    {
                        pistonOutput.Append("\n\n\n\nPISTON\n");
                        rotorOutput.Append("\n\n\nROTOR\n");

                        if (craneConnector != null)
                        {
                            if (craneCabin.MoveIndicator.Z > 0)
                            {
                                craneConnector.Disconnect();
                            }

                            if (craneConnector.Status == MyShipConnectorStatus.Unconnected)
                            {
                                connectorOutput.Append("DISCONNECTED");
                                connectorMonitor.FontColor = Color.Red;
                            }
                            else if (craneConnector.Status == MyShipConnectorStatus.Connected)
                            {
                                connectorOutput.Append("CONNECTED\n");
                                connectorMonitor.FontColor = Color.Green;
                                string otherName = craneConnector.OtherConnector.CustomName;
                                connectorOutput.Append(otherName.Substring(0, otherName.Length - 10));
                            }
                            else
                            {
                                connectorOutput.Append("READY");
                                connectorMonitor.FontColor = Color.Yellow;
                            }
                        }

                        if (cranePiston != null)
                        {
                            cranePiston.Velocity = (float)ClampVelocity(-craneCabin.MoveIndicator.Z, 1);

                            pistonOutput.Append("[ ");
                            pistonOutput.Append((Math.Floor(cranePiston.CurrentPosition * 10) / 10).ToString("F1"));
                            pistonOutput.Append("m ]");
                        }

                        if (craneRotor != null)
                        {
                            if (craneConnector.Status != MyShipConnectorStatus.Connected)
                            {
                                if (craneCabin.MoveIndicator.X != 0 && Math.Sign(craneCabin.MoveIndicator.X) != Math.Sign(lastRotorInput))
                                {
                                    rotorMultiplier *= -1;
                                }

                                lastRotorInput = (craneCabin.MoveIndicator.X == 0 ? lastRotorInput : craneCabin.MoveIndicator.X);
                                if (craneCabin.MoveIndicator.X != 0)
                                {
                                    rotorMultiplier = Math.Min(Math.Max(rotorMultiplier + (Math.Abs(craneCabin.MoveIndicator.X) * 0.02f), -1), 1);
                                }
                                else
                                {
                                    rotorMultiplier += Math.Max(Math.Min(Math.Abs(0 - rotorMultiplier), 0.02f), 0) * -Math.Sign(rotorMultiplier);
                                }

                                craneRotor.TargetVelocityRPM = (float)ClampVelocity(lastRotorInput, 1) * rotorMultiplier;
                            }

                            rotorOutput.Append("[ ");
                            rotorOutput.Append(Math.Floor((craneRotor.Angle * (180 / Math.PI)) + 0.5).ToString("000.##"));
                            rotorOutput.Append("° ]");
                        }
                    }
                    else
                    {
                        connectorOutput.Append("STANDING BY");
                        connectorMonitor.FontColor = Color.White;

                        if (rotorMultiplier > 0)
                        {
                            rotorMultiplier = Math.Max(rotorMultiplier - 0.02f, 0);
                        }
                        else if (rotorMultiplier < 0)
                        {
                            rotorMultiplier = Math.Min(rotorMultiplier + 0.02f, 0);
                        }
                        else
                        {
                            lastRotorInput = 0;
                        }

                        craneRotor.TargetVelocityRPM = (float)ClampVelocity(lastRotorInput, 1) * rotorMultiplier;
                    }

                    pistonMonitor.WriteText(pistonOutput, false);
                    connectorMonitor.WriteText(connectorOutput, false);
                    rotorMonitor.WriteText(rotorOutput, false);
                }
                else if (craneCabin == null)
                {
                    lastRotorInput  = 0;
                    rotorMultiplier = 0;

                    if (cranePiston != null)
                    {
                        cranePiston.Velocity = 0;
                    }

                    if (craneRotor != null)
                    {
                        craneRotor.TargetVelocityRPM = 0;
                    }
                }
            }
            else
            {
                if (craneConnector == null || cranePiston == null || craneRotor == null)
                {
                    callOverride = null;
                    UpdateCallPanels();
                    return;
                }

                if (Math.Abs((craneRotor.Angle * (180 / Math.PI)) - (float)callOverride) < 0.25)
                {
                    craneRotor.TargetVelocityRPM = 0;
                    craneRotor.UpperLimitDeg     = 135;
                    craneRotor.LowerLimitDeg     = -135;

                    cranePiston.Velocity = 1;

                    if (Math.Abs(cranePiston.CurrentPosition - cranePiston.MaxLimit) < 0.1 && craneConnector.Status == MyShipConnectorStatus.Connectable)
                    {
                        cranePiston.Velocity = 0;
                        craneConnector.Connect();
                        callOverride = null;
                        UpdateCallPanels();
                        return;
                    }
                }
                else
                {
                    cranePiston.Velocity = -1;
                }

                if (craneCabin != null)
                {
                    connectorOutput.Length = 0;
                    rotorOutput.Length     = 0;
                    pistonOutput.Length    = 0;

                    connectorOutput.Append("\n\n\n\nAUTO-DOCKING\n");
                    connectorOutput.Append(((float)callOverride).ToString("000.##"));
                    connectorOutput.Append("°");
                    connectorMonitor.FontColor = Color.Blue;

                    pistonOutput.Append("\n\n\n\nPISTON\n");
                    pistonOutput.Append("[ ");
                    pistonOutput.Append((Math.Floor(cranePiston.CurrentPosition * 10) / 10).ToString("F1"));
                    pistonOutput.Append("m ]");

                    rotorOutput.Append("\n\n\nROTOR\n");
                    rotorOutput.Append("[ ");
                    rotorOutput.Append(Math.Floor((craneRotor.Angle * (180 / Math.PI)) + 0.5).ToString("000.##"));
                    rotorOutput.Append("° ]");

                    pistonMonitor.WriteText(pistonOutput, false);
                    connectorMonitor.WriteText(connectorOutput, false);
                    rotorMonitor.WriteText(rotorOutput, false);
                }
            }
        }
Beispiel #21
0
            public bool Perform()
            {
                switch (State)
                {
                case "Initial":
                    State = "Requesting Clearance";
                    break;

                case "Requesting Clearance":
                    SendRequest();
                    State = "Waiting for Clearance";
                    break;

                case "Waiting for Clearance":
                    Drone.Log("Waiting for clearance");
                    break;

                case "Approaching Dock":
                    if (Move == null)
                    {
                        Move = new Move(Drone, new Queue <Vector3D>(new[] { ApproachPath[0] }), Drone.Remote, true);
                    }

                    if (Move.Perform())
                    {
                        Move  = null;
                        State = "Docking";
                    }

                    break;

                case "Docking":
                    DockingPort.Enabled = true;

                    Vector3D nearDock = ApproachPath[1] + Vector3D.Normalize(ApproachPath[0] - ApproachPath[1]) * 2.5;
                    if (Move == null)
                    {
                        Move = new Move(Drone, new Queue <Vector3D>(new[] { nearDock }), DockingPort, true);
                    }

                    if (Move.Perform())
                    {
                        Move = null;
                        Drone.AllStop();
                        State = "Final Approach";
                    }

                    break;

                case "Final Approach":
                    if (Move == null)
                    {
                        Move = new Move(Drone, new Queue <Vector3D>(new[] { ApproachPath[1] }), DockingPort, true, 0.25);
                    }

                    if (Move.Perform() || DockingPort.Status == MyShipConnectorStatus.Connected)
                    {
                        Move = null;
                        Drone.AllStop();
                        State = "Connecting";
                    }
                    DockingPort.Connect();
                    break;

                case "Connecting":
                    if (DockingPort.Status == MyShipConnectorStatus.Connected)
                    {
                        Drone.AllStop();
                        State = "Final";
                    }
                    DockingPort.Connect();
                    break;

                case "Final":
                    return(true);
                }

                return(false);
            }