Exemplo n.º 1
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()));
     }
 }
Exemplo n.º 2
0
            public bool setSpin(IMyGyro gyro, string direct, float speed)
            {
                try
                {
                    gyro.SetValue("Pitch", 0.0f);
                    gyro.SetValue("Yaw", 0.0f);
                    gyro.SetValue("Roll", 0.0f);

                    gyro.SetValue(direct, speed);
                    return(true);
                }
                catch (Exception e)
                {
                    _program.debugSB.AppendLine("Set Spin Error:").AppendLine($"Exception: {e}\n---");
                    return(false);
                }
            }
Exemplo n.º 3
0
    void GyroOverride(bool isOverride, Vector3 v, float power = 1)
    {
        var gyros = new List <IMyTerminalBlock>();

        GridTerminalSystem.SearchBlocksOfName("Gyro", gyros);
        for (int i = 0; i < gyros.Count; i++)
        {
            IMyGyro gyro = gyros[i] as IMyGyro;
            if (gyro != null)
            {
                if ((!gyro.GyroOverride && isOverride) || (gyro.GyroOverride && !isOverride))
                {
                    gyro.ApplyAction("Override");
                }

                gyro.SetValue("Power", power);
                gyro.SetValue("Yaw", v.GetDim(0));
                gyro.SetValue("Pitch", v.GetDim(1));
                gyro.SetValue("Roll", v.GetDim(2));
            }
        }
    }
Exemplo n.º 4
0
            } //GetChangeInPose()

            protected void TurnGyros(List <IMyTerminalBlock> gyroList, Vector3D axis, double angle, float coEff = 0.5f)
            {
                float   ctrlVel = 0.1f; // control velocity
                IMyGyro gyro    = null; // for looping through gyros
                int     i       = 0;    // counter for looping

                gyro = gyroList[0] as IMyGyro;

                ctrlVel = gyro.GetMaximum <float>("Yaw") * (float)(angle / Math.PI) * coEff;
                ctrlVel = Math.Min(gyro.GetMaximum <float>("Yaw"), ctrlVel);
                ctrlVel = (float)Math.Max(0.005, ctrlVel);
                axis.Normalize();
                axis *= ctrlVel;

                for (i = 0; i < gyroList.Count; i++)
                {
                    gyro = gyroList[i] as IMyGyro;
                    gyro.SetValue("Pitch", Convert.ToSingle(axis.GetDim(0)));
                    gyro.SetValue("Yaw", -Convert.ToSingle(axis.GetDim(1)));
                    gyro.SetValue("Roll", -Convert.ToSingle(axis.GetDim(2)));
                } // for i loop
            }     //TurnGyros method
Exemplo n.º 5
0
            /// <summary>
            /// Rotates the ship relative to the reference block.
            /// A positive Yaw value rotates around the Up vector, such that the Right vector is moved to the Backward vector on the shortest way.
            /// A positive Pitch value rotates around the Right vector, such that the Up vector is moved to the Backward vector on the shortest way.
            /// A positive Roll value rotates around the Backward vector, such that the Up vector is moved to the Right vector on the shortest way.
            /// </summary>
            /// <param name="axis"></param>
            /// <param name="value"></param>
            public void Rotate(VRageMath.Vector3 axis, float value)
            {
                if (value < gyroRotateMin || value > gyroRotateMax)
                {
                    throw new Exception("Value out of range [" + gyroRotateMin + ", " + gyroRotateMax + "].");
                }

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

                for (int i = 0; i < gyros.Count; ++i)
                {
                    IMyGyro gyro = gyros[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 = gyroActions[transformedAxis];
                    gyro.SetValue(action.GetName(), action.Reversed ? -value : value);
                }
            }
Exemplo n.º 6
0
        /// <summary>
        /// Rotates the ship relative to the reference block.
        /// A positive Yaw value rotates around the Up vector, such that the Right vector is moved to the Backward vector on the shortest way.
        /// A positive Pitch value rotates around the Right vector, such that the Up vector is moved to the Backward vector on the shortest way.
        /// A positive Roll value rotates around the Backward vector, such that the Up vector is moved to the Right vector on the shortest way.
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="value"></param>
        private void Rotate(VRageMath.Vector3 axis, float value)
        {
            if (value < Min || value > Max)
            {
                throw new Exception("Value '" + value + "' out of range [" + Min + ", " + Max + "].");
            }

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

            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);
                gyro.SetValue(action.Name, action.Reversed ? -value : value);
            }
        }