예제 #1
0
 public void AddPart(IMyTerminalBlock part)
 {
     if (part is IMyShipConnector)
     {
         connector = (IMyShipConnector)part;
     }
     if (part is IMyPistonBase)
     {
         extender = (IMyPistonBase)part;
     }
     if (part is IMyMotorAdvancedStator)
     {
         rotor = (IMyMotorAdvancedStator)part;
     }
     if (part is IMyAirtightHangarDoor)
     {
         gates.Add((IMyAirtightHangarDoor)part);
     }
     if (part is IMyTextPanel)
     {
         display = (IMyTextPanel)part;
     }
     if (part is IMyInteriorLight)
     {
         IMyInteriorLight light = (IMyInteriorLight)part;
         lights.Add(light);
         light.Intensity = 2f;
         light.Radius    = 12f;
     }
 }
예제 #2
0
        public void Initialise()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update10;

            List <IMyCockpit> cockpits = new List <IMyCockpit>();

            GridTerminalSystem.GetBlocksOfType <IMyCockpit>(cockpits);
            cockpit = cockpits.FirstOrDefault();


            //Instantiate Cargo Tracking
            cargoScreen = cockpit.GetSurface(int.Parse(argument.Split(' ')[1]));

            inventories = new List <IMyInventory>();

            foreach (var item in blocks.Where(x => x.HasInventory))
            {
                inventories.Add(item.GetInventory());
            }
            Echo("Inventories found: " + inventories.Count());

            //Instantiate Rotation tracking
            angleScreen = cockpit.GetSurface(int.Parse(argument.Split(' ')[2]));

            rightRotor = blocks.Where(x => x.CustomData.Contains(argument.Split(' ')[0]) && x is IMyMotorAdvancedStator).First() as IMyMotorAdvancedStator;
            Echo((rightRotor != null ? "Rotor found" : "Rotor NOT found"));
        }
예제 #3
0
            public TP(ushort id, SubP p) : base(id, p)
            {
                OS.GTS.GetBlocksOfType(Controllers, x => x.CanControlShip);
                RotorSusp  = OS.GTS.GetBlockWithName("Suspension Rotor") as IMyMotorStator;
                HingeNeck  = OS.GTS.GetBlockWithName("Neck Hinge") as IMyMotorAdvancedStator;
                RotorSolar = OS.GTS.GetBlockWithName("Solar Rotor") as IMyMotorStator;
                HingeSolar = OS.GTS.GetBlockWithName("Solar Hinge") as IMyMotorAdvancedStator;
                OS.GTS.GetBlocksOfType(HingesSolar, x => x.CustomName.StartsWith("Solar Hinge") && x.CustomName != "Solar Hinge");
                OS.GTS.GetBlocksOfType(Hinges, x => x.CustomName.StartsWith("Suspension"));
                OS.GTS.GetBlocksOfType(Wheels);
                SetCmd("tsp", new Cmd(CmdTurnSolar, "Turn solar panels"));

                if (Controllers.Count == 0 || RotorSusp == null || HingeNeck == null)
                {
                    Terminate("Dalnoboy blocks not found.");
                }
                else
                {
                    if (HingeSolar == null || RotorSolar == null)
                    {
                        Solar = false;
                    }
                    AddAct(ref GC, GetController, 20);
                    AddAct(ref MA, Control, 5, 1);
                }
            }
예제 #4
0
        public void workIsFinished(List <IMyTerminalBlock> drillList, List <IMyTerminalBlock> pistonList, List <IMyTerminalBlock> rotorList)
        {
            if (getActualPistonExtend(pistonList, false) == 0 && isExtended && finishedMining)
            {
                for (int i = 0; i < drillList.Count; i++)
                {
                    IMyShipDrill drillList_X = GridTerminalSystem.GetBlockWithName(drillList[i].CustomName) as IMyShipDrill;
                    if (drillList_X.CustomName.Contains(drillNameTag))
                    {
                        drillList_X.Enabled = false;
                    }
                }

                for (int i = 0; i < pistonList.Count; i++)
                {
                    IMyPistonBase pistonList_X = GridTerminalSystem.GetBlockWithName(pistonList[i].CustomName) as IMyPistonBase;
                    if (pistonList_X.CustomName.Contains(pistonNameTag) && !pistonList_X.CustomName.Contains("Extender"))
                    {
                        pistonList_X.Enabled = false;
                    }
                }

                for (int i = 0; i < rotorList.Count; i++)
                {
                    IMyMotorAdvancedStator rotorList_X = GridTerminalSystem.GetBlockWithName(rotorList[i].CustomName) as IMyMotorAdvancedStator;
                    if (rotorList_X.CustomName.Contains(rotorNameTag))
                    {
                        rotorList_X.Enabled = false;
                    }
                }
                Echo("Work is finished");
                workFinished = true;
            }
        }
        Program()
        {
            LCD             = (IMyTextPanel)GridTerminalSystem.GetBlockWithName("LCDRotor");
            LCD.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;

            rotor = (IMyMotorAdvancedStator)GridTerminalSystem.GetBlockWithName("Drill_Rotor");

            currentRotorPos = rotor.Angle;
        }
예제 #6
0
        public Program()
        {
            var pistonGroup = GridTerminalSystem.GetBlockGroupWithName("Drill Rig Pistons");

            pistonGroup.GetBlocksOfType(_pistons);
            var drillGroup = GridTerminalSystem.GetBlockGroupWithName("Drill Rig Drills");

            drillGroup.GetBlocksOfType(_drills);
            _drillHeadRotor = GridTerminalSystem.GetBlockWithName("Rotor Drill Head") as IMyMotorAdvancedStator;
        }
예제 #7
0
    public Program()
    {
        allBlocks = new List <IMyTerminalBlock>();
        rPistons  = new List <IMyPistonBase>();
        vPistons  = new List <IMyPistonBase>();
        drills    = new List <IMyShipDrill>();
        cargo     = new List <IMyInventory>();

        GridTerminalSystem.GetBlocks(allBlocks);
        foreach (IMyTerminalBlock block in allBlocks)
        {
            IMyPistonBase piston = block as IMyPistonBase;
            if (piston != null)
            {
                if (piston.CustomName.Contains("[R]"))
                {
                    rPistons.Add(piston);
                }
                if (piston.CustomName.Contains("[V]"))
                {
                    vPistons.Add(piston);
                }
            }

            IMyShipDrill drill = block as IMyShipDrill;
            if (drill != null)
            {
                drills.Add(drill);
            }

            IMyInventory cont = block.GetInventory();
            if (cont != null)
            {
                if (!block.CustomName.Contains("Stone Ejector"))
                {
                    cargo.Add(cont);
                }
            }

            IMyMotorAdvancedStator rot = block as IMyMotorAdvancedStator;
            if (rot != null)
            {
                rotor = rot;
            }

            /*IMyTextPanel tp = block as IMyTextPanel;
             * if (tp != null)
             * {
             *  lcd = tp;
             * }*/
        }
        InitMiner();

        Runtime.UpdateFrequency = UpdateFrequency.Update1;
    }
예제 #8
0
    public WelderArm(Program MyProgram, IMyPistonBase PistonX1, IMyPistonBase PistonX2, IMyPistonBase PistonY1, IMyPistonBase PistonY2, IMyMotorAdvancedStator Hinge1, IMyMotorAdvancedStator Hinge2, IMyMotorAdvancedStator Hinge3)
    {
        this.MyProgram = MyProgram;

        this.PistonX1 = PistonX1;
        this.PistonX2 = PistonX2;
        this.PistonY1 = PistonY1;
        this.PistonY2 = PistonY2;
        this.Hinge1   = Hinge1;
        this.Hinge2   = Hinge2;
        this.Hinge3   = Hinge3;
    }
예제 #9
0
        bool CollectParts(IMyTerminalBlock block)
        {
            if (!block.IsSameConstructAs(Me))
            {
                return(false);
            }
            //if (!block.CustomName.Contains(Me.CustomName.Last())) return false;
            if (block is IMyMotorAdvancedStator && block.CustomName.Contains("Small Hinge"))
            {
                SmallHinge = (IMyMotorAdvancedStator)block;
            }
            if (block is IMyMotorAdvancedStator && block.CustomName.Contains("Large Hinge"))
            {
                LargeHinge = (IMyMotorAdvancedStator)block;
            }
            if (block is IMyMotorAdvancedStator && block.CustomName.Contains("Elevation"))
            {
                Elevation = (IMyMotorAdvancedStator)block;
            }
            if (block is IMyMotorStator && block.CustomName.Contains("Sweeper"))
            {
                Sweeper = (IMyMotorStator)block;
            }

            if (block is IMyProjector && block.CustomName.Contains("Base Projector"))
            {
                BaseProjector = (IMyProjector)block;
            }
            if (block is IMyProjector && block.CustomName.Contains("Top Projector"))
            {
                TopProjector = (IMyProjector)block;
            }

            if (block is IMyShipMergeBlock && block.CustomName.Contains("Top Release"))
            {
                TopMerge = (IMyShipMergeBlock)block;
            }
            if (block is IMyShipMergeBlock && block.CustomName.Contains("Base Release"))
            {
                BaseMerge = (IMyShipMergeBlock)block;
            }

            if (block is IMyShipWelder)
            {
                Welders.Add((IMyShipWelder)block);
            }
            if (block is IMyTextPanel)
            {
                Display = (IMyTextPanel)block;
            }

            return(false);
        }
예제 #10
0
        public void Reset(MyTuple <IntelItemType, long> intelKey, IMyMotorAdvancedStator Rotor)
        {
            Reset();

            Approach.MoveReference      = Rotor;
            FinalApproach.MoveReference = Rotor;


            TaskQueue.Enqueue(Approach);
            TaskQueue.Enqueue(FinalApproach);
            TaskQueue.Enqueue(Unapproach);
            TaskQueue.Enqueue(Return);
        }
예제 #11
0
            void DampSuspHinge(IMyMotorAdvancedStator h, double r, double p)
            {
                var T =
                    30000
                    + h.Angle / Math.Abs(h.LowerLimitRad) * 30000
                    + (float)(2 * p / Math.PI) * Math.Sign(Vector3D.Dot(h.GetPosition() - HingeNeck.GetPosition(), HingeNeck.WorldMatrix.Up)) * 20000
                    + (float)(2 * r / Math.PI) * Math.Sign(Vector3D.Dot(h.GetPosition() - HingeNeck.GetPosition(), HingeNeck.WorldMatrix.Forward)) * 20000
                ;
                byte upLegs = (byte)Convert.ToSingle(Controller.MoveIndicator.Y < 0 && ((Vector3D.Dot(h.GetPosition() - HingeNeck.GetPosition(), HingeNeck.WorldMatrix.Up) < 0 && Controller.MoveIndicator.Z <= 0) || (Vector3D.Dot(h.GetPosition() - HingeNeck.GetPosition(), HingeNeck.WorldMatrix.Up) > 0 && Controller.MoveIndicator.Z > 0)));

                h.Torque            = Convert.ToSingle(T > 0) * T + upLegs * 100000;
                h.TargetVelocityRPM = upLegs * 80 - 40;
            }
예제 #12
0
        /// <inheritdoc />
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            using (Log.BeginMethod(nameof(Init))) {
                Log.Debug($"START {nameof(Init)}");
                base.Init(objectBuilder);

                Stator = Entity as IMyMotorAdvancedStator;

                if (Stator == null)
                {
                    return;
                }

                if (Stator.IsProjected())
                {
                    return;
                }

                if (Mod.Static.Network == null || Mod.Static.Network.IsServer)
                {
                    if (Entity.Storage == null)
                    {
                        Entity.Storage = new MyModStorageComponent();
                    }

                    try {
                        _settings = Stator.Load <SmartRotorSettings>(new Guid(SmartRotorSettings.GUID));
                        if (_settings != null)
                        {
                            Log.Debug("Settings loaded");
                            if (_settings.Version < SmartRotorSettings.VERSION)
                            {
                                // todo: merge old and new settings in future versions.
                            }
                        }
                        else
                        {
                            Log.Debug("New Block creating settings");
                            _settings = new SmartRotorSettings();
                        }
                    } catch (Exception exception) {
                        Log.Error(exception);
                        _settings = new SmartRotorSettings();
                    }

                    Stator.AttachedEntityChanged += OnAttachedEntityChanged;
                }

                Log.Debug($"END {nameof(Init)}");
            }
        }
        private bool initPivot()
        {
            IMyTerminalBlock       block       = GridTerminalSystem.GetBlockWithName("Balancer Rotor 1");
            IMyMotorAdvancedStator rotorStatus = block as IMyMotorAdvancedStator;

            if (rotorStatus == null)
            {
                return(false);
            }
            else
            {
                this.pivot = rotorStatus;
                return(true);
            }
        }
예제 #14
0
        private bool findRotor()
        {
            IMyTerminalBlock       block       = GridTerminalSystem.GetBlockWithName("Flattener Rotor");
            IMyMotorAdvancedStator rotorStatus = block as IMyMotorAdvancedStator;

            if (rotorStatus == null)
            {
                return(false);
            }
            else
            {
                this.rotor = rotorStatus;
                return(true);
            }
        }
예제 #15
0
        /// <inheritdoc />
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            using (Mod.PROFILE ? Profiler.Measure(nameof(SmartRotorBase), nameof(Init)) : null) {
                using (Log.BeginMethod(nameof(Init))) {
                    base.Init(objectBuilder);

                    Stator = Entity as IMyMotorAdvancedStator;
                    if (Stator == null)
                    {
                        return;
                    }

                    IsJustPlaced = Stator.CubeGrid?.Physics != null;
                }
            }
        }
예제 #16
0
        Program()
        {
            //LCD = (IMyTextPanel)GridTerminalSystem.GetBlockWithName("LCD");
            //LCD.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE;

            drills     = GridTerminalSystem.GetBlockGroupWithName("Barge_Drills");
            drillsList = new List <IMyTerminalBlock>();
            drills.GetBlocks(drillsList);

            pistons     = GridTerminalSystem.GetBlockGroupWithName("Barge_Pistons");
            pistonsList = new List <IMyTerminalBlock>();
            pistons.GetBlocks(pistonsList);

            rotor = (IMyMotorAdvancedStator)GridTerminalSystem.GetBlockWithName("Drill_Rotor");
            gyro  = GridTerminalSystem.GetBlockWithName("Drill_Gyro");
        }
예제 #17
0
파일: Miner2.cs 프로젝트: Sunduc/SE-Scripts
    public Program()
    {
        allBlocks = new List <IMyTerminalBlock>();
        //cargo = new List<IMyInventory>();
        rPistons = new List <IMyPistonBase>();
        vPistons = new List <IMyPistonBase>();

        GridTerminalSystem.GetBlocks(allBlocks);
        foreach (IMyTerminalBlock block in allBlocks)
        {
            IMyPistonBase piston = block as IMyPistonBase;
            if (piston != null)
            {
                if (piston.CustomName.Contains(RADIAL_PISTON_TAG))
                {
                    rPistons.Add(piston);
                }
                if (piston.CustomName.Contains(VERTICAL_PISTON_TAG))
                {
                    vPistons.Add(piston);
                }
            }

            IMyShipDrill drill = block as IMyShipDrill;
            if (drill != null)
            {
                drills = drill;
            }

            IMyInventory cont = block.GetInventory();
            if (cont != null)
            {
                if (block.CustomName.Contains("Cargo"))
                {
                    cargo = cont;
                }
            }

            IMyMotorAdvancedStator rot = block as IMyMotorAdvancedStator;
            if (rot != null)
            {
                rotor = rot;
            }
        }
        Runtime.UpdateFrequency = UpdateFrequency.Update100;
    }
예제 #18
0
        public Program()
        {
            IMyBlockGroup drills = GridTerminalSystem.GetBlockGroupWithName("drills");

            drills.GetBlocksOfType <IMyShipDrill>(d, drill => drill.Enabled = true);
            IMyMotorAdvancedStator rotor_up, rotor_down;

            piston          = GridTerminalSystem.GetBlockWithName("p") as IMyPistonBase;
            piston.MaxLimit = 8.5f;
            rotor_up        = GridTerminalSystem.GetBlockWithName("rotor oben") as IMyMotorAdvancedStator;
            rotor_down      = GridTerminalSystem.GetBlockWithName("rotor unten") as IMyMotorAdvancedStator;

            currentStep = "STEP_1";

            if (piston.CurrentPosition < piston.MaxLimit)
            {
                piston.Velocity = 1f;
            }
        }
예제 #19
0
        public void Main(string argument, UpdateType updateSource)
        {
            counter++;
            Echo("Run: " + counter);
            //rotor = new List<IMyMotorAdvancedStator>();


            if (updateSource == UpdateType.Terminal)
            {
                string target = argument.Split(' ')[0];

                Runtime.UpdateFrequency = UpdateFrequency.Update10;

                List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>();
                GridTerminalSystem.GetBlocksOfType <IMyCockpit>(blocks);
                screen = (blocks.Where(x => x.CustomData.Contains(target)).FirstOrDefault() as IMyCockpit).GetSurface(int.Parse(argument.Split(' ')[1]));

                GridTerminalSystem.GetBlocksOfType <IMyMotorAdvancedStator>(blocks);
                foreach (var item in blocks)
                {
                    if (item.CustomData.Contains(target))
                    {
                        rotor = item as IMyMotorAdvancedStator;
                    }
                }

                minAngle = rotor.LowerLimitDeg;
                maxAngle = rotor.UpperLimitDeg;
            }

            float  curAngle = (rotor.Angle * 180) / (float)(Math.PI);
            string text     = "Angle\n" + Math.Round(curAngle - minAngle);

            screen.WriteText(text);

            Echo("Angle: " + curAngle);
            Echo("Min:     " + minAngle);
            Echo("Max:    " + maxAngle);
            Echo("Text:    " + text);
        }
            private double PointRotorAtVector(IMyMotorAdvancedStator rotor, Vector3D currentDirection, Vector3D rotorPlaneNormal, Vector3D targetDirection)
            {
                // Get max RPM for a rotor
                float maxRPM = rotor.GetMaximum <float>("Velocity");

                // maxRPM rad
                double errorScale = Math.PI * maxRPM;

                // Grab target vector projected onto the plane of the engine
                Vector3D targetOnPlane = targetDirection - targetDirection.Projected(rotorPlaneNormal);

                // Normalized (set length to 1)
                var targetNormalized  = targetOnPlane.Normalized();
                var currentNormalized = currentDirection.Normalized();

                // Calculate angle between target and current direction, in [-pi to pi]. The first value is a triple product
                double angle = Math.Atan2(rotorPlaneNormal.Normalized().Dotted(targetNormalized.Crossed(currentNormalized)), targetNormalized.Dotted(currentNormalized));

                if (angle > Math.PI)
                {
                    angle -= 2 * Math.PI;
                }
                else if (angle <= -Math.PI)
                {
                    angle += 2 * Math.PI;
                }

                // Find rotation speed value using a PID
                var rotVal = pid.Update(angle * errorScale);

                //logger.Log($"angle: {angle} rotVal: {rotVal}");

                // The rpm value must be -maxRPM <= rpm <= maxRPM
                double rpm = MathHelper.Clamp(rotVal, maxRPM * -1, maxRPM);

                rotor.TargetVelocityRPM = (float)rpm;

                return(angle);
            }
예제 #21
0
        bool CollectAllPartsHummingbird(IMyTerminalBlock block)
        {
            if (block == Me)
            {
                return(false);
            }
            if (!Me.IsSameConstructAs(block))
            {
                return(false);
            }
            if (block.CubeGrid == Me.CubeGrid)
            {
                PartsOfInterest.Add(block);
            }
            else
            {
                PartsOfInterest2.Add(block);
            }
            if (block is IMyShipMergeBlock && block.CustomName.Contains("<BASE>"))
            {
                Base = (IMyShipMergeBlock)block;
            }
            if (block is IMyMotorAdvancedStator)
            {
                Rotor = (IMyMotorAdvancedStator)block;
            }
            if (block is IMyProjector)
            {
                Projector = (IMyProjector)block;
            }
            if (block is IMyShipConnector)
            {
                Connector = (IMyShipConnector)block;
            }

            return(false);
        }
예제 #22
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (argument == "releaseremote")
            {
                IGC.SendBroadcastMessage("[PDCFORGE]", "");
            }
            else if (argument == "save")
            {
                if (Elevation != null && BaseMerge != null)
                {
                    var list = new List <IMyTerminalBlock>();
                    list.Add(Elevation);
                    BaseMerge.CustomData = GridTerminalHelper.BlockListBytePosToBase64(list, BaseMerge);
                }
            }
            else if (argument == "release")
            {
                while (ReleaseListener.HasPendingMessage)
                {
                    var msg = ReleaseListener.AcceptMessage();
                    if (msg.Data is string && Me.CustomName.Contains((string)msg.Data))
                    {
                        var otherMerge = GridTerminalHelper.OtherMergeBlock(TopMerge);
                        if (otherMerge != null)
                        {
                            otherMerge.Enabled = false;
                        }
                    }
                }
            }
            else
            {
                if (State == 0)
                {
                    foreach (var welder in Welders)
                    {
                        welder.Enabled = true;
                    }

                    if (Display != null)
                    {
                        Display.WriteText("STATE 0: WELDING - WAITING FOR COMPLETION");
                    }

                    if (TopProjector.RemainingBlocks == 0 && BaseProjector.RemainingBlocks == 0)
                    {
                        GraceTimer = 5;
                        State      = 1;
                    }
                }
                else if (State == 1)
                {
                    GraceTimer--;

                    if (Display != null)
                    {
                        Display.WriteText($"STATE 1: WELDING GRACE PERIOD - {GraceTimer}");
                    }

                    if (GraceTimer <= 0)
                    {
                        foreach (var welder in Welders)
                        {
                            welder.Enabled = false;
                        }
                        BaseProjector.Enabled = false;
                        TopProjector.Enabled  = false;

                        State = 2;
                    }
                }
                else if (State == 2)
                {
                    ElevationScratchpad.Clear();
                    var block = GridTerminalHelper.Base64BytePosToBlockList(BaseMerge.CustomData, BaseMerge, ref ElevationScratchpad);

                    if (ElevationScratchpad.Count == 1)
                    {
                        Elevation = ElevationScratchpad[0];

                        if (Display != null)
                        {
                            Display.WriteText($"ELEVATION ROTOR FOUND", true);
                        }

                        Elevation.Detach();

                        var degrees = -90f * Math.PI / 180f;
                        DriveHinge(SmallHinge, (float)(degrees), 0.3f);
                        DriveHinge(LargeHinge, (float)(degrees), 1f);
                        Sweeper.TargetVelocityRPM = -10;

                        if (Display != null)
                        {
                            Display.WriteText($"STATE 2: SWINGING HINGES SMALL - {SmallHinge.Angle * 180 / Math.PI} / -90 | LARGE - {LargeHinge.Angle * 180 / Math.PI} / -90");
                        }

                        if (Math.Abs(SmallHinge.Angle - degrees) < 0.01 && Math.Abs(LargeHinge.Angle - degrees) < 0.01)
                        {
                            State = 3;
                        }
                    }
                    else
                    {
                        if (Display != null)
                        {
                            Display.WriteText($"\nCRITICAL ERROR: ELEVATION ROTOR NOT FOUND", true);
                        }
                    }
                }
                else if (State == 3)
                {
                    if (Display != null)
                    {
                        Display.WriteText($"STATE 3: ATTEMPTING ATTACH");
                    }

                    ElevationScratchpad.Clear();
                    var block = GridTerminalHelper.Base64BytePosToBlockList(BaseMerge.CustomData, BaseMerge, ref ElevationScratchpad);

                    if (ElevationScratchpad.Count == 1)
                    {
                        Elevation = ElevationScratchpad[0];

                        if (Display != null)
                        {
                            Display.WriteText($"ELEVATION ROTOR FOUND", true);
                        }

                        Elevation.Attach();

                        if (Elevation.IsAttached)
                        {
                            GridTerminalHelper.OtherMergeBlock(BaseMerge).Enabled = false;
                            State = 4;
                        }
                    }
                    else
                    {
                        if (Display != null)
                        {
                            Display.WriteText($"\nCRITICAL ERROR: ELEVATION ROTOR NOT FOUND", true);
                        }
                    }
                }
                else if (State == 4)
                {
                    var degrees = 90f * Math.PI / 180f;
                    DriveHinge(SmallHinge, (float)(degrees), 0.3f);

                    if (Display != null)
                    {
                        Display.WriteText($"STATE 4: SWINGING SMALL HINGE - {SmallHinge.Angle * 180 / Math.PI} / 90");
                    }

                    if (Math.Abs(SmallHinge.Angle - degrees) < 0.01)
                    {
                        State = 5;
                    }
                }
                else if (State == 5)
                {
                    if (Display != null)
                    {
                        Display.WriteText($"STATE 5: COMPLETE - AWAITING PICKUP");
                    }
                    if (GridTerminalHelper.OtherMergeBlock(TopMerge) == null)
                    {
                        State      = 6;
                        GraceTimer = 5;
                    }
                }
                else if (State == 6)
                {
                    GraceTimer--;

                    if (Display != null)
                    {
                        Display.WriteText($"STATE 6: DETACH GRACE PERIOD - {GraceTimer}");
                    }

                    if (GraceTimer <= 0)
                    {
                        State = 7;
                    }
                }
                else if (State == 7)
                {
                    var degrees  = 90f * Math.PI / 180f;
                    var degrees2 = 0;
                    DriveHinge(LargeHinge, (float)(degrees), 1f);
                    DriveHinge(SmallHinge, (float)(degrees2), 1f);
                    Sweeper.TargetVelocityRPM = 10;

                    BaseProjector.Enabled = true;
                    TopProjector.Enabled  = true;

                    if (Display != null)
                    {
                        Display.WriteText($"STATE 7: RESETTING SMALL - {SmallHinge.Angle * 180 / Math.PI} / 0 | LARGE - {LargeHinge.Angle * 180 / Math.PI} / 90");
                    }

                    if (Math.Abs(SmallHinge.Angle - degrees2) < 0.01 && Math.Abs(LargeHinge.Angle - degrees) < 0.01)
                    {
                        State = 0;
                    }
                }
            }
        }
예제 #23
0
 public void ExecuteDriver(IMyMotorAdvancedStator driver, float RotorDisplacement)
 {
     driver.SetValue <float>("Displacement", restDisplacement + RotorDisplacement);
 }
예제 #24
0
파일: Main.cs 프로젝트: hvgab/SE_PitMiner
        public void Main(string argument, UpdateType updateType)
        {
            if (argument.StartsWith("coords");
            // go to spesified coords
            {
                float _angle;
                float _pistonLength;

                // Parse argument
                string[] args = argument.Split(' ');

                // Get coords data
                int x = args[1];
                int y = args[2];
                float lengthOfVector = GetLengthOfVector(x, y);
                float angleOfVector = GetAngleOfVector(x, y);
                float pistonLengthSetting = GetPistonLengthSetting(lengthOfVector);

                // move the drill to position
                MoveDrillToPosition();
                isMoving = true;
            }

            if (this.isIdle)
            {
                return;
            }

            else if (this.isMoving)
            {
                foreach rotor in rotors{
                    if (rotor.)
                }
            }

            else if (this.isInPosition)
            {
                // If we are in position
                // Start drilling
            }

            else if (this.isDrilling)
            {
                // Check if drill pistons are fully extended

                // Retract drills
            }
            else if (this.isRetracting)
            {
                // check if retracted
            }

            // block declarations
            string ERR_TXT = "";
            
            List<IMyTerminalBlock> advancedRotors = new List<IMyTerminalBlock>();
            IMyMotorAdvancedStator advancedRotor = null;
            GridTerminalSystem.GetBlocksOfType<IMyMotorAdvancedStator>(advancedRotors, filterThis);
            if (advancedRotors.Count == 0)
            {
                ERR_TXT += "no Advanced Rotor blocks found\n";
            }
            else
            {
                for (int i = 0; i < advancedRotors.Count; i++)
                {
                    if (advancedRotors[i].CustomName == "Advanced Rotor")
                    {
                        advancedRotor = (IMyMotorAdvancedStator)advancedRotors[i];
                        break;
                    }
                }
                if (advancedRotor == null)
                {
                    ERR_TXT += "no Advanced Rotor block named Advanced Rotor found\n";
                }
            }
            List<IMyTerminalBlock> horizontalPistons = new List<IMyTerminalBlock>();
            if (GridTerminalSystem.GetBlockGroupWithName("pit horizontal") != null)
            {
                GridTerminalSystem.GetBlockGroupWithName("pit horizontal").GetBlocksOfType<IMyPistonBase>(horizontalPistons, filterThis);
                if (horizontalPistons.Count == 0)
                {
                    ERR_TXT += "group pit horizontal has no Piston blocks\n";
                }
            }
            else
            {
                ERR_TXT += "group pit horizontal not found\n";
            }

            // user variable declarations
            float pistonsHorizontalCurrentPosition = 0.0f;

            // display errors
            if (ERR_TXT != "")
            {
                Echo("Script Errors:\n" + ERR_TXT + "(make sure block ownership is set correctly)");
                return;
            }
            else { Echo(""); }

            // logic
            v0.CustomData = new StringBuilder("7").ToString();
            for (int i = 0; i < horizontalPistons.Count; i++)
            {
                horizontalPistons[i].MinLimit = (float)15;
                horizontalPistons[i].MaxLimit = (float)15;
                pistonsHorizontalCurrentPosition = getExtraFieldFloat(horizontalPistons[i], "Current position: (\\d+\\.?\\d*)");
            }
        }
예제 #25
0
 public void ResetDriver(IMyMotorAdvancedStator driver)
 {
     driver.SetValue <float>("Displacement", restDisplacement);
 }
        public void SetupMiner()
        {
            basePistons    = new List <IMyPistonBase>();
            forwardPistons = new List <IMyPistonBase>();
            downPistons    = new List <IMyPistonBase>();
            drills         = new List <IMyShipDrill>();
            cameras        = new List <IMyCameraBlock>();
            textPanels     = new List <IMyTextPanel>();

            IMyBlockGroup minerGroup = GridTerminalSystem.GetBlockGroupWithName(minerGroupName);

            if (minerGroup == null)
            {
                this.currentState = "stopped";
                Echo("Could not find group with name: " + minerGroupName);
                return;
            }

            minerGroup.GetBlocksOfType <IMyTextPanel>(textPanels);

            List <IMyMotorAdvancedStator> rotors = new List <IMyMotorAdvancedStator>();

            minerGroup.GetBlocksOfType <IMyMotorAdvancedStator>(rotors);
            if (rotors.Count == 0)
            {
                Echo("Could not find an advanced rotor!");
                this.currentState = "stopped";
                return;
            }
            rotor = rotors[0];

            List <IMyPistonBase> pistons = new List <IMyPistonBase>();

            minerGroup.GetBlocksOfType <IMyPistonBase>(pistons);

            Echo("Detected " + pistons.Count + " pistons");

            var UP       = Me.WorldMatrix.Up;
            var FORWARD  = Me.WorldMatrix.Forward;
            var DOWN     = Me.WorldMatrix.Down;
            var BACKWARD = Me.WorldMatrix.Backward;

            UP.Normalize();
            FORWARD.Normalize();
            DOWN.Normalize();
            BACKWARD.Normalize();

            foreach (IMyPistonBase piston in pistons)
            {
                piston.Velocity = 0.0f;
                Vector3D pbf = piston.Top.GetPosition() - piston.GetPosition();
                pbf.Normalize();
                double distanceup       = pbf.Dot(UP);
                double distancedown     = pbf.Dot(DOWN);
                double distanceforward  = pbf.Dot(FORWARD);
                double distancebackward = pbf.Dot(BACKWARD);

                double maxDir = Math.Max(Math.Max(Math.Max(distanceup, distancedown), distanceforward), distancebackward);

                if (distanceup == maxDir)
                {
                    basePistons.Add(piston);
                }
                else if (distanceforward == maxDir)
                {
                    piston.MaxLimit = piston.CurrentPosition;
                    forwardPistons.Add(piston);
                }
                else if (distancedown == maxDir)
                {
                    downPistons.Add(piston);
                }
            }

            minerGroup.GetBlocksOfType <IMyShipDrill>(drills);
            if (doRaycasting)
            {
                minerGroup.GetBlocksOfType <IMyCameraBlock>(cameras);
                foreach (IMyCameraBlock camera in cameras)
                {
                    camera.EnableRaycast = true;
                }
                Echo("Enabled raycasting");
            }



            // Set limits on the pistons
            float minLimitPerVertPiston = minVerticalAltitude / (basePistons.Count + downPistons.Count);

            foreach (var piston in basePistons)
            {
                piston.MinLimit = piston.LowestPosition;
                piston.MaxLimit = piston.HighestPosition - minLimitPerVertPiston;
                piston.SetValue <float>("MaxImpulseAxis", pistonMaxImpulseAxis);
                piston.SetValue <float>("MaxImpulseNonAxis", pistonMaxImpulseNonAxis);
                piston.SetValue <bool>("ShareInertiaTensor", true);
            }
            foreach (var piston in downPistons)
            {
                piston.MinLimit = minLimitPerVertPiston;
                piston.MaxLimit = piston.HighestPosition;
                piston.SetValue <float>("MaxImpulseAxis", pistonMaxImpulseAxis);
                piston.SetValue <float>("MaxImpulseNonAxis", pistonMaxImpulseNonAxis);
                piston.SetValue <bool>("ShareInertiaTensor", true);
            }

            foreach (var piston in forwardPistons)
            {
                piston.MinLimit = piston.LowestPosition;
                piston.MaxLimit = piston.HighestPosition;
                piston.SetValue <float>("MaxImpulseAxis", pistonMaxImpulseAxis);
                piston.SetValue <float>("MaxImpulseNonAxis", pistonMaxImpulseNonAxis);
                piston.SetValue <bool>("ShareInertiaTensor", true);
            }

            rotor.SetValue <bool>("ShareInertiaTensor", false);

            this.currentState = "ready";
        }
예제 #27
0
    public Program()
    {
        //tp = GridTerminalSystem.GetBlockWithName("DEBUG") as IMyTextPanel;
        //tp.WritePublicText("");
        allBlocks = new List <IMyTerminalBlock>();
        rPistons  = new List <IMyPistonBase>();
        vPistons  = new List <IMyPistonBase>();
        drills    = new List <IMyShipDrill>();
        cargo     = new List <IMyInventory>();

        GridTerminalSystem.GetBlocks(allBlocks);
        foreach (IMyTerminalBlock block in allBlocks)
        {
            //tp.WritePublicText(block.CustomName + "\n", true);
            IMyPistonBase piston = block as IMyPistonBase;
            if (piston != null)
            {
                //tp.WritePublicText(piston.CustomName + "\n", true);
                if (piston.CustomName.Contains("[R]"))
                {
                    rPistons.Add(piston);
                }
                if (piston.CustomName.Contains("[V]"))
                {
                    vPistons.Add(piston);
                }
            }

            IMyShipDrill drill = block as IMyShipDrill;
            if (drill != null)
            {
                //tp.WritePublicText(drill.CustomName + "\n", true);
                drills.Add(drill);
            }

            IMyInventory cont = block.GetInventory();
            if (cont != null)
            {
                //tp.WritePublicText(block.CustomName + "\n", true);
                if (!block.CustomName.Contains("Stone Ejector"))
                {
                    cargo.Add(cont);
                }
            }

            IMyMotorAdvancedStator rot = block as IMyMotorAdvancedStator;
            if (rot != null)
            {
                rotor = rot;
                //tp.WritePublicText(rot.CustomName + "\n", true);
            }
            IMyTimerBlock tim = block as IMyTimerBlock;
            if (tim != null)
            {
                timer = tim;
            }

            //ResetMiner();

            //Runtime.UpdateFrequency = UpdateFrequency.Update1;
        }
        ResetMiner();

        //Runtime.UpdateFrequency = UpdateFrequency.Update10;
    }
예제 #28
0
 public void SetHinge(IMyMotorAdvancedStator Hinge, float Angle, float Speed)
 {
     //Hinge.UpperLimitRad = Angle;
     //Hinge.LowerLimitRad = Angle;
     Hinge.TargetVelocityRad = Speed;
 }
예제 #29
0
        public void Main(string argument, UpdateType updateSource)
        {
            IMyPistonBase          PistonOne         = GridTerminalSystem.GetBlockWithName("Piston") as IMyPistonBase;
            IMyPistonBase          PistonTwo         = GridTerminalSystem.GetBlockWithName("Piston 2") as IMyPistonBase;
            IMyPistonBase          PistonThree       = GridTerminalSystem.GetBlockWithName("Piston 3") as IMyPistonBase;
            IMyCargoContainer      StorageBlock      = GridTerminalSystem.GetBlockWithName("Large Cargo Container") as IMyCargoContainer;
            IMyMotorAdvancedStator Rotor             = GridTerminalSystem.GetBlockWithName("Advanced Rotor") as IMyMotorAdvancedStator;
            IMyBlockGroup          Drills            = GridTerminalSystem.GetBlockGroupWithName("Drillers");
            IMyProgrammableBlock   programmableBlock = GridTerminalSystem.GetBlockWithName("Programmable block") as IMyProgrammableBlock;
            IMyTextSurface         screen            = ((IMyTextSurfaceProvider)programmableBlock).GetSurface(0);

            screen.WriteText("1234");

            if (Drills == null)
            {
                Echo("Drillers group not found");
                return;
            }
            List <IMyTerminalBlock> listBlocks = new List <IMyTerminalBlock>();

            Drills.GetBlocks(listBlocks);

            Echo($"{PistonOne.CustomName}");
            Echo($"{PistonTwo.CustomName}");
            Echo($"{PistonThree.CustomName}");
            Echo($"{StorageBlock.CustomName}");
            Echo($"{Rotor.CustomName}");
            Echo($"Number of Drills: {listBlocks.Count}");
            Echo($"Current Mass of {StorageBlock.CustomName}: {StorageBlock.Mass}");
            var          storageBlock       = StorageBlock.GetInventory();
            MyFixedPoint storageBlockVolume = storageBlock.CurrentVolume;
            float        volume             = (float)storageBlockVolume;
            float        maxVolume          = (float)storageBlock.MaxVolume;

            Echo($"Current Volume: {volume}");

            if (Rotor == null)
            {
                Echo("Rotor Block Not Found");
                return;
            }
            if (volume >= maxVolume)
            {
                Echo("[WARNING] Cargo Full");
                Rotor.RotorLock = true;
                foreach (var drill in listBlocks)
                {
                    var d = drill as IMyShipDrill;
                    d.Enabled = false;
                }
            }
            else
            {
                Rotor.RotorLock = false;
                foreach (var drill in listBlocks)
                {
                    var d = drill as IMyShipDrill;
                    d.Enabled = true;
                }
            }
            //180/piRads
            double rotorAngle = Rotor.Angle * (180 / Math.PI);

            //double rotorAngle = 180 / (Math.PI * rotor.Angle);
            Echo("Rotor Angle: " + Math.Round(rotorAngle, 2));
            if (rotorAngle < 40 && rotorAngle > 39.9)
            {
                if (PistonOne.CurrentPosition < 10)
                {
                    PistonOne.MaxLimit += 1;
                }
                else if (PistonTwo.CurrentPosition < 10)
                {
                    PistonTwo.MaxLimit += 1;
                }
                else if (PistonThree.CurrentPosition < 10)
                {
                    PistonThree.MaxLimit += 1;
                }
            }
        }
예제 #30
0
 public MiningRotor(IMyMotorAdvancedStator rotor)
 {
     _rotor = rotor;
 }