public void Run(ZACommons commons, EventDriver eventDriver) { var groups = commons.GetBlockGroupsWithPrefix(SIMPLE_AIRLOCK_GROUP_PREFIX); for (var e = groups.GetEnumerator(); e.MoveNext();) { var doors = ZACommons.GetBlocksOfType<IMyDoor>(e.Current.Blocks, door => door.CubeGrid == commons.Me.CubeGrid && door.IsFunctional); var opened = IsAnyDoorOpen(doors); for (var f = doors.GetEnumerator(); f.MoveNext();) { var door = (IMyDoor)f.Current; if (door.OpenRatio == 0.0f && opened) { // This door is not open and some other door in the group is, lock it down if (door.Enabled) door.SetValue<bool>("OnOff", false); } else { if (!door.Enabled) door.SetValue<bool>("OnOff", true); } } } eventDriver.Schedule(RunDelay, Run); }
public void Init(ZACommons commons, EventDriver eventDriver) { var previous = commons.GetValue(LOSMinerKey); if (previous != null) { var parts = previous.Split(';'); if (parts.Length == 13) { // Resume original mode and line-of-sight vector var newMode = int.Parse(parts[0]); StartPoint = new Vector3D(); StartDirection = new Vector3D(); StartUp = new Vector3D(); StartLeft = new Vector3D(); for (int i = 0; i < 3; i++) { StartPoint.SetDim(i, double.Parse(parts[i+1])); StartDirection.SetDim(i, double.Parse(parts[i+4])); StartUp.SetDim(i, double.Parse(parts[i+7])); StartLeft.SetDim(i, double.Parse(parts[i+10])); } if (newMode == MINING) { Start((ShipControlCommons)commons, eventDriver); } else if (newMode == REVERSING) { StartReverse((ShipControlCommons)commons, eventDriver); } } } }
public void Run(ZACommons commons, EventDriver eventDriver) { if (!AutopilotEngaged) { Reset(commons); return; } var shipControl = (ShipControlCommons)commons; var targetVector = AutopilotTarget - shipControl.ReferencePoint; var distance = targetVector.Normalize(); double yawError, pitchError; var gyroControl = seeker.Seek(shipControl, targetVector, out yawError, out pitchError); var targetSpeed = Math.Min(distance / AUTOPILOT_TTT_BUFFER, AutopilotSpeed); targetSpeed = Math.Max(targetSpeed, AUTOPILOT_MIN_SPEED); // Avoid Zeno's paradox... cruiser.Cruise(shipControl, eventDriver, targetSpeed); if (distance < AUTOPILOT_DISENGAGE_DISTANCE) { Reset(commons); if (DoneAction != null) DoneAction(commons, eventDriver); } else { eventDriver.Schedule(FramesPerRun, Run); } }
public void LowBattery(ZACommons commons, EventDriver eventDriver, bool started) { if (started) { // Just change the name of the first active antenna for (var e = ZACommons.GetBlocksOfType<IMyRadioAntenna>(commons.Blocks).GetEnumerator(); e.MoveNext();) { var antenna = e.Current; if (antenna.IsFunctional && antenna.IsWorking) { OldAntennaName = antenna.CustomName; antenna.SetCustomName(Message); break; } } } else { // Scan for the antenna with the message, change it back for (var e = ZACommons.GetBlocksOfType<IMyRadioAntenna>(commons.Blocks).GetEnumerator(); e.MoveNext();) { var antenna = e.Current; if (antenna.CustomName == Message) { antenna.SetCustomName(OldAntennaName); break; } } } }
public void Init(ZACommons commons, EventDriver eventDriver, double maxError, Base6Directions.Direction thrusterDirection = Base6Directions.Direction.Forward) { MaxError = maxError; ThrusterDirection = thrusterDirection; var shipControl = (ShipControlCommons)commons; var forward = shipControl.ShipBlockOrientation.TransformDirection(ThrusterDirection); // Don't really care about "up," just pick a perpindicular direction seeker.Init(shipControl, shipUp: Base6Directions.GetPerpendicular(forward), shipForward: forward); var gyroControl = shipControl.GyroControl; gyroControl.Reset(); gyroControl.EnableOverride(true); LastPosition = shipControl.ReferencePoint; Enabled = true; shipControl.ThrustControl.Enable(false); eventDriver.Schedule(SampleDelay, DetermineVelocity); }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument, Action<ZACommons, Vector3D> targetAction) { argument = argument.Trim().ToLower(); switch (argument) { case "compute": var firstReference = GetReference(commons, STATIC_REFERENCE_GROUP); var rotorReference = GetReference(commons, ROTOR_REFERENCE_GROUP); var first = new Rangefinder.LineSample(firstReference); var second = new Rangefinder.LineSample(rotorReference); Vector3D closestFirst, closestSecond; if (Rangefinder.Compute(first, second, out closestFirst, out closestSecond)) { // Take midpoint of closestFirst-closestSecond segment var target = (closestFirst + closestSecond) / 2.0; targetAction(commons, target); } break; default: rotorStepper.HandleCommand(commons, eventDriver, argument); break; } }
public void Run(ZACommons commons, EventDriver eventDriver) { var vents = ZACommons.GetBlocksOfType<IMyAirVent>(commons.AllBlocks, vent => vent.IsFunctional && vent.CustomName.IndexOf("[Excluded]", ZACommons.IGNORE_CASE) < 0 && vent.CustomName.IndexOf("[Intake]", ZACommons.IGNORE_CASE) < 0); vents.ForEach(block => { var vent = (IMyAirVent)block; var level = vent.GetOxygenLevel(); if (vent.IsDepressurizing && !vent.Enabled && level > 0.0f) { vent.SetValue<bool>("OnOff", true); } else if (!vent.IsDepressurizing) { if (level < MIN_AIR_VENT_PRESSURE && !vent.Enabled) { vent.SetValue<bool>("OnOff", true); } else if (level > MAX_AIR_VENT_PRESSURE && vent.Enabled) { vent.SetValue<bool>("OnOff", false); } } }); eventDriver.Schedule(RunDelay, Run); }
private void CloseDoors(ZACommons commons, EventDriver eventDriver, List<IMyTerminalBlock> doors, double openDurationSeconds) { var openDuration = TimeSpan.FromSeconds(openDurationSeconds); doors.ForEach(block => { var door = (IMyDoor)block; if (door.Open) { TimeSpan closeTime; if (opened.TryGetValue(door, out closeTime)) { if (closeTime <= eventDriver.TimeSinceStart) { // Time to close it door.SetValue<bool>("Open", false); opened.Remove(door); } } else { opened.Add(door, eventDriver.TimeSinceStart + openDuration); } } else { opened.Remove(door); } }); }
private void Start(ZACommons commons, EventDriver eventDriver, bool auto) { Show(commons); if (Mode == IDLE) eventDriver.Schedule(RunDelay, Run); Mode = auto ? AUTO : ACTIVE; SaveMode(commons); }
public void Run(ZACommons commons, EventDriver eventDriver) { if (Indexes.Count == 0) return; var newIndexes = new Dictionary<string, int>(); for (var e = Indexes.GetEnumerator(); e.MoveNext();) { var kv = e.Current; var sequence = kv.Key; var index = kv.Value; var blocks = GetSequenceBlocks(commons, sequence); if (blocks == null) continue; ZACommons.EnableBlocks(blocks, false); // TODO sort? index++; index %= blocks.Count; blocks[index].SetValue<bool>("OnOff", true); newIndexes.Add(sequence, index); } Indexes = newIndexes; eventDriver.Schedule(SEQUENCER_FRAMES_PER_RUN, Run); }
public void Run(ZACommons commons, EventDriver eventDriver) { var myConnectors = ZACommons.GetBlocksOfType<IMyShipConnector>(commons.Blocks, block => block.DefinitionDisplayNameText == "Connector" && ((IMyShipConnector)block).IsLocked && ((IMyShipConnector)block).IsConnected); var currentConnectorCount = myConnectors.Count; if (currentConnectorCount > ConnectorCount) { // New connection, force re-evaluation State = null; } ConnectorCount = currentConnectorCount; var myReactors = ZACommons.GetBlocksOfType<IMyReactor>(commons.Blocks, block => block.IsWorking); var currentState = myReactors.Count > 0; // Only on state change if (State == null || currentState != (bool)State) { State = currentState; if (!(bool)State) { // Disable reactors on all connected grids var reactors = ZACommons.GetBlocksOfType<IMyReactor>(commons.AllBlocks, block => block.CubeGrid != commons.Me.CubeGrid); reactors.ForEach(block => block.SetValue<bool>("OnOff", false)); } } eventDriver.Schedule(RunDelay, Run); }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { argument = argument.Trim().ToLower(); var parts = argument.Split(new char[] { ' ' }, 2); if (parts.Length != 2 || parts[0] != "damecon") return; var command = parts[1]; switch (command) { case "reset": case "stop": commons.AllBlocks.ForEach(block => { if (block.GetProperty("ShowOnHUD") != null) block.SetValue<bool>("ShowOnHUD", false); }); ResetMode(commons); break; case "show": Show(commons); ResetMode(commons); break; case "start": Start(commons, eventDriver, false); break; case "auto": Start(commons, eventDriver, true); break; } }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { var command = argument.Trim().ToLower(); switch (command) { case "start": { var shipControl = (ShipControlCommons)commons; SetTarget(shipControl); Start(shipControl, eventDriver); SaveTarget(shipControl); } break; case "reverse": { var shipControl = (ShipControlCommons)commons; SetTarget(shipControl); StartReverse(shipControl, eventDriver); SaveTarget(shipControl); } break; case "stop": { var shipControl = (ShipControlCommons)commons; shipControl.Reset(gyroOverride: false); Mode = IDLE; ForgetTarget(shipControl); } break; } }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { var command = argument.Trim().ToLower(); switch (command) { case "reactors": { // Turn on all reactors GetAllReactors(commons).ForEach(block => block.SetValue<bool>("OnOff", true)); eventDriver.Schedule(1.0, (c,ed) => { // Turn off all local batteries GetBatteries(c).ForEach(block => block.SetValue<bool>("OnOff", false)); }); break; } case "batteries": { // Turn on all local batteries // and disable recharge/discharge GetBatteries(commons).ForEach(block => { block.SetValue<bool>("OnOff", true); block.SetValue<bool>("Recharge", false); block.SetValue<bool>("Discharge", false); }); eventDriver.Schedule(1.0, (c,ed) => { // Turn off all reactors GetAllReactors(c).ForEach(block => block.SetValue<bool>("OnOff", false)); }); break; } } }
public void DockingAction(ZACommons commons, EventDriver eventDriver, bool docked) { var wheels = ZACommons.GetBlocksOfType<IMyMotorSuspension>(commons.Blocks); ZACommons.EnableBlocks(wheels, !docked); if (!docked) { // Set suspension strength to configured value wheels.ForEach(wheel => { wheel.SetValue<float>("Strength", UNDOCK_SUSPENSION_STRENGTH); }); } else { // Apply handbrake var controllers = ZACommons.GetBlocksOfType<IMyShipController>(commons.Blocks); controllers.ForEach(controller => { if (!((IMyShipController)controller).HandBrake) { controller.SetValue<bool>("HandBrake", true); } }); } }
public void Prime(ZACommons commons, EventDriver eventDriver) { // Wake up batteries var batteryGroup = commons.GetBlockGroupWithName(BATTERY_GROUP + MISSILE_GROUP_SUFFIX); if (batteryGroup == null) { throw new Exception("Group missing: " + BATTERY_GROUP + MISSILE_GROUP_SUFFIX); } var systemsGroup = commons.GetBlockGroupWithName(SYSTEMS_GROUP + MISSILE_GROUP_SUFFIX); if (systemsGroup == null) { throw new Exception("Group missing: " + SYSTEMS_GROUP + MISSILE_GROUP_SUFFIX); } var batteries = ZACommons.GetBlocksOfType<IMyBatteryBlock>(batteryGroup.Blocks); batteries.ForEach(battery => { battery.SetValue<bool>("OnOff", true); battery.SetValue<bool>("Recharge", false); battery.SetValue<bool>("Discharge", true); }); // Activate flight systems ZACommons.EnableBlocks(systemsGroup.Blocks, true); eventDriver.Schedule(1.0, Release); }
public void Init(ZACommons commons, EventDriver eventDriver, params DockingHandler[] dockingHandlers) { DockingHandlers = dockingHandlers; var docked = ZACommons.IsConnectedAnywhere(commons.Blocks); ManageShip(commons, eventDriver, docked); }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { argument = argument.Trim().ToLower(); var parts = argument.Split(new char[] { ' ' }, 3); if (parts.Length < 3 || parts[0] != "sequence") return; var command = parts[1]; var sequence = parts[2]; if (command == "start") { var blocks = GetSequenceBlocks(commons, sequence); if (blocks == null) return; ZACommons.EnableBlocks(blocks, false); blocks[0].SetValue<bool>("OnOff", true); var first = Indexes.Count == 0; if (!Indexes.ContainsKey(sequence)) Indexes.Add(sequence, 0); if (first) { eventDriver.Schedule(SEQUENCER_FRAMES_PER_RUN, Run); } } else if (command == "stop") { var blocks = GetSequenceBlocks(commons, sequence); if (blocks != null) ZACommons.EnableBlocks(blocks, true); Indexes.Remove(sequence); } }
public void Run(ZACommons commons, EventDriver eventDriver) { var groups = commons.GetBlockGroupsWithPrefix(DOOR_AUTO_CLOSER_PREFIX); if (groups.Count > 0) { groups.ForEach(group => { // Determine open duration var parts = group.Name.Split(new char[] { DURATION_DELIMITER }, 2); var duration = DEFAULT_DOOR_OPEN_DURATION; if (parts.Length == 2) { if (!double.TryParse(parts[1], out duration)) { duration = DEFAULT_DOOR_OPEN_DURATION; } } var doors = ZACommons.GetBlocksOfType<IMyDoor>(group.Blocks, block => block.IsFunctional); CloseDoors(commons, eventDriver, doors, duration); }); } else { // Default behavior (all doors except vanilla Airtight Hangar Doors and tagged doors) var doors = ZACommons .GetBlocksOfType<IMyDoor>(commons.Blocks, block => block.IsFunctional && block.CustomName.IndexOf("[Excluded]", ZACommons.IGNORE_CASE) < 0 && block.DefinitionDisplayNameText != "Airtight Hangar Door"); CloseDoors(commons, eventDriver, doors, DEFAULT_DOOR_OPEN_DURATION); } eventDriver.Schedule(RunDelay, Run); }
public void Demass(ZACommons commons, EventDriver eventDriver) { var shipControl = (ShipControlCommons)commons; var deltaTime = (eventDriver.TimeSinceStart - InitialTime).TotalSeconds; var launcherDelta = LauncherVelocity * deltaTime; var distanceFromLauncher = (shipControl.ReferencePoint - (InitialPosition + launcherDelta)).LengthSquared(); if (distanceFromLauncher < DemassDistance * DemassDistance) { // Not yet eventDriver.Schedule(TicksPerRun, Demass); return; } // Disable mass var group = commons.GetBlockGroupWithName(MASS_GROUP); if (group != null) ZACommons.EnableBlocks(group.Blocks, false); // Start roll shipControl.GyroControl.EnableOverride(true); shipControl.GyroControl.SetAxisVelocity(GyroControl.Roll, MathHelper.Pi); // All done if (PostLaunch != null) PostLaunch(commons, eventDriver); }
public void Init(ZACommons commons, EventDriver eventDriver) { pid.Kp = RotorKp; pid.Ki = RotorKi; pid.Kd = RotorKd; UpdateStepAmount(commons); }
public void Init(ZACommons commons, EventDriver eventDriver, Action<ZACommons, EventDriver> postLaunch = null) { PostLaunch = postLaunch; InitialPosition = ((ShipControlCommons)commons).ReferencePoint; InitialTime = eventDriver.TimeSinceStart; eventDriver.Schedule(0.0, Prime); }
public void Run(ZACommons commons, EventDriver eventDriver) { if (IsDocked) return; RunInternal(commons, eventDriver); eventDriver.Schedule(RunDelay, Run); }
public void Init(ZACommons commons, EventDriver eventDriver) { Active = true; SaveActive(commons); MaxPowers.Clear(); TotalPower = 0.0f; eventDriver.Schedule(0.0, Run); }
public void DHRun(ZACommons commons, EventDriver eventDriver) { if (IsDocked) return; Run(commons); eventDriver.Schedule(RunDelay, DHRun); }
public void SafeMode(ZACommons commons, EventDriver eventDriver) { // Check after 1 second (let timer block's action take effect) eventDriver.Schedule(1.0, (c,ed) => { new EmergencyStop().SafeMode(c, ed); }); }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { argument = argument.Trim().ToLower(); var parts = argument.Split(new char[] { ' ' }, 2); if (parts.Length < 2 || parts[0] != "projaction") return; DoAction(commons, eventDriver, parts[1]); }
public void MainBurn(ZACommons commons, EventDriver eventDriver) { var shipControl = (ShipControlCommons)commons; var thrustControl = shipControl.ThrustControl; thrustControl.SetOverride(Base6Directions.Direction.Down, false); thrustControl.SetOverride(Base6Directions.Direction.Forward, BURN_FRACTION); eventDriver.Schedule(BURN_TIME, Arm); }
public void PreDock(ZACommons commons, EventDriver eventDriver) { // Lower suspension strength all the way var wheels = ZACommons.GetBlocksOfType<IMyMotorSuspension>(commons.Blocks); wheels.ForEach(wheel => { wheel.SetValue<float>("Strength", wheel.GetMinimum<float>("Strength")); }); }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { var command = argument.Trim().ToLower(); if (command == "safemode") { TriggerSafeMode(commons, eventDriver); } }
private bool ShouldAbort(ZACommons commons, EventDriver eventDriver, Modes expectedMode, bool ignoreLiveness) { if (!ignoreLiveness && LivenessCheck != null && !LivenessCheck(commons, eventDriver)) { Reset((ShipControlCommons)commons); } return(Mode != expectedMode); }
public void PreDock(ZACommons commons, EventDriver eventDriver) { // Lower suspension strength all the way var wheels = ZACommons.GetBlocksOfType <IMyMotorSuspension>(commons.Blocks); wheels.ForEach(wheel => { wheel.SetValue <float>("Strength", wheel.GetMinimum <float>("Strength")); }); }
private void Start(ZACommons commons, EventDriver eventDriver, bool auto) { Show(commons); if (Mode == Modes.Idle) { eventDriver.Schedule(RunDelay, Run); } Mode = auto ? Modes.Auto : Modes.Active; SaveMode(commons); }
public void MainBurn(ZACommons commons, EventDriver eventDriver) { var shipControl = (ShipControlCommons)commons; var thrustControl = shipControl.ThrustControl; thrustControl.SetOverride(DETACH_BURN_DIRECTION, false); thrustControl.SetOverride(Base6Directions.Direction.Forward, BURN_FRACTION); eventDriver.Schedule(BURN_TIME, Arm); }
private void Start(ZACommons commons, EventDriver eventDriver, bool auto) { Show(commons); if (Mode == IDLE) { eventDriver.Schedule(RunDelay, Run); } Mode = auto ? AUTO : ACTIVE; SaveMode(commons); }
public void Init(ZACommons commons, EventDriver eventDriver) { IsControlled = null; ResetAbandonment(eventDriver); IsDocked = false; eventDriver.Schedule(0.0, Fast); eventDriver.Schedule(0.0, Slow); }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { argument = argument.ToLower().Trim(); if (argument == "reset") { turretInfos.Clear(); Triggered = false; } }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { argument = argument.Trim().ToLower(); if (CommandPrefix != null) { var parts = argument.Split(new char[] { ' ' }, 2); if (parts.Length != 2 || !parts[0].Equals(CommandPrefix, ZACommons.IGNORE_CASE)) { return; } argument = parts[1]; } switch (argument) { case "left": SetPoint -= StepAmount; Schedule(eventDriver); break; case "right": SetPoint += StepAmount; Schedule(eventDriver); break; case "reset": SetPoint = 0.0; Schedule(eventDriver); break; case "factorup": StepFactor++; UpdateStepAmount(commons); Schedule(eventDriver); break; case "factordown": StepFactor--; UpdateStepAmount(commons); Schedule(eventDriver); break; case "factorreset": StepFactor = -1; UpdateStepAmount(commons); Schedule(eventDriver); break; default: break; } }
private void RunInternal(ZACommons commons, EventDriver eventDriver) { var lowBattery = ZACommons.GetBlockWithName <IMyTimerBlock>(commons.Blocks, LOW_BATTERY_NAME); // Don't bother if there's no timer block or handler if (lowBatteryHandler == null && lowBattery == null) { return; } var batteries = ZACommons.GetBlocksOfType <IMyBatteryBlock>(commons.Blocks, battery => battery.IsFunctional && ((IMyBatteryBlock)battery).Enabled); // Avoid divide-by-zero in case there are no batteries if (batteries.Count == 0) { return; } var currentStoredPower = 0.0f; var maxStoredPower = 0.0f; // Hmm, doesn't check battery recharge state... // With the "full-auto mode" (if it worked as advertised), // it probably doesn't make sense to check input/output state anyway for (var e = batteries.GetEnumerator(); e.MoveNext();) { var battery = e.Current as IMyBatteryBlock; currentStoredPower += battery.CurrentStoredPower; maxStoredPower += battery.MaxStoredPower; } var batteryPercent = currentStoredPower / maxStoredPower; if (!Triggered && batteryPercent < BATTERY_THRESHOLD) { Triggered = true; if (lowBatteryHandler != null) { lowBatteryHandler.LowBattery(commons, eventDriver, true); } if (lowBattery != null) { lowBattery.ApplyAction("Start"); } } else if (Triggered && batteryPercent >= BATTERY_THRESHOLD) { Triggered = false; if (lowBatteryHandler != null) { lowBatteryHandler.LowBattery(commons, eventDriver, false); } } }
private void Burn(ZACommons commons, EventDriver eventDriver) { var velocity = velocimeter.GetAverageVelocity(); if (velocity != null) { var shipControl = (ShipControlCommons)commons; cruiser.Cruise(shipControl, FULL_BURN_SPEED, (Vector3D)velocity, enableBackward: false); } }
public void Arm(ZACommons commons, EventDriver eventDriver) { // Find all warheads on board and turn off safeties var warheads = ZACommons.GetBlocksOfType <IMyWarhead>(commons.Blocks); warheads.ForEach(warhead => warhead.IsArmed = true); // We're done, let other systems take over Launched = true; PostLaunch(commons, eventDriver); }
public void Run(ZACommons commons, EventDriver eventDriver) { if (IsDocked) { return; } RunInternal(commons, eventDriver); eventDriver.Schedule(RunDelay, Run); }
public void Init(ZACommons commons, EventDriver eventDriver) { var shipControl = (ShipControlCommons)commons; seeker.Init(shipControl, shipUp: shipControl.ShipUp, shipForward: shipControl.ShipForward); eventDriver.Schedule(0, Run); eventDriver.Schedule(FULL_BURN_DELAY, FullBurn); }
public void DHRun(ZACommons commons, EventDriver eventDriver) { if (IsDocked) { return; } Run(commons); eventDriver.Schedule(RunDelay, DHRun); }
public void Run(ZACommons commons, EventDriver eventDriver) { var shipControl = (ShipControlCommons)commons; ResetIfNotLive(commons, eventDriver); if (!Active) { return; } // Determine velocity var velocity = shipControl.LinearVelocity; // If we have no velocity, we have no ship controllers. // In theory, ResetIfNotLive should have caught it above if (velocity != null) { var cruiseDirectionFlipped = Base6Directions.GetFlippedDirection(CruiseDirection); // Determine forward vector var forward3I = shipControl.Reference.Position + Base6Directions.GetIntVector(shipControl.ShipBlockOrientation.TransformDirection(CruiseDirection)); var forward = Vector3D.Normalize(shipControl.Reference.CubeGrid.GridIntegerToWorld(forward3I) - shipControl.ReferencePoint); CurrentSpeed = Vector3D.Dot((Vector3D)velocity, forward); var error = TargetSpeed - CurrentSpeed; var force = thrustPID.Compute(error); //commons.Echo("Force: " + force); var thrustControl = shipControl.ThrustControl; var collect = ParseCruiseFlags(); if (Math.Abs(error) < CRUISE_CONTROL_DEAD_ZONE * TargetSpeed) { // Close enough, just disable both sets of thrusters thrustControl.Enable(CruiseDirection, false, collect); thrustControl.Enable(cruiseDirectionFlipped, false, collect); } else if (force > 0.0) { // Thrust forward thrustControl.Enable(CruiseDirection, true, collect); thrustControl.SetOverride(CruiseDirection, force, collect); thrustControl.Enable(cruiseDirectionFlipped, false, collect); } else { thrustControl.Enable(CruiseDirection, false, collect); thrustControl.Enable(cruiseDirectionFlipped, true, collect); thrustControl.SetOverride(cruiseDirectionFlipped, -force, collect); } } eventDriver.Schedule(FramesPerRun, Run); }
public void Init(ZACommons commons, EventDriver eventDriver, Vector3D target, double speed, double delay = 1.0) { if (!AutopilotEngaged) { AutopilotTarget = target; AutopilotSpeed = speed; AutopilotEngaged = true; eventDriver.Schedule(delay, Start); } }
private void BeginUndock(ZACommons commons, EventDriver eventDriver) { var shipControl = (ShipControlCommons)commons; autopilot.Init(commons, eventDriver, (Vector3D)UndockTarget, SMART_UNDOCK_UNDOCK_SPEED, delay: 2.0, localForward: shipControl.ShipBlockOrientation.TransformDirectionInverse((Base6Directions.Direction)UndockBackward), doneAction: (c, ed) => { ResetMode(c); }); }
public void Release(ZACommons commons, EventDriver eventDriver) { var relayRelease = commons.GetBlockGroupWithName(RELEASE_GROUP); if (relayRelease == null) { throw new Exception("Missing group: " + RELEASE_GROUP); } ZACommons.EnableBlocks(relayRelease.Blocks, false); eventDriver.Schedule(1.0, Burn); }
public void Init(ZACommons commons, EventDriver eventDriver) { pid.Kp = PistonKp; pid.Ki = PistonKi; pid.Kd = PistonKd; var piston = GetPiston(commons); BasePistonStep = piston.CubeGrid.GridSize; UpdateStepAmount(commons); }
private void TriggerSafeMode(ZACommons commons, EventDriver eventDriver, string timerBlockName = SAFE_MODE_NAME) { Abandoned = true; // No need to trigger any other condition until reset for (var i = 0; i < SafeModeHandlers.Length; i++) { SafeModeHandlers[i].SafeMode(commons, eventDriver); } ZACommons.StartTimerBlockWithName(commons.Blocks, timerBlockName); }
public void Cleanup(ZACommons commons, EventDriver eventDriver) { // Clean up received pings var toDelete = ReceivedInfos.Where((kv, index) => kv.Value.ExpireTime <= eventDriver.TimeSinceStart).ToArray(); foreach (var kv in toDelete) { ReceivedInfos.Remove(kv.Key); } eventDriver.Schedule(RunDelay, Cleanup); }
public void Init(ZACommons commons, EventDriver eventDriver, Func <ZACommons, EventDriver, bool> livenessCheck = null) { LivenessCheck = livenessCheck; var lastCommand = commons.GetValue(LastCommandKey); if (lastCommand != null) { HandleCommand(commons, eventDriver, lastCommand); } }
public void Run(ZACommons commons, EventDriver eventDriver) { var shipControl = (ShipControlCommons)commons; Vector3D?velocity = shipControl.LinearVelocity; if (velocity != null) { // Vector from launcher to missile var launcherVector = shipControl.ReferencePoint - LauncherReferencePoint; // Determine projection on launcher direction vector var launcherDot = launcherVector.Dot(LauncherReferenceDirection); var launcherProj = launcherDot * LauncherReferenceDirection; Vector3D prediction; if (launcherDot >= 0.0) { // Set prediction to that projection prediction = launcherProj; } else { // Or set it to the launcher (0,0,0) if the missile is // behind the launcher prediction = new Vector3D(0, 0, 0); } // Offset forward by some amount prediction += LEAD_DISTANCE * LauncherReferenceDirection; // Offset by launcher position prediction += LauncherReferencePoint; // Determine relative vector to aim point var targetVector = prediction - shipControl.ReferencePoint; // Project onto our velocity var velocityNorm = Vector3D.Normalize((Vector3D)velocity); var forwardProj = velocityNorm * Vector3D.Dot(targetVector, velocityNorm); // Use scaled rejection for oversteer var forwardRej = (targetVector - forwardProj) * OVERSTEER_FACTOR; // Add to projection to get adjusted aimpoint var aimPoint = forwardProj + forwardRej; double yawPitchError; seeker.Seek(shipControl, aimPoint, out yawPitchError); } else { // Can't really do crap w/o our own velocity shipControl.GyroControl.Reset(); } eventDriver.Schedule(FramesPerRun, Run); }
public void Init(ZACommons commons, EventDriver eventDriver) { var shipControl = (ShipControlCommons)commons; shipControl.GyroControl.Reset(); shipControl.GyroControl.EnableOverride(true); seeker.Init(shipControl, shipUp: shipControl.ShipUp, shipForward: shipControl.ShipForward); eventDriver.Schedule(0, Run); }
public void Init(ZACommons commons, EventDriver eventDriver) { commons.Blocks.ForEach(block => { if (block is IMyProgrammableBlock || block is IMyTimerBlock) { BlocksToCheck.Add(block); } }); StartPoint = ((ShipControlCommons)commons).ReferencePoint; eventDriver.Schedule(0, Run); }
private void RunInternal(ZACommons commons, EventDriver eventDriver, string argument) { Init(commons); if (!string.IsNullOrWhiteSpace(argument)) { HandleCommandInternal(argument); } OpenCloseDoorsAsNeeded(eventDriver); Clear(); }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { argument = argument.Trim().ToLower(); var parts = argument.Split(new char[] { ' ' }, 2); if (parts.Length < 2 || parts[0] != "projaction") { return; } DoAction(commons, eventDriver, parts[1]); }
public void HandleCommand(ZACommons commons, EventDriver eventDriver, string argument) { if (Triggered) { return; } argument = argument.Trim().ToLower(); if (argument == "firefirefire") { Triggered = true; TriggerAction(commons, eventDriver); } }
public void DockingAction(ZACommons commons, EventDriver eventDriver, bool docked) { if (docked) { IsDocked = true; } else if (IsDocked) { IsDocked = false; eventDriver.Schedule(RunDelay, DHRun); } }