Example #1
0
 private void StopAllRotors()
 {
     azimuthRotor.SetValue("Velocity", 0f);
     foreach (var rotor in elevationRotors)
     {
         rotor.SetValue("Velocity", 0f);
     }
 }
 public void setup()
 {
     stator_.SetValue <float>(Program.PropertyLowerLimit, float.MinValue);
     stator_.SetValue <float>(Program.PropertyUpperLimit, float.MaxValue);
     stator_.TargetVelocityRPM = 0f;
     stator_.SetValue <bool>(Program.PropertyInertiaTensor, true);
     RotorLock = true;
 }
        /// <summary>
        /// This code is taken from Whip's AI Rotor Turret Control Script. All credit to Whiplash.
        /// https://steamcommunity.com/sharedfiles/filedetails/?id=672678005&
        /// </summary>
        /// <param name="targetPosition">point to face</param>
        private void TurnToFacePosition(Vector3D targetPosition)
        {
            IMyTerminalBlock turretReference      = remoteControl;
            Vector3D         turretFrontVec       = turretReference.WorldMatrix.Forward;
            Vector3D         absUpVec             = rotor.WorldMatrix.Up;
            Vector3D         turretSideVec        = turretReference.WorldMatrix.Right;
            Vector3D         turretFrontCrossSide = turretFrontVec.Cross(turretSideVec);
            Vector3D         turretLeftVec;

            if (DotIsSameDirection(absUpVec, turretFrontCrossSide))
            {
                turretLeftVec = turretSideVec;
            }
            else
            {
                turretLeftVec = -1 * turretSideVec;
            }
            Vector3D referenceToTargetVec = targetPosition - turretReference.GetPosition();
            //get projections onto axis made out of our plane orientation
            Vector3D projOnFront          = VectorProjection(referenceToTargetVec, turretFrontVec);
            Vector3D projOnLeft           = VectorProjection(referenceToTargetVec, turretLeftVec);
            Vector3D projOnFrontLeftPlane = projOnFront + projOnLeft;
            double   azimuthAngle         = Math.Asin(MathHelper.Clamp(projOnLeft.Length() * DotGetSign(projOnLeft, turretLeftVec) / projOnFrontLeftPlane.Length(), -1, 1));
            double   azimuthSpeed         = 40 * azimuthAngle;   //derivitave term is useless as rotors dampen by default

            rotor.SetValue("Velocity", -(float)azimuthSpeed);    //negative because we want to cancel the positive angle via our movements
        }
Example #4
0
            private void SetRotorPosition(int index)
            {
                if (index < 0)
                {
                    index += carouselSlots.Length;
                }
                if (index >= carouselSlots.Length)
                {
                    index -= carouselSlots.Length;
                }

                var currentSLot = carouselSlots[index];

                if (currentSLot == null)
                {
                    return;
                }

                float speed = (program.GetDirection(index, carouselIndex, 8) == Direction.Clockwise) ? -rotorSpeed : rotorSpeed;

                carouselIndex = index;

                vendingRotor.SetValue <float>("UpperLimit", currentSLot.angle);
                vendingRotor.SetValue <float>("LowerLimit", currentSLot.angle);
                vendingRotor.SetValue <float>("Velocity", speed);

                foreach (var slot in carouselSlots)
                {
                    int screenIndex = slot.index - carouselIndex;
                    if (screenIndex < 0)
                    {
                        screenIndex += carouselScreens.Length;
                    }

                    slot.SetScreen(carouselScreens[screenIndex]);
                }

                output.Print("Moving rotor to " + currentSLot.angle + " degrees");
            }
Example #5
0
            public AutomatedRotor(IMyMotorStator r, Operations o, Modes m, List <InstructionSet> i)
            {
                Rotor = r;
                Rotor.BrakingTorque = 33600000;
                LockRotor           = false;
                Precision           = 0.01f;
                Rotor.SetValue("RotorLock", LockRotor);

                Operation         = o;
                Mode              = m;
                State             = RotorState.idle;
                Instructions      = i;
                IncrementAngle    = MathHelper.ToDegrees(r.Angle);
                ResetInstructions = new InstructionSet(1, MathHelper.ToDegrees(r.Angle), 0);
            }
            protected override void LoadBlocks()
            {
                listDrill = new List <IMyShipDrill>();
                GetProgram().GridTerminalSystem.GetBlocksOfType(listDrill);

                listPiston = new List <IMyPistonBase>();
                GetProgram().GridTerminalSystem.GetBlocksOfType(listPiston);
                foreach (IMyPistonBase p in listPiston)
                {
                    p.SetValue("ShareInertiaTensor", true);
                }

                listLight = new List <IMyLightingBlock>();
                GetProgram().GridTerminalSystem.GetBlocksOfType(listLight);


                mainRotor = GetProgram().GridTerminalSystem.GetBlockWithName(Params.MainRotorName) as IMyMotorStator;
                if (mainRotor == null)
                {
                    logger.Warn("No rotor \"" + Params.MainRotorName + "\" found");
                }
                else
                {
                    mainRotor.SetValue("ShareInertiaTensor", true);
                }

                mainHinge = GetProgram().GridTerminalSystem.GetBlockWithName(Params.MainHingeName) as IMyMotorStator;
                if (mainHinge == null)
                {
                    logger.Warn("No hinge \"" + Params.MainHingeName + "\" found");
                }
                else
                {
                    mainHinge.SetValue("ShareInertiaTensor", true);
                }
            }
 protected override void Stop()
 {
     base.Stop();
     // Turn off drills
     SetDrillsOnOff(false);
     // Stop pistons
     foreach (IMyPistonBase p in listPistonMDir)
     {
         p.SetValue("Velocity", 0F);
     }
     foreach (IMyPistonBase p in listPistonMODir)
     {
         p.SetValue("Velocity", 0F);
     }
     if (mainMotor != null)
     {
         mainMotor.SetValue("Velocity", 0F);
     }
 }
Example #8
0
            /// <summary>
            /// Carousel
            /// </summary>
            private void InitCarousel()
            {
                for (int i = 0; i < 8; i++)
                {
                    carouselSlots[i] = new CarouselSlot(this, i);
                }


                var rotors = new List <IMyTerminalBlock>();

                program.GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(rotors, IsRotor);

                //Parse Connectors
                foreach (var item in allConnectors)
                {
                    if (item.CustomName.ToLower().Contains(carouselTag))
                    {
                        //Find out what index
                        string[] splits = item.CustomName.ToLower().Split(program.delimiterChars);

                        if (splits.Length >= 4)
                        {
                            int i;
                            if (Int32.TryParse(splits[3], out i))
                            {
                                carouselSlots[i].SetConnector(item);

                                if (item.Status == MyShipConnectorStatus.Connected)
                                {
                                    output.Print(item.OtherConnector.CubeGrid.DisplayName + " is connected to slot " + i);
                                }
                                else
                                {
                                    output.Print(item.CustomName + " status: " + item.Status);
                                }
                            }
                        }
                    }
                }

                //Parse Screens
                var tempScreens = new List <IMyTextPanel>();

                program.GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(tempScreens, screen => screen.CustomName.Contains(tag));

                foreach (var item in tempScreens)
                {
                    if (item.CustomName.ToLower().Contains(carouselTag))
                    {
                        //This is a screen for displaying a carousel slot- parse
                        string[] splits = item.CustomName.ToLower().Split(program.delimiterChars);

                        if (splits.Length >= 4)
                        {
                            int i;
                            if (Int32.TryParse(splits[3], out i))
                            {
                                carouselSlots[i].SetScreen(item);
                                carouselScreens[i] = item;
                                output.Print("Display " + item.CustomName + " has been allocated");
                            }
                        }
                    }
                }

                if (rotors.Count > 0)
                {
                    vendingRotor = rotors[0] as IMyMotorStator;
                    vendingRotor.SetValue <float>("UpperLimit", 180);
                    vendingRotor.SetValue <float>("LowerLimit", 0);
                    vendingRotor.SetValue <float>("Velocity", rotorSpeed);

                    output.Print("Found vending rotor: " + vendingRotor.CustomName);
                }
                else
                {
                    output.Print("did not find a rotor :(");
                }
            }
Example #9
0
 public static void SetUpperLimit(IMyMotorStator motorStator, float upperLimit)
 {
     motorStator.SetValue <float>("UpperLimit", upperLimit);
 }
Example #10
0
 public static void SetLowerLimit(IMyMotorStator motorStator, float lowerLimit)
 {
     motorStator.SetValue <float>("LowerLimit", lowerLimit);
 }
Example #11
0
 {               //IMyMotorStator API wrapper
                 //Velocity is measured internally in RPM
                 //Angle is measured internally in radians. (0-2pi for unlimited rotors)
                 //PROPERTIES:
     ///public static void SetTorque(IMyMotorStator motorStator, float torque){
     ///	motorStator.SetValue<float>("Torque", torque);
     ///}
     ///public static void SetBrakingTorque(IMyMotorStator motorStator, float brakingTorque){
     ///	motorStator.SetValue<float>("BrakingTorque", brakingTorque);
     ///}
     public static void SetVelocity(IMyMotorStator motorStator, float velocity)
     {
         motorStator.SetValue <float>("Velocity", velocity);
     }
Example #12
0
 public void SetSpeed(float oSpeed)
 {
     m_oBlock.SetValue("Velocity", oSpeed);
 }
            protected override void LoadBlocks()
            {
                listDrills = new List <IMyShipDrill>();
                GetProgram().GridTerminalSystem.GetBlocksOfType(listDrills);

                IMyBlockGroup groupPistonsMDir = GetProgram().GridTerminalSystem.GetBlockGroupWithName(Params.GrpNamePistonMDir);

                listPistonMDir = new List <IMyPistonBase>();
                if (groupPistonsMDir == null)
                {
                    logger.Error("Group \"" + Params.GrpNamePistonMDir + "\" not found");
                }
                else
                {
                    groupPistonsMDir.GetBlocksOfType(listPistonMDir);
                }

                IMyBlockGroup groupPistonMODir = GetProgram().GridTerminalSystem.GetBlockGroupWithName(Params.GrpNamePistonMODir);

                listPistonMODir = new List <IMyPistonBase>();
                if (groupPistonMODir == null)
                {
                    logger.Info("Group \"" + Params.GrpNamePistonMODir + "\" not found");
                }
                else
                {
                    GetProgram().GridTerminalSystem.GetBlocksOfType(listPistonMODir);
                }

                List <IMyBeacon> listBeacon = new List <IMyBeacon>();

                GetProgram().GridTerminalSystem.GetBlocksOfType(listBeacon);
                if (listBeacon.Count > 0)
                {
                    beacon = listBeacon.First();
                    beacon.SetValue("Radius", Params.MinBeaconRadius);
                }
                else
                {
                    logger.Info("No beacon found");
                }

                mainMotor = GetProgram().GridTerminalSystem.GetBlockWithName(Params.MainRotorName) as IMyMotorStator;
                if (mainMotor == null)
                {
                    logger.Info("No rotor \"" + Params.MainRotorName + "\" found");
                }
                else
                {
                    mainMotor.SetValue("LowerLimit", Params.MinRotorAngle);
                    mainMotor.SetValue("UpperLimit", Params.MinRotorAngle);
                }

                IMyBlockGroup groupLights = GetProgram().GridTerminalSystem.GetBlockGroupWithName(Params.GrpNameLight);

                listLight = new List <IMyLightingBlock>();
                if (groupLights == null)
                {
                    logger.Info("Group \"" + Params.GrpNameLight + "\" not found");
                }
                else
                {
                    groupLights.GetBlocksOfType(listLight);
                }

                IMyBlockGroup groupCargo = GetProgram().GridTerminalSystem.GetBlockGroupWithName(Params.GrpNameCargo);

                listCargo = new List <IMyCargoContainer>();
                if (groupCargo == null)
                {
                    logger.Info("Group \"" + Params.GrpNameCargo + "\" not found");
                }
                else
                {
                    groupCargo.GetBlocksOfType(listCargo);
                }
            }
Example #14
0
        public void DrillArmToggle()
        {
            if (!drillMoving)
            {
                drillMoving  = true;
                drillRaising = !drillRaising;

                drillRotor1.RotorLock = false;
                drillRotor1.SetValue <bool>("ShareInertiaTensor", false);
                drillRotor2.RotorLock = false;

                if (drillRaising)
                {
                    drillRotor2.TargetVelocityRPM = 2;
                }
                else
                {
                    drillRotor1.TargetVelocityRPM = -1;
                }
            }
            else
            {
                if (drillRaising)
                {
                    if (!rotorMoving(drillRotor2, true))                        //drill rotor 2 is up
                    {
                        if (!rotorMoving(drillRotor1, false))                   //drill rotor 1 is down
                        {
                            drillRotor2.RotorLock         = true;
                            drillRotor1.TargetVelocityRPM = 1;
                        }
                        else if (!rotorMoving(drillRotor1, true))                           //drill rotor 1 is up
                        {
                            drillRotor1.RotorLock = true;
                            drillRotor1.SetValue <bool>("ShareInertiaTensor", true);
                            drillMoving = false;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (!rotorMoving(drillRotor1, false))                       //drill rotor 1 is down
                    {
                        if (!rotorMoving(drillRotor2, true))                    //drill rotor 2 is up
                        {
                            drillRotor1.RotorLock         = true;
                            drillRotor2.TargetVelocityRPM = -2;
                        }
                        else if (!rotorMoving(drillRotor2, false))                         //drill rotor 2 is down
                        {
                            drillRotor2.RotorLock = true;
                            drillRotor1.SetValue <bool>("ShareInertiaTensor", true);
                            drillMoving = false;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
Example #15
0
 public static void SetSpeed(IMyMotorStator rotor, float speed) {
     if (rotor.CustomName.EndsWith(Configuration.InvertedRotorSuffix)) speed = -speed;
     rotor.SetValue("Velocity", speed);
 }
    public SolarController()
    {
        // Get all solar panels
        List <IMyTerminalBlock> panels = new List <IMyTerminalBlock>();

        GridTerminalSystem.GetBlocksOfType <IMySolarPanel>(panels);

        // Get current and total power output
        int   panelCnt  = 0;
        float curUse    = 0f; // Amount of power currently being used
        float genOut    = 0f; // Power output potential
        float lowestOut = 0f;

        for (int i = 0; i < panels.Count; i++)
        {
            IMySolarPanel panel = panels[i] as IMySolarPanel;
            if (panel != null && panel.IsFunctional)
            {
                panelCnt++;
                float cur = panel.CurrentOutput;
                float max = panel.MaxOutput;

                curUse += cur;
                genOut += max;

                if (lowestOut == 0f || max < lowestOut)
                {
                    lowestOut = max;
                }
            }
        }

        // Display status
        pr(String.Format("Solar Panel Count: {0}", panelCnt));
        pr(String.Format("Solar Power Usage: {0:0.0}/{1:0.0} MW", curUse, genOut));

        // Nothing else to do if no panels
        if (panelCnt == 0)
        {
            return;
        }

        // Rotor control
        IMyMotorStator rotor  = (IMyMotorStator)GridTerminalSystem.GetBlockWithName("Solar Panel Rotor");
        float          thresh = target * maxOut;

        if (lowestOut < thresh)
        {
            float speed = ((thresh - lowestOut) / thresh) * 1.5f;
            if (speed < 0.05f)
            {
                speed = 0.05f;
            }
            rotor.SetValue("Velocity", speed);
            rotor.ApplyAction("OnOff_On");
            pr(String.Format("Rotor Status: On ({0:0.00} rpm)", speed));
        }
        else
        {
            rotor.ApplyAction("OnOff_Off");
            pr("Rotor Status: Off");
        }
    }