Example #1
0
            //Use For Precise Turning (docking, mining, attacking)
            //----------==--------=------------=-----------=---------------=------------=-----=-----*/
            void GyroTurn6(Vector3D TARGET, double GAIN, IMyGyro GYRO, IMyRemoteControl REF_RC, double ROLLANGLE, double MAXANGULARVELOCITY)
            {
                //确保自动驾驶仪没有功能
                REF_RC.SetAutoPilotEnabled(false);
                //检测前、上 & Pos
                Vector3D ShipForward = REF_RC.WorldMatrix.Forward;
                Vector3D ShipUp      = REF_RC.WorldMatrix.Up;
                Vector3D ShipPos     = REF_RC.GetPosition();

                //创建和使用逆Quatinion
                Quaternion Quat_Two               = Quaternion.CreateFromForwardUp(ShipForward, ShipUp);
                var        InvQuat                = Quaternion.Inverse(Quat_Two);
                Vector3D   DirectionVector        = Vector3D.Normalize(TARGET - ShipPos);         //RealWorld Target Vector
                Vector3D   RCReferenceFrameVector = Vector3D.Transform(DirectionVector, InvQuat); //Target Vector In Terms Of RC Block

                //转换为局部方位和高度
                double ShipForwardAzimuth = 0; double ShipForwardElevation = 0;

                Vector3D.GetAzimuthAndElevation(RCReferenceFrameVector, out ShipForwardAzimuth, out ShipForwardElevation);

                //Does Some Rotations To Provide For any Gyro-Orientation做一些旋转来提供任何旋转方向
                var RC_Matrix = REF_RC.WorldMatrix.GetOrientation();
                var Vector     = Vector3.Transform((new Vector3D(ShipForwardElevation, ShipForwardAzimuth, ROLLANGLE)), RC_Matrix); //Converts To World转换为世界
                var TRANS_VECT = Vector3.Transform(Vector, Matrix.Transpose(GYRO.WorldMatrix.GetOrientation()));                    //Converts To Gyro Local转换为陀螺仪方位

                //Applies To Scenario适用于场景
                GYRO.Pitch        = (float)MathHelper.Clamp((-TRANS_VECT.X * GAIN), -MAXANGULARVELOCITY, MAXANGULARVELOCITY);
                GYRO.Yaw          = (float)MathHelper.Clamp(((-TRANS_VECT.Y) * GAIN), -MAXANGULARVELOCITY, MAXANGULARVELOCITY);
                GYRO.Roll         = (float)MathHelper.Clamp(((-TRANS_VECT.Z) * GAIN), -MAXANGULARVELOCITY, MAXANGULARVELOCITY);
                GYRO.GyroOverride = true;

                //GYRO.SetValueFloat("Pitch", (float)((TRANS_VECT.X) * GAIN));
                //GYRO.SetValueFloat("Yaw", (float)((-TRANS_VECT.Y) * GAIN));
                //GYRO.SetValueFloat("Roll", (float)((-TRANS_VECT.Z) * GAIN));
            }
        bool CollectParts(IMyTerminalBlock block)
        {
            if (Context.Reference.CubeGrid.EntityId != block.CubeGrid.EntityId)
            {
                return(false);
            }

            if (block is IMyShipController && ((IMyShipController)block).CanControlShip)
            {
                controller = (IMyShipController)block;
            }

            if (block is IMyThrust)
            {
                IMyThrust thruster = (IMyThrust)block;
                thrustersList.Add(thruster);
                thruster.ThrustOverride = 0;
                thrusterManager.AddThruster(thruster);
            }

            if (block is IMyGyro)
            {
                IMyGyro gyro = (IMyGyro)block;
                gyros.Add(gyro);
                gyro.Pitch        = 0;
                gyro.Yaw          = 0;
                gyro.Roll         = 0;
                gyro.GyroOverride = false;
            }

            return(false);
        }
Example #3
0
        public GyroscopeProfile(IMyTerminalBlock block, IMyRemoteControl remoteControl, IBehavior behavior)
        {
            Block         = block as IMyGyro;
            RemoteControl = remoteControl;
            Behavior      = behavior;

            EnableOverride = false;
            RawValues      = Vector3D.Zero;
            RefMatrix      = MatrixD.Identity;
            Yaw            = 0;
            Pitch          = 0;
            Roll           = 0;



            Valid = true;

            Block.OnClosing        += CloseEntity;
            Block.IsWorkingChanged += WorkingChange;
            WorkingChange(Block);

            if (Working)
            {
                /*
                 * Block.GyroOverride = false;
                 * Block.Yaw = 0;
                 * Block.Pitch = 0;
                 * Block.Roll = 0;
                 */
            }
        }
            public Gyroscope(IMyGyro gyroscope, IMyTerminalBlock reference)
            {
                gyro = gyroscope;

                for (int i = 0; i < 3; i++)
                {
                    Vector3D vectorShip = GetAxis(i, reference);

                    for (int j = 0; j < 3; j++)
                    {
                        double dot = vectorShip.Dot(GetAxis(j, gyro));

                        if (dot > 0.9)
                        {
                            conversionVector[j] = i;
                            break;
                        }
                        if (dot < -0.9)
                        {
                            conversionVector[j] = i + 3;
                            break;
                        }
                    }
                }
            }
Example #5
0
        public void GyroSetOverrideFromGridReferenceFrame(Quaternion targetRotation, IMyGyro specificGyro = null, bool allGyros = false)
        {
            List <IMyGyro> gyros;

            if (allGyros)
            {
                gyros = GetBlocks <IMyGyro>();
            }
            else if (specificGyro == null)
            {
                //TODO Error message location
                return;
            }
            else
            {
                gyros = new List <IMyGyro>();
                gyros.Add(specificGyro);
            }

            //TODO: Optimise quaternion operations, possibly by sorting gyros using their orientaions
            foreach (IMyGyro gyro in gyros)
            {
                Quaternion   rotationOperation = GyroMovementFromLocalRotation(targetRotation, gyro);
                RollPitchYaw rpy = QuaternionToRollPitchYaw(rotationOperation);
                GyroSetOverrideToRollPitchYaw(gyro, rpy);
            }
        }
Example #6
0
        private float RotationSpeed = 0.02f; // Base rotation speed which will be used when creating subpart rotations.

        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            NeedsUpdate    = MyEntityUpdateEnum.EACH_FRAME;
            Gyro_block     = (IMyGyro)Entity;
            Rotate_MatrixX = Matrix.Identity;
            Rotate_MatrixY = Matrix.Identity;
            Rotate_MatrixZ = Matrix.Identity;

            // Here you can add different hinge positions and subpart names for the Gyros you have added at the top.
            Vector3 hingePos;

            switch (Gyro_block.BlockDefinition.SubtypeId)
            {
            case "LargeBlockGyro":
                hingePos    = new Vector3(x: 0, y: -0.051649f, z: -0.088645f);
                SubpartName = "AnimGyro";
                break;

            case "LBAnimGyroInside":
                hingePos    = new Vector3(x: 0, y: -0.051649f, z: -0.088645f);
                SubpartName = "AnimGyroInside";
                break;

            case "SmallBlockGyro":
                hingePos    = new Vector3(x: 0, y: 0, z: 0);
                SubpartName = "SAnimGyro";
                break;

            default:
                hingePos = Vector3.Zero;
                break;
            }
            Matrix_Translate1 = Matrix.CreateTranslation(-hingePos);
            Matrix_Translate2 = Matrix.CreateTranslation(hingePos);
        }
Example #7
0
        private void SetAxisDetails(IMyGyro gyro, int axis,
                                    Base6Directions.Direction axisDirection)
        {
            switch (gyro.Orientation.TransformDirectionInverse(axisDirection))
            {
                case Base6Directions.Direction.Up:
                    AxisDetails[axis] = new GyroAxisDetails(Yaw, -1);
                    break;
                case Base6Directions.Direction.Down:
                    AxisDetails[axis] = new GyroAxisDetails(Yaw, 1);
                    break;
                case Base6Directions.Direction.Left:
                    AxisDetails[axis] = new GyroAxisDetails(Pitch, -1);
                    break;
                case Base6Directions.Direction.Right:
                    AxisDetails[axis] = new GyroAxisDetails(Pitch, 1);
                    break;
                case Base6Directions.Direction.Forward:
                    AxisDetails[axis] = new GyroAxisDetails(Roll, 1);
                    break;
                case Base6Directions.Direction.Backward:
                    AxisDetails[axis] = new GyroAxisDetails(Roll, -1);
                    break;
            }

        }
        private float GetRotate(VRageMath.Vector3 axis)
        {
            if (!XUtils.Directions.Contains(axis))
            {
                throw new Exception("Invalid axis vector used: " + axis);
            }

            VRageMath.Matrix local = new VRageMath.Matrix();
            referenceBlock.Orientation.GetMatrix(out local);
            axis = VRageMath.Vector3.Transform(axis, local);

            float totalValue = 0;

            for (int i = 0; i < gyroscopeBlocks.Count; ++i)
            {
                IMyGyro gyro = gyroscopeBlocks[i] as IMyGyro;
                gyro.Orientation.GetMatrix(out local);

                VRageMath.Matrix  toGyro          = VRageMath.Matrix.Transpose(local);
                VRageMath.Vector3 transformedAxis = VRageMath.Vector3.Transform(axis, toGyro);

                GyroAction action = GyroAction.getActionAroundAxis(transformedAxis);
                float      value  = gyro.GetValue <float>(action.Name);
                totalValue += action.Reversed ? -value : value;
            }

            return(totalValue);
        }
Example #9
0
        public void Init(IMyGridTerminalSystem gridTerminalSystem)
        {
            List <IMyTerminalBlock> blockList = new List <IMyTerminalBlock> ();

            gridTerminalSystem.GetBlocksOfType <IMyTerminalBlock> (blockList, searchItem => searchItem.CustomName.Contains(m_missileTag));

            foreach (IMyTerminalBlock block in blockList)
            {
                if ((block is IMyGyro) && (m_gyroBlock == null))
                {
                    m_gyroBlock = ( IMyGyro )block;
                }
                //else if (( block is IMyLargeTurretBase ) && ( m_remoteTurretBlock == null ))
                //{
                //   m_remoteTurretBlock = ( IMyLargeTurretBase ) block;
                //}
                else if ((block is IMyShipMergeBlock) && (m_mergeBlock == null))
                {
                    m_mergeBlock = ( IMyShipMergeBlock )block;
                }
                else if (block is IMyPowerProducer)
                {
                    m_powerBlock.Add(( IMyPowerProducer )block);
                }
                else if (block is IMyThrust)
                {
                    m_thrusterBlockList.Add(( IMyThrust )block);
                }
                else if (block is IMyWarhead)
                {
                    m_warheadBlockList.Add(( IMyWarhead )block);
                }
            }
        }
                public void LookAt(Vector3D target, IMyGyro gyro, IMyRemoteControl control)
                {
                    Vector3D offet = (target - control.GetPosition());

                    if (offet.Length() < 100.0f)
                    {
                        ApplyGyro(Vector3.Zero);
                        return;
                    }

                    Vector3 direction = Vector3D.Normalize(offet);

                    if (spaceship.gravity.LengthSquared() > 1e-1f)
                    {
                        Allign(direction, spaceship.gravity, gyro, control);
                    }
                    else
                    {
                        Quaternion quat = Quaternion.CreateFromForwardUp(control.WorldMatrix.Forward, control.WorldMatrix.Up);
                        quat.Conjugate();
                        direction = quat * direction;
                        Vector3.GetAzimuthAndElevation(direction, out azimuth, out elevation);
                        Vector3 final = Vector3.Transform(new Vector3(elevation, azimuth, 0.0f),
                                                          control.WorldMatrix.GetOrientation() * Matrix.Transpose(gyro.WorldMatrix.GetOrientation()));

                        ApplyGyro(-final);
                    }
                }
 public Program()
 {
     // The constructor, called only once every session and
     // always before any other method is called. Use it to
     // initialize your script.
     //
     // The constructor is optional and can be removed if not
     // needed.
     //
     // It's recommended to set Runtime.UpdateFrequency
     // here, which will allow your script to run itself without a
     // timer block.
     Runtime.UpdateFrequency = UpdateFrequency.Update1;
     g         = GridTerminalSystem.GetBlockWithName("Gyro") as IMyGyro;
     sc        = GridTerminalSystem.GetBlockWithName("Cockpit") as IMyShipController;
     lcd       = GridTerminalSystem.GetBlockWithName("LCD") as IMyTextPanel;
     thrusters = new List <IMyThrust>();
     GridTerminalSystem.GetBlockGroupWithName("Thrusters").GetBlocksOfType <IMyThrust>(thrusters);
     hDamp        = false;
     manualAlt    = true;
     vDamp        = false;
     targAltitude = GetAltitude();
     mass         = sc.CalculateShipMass().PhysicalMass;
     curSpeed     = 0;
     lastHeading  = sc.WorldMatrix.Forward;
 }
Example #12
0
        private void SetAxisDetails(IMyGyro gyro, int axis,
                                    Base6Directions.Direction axisDirection)
        {
            switch (gyro.Orientation.TransformDirectionInverse(axisDirection))
            {
            case Base6Directions.Direction.Up:
                AxisDetails[axis] = new GyroAxisDetails(Yaw, -1);
                break;

            case Base6Directions.Direction.Down:
                AxisDetails[axis] = new GyroAxisDetails(Yaw, 1);
                break;

            case Base6Directions.Direction.Left:
                AxisDetails[axis] = new GyroAxisDetails(Pitch, -1);
                break;

            case Base6Directions.Direction.Right:
                AxisDetails[axis] = new GyroAxisDetails(Pitch, 1);
                break;

            case Base6Directions.Direction.Forward:
                AxisDetails[axis] = new GyroAxisDetails(Roll, 1);
                break;

            case Base6Directions.Direction.Backward:
                AxisDetails[axis] = new GyroAxisDetails(Roll, -1);
                break;
            }
        }
Example #13
0
    Program()
    {
        // Создаем списки
        ThrList      = new List <IMyThrust>();
        MassList     = new List <IMyArtificialMassBlock>();
        gravigenlist = new List <IMyGravityGenerator>();

        // Находим генераторы гравитации
        GridTerminalSystem.GetBlocksOfType <IMyGravityGenerator>(gravigenlist);

        //Находим гироскоп
        gyroscope = GridTerminalSystem.GetBlockWithName("MB-1 Gyro GD") as IMyGyro;

        // Находим движки
        GridTerminalSystem.GetBlocksOfType <IMyThrust>(ThrList);
        foreach (IMyThrust thr in ThrList)
        {
            if (thr.CustomName.Contains("[Backward]"))
            {
                ThrBackward = thr;
            }
            else if (thr.CustomName.Contains("[Forward]"))
            {
                ThrForward = thr;
            }
        }
        // Находим блоки искусст. массы

        GridTerminalSystem.GetBlocksOfType <IMyArtificialMassBlock>(MassList);

        Runtime.UpdateFrequency = UpdateFrequency.Update1;
    }
Example #14
0
        public void Main(string argument, UpdateType updateSource)
        {
            //argument:"LandingGearName1,LandingGearName2,LandingGearName3,...|TimerBlockName"
            var arguments        = argument.Split('|');
            var landingGearNames = arguments[0].Split(',');
            var lockedCount      = 0;

            foreach (string pistonName in landingGearNames)
            {
                var landingGear = (IMyLandingGear)GridTerminalSystem.GetBlockWithName(pistonName);
                if (!landingGear.AutoLock)
                {
                    landingGear.ResetAutoLock();
                }
                if (landingGear.IsLocked)
                {
                    lockedCount++;
                }
            }
            if (lockedCount == landingGearNames.Length)
            {
                //启动挖矿
                var timerBlock = (IMyTimerBlock)GridTerminalSystem.GetBlockWithName(arguments[1]);
                timerBlock.StartCountdown();
            }
            IMyGyro myGyro = (IMyGyro)GridTerminalSystem.GetBlockWithName("TLY");

            myGyro.GyroOverride = true;
            myGyro.Yaw          = 20;
        }
 public static void SetGyro(IMyGyro g, float power = 1, bool active = false, float p = 0, float y = 0, float r = 0)
 {
     g.GyroOverride = active;
     g.Pitch        = p;
     g.Yaw          = y;
     g.Roll         = r;
     g.GyroPower    = power;
 }
Example #16
0
 public static void SetGyroRad(IMyGyro g, float power = 1, bool overrule = false, float p = 0, float y = 0, float r = 0)
 {
     g.GyroOverride = overrule;
     g.Pitch        = p / pi2;
     g.Yaw          = y / pi2;
     g.Roll         = r / pi2;
     g.GyroPower    = power;
 }
Example #17
0
 public bool checkMine(IMyGyro gg)
 {
     if (gg == G)
     {
         return(true);
     }
     return(false);
 }
Example #18
0
    private Vector3D calculateGyroRotation(IMyGyro gyro, Quaternion desiredOrientation)
    {
        Quaternion gyroOrientation;

        gyro.Orientation.GetQuaternion(out gyroOrientation);
        Quaternion relativeOrientation = Quaternion.Inverse(Quaternion.CreateFromRotationMatrix(gyro.WorldMatrix)) * Quaternion.Inverse(gyroOrientation) * desiredOrientation;

        return(quaternionToYPR(relativeOrientation));
    }
Example #19
0
        bool DoRotate(double rollAngle, string sPlane = "Roll", float maxYPR = -1)
        {
//            Echo("DR:angle=" + rollAngle.ToString("0.00"));
            float   targetRoll = 0;
            IMyGyro gyro       = gyros[0] as IMyGyro;
            float   maxRoll    = gyro.GetMaximum <float>(sPlane);

            if (maxYPR > 0)
            {
                maxRoll = maxYPR;
            }

            //           float minRoll = gyro.GetMinimum<float>(sPlane);

            if (Math.Abs(rollAngle) > 1.0)
            {
//                Echo("MAx gyro");
                targetRoll = (float)maxRoll * (float)(rollAngle);
            }
            else if (Math.Abs(rollAngle) > .7)
            {
                // need to dampen
//                 Echo(".7 gyro");
                targetRoll = (float)maxRoll * (float)(rollAngle) / 4;
            }
            else if (Math.Abs(rollAngle) > 0.5)
            {
//                 Echo(".5 gyro");
                targetRoll = 0.11f * Math.Sign(rollAngle);
            }
            else if (Math.Abs(rollAngle) > 0.1)
            {
//                 Echo(".1 gyro");
                targetRoll = 0.11f * Math.Sign(rollAngle);
            }
            else if (Math.Abs(rollAngle) > 0.01)
            {
//                 Echo(".01 gyro");
                targetRoll = 0.11f * Math.Sign(rollAngle);
            }
            else if (Math.Abs(rollAngle) > 0.001)
            {
//                 Echo(".001 gyro");
                targetRoll = 0.09f * Math.Sign(rollAngle);
            }
            else
            {
                targetRoll = 0;
            }

            GyroControl.SetYaw(targetRoll);
            GyroControl.SetOverride(true);
            GyroControl.RequestEnable(true);

            return(true);
        }
Example #20
0
 public void StopRotation()
 {
     for (int i = 0; i < gyros.Count; ++i)
     {
         IMyGyro gyro = gyros[i] as IMyGyro;
         gyro.SetValue(GyroAction.Pitch.GetName(), gyro.GetDefaultValue <float>(GyroAction.Pitch.GetName()));
         gyro.SetValue(GyroAction.Yaw.GetName(), gyro.GetDefaultValue <float>(GyroAction.Yaw.GetName()));
         gyro.SetValue(GyroAction.Roll.GetName(), gyro.GetDefaultValue <float>(GyroAction.Roll.GetName()));
     }
 }
Example #21
0
        public void ApplyGyroRotation()
        {
            MyAPIGateway.Utilities.InvokeOnGameThread(() => {
                foreach (var gyro in this.BrokenGyros.ToList())
                {
                    if (gyro != null && MyAPIGateway.Entities.Exist(gyro?.SlimBlock?.CubeGrid) == true)
                    {
                        gyro.GyroOverride = false;
                    }

                    this.BrokenGyros.Remove(gyro);
                }

                if (MyAPIGateway.Entities.Exist(this.ControlGyro?.SlimBlock?.CubeGrid) == false || this.ControlGyro == null)
                {
                    this.ControlGyro = null;
                    return;
                }

                if (this.RotationToApply != Vector3.Zero && this.RotationEnabled == true)
                {
                    this.ControlGyro.GyroOverride = true;
                }
                else
                {
                    this.ControlGyro.GyroOverride = false;
                }

                /*
                 * this.ControlGyro.GyroPower = this.ControlGyroStrength;
                 * this.ControlGyro.Yaw = this.RotationToApply.Y * this.RotationMultiplier;
                 * this.ControlGyro.Pitch = this.RotationToApply.X * this.RotationMultiplier;
                 * this.ControlGyro.Roll = this.RotationToApply.Z * this.RotationMultiplier;
                 * //Logger.AddMsg(this.ControlGyro.Pitch.ToString() + " - " + this.ControlGyro.Yaw.ToString() + " - " + this.ControlGyro.Roll.ToString(), true);
                 */

                ApplyGyroOverride(this.RotationToApply.X * this.RotationMultiplier, this.RotationToApply.Y * this.RotationMultiplier, this.RotationToApply.Z * this.RotationMultiplier);

                if (this?.ControlGyro?.SlimBlock?.CubeGrid?.Physics != null && this.BarrelRollEnabled == false)
                {
                    if (this.CurrentAngleToTarget < 45)
                    {
                        var angularVel = this.ControlGyro.SlimBlock.CubeGrid.Physics.AngularVelocity;
                        var angularMag = angularVel.Length();

                        if (angularMag > 0.4)
                        {
                            //Logger.AddMsg("Fix Rotation", true);
                            this.ControlGyro.SlimBlock.CubeGrid.Physics.AngularVelocity = angularVel - (angularVel * 0.25f);
                        }
                    }
                }
            });
        }
Example #22
0
        public Gyroscopes(IMyTerminalBlock referenceBlock, List <IMyTerminalBlock> blocks)
            : base(referenceBlock)
        {
            UpdateGyroscopes(blocks);

            IMyGyro gyro = gyroscopeBlocks[0];

            Min     = gyro.GetMininum <float>(GyroAction.Pitch.Name);
            Max     = gyro.GetMaximum <float>(GyroAction.Pitch.Name);
            Default = gyro.GetDefaultValue <float>(GyroAction.Pitch.Name);
        }
Example #23
0
 bool _alreadyThere(IMyGyro gg)
 {
     for (int i = 0; i < GYROS.Count; i++)
     {
         if (GYROS[i].checkMine(gg))
         {
             return(true);
         }
     }
     return(false);
 }
Example #24
0
 public gyro(
     IMyGyro g,
     IMyTerminalBlock b
     )
 {
     if (g == null || _checkExists(b))
     {
         throw new Exception("gyro(): null args");
     }
     G = g;
     set_matrix(b);
 }
                public void Allign(Vector3D ws_fwd, Vector3D ws_up, IMyGyro gyro, IMyTerminalBlock block)
                {
                    Quaternion quat  = Quaternion.Conjugate(Quaternion.CreateFromForwardUp(block.WorldMatrix.Forward, block.WorldMatrix.Up));
                    Vector3D   up    = Vector3D.Normalize(quat * ws_up);
                    Vector3D   right = Vector3D.Normalize(Vector3D.Cross(up, quat * ws_fwd));
                    Vector3D   front = Vector3D.Normalize(Vector3D.Cross(right, up));

                    Vector3.GetAzimuthAndElevation(front, out azimuth, out elevation);
                    Vector3 final = Vector3.Transform(new Vector3(elevation, azimuth, (float)Vector3D.Dot(-Vector3D.UnitX, -up)),
                                                      block.WorldMatrix.GetOrientation() * Matrix.Transpose(gyro.WorldMatrix.GetOrientation()));

                    ApplyGyro(-final);
                }
Example #26
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            m_gyro   = Entity as IMyGyro;
            m_parent = Entity as IMyCubeBlock;

            m_parent.AddUpgradeValue("GyroBoost", 0f);

            m_objectBuilder = objectBuilder;

            m_parent.OnUpgradeValuesChanged += OnUpgradeValuesChanged;
        }
Example #27
0
        public Program()
        {
            Runtime.UpdateFrequency = UpdateFrequency.Update1;
            info  = GridTerminalSystem.GetBlockWithName("Lcd") as IMyTextPanel;
            brain = GridTerminalSystem.GetBlockWithName("controller") as IMyRemoteControl;
            GridTerminalSystem.GetBlocksOfType <IMyThrust>(term);
            antenna = GridTerminalSystem.GetBlockGroupWithName("receiver") as IMyRadioAntenna;
            gyro    = GridTerminalSystem.GetBlockWithName("gyro") as IMyGyro;

            IGC.RegisterBroadcastListener("pack");
            IGC.RegisterBroadcastListener("pack2");
            IGC.GetBroadcastListeners(listeners);
        }
Example #28
0
        //TODO: Clean this up and debug the value issues.

        /// <summary>
        /// Sets override to given roll pitch yaw object.
        /// </summary>
        /// <param name="gyro"></param>
        /// <param name="rpy"></param>
        public void GyroSetOverrideToRollPitchYaw(IMyGyro gyro, RollPitchYaw rpy, bool enableGyro = true)
        {
            RollPitchYaw tmpRpy = rpy;

            tmpRpy.ConvertToUnit(AngleUnit.FREQUENCY);

            if (enableGyro)
            {
                gyro.GyroOverride = true;
            }
            gyro.Roll  = tmpRpy.roll;
            gyro.Pitch = tmpRpy.pitch;
            gyro.Yaw   = tmpRpy.yaw;
        }
Example #29
0
 public void Reset()
 {
     for (int i = 0; i < gyros.Count; i++)
     {
         IMyGyro g = gyros [i];
         if (g == null)
         {
             gyros.RemoveAtFast(i);
             continue;
         }
         g.GyroOverride = false;
     }
     anglePID.Reset();
 }
        bool DoRoll(double rollAngle, string sPlane = "Roll")
        {
            //Echo("rollAngle=" + Math.Round(rollAngle,5));
            float   targetRoll = 0;
            IMyGyro gyro       = gyros[0] as IMyGyro;
            float   maxRoll    = 60; // gyro.GetMaximum<float>(sPlane);

//            float minRoll = gyro.GetMinimum<float>(sPlane);

            if (Math.Abs(rollAngle) > 1.0)
            {
                targetRoll = (float)maxRoll * (float)(rollAngle);
            }
            else if (Math.Abs(rollAngle) > .7)
            {
                // need to dampen
                targetRoll = (float)maxRoll * (float)(rollAngle) / 4;
            }
            else if (Math.Abs(rollAngle) > 0.5)
            {
                targetRoll = 0.11f * Math.Sign(rollAngle);
            }
            else if (Math.Abs(rollAngle) > 0.1)
            {
                targetRoll = 0.07f * Math.Sign(rollAngle);
            }
            else if (Math.Abs(rollAngle) > 0.01)
            {
                targetRoll = 0.05f * Math.Sign(rollAngle);
            }
            else if (Math.Abs(rollAngle) > 0.001)
            {
                targetRoll = 0.035f * Math.Sign(rollAngle);
            }
            else
            {
                targetRoll = 0;
            }

            //				Echo("targetRoll=" + targetRoll);
            //	rollLevel = (int)(targetRoll * 1000);

            for (int i = 0; i < gyros.Count; i++)
            {
                gyro = gyros[i] as IMyGyro;
                gyro.SetValueFloat(sPlane, targetRoll);
                gyro.SetValueBool("Override", true);
            }
            return(true);
        }
Example #31
0
        bool FuncTest(IMyGyro block)
        {
            //Gyroscope
            //Interface name: IMyGyro
            //Parent: IMyFunctionalBlock
            //Fields:
            float GyroPower    = block.GyroPower;
            bool  GyroOverride = block.GyroOverride;
            float Yaw          = block.Yaw;
            float Pitch        = block.Pitch;
            float Roll         = block.Roll;

            return(true);
        }
Example #32
0
        public GyroDetails(IMyGyro gyro, Base6Directions.Direction shipUp,
                           Base6Directions.Direction shipForward)
        {
            Gyro = gyro;
            AxisDetails = new GyroAxisDetails[3];

            var shipLeft = Base6Directions.GetLeft(shipUp, shipForward);

            // Determine yaw axis
            SetAxisDetails(gyro, Yaw, shipUp);

            // Determine pitch axis
            SetAxisDetails(gyro, Pitch, shipLeft);

            // Determine roll axis
            SetAxisDetails(gyro, Roll, shipForward);
        }
Example #33
0
        public void set_oriented_gyros(IMyGyro[] gyros, IMyTerminalBlock pivot, Vector3D tar){
            Matrix orientation;


            pivot.Orientation.GetMatrix(out orientation);
            MatrixD invMatrix = MatrixD.Invert(orientation);
            Vector3D localTar = Vector3D.Transform(tar, MatrixD.Invert(MatrixD.CreateFromDir(pivot.WorldMatrix.Forward, pivot.WorldMatrix.Up)) * orientation);
            Vector3D angsin = Vector3D.Cross(orientation.Forward, localTar);
            Vector3D ang = new Vector3D(Math.Sin(angsin.GetDim(0)), Math.Sin(angsin.GetDim(1)), Math.Sin(angsin.GetDim(2)));
            for (int i = 0; i < gyros.Length; i++)
            {
                Matrix gyro_or;
                gyros[i].Orientation.GetMatrix(out gyro_or);
                MatrixD invGyroMatrix = invMatrix*MatrixD.Invert(gyro_or);
                Vector3D angle = Vector3D.Transform(ang,invGyroMatrix);
                gyros[i].SetValueFloat("Pitch", (float)angle.GetDim(0));
                gyros[i].SetValueFloat("Yaw", (float)angle.GetDim(1));
                gyros[i].SetValueFloat("Roll", (float)angle.GetDim(2));
            }
        }
Example #34
0
 public GyroWrapper( MySlimBlock block )
     : base(block)
 {
     Block = (MyGyro)block.FatBlock;
     IBlock = Block;
 }
    public AutoHoverController(IMyGridTerminalSystem gts, IMyProgrammableBlock pb)
    {
        Me = pb;
        GridTerminalSystem = gts;

        remote = GridTerminalSystem.GetBlockWithName(RemoteControlName) as IMyRemoteControl;
        gyro = GridTerminalSystem.GetBlockWithName(GyroName) as IMyGyro;

        if (!String.IsNullOrEmpty(TextPanelName))
          screen = GridTerminalSystem.GetBlockWithName(TextPanelName) as IMyTextPanel;

        var list = new List<IMyTerminalBlock>();
        GridTerminalSystem.GetBlocksOfType<IMyGyro>(list, x => x.CubeGrid == Me.CubeGrid && x != gyro);
        gyros = list.ConvertAll(x => (IMyGyro)x);
        gyros.Insert(0, gyro);
        gyros = gyros.GetRange(0, GyroCount);

        mode = "Hover";
        setSpeed = 0;
    }