Example #1
0
			public Stator(IMyCubeBlock block)
				: base(block, AttachedGrid.AttachmentKind.Motor)
			{
				this.myLogger = new Logger("Stator", block);
				this.myStator = block as IMyMotorStator;
				Registrar.Add(this.myStator, this);
			}
Example #2
0
 /// <summary>
 /// Tries to get a stator attached to a rotor.
 /// </summary>
 /// <param name="rotor">rotor attached to stator</param>
 /// <param name="stator">stator attached to rotor</param>
 /// <returns>true iff successful</returns>
 /// Not an extension because IMyCubeBlock are rarely rotors.
 public static bool TryGetStator(IMyCubeBlock rotor, out IMyMotorStator stator)
 {
     Rotor value;
     if (!Registrar.TryGetValue(rotor.EntityId, out value))
     {
         myLogger.alwaysLog("failed to get rotor from registrar: " + rotor.DisplayNameText, Logger.severity.WARNING);
         stator = null;
         return false;
     }
     if (value.partner == null)
     {
         stator = null;
         return false;
     }
     stator = value.partner.myStator;
     return true;
 }
Example #3
0
 public static void RotateTowards(IMyMotorStator rotor, float target, float speed) {
     float angle = ToDegrees(rotor.Angle);
     if (RotationEquals(angle, target)) SetSpeed(rotor, 0);
     float posrot = (target + 360 - angle) % 360;
     float negrot = (angle + 360 - target) % 360;
     if (posrot < negrot) {
         if (HasUpperLimit(rotor) && rotor.UpperLimit <= target) SetSpeed(rotor, -speed);
         else SetSpeed(rotor, speed);
     } else {
         if (HasLowerLimit(rotor) && rotor.LowerLimit >= target) SetSpeed(rotor, speed);
         else SetSpeed(rotor, -speed);
     }
 }
Example #4
0
 private static bool StatorOk(IMyMotorStator stator)
 {
     return(stator != null && !stator.Closed && stator.IsAttached);
 }
Example #5
0
 public ArmController(Ship ship, String sy_name, String sp_name, String elbow_name, String wp_name, String wy_name, bool wristyawlocal = false)
 {
     this.ship = ship;
     this.shoulderYaw = (IMyMotorStator)ship.GridTerminalSystem.GetBlockWithName(sy_name);
     this.shoulderPitch = (IMyMotorStator)ship.GridTerminalSystem.GetBlockWithName(sp_name);
     this.Elbow = (IMyMotorStator)ship.GridTerminalSystem.GetBlockWithName(elbow_name);
     this.wristPitch = (IMyMotorStator)ship.GridTerminalSystem.GetBlockWithName(wp_name);
     this.wristYaw = (IMyMotorStator)ship.GridTerminalSystem.GetBlockWithName(wy_name);
     this.wristYawIsLocal = wristyawlocal;
     ship.Me.Echo("Finished init controller " + (bool)(shoulderPitch == null));
 }
Example #6
0
	static void Reverse(IMyMotorStator rotor) {
		rotor.GetActionWithName("Reverse").Apply(rotor);
	}
Example #7
0
        public AutoDoorProgram(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime)
        {
            GridTerminalSystem = grid;
            Echo = echo;
            ElapsedTime = elapsedTime;
            Me = me;

            doors = new List<IMyDoor>();
            sensors = new List<IMySensorBlock>();

            List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();

            grid.SearchBlocksOfName(PREFIX, blocks);

            // Add some error handling for blocks not found

            for (int i = 0; i < blocks.Count; i++)
            {
                IMyTerminalBlock block = blocks[i];
                String blockType = block.DefinitionDisplayNameText;
                String blockName = block.CustomName;

                //Echo("Processing block " + blockName);

                if (blockType.Equals("Sensor"))
                {
                    IMySensorBlock sensor = block as IMySensorBlock;
                    sensor.ApplyAction("OnOff_On");

                    List<ITerminalProperty> properties = new List<ITerminalProperty>();
                    sensor.GetProperties(properties);

                    sensor.SetValueFloat("Back", SensorBack);
                    sensor.SetValueFloat("Bottom", SensorBottom);
                    sensor.SetValueFloat("Top", SensorTop);
                    sensor.SetValueFloat("Left", SensorLeft);
                    sensor.SetValueFloat("Right", SensorRight);
                    sensor.SetValueFloat("Front", SensorFront);
                    sensor.SetValueBool("Detect Asteroids", false);
                    sensor.SetValueBool("Detect Enemy", false);
                    sensor.SetValueBool("Detect Floating Objects", false);
                    sensor.SetValueBool("Detect Friendly", true);
                    sensor.SetValueBool("Detect Large Ships", false);
                    sensor.SetValueBool("Detect Neutral", false);
                    sensor.SetValueBool("Detect Owner", true);
                    sensor.SetValueBool("Detect Players", true);
                    sensor.SetValueBool("Detect Small Ships", false);
                    sensor.SetValueBool("Detect Stations", false);
                    sensor.SetValueBool("Audible Proximity Alert", false);
                    sensors.Add(sensor);

                }
                else if (blockType.Equals("Sliding Door") || blockType.Equals("Door"))
                {
                    IMyDoor door = block as IMyDoor;
                    door.ApplyAction("Open_Off");
                    doors.Add(door);
                }
                else if (blockType.Equals("Rotor") || blockType.Equals("Advanced Rotor"))
                {
                    rotor = block as IMyMotorStator;
                    rotor.ApplyAction("OnOff_On");
                    rotor.SetValueFloat("Torque", 3.36E+07f);
                    rotor.SetValueFloat("BrakingTorque", 3.36E+07f);
                    rotor.SetValueFloat("Velocity", rotorSpeed);
                    rotor.SetValueFloat("UpperLimit", float.PositiveInfinity);
                    rotor.SetValueFloat("LowerLimit", float.NegativeInfinity);

                    // Add config here
                }
            }
        }
Example #8
0
	void Main() {
		// get a list of all blocks in the grid terminal system
		List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
		GridTerminalSystem.GetBlocks(blocks);

		// initialize the reference solar panel if it hasn't been initialized yet
		if (referencePanel == null) {
			// search all available blocks for one containing the reference panel name
			for (int i = 0; i < blocks.Count; i++) {
				if (blocks[i].CustomName.Contains(referencePanelName)) {
					referencePanel = blocks[i] as IMySolarPanel;
					if (referencePanel != null) break;
				}
			}
			if (referencePanel == null) throw new Exception(" Main(): failed to find solar panel with name '" + referencePanelName + "'");
		}

		// initialize the timer if it hasn't been initialized yet
		if (timer == null) {
			// search all available blocks for one containing the timer name
			for (int i = 0; i < blocks.Count; i++) {
				if (blocks[i].CustomName.Contains(timerName)) {
					timer = blocks[i] as IMyTimerBlock;
					if (timer != null)
						break;
				}
			}
			if (timer == null) throw new Exception(" Main(): failed to find timer block with name '" + timerName + "'");
		}

		// initialize the rotors list if no rotors have been registered yet
		if (rotors.Count <= 0) {
			for (int i = 0; i < rotorNames.Length; i++) {
				IMyTerminalBlock rotor = GridTerminalSystem.GetBlockWithName(rotorNames[i]);

				// only add rotors that actually exist and haven't been added yet
				if (rotor != null && !rotors.Contains(rotor)) {
					rotors.Add(rotor);
					rotor.SetValue("Velocity", rotorSpeed);
					ToggleOff(rotor);
				}
			}
			if (rotors.Count <= 0) throw new Exception(" Main(): failed to find any rotors with the specified names");
		}

		// rotate the current rotor
		float currentPower;
		if (!MaxOutput(referencePanel, out currentPower)) throw new Exception(" Main(): failed to read current power output from DetailedInfo");
		if (currentPower >= targetPowerOutput) {
			for (int i = 0; i < rotors.Count; i++) {
				ToggleOff(rotors[i]);
			}
			UpdateName(referencePanel);
			TriggerTimerIdle();
			return;
		}
		if (currentRotor == null) {
			currentRotor = rotors[currentIndex] as IMyMotorStator;
			updatedRotor = true;
		}
		if (currentRotor == null) throw new Exception(" Main(): block '" + rotors[currentIndex].CustomName + "' is not a rotor but was registered as rotor to use");

		if (updatedRotor) {
			if (!testingDirection) {
				// set the best rotation direction
				UpdateName(referencePanel);
				ToggleOn(currentRotor);
				testingDirection = true;
				TriggerTimer();
				return;
			}

			ToggleOff(currentRotor);
			float oldPowerWDIHTCT;
			UpdateName(referencePanel, out oldPowerWDIHTCT, out currentPower);
			if (oldPowerWDIHTCT > currentPower) Reverse(currentRotor);
			updatedRotor = false;
			testingDirection = false;
		}

		// get the optimal rotation
		if (!setting) {
			ToggleOn(currentRotor);
			setting = true;
			UpdateName(referencePanel);
			TriggerTimer();
			return;
		}

		float oldPower;
		UpdateName(referencePanel, out oldPower, out currentPower);
		if (oldPower > currentPower) {
			ToggleOff(currentRotor);
			currentRotor = null;
			currentIndex = (currentIndex + 1) % rotors.Count;
		}
		setting = false;
		TriggerTimer();
	}
 public Turret(IMyRemoteControl CTRL = null, IMyMotorStator XROT = null, IMyMotorStator YROT = null, IMyMotorStator YROTA = null, IMyShipConnector RLDCon = null, IMyShipConnector BSDCon = null, List <IMySmallGatlingGun> weaponry = null)
 {
     this.CTRL   = CTRL;
     this.XROT   = XROT;
     this.YROT   = YROT;
     this.YROTA  = YROTA;
     this.RLDCon = RLDCon;
     this.BSDCon = BSDCon;
     ChangeState(State.STOW);
     SetAngle(BSDCon);
     this.targetCoords = new Vector3D(0, 0, 0);
     this.hasTarget    = false;
     if (weaponry != null)
     {
         this.weaponry = weaponry;
     }
     else
     {
         this.weaponry = new List <IMySmallGatlingGun>();
     }
 }
        //called whenever the program is recompiled and run or the game loads the save again
        public Program()
        {
            //setting the commands
            commands             = new Dictionary <string, Action>(StringComparer.OrdinalIgnoreCase);
            commands["man/auto"] = ManAuto;
            commands["continue"] = Continue;
            commands["pause"]    = Pause;
            commands["restart"]  = Restart;
            commands["test"]     = Test;

            ini = new MyIni();

            //filling the lists that represent the drillarm with blocks from the grid
            armPiston   = fillPistonList("armpistons");
            chestPiston = fillPistonList("chestpistons");
            drillPiston = fillPistonList("drillpistons");
            drillHead   = fillDrillList("drillhead");
            rotor       = (IMyMotorStator)GridTerminalSystem.GetBlockWithName("drillrotor");

            //filling the variables from storage
            if (Storage != null && !Storage.Equals(""))
            {
                try
                {
                    //TODO redo this
                    string[] loaded = Storage.Split(';');
                    Boolean.TryParse(loaded[0], out direction);
                    Boolean.TryParse(loaded[1], out isPaused);
                    byte.TryParse(loaded[2], out state);
                    float.TryParse(loaded[3], out angle);
                    float.TryParse(loaded[4], out radius);
                }
                catch (Exception e)
                {
                    Echo(e.StackTrace);
                }
            }
            else
            {
                //setting default values if the storage string is empty
                direction = true;
                isPaused  = true;
                state     = 0;
                angle     = rotor.Angle;
                radius    = calculateRadius();
            }

            if (isPaused)
            {
                //if the script starts in the paused state
                settingDrillarmEnabled(false);

                printIniToCustomData();

                Runtime.UpdateFrequency = UpdateFrequency.None;

                Echo("- Paused -\n\nFeel free to edit the configurations in \"Custom Data\"");
            }
            else
            {
                //Script is fired every 100 ticks / 1,6s
                Runtime.UpdateFrequency = UpdateFrequency.Update100;
            }



            /*
             * //checking some values
             * for (int i = 0; i < armPiston.Count; i++)
             * {
             *  float force = armPiston[i].GetValue<float>("MaxImpulseAxis");
             *  if (force != 100000) armPiston[i].SetValue<float>("MaxImpulseAxis", 100000);
             *  force = armPiston[i].GetValue<float>("MaxImpulseNonAxis");
             *  if (force != 100000) armPiston[i].SetValue<float>("MaxImpulseNonAxis", 100000);
             * }
             *
             * for (int i = 0; i < chestPiston.Count; i++)
             * {
             *  float force = chestPiston[i].GetValue<float>("MaxImpulseAxis");
             *  if (force != 100000) chestPiston[i].SetValue<float>("MaxImpulseAxis", 100000);
             *  force = chestPiston[i].GetValue<float>("MaxImpulseNonAxis");
             *  if (force != 100000) chestPiston[i].SetValue<float>("MaxImpulseNonAxis", 100000);
             * }
             *
             * for (int i = 0; i < drillPiston.Count; i++)
             * {
             *  float force = drillPiston[i].GetValue<float>("MaxImpulseAxis");
             *  if (force != 100000) drillPiston[i].SetValue<float>("MaxImpulseAxis", 100000);
             *  force = drillPiston[i].GetValue<float>("MaxImpulseNonAxis");
             *  if (force != 100000) drillPiston[i].SetValue<float>("MaxImpulseNonAxis", 100000);
             * }
             */
        }
Example #11
0
 /// <summary>
 /// Constructs docking strategy for a rotor stator (on ship's side).
 /// </summary>
 /// <param name="goal">Location of the landing zone, world-space.</param>
 /// <param name="rotor">Rotor to use.</param>
 /// <param name="approach">Direction in which rotor's working end should be facing.</param>
 /// <param name="facing">Direction in which rotor's forward vector should be facing.</param>
 public DockingStrategy(Waypoint goal, IMyMotorStator rotor, Vector3D approach, Vector3D?facing = null)
     : this(goal, rotor, Base6Directions.Direction.Up, Base6Directions.Direction.Forward, approach, facing)
 {
 }
Example #12
0
            void UnlockStator()
            {
                IMyMotorStator clamp = Reference as IMyMotorStator;

                clamp.Detach();
            }
Example #13
0
 public RotorMotionController(IMyMotorStator rotor, Program program) : base(program)
 {
     this.rotor = rotor;
 }
Example #14
0
 private void SetVelocity(IMyMotorStator stator, float angle)
 {
     SetVelocity((MyMotorStator)stator, angle);
 }
Example #15
0
 private static bool ArePerpendicular(IMyMotorStator statorOne, IMyMotorStator statorTwo)
 {
     Logger.TraceLog(nameof(statorOne) + ": " + statorOne.nameWithId() + ", Up: " + statorOne.WorldMatrix.Up + ", " + nameof(statorTwo) + ": " + statorTwo.nameWithId() + ", Up: " + statorTwo.WorldMatrix.Up + ", dot: " + statorOne.WorldMatrix.Up.Dot(statorTwo.WorldMatrix.Up));
     return(Math.Abs(statorOne.WorldMatrix.Up.Dot(statorTwo.WorldMatrix.Up)) < 0.1f);
 }
Example #16
0
 public static bool HasUpperLimit(IMyMotorStator rotor) {
     return !float.IsInfinity(rotor.UpperLimit);
 }
Example #17
0
 public static bool ReachedUpperLimit(IMyMotorStator rotor) {
     return !HasUpperLimit(rotor) || (HasUpperLimit(rotor) && RotationEquals(ToDegrees(rotor.Angle), ToDegrees(rotor.UpperLimit)));
 }
 public void SetXROT(IMyMotorStator XROT)
 {
     this.XROT = XROT;
 }
Example #19
0
 public static void SetSpeed(IMyMotorStator rotor, float speed) {
     if (rotor.CustomName.EndsWith(Configuration.InvertedRotorSuffix)) speed = -speed;
     rotor.SetValue("Velocity", speed);
 }
 public void SetYROT(IMyMotorStator YROT)
 {
     this.YROT = YROT;
 }
Example #21
0
        /// <summary>
        /// Creates an obstruction list from stators and rotors.
        /// </summary>
        private void MyMotorTurret_OnStatorChange(IMyMotorStator statorEl, IMyMotorStator statorAz)
        {
            //myLogger.debugLog("entered MyMotorTurret_OnStatorChange()", "MyMotorTurret_OnStatorChange()");

            List<IMyEntity> ignore = new List<IMyEntity>();
            if (statorEl != null)
            {
                //myLogger.debugLog("added statorEl.CubeGrid: " + statorEl.CubeGrid.getBestName(), "MyMotorTurret_OnStatorChange()");
                ignore.Add(statorEl.CubeGrid);

                // elevation rotor will be on same grid as weapon, already ignored
            }
            if (statorAz != null)
            {
                //myLogger.debugLog("added statorAz: " + statorAz.getBestName(), "MyMotorTurret_OnStatorChange()");
                ignore.Add(statorAz);

                // azimuth rotor will be on same grid as elevation stator, ignored above
            }
            Ignore(ignore);
        }
 public void SetYROTA(IMyMotorStator YROTA)
 {
     this.YROTA = YROTA;
 }
Example #23
0
	void Main() {
		// initialize the reference solar panel
		if (ReferencePanel == null) {
			// get a list of all available solar panels
			List<IMyTerminalBlock> solarPanels = new List<IMyTerminalBlock>();
			GridTerminalSystem.GetBlocksOfType<IMySolarPanel>(solarPanels);

			// search all available blocks for one containing the reference solar panel's name
			for (int i = 0; i < solarPanels.Count; i++) {
				IMySolarPanel solarPanel = solarPanels[i] as IMySolarPanel;
				if (solarPanel != null && solarPanel.CustomName.StartsWith(Configuration.ReferencePanelName)) {
					ReferencePanel = solarPanel;
					if (ReferencePanel != null) break;
				}
			}
			if (ReferencePanel == null) throw new Exception(" Main(): Failed to find solar panel with name \"" + Configuration.ReferencePanelName + "\"");
		}

		// initialize the timer
		if (Timer == null) {
			Timer = GridTerminalSystem.GetBlockWithName(Configuration.TimerName) as IMyTimerBlock;
			if (Timer == null) throw new Exception(" Main(): Failed to find timer block with name \"" + Configuration.TimerName + "\"");
		}

		// initialize rotors list
		if (Rotors.Count <= 0) {
			for (int i=0; i < Configuration.RotorNames.Length; i++) {
				IMyMotorStator rotor = GridTerminalSystem.GetBlockWithName(Configuration.RotorNames[i]) as IMyMotorStator;

				// only add rotors that exist and haven't been added yet
				if (rotor != null && !Rotors.Contains(rotor)) {
					Rotors.Add(rotor);
					rotor.SetValue("Velocity", Configuration.RotorSpeed);
					ToggleOff(rotor);
				}
			}
			if (Rotors.Count < Configuration.RotorNames.Length) throw new Exception(" Main(): Failed to find all rotors - found " + Rotors.Count + " rotors, " + Configuration.RotorNames.Length + " were specified");
		}

		// rotate the current rotor
		float currentPower;
		if (!MaxOutput(ReferencePanel, out currentPower)) throw new Exception(" Main(): Failed to read maximum power output from the solar panel's information");

		// check if the target power output has been reached
		if (currentPower >= Configuration.TargetPowerOutput) {
			for (int i=0; i < Rotors.Count; i++) {
				ToggleOff(Rotors[i]);
			}
			UpdateName(ReferencePanel);
			TriggerTimerIdle();
			return;
		}

		// update the rotor and test which direction yields the higher power output
		if (CurrentRotor == null || CurrentStatus == Status.UPDATING) {
			CurrentRotor = Rotors[CurrentRotorIndex];
			UpdateName(ReferencePanel);
			ToggleOn(CurrentRotor);
			CurrentStatus = Status.TESTING;
			TriggerTimer();
			return;
		}

		// set the direction towards the higher power output
		if (CurrentStatus == Status.TESTING) {
			ToggleOff(CurrentRotor);
			float oldPower;
			UpdateName(ReferencePanel, out oldPower, out currentPower);
			if (oldPower > currentPower) Reverse(CurrentRotor);
			CurrentStatus = Status.ALIGNING;
		}

		// rotate towards maximum power output
		if (CurrentStatus == Status.ALIGNING) {
			ToggleOn(CurrentRotor);
			UpdateName(ReferencePanel);
			CurrentStatus = Status.CHECKING;
			TriggerTimer();
			return;
		}

		if (CurrentStatus == Status.CHECKING) {
			float oldPower;
			UpdateName(ReferencePanel, out oldPower, out currentPower);
			if (oldPower > currentPower) {
				ToggleOff(CurrentRotor);
				CurrentStatus = Status.UPDATING;
				CurrentRotorIndex = (CurrentRotorIndex + 1) % Rotors.Count;
			}
			TriggerTimer();
			return;
		}
	}
Example #24
0
        private bool GetStatorRotor(IMyCubeGrid grid, out IMyMotorStator Stator, out IMyCubeBlock Rotor, IMyMotorStator IgnoreStator = null, IMyCubeBlock IgnoreRotor = null)
        {
            CubeGridCache cache = CubeGridCache.GetFor(grid);

            foreach (MyObjectBuilderType type in types_Rotor)
            {
                var blocksOfType = cache.GetBlocksOfType(type);
                if (blocksOfType == null || blocksOfType.Count == 0)
                    continue;

                foreach (IMyCubeBlock motorPart in blocksOfType)
                {
                    if (!FaceBlock.canControlBlock(motorPart))
                        continue;

                    Stator = motorPart as IMyMotorStator;
                    if (Stator != null)
                    {
                        if (Stator == IgnoreStator)
                            continue;
                        if (StatorRotor.TryGetRotor(Stator, out Rotor) && FaceBlock.canControlBlock(Stator as IMyCubeBlock))
                            return true;
                    }
                    else
                    {
                        Rotor = motorPart;
                        if (Rotor == IgnoreRotor)
                            continue;
                        if (StatorRotor.TryGetStator(Rotor, out Stator) && FaceBlock.canControlBlock(Stator as IMyCubeBlock))
                            return true;
                    }
                }
            }

            Stator = null;
            Rotor = null;
            return false;
        }
Example #25
0
        /// <summary>
        /// Creates an obstruction list from stators and rotors.
        /// </summary>
        private void MyMotorTurret_OnStatorChange(IMyMotorStator statorEl, IMyMotorStator statorAz)
        {
            myLogger.debugLog("entered MyMotorTurret_OnStatorChange()", "MyMotorTurret_OnStatorChange()");

            List<IMyEntity> ignore = new List<IMyEntity>();
            if (statorEl != null)
            {
                myLogger.debugLog("added statorEl.CubeGrid: " + statorEl.CubeGrid.getBestName(), "MyMotorTurret_OnStatorChange()");
                ignore.Add(statorEl.CubeGrid);
            }
            if (statorAz != null)
            {
                myLogger.debugLog("added statorAz: " + statorAz.getBestName(), "MyMotorTurret_OnStatorChange()");
                ignore.Add(statorAz);

                IMyCubeBlock statorAzRotor;
                if (StatorRotor.TryGetRotor(statorAz, out statorAzRotor))
                {
                    myLogger.debugLog("added statorAzRotor: " + statorAzRotor.getBestName(), "MyMotorTurret_OnStatorChange()");
                    ignore.Add(statorAzRotor);
                }
            }
            ObstructionIgnore = ignore;
        }
Example #26
0
        private bool SetupStators()
        {
            if (StatorOK())
            {
                //myLogger.debugLog("Stators are already set up", "SetupStators()");
                return true;
            }

            // get StatorEl from FaceBlock's grid
            IMyMotorStator tempStator;
            IMyCubeBlock RotorEl;
            if (!GetStatorRotor(FaceBlock.CubeGrid, out tempStator, out RotorEl))
            {
                myLogger.debugLog("Failed to get StatorEl");
                StatorEl = null;
                OnStatorChange(StatorEl, StatorAz);
                return false;
            }
            StatorEl = tempStator;

            // get StatorAz from grid from either StatorEl or RotorEl, whichever is not on Faceblock's grid
            IMyCubeGrid getBFrom;
            if (RotorEl.CubeGrid == FaceBlock.CubeGrid)
                getBFrom = StatorEl.CubeGrid as IMyCubeGrid;
            else
                getBFrom = RotorEl.CubeGrid;

            IMyCubeBlock RotorAz;
            if (!GetStatorRotor(getBFrom, out tempStator, out RotorAz, StatorEl, RotorEl))
            {
                myLogger.debugLog("Failed to get StatorAz");
                StatorAz = null;
                OnStatorChange(StatorEl, StatorAz);
                return false;
            }
            StatorAz = tempStator;

            myLogger.debugLog("Successfully got stators. Elevation = " + StatorEl.DisplayNameText + ", Azimuth = " + StatorAz.DisplayNameText);
            OnStatorChange(StatorEl, StatorAz);
            Stop();
            return true;
        }
Example #27
0
        private void SetVelocity(IMyMotorStator Stator, float angle)
        {
            myLogger.debugLog(!MyAPIGateway.Multiplayer.IsServer, "Not server!", Logger.severity.FATAL);

            float speed = angle * RotationSpeedMultiplier;

            if (!speed.IsValid())
            {
                myLogger.debugLog("invalid speed: " + speed);
                speed = 0;
            }
            else
                speed = MathHelper.Clamp(speed, -mySpeedLimit, mySpeedLimit);

            float prevSpeed;
            if (Stator == StatorEl)
                prevSpeed = previousSpeed_StatorEl;
            else
                prevSpeed = previousSpeed_StatorAz;

            if (Math.Abs(speed - prevSpeed) < 0.1)
            {
                //myLogger.debugLog(Stator.DisplayNameText + ", no change in speed: " + speed, "SetVelocity()");
                return;
            }

            //myLogger.debugLog(Stator.DisplayNameText + ", speed changed to " + speed, "SetVelocity()");
            var prop = Stator.GetProperty("Velocity").AsFloat();

            if (Stator == StatorEl)
                previousSpeed_StatorEl = speed;
            else
                previousSpeed_StatorAz = speed;

            prop.SetValue(Stator, speed);
        }
Example #28
0
        public bool init()
        {
            IMyBlockGroup group = GridTerminalSystem.GetBlockGroupWithName(groupName_);

            if (group != null)
            {
                pistons_.Clear();
                drills_.Clear();

                group.GetBlocksOfType <IMyTerminalBlock>(null, (block) =>
                {
                    IMyPistonBase piston = block as IMyPistonBase;
                    if (piston != null)
                    {
                        PistonController controller = new PistonController(this, piston);
                        pistons_.Add(controller);
                        return(false);
                    }

                    IMyMotorStator stator = block as IMyMotorStator;
                    if (stator != null)
                    {
                        drillRotor_ = new RotorController(this, stator);
                        return(false);
                    }

                    IMyShipDrill drill = block as IMyShipDrill;
                    if (drill != null)
                    {
                        drills_.Add(drill);
                        return(false);
                    }

                    // production block
                    IMyProductionBlock pu = block as IMyProductionBlock;
                    if (pu != null)
                    {
                        production_ = new ProductionUnit(this, pu);
                        return(false);
                    }

                    IMyCargoContainer container = block as IMyCargoContainer;
                    if (container != null)
                    {
                        containers_.Add(container);
                        return(false);
                    }

                    return(false);
                });
            }
            else
            {
                addMessageLine("Error: Minig Group not found!");
                return(false);
            }

            // check drills
            if (drills_.Count == 0)
            {
                addMessageLine("Error: No drills found!");
                return(false);
            }

            // read config
            miningDepth_ = GetConfigMiningDepth();

            return(true);
        }