public Program() { // Retrieve the blocks we're going to use. blocks = new ExpectedBlocks(GridTerminalSystem); _panelLight = blocks.GetBlock <IMyInteriorLight>("Interior Light"); _textPanel = blocks.GetBlock <IMyTextPanel>("LCD Panel"); }
public ThrustControl(ExpectedBlocks blocks) { thrusters = blocks.GetBlocks <IMyThrust>(CRANE_ARM_THRUSTER); rotor = blocks.GetBlock <IMyMotorStator>(CRANE_ARM_ROTOR); piston = blocks.GetBlock <IMyPistonBase>(CRANE_ARM_PISTON); thrust = thrusters[0].ThrustOverride / 1000; targetAngle = BOTTOM_ANGLE; previousAngle = ConvertAngle(rotor.Angle); speedHistory = new float[60]; accelerationHistory = new float[120]; }
public PayloadTransportStateMachine(ExpectedBlocks blocks, ThrustControl thrustControl) { craneArmRotor = blocks.GetBlock <IMyMotorStator>(CRANE_ARM_ROTOR); craneLiftPistons = blocks.GetBlocks <IMyPistonBase>(CRANE_LIFT_PISTON); this.thrustControl = thrustControl; }
public void Main(string argument, UpdateType updateType) { if ((updateType & UpdateType.Update1) == UpdateType.Update1) { thrustControl.Update(); blocks.GetBlock <IMyTextPanel>(CRANE_ARM_STATUS_PANEL).WritePublicText("Crane Arm Status\n\n" + "Program\n" + " State: " + state.ToString() + "\n\n" + thrustControl.GetDebugText()); } if ((updateType & UpdateType.Terminal) == UpdateType.Terminal || (updateType & UpdateType.Trigger) == UpdateType.Trigger) { switch (argument) { case LOW: thrustControl.Adjust(ThrustControl.BOTTOM_ANGLE); break; case HIGH: thrustControl.Adjust(ThrustControl.TOP_ANGLE); break; case PICKUP: if (state == State.WaitingForPayload) { state = State.AcceptingPayload; stateMachine = payloadPickupStateMachine.GenerateStateMachine(); Runtime.UpdateFrequency |= UpdateFrequency.Once; } break; case DUMP: if (state == State.WaitingForTransport || state == State.WaitingForPayload) { blocks.GetBlocks <IMyShipConnector>(CRANE_ARM_CONNECTOR).ForEach(connector => { connector.Disconnect(); connector.Enabled = false; }); thrustControl.OverrideThrust(50); state = State.WaitingForPayload; } break; case TRANSPORT: if (state == State.WaitingForTransport) { state = State.TransportingPayload; stateMachine = payloadTransportStateMachine.GenerateStateMachine(); Runtime.UpdateFrequency |= UpdateFrequency.Once; } break; case DROPOFF: if (state == State.WaitingForDropoff) { blocks.GetBlocks <IMyShipConnector>(CRANE_ARM_CONNECTOR).ForEach(connector => { connector.Disconnect(); connector.Enabled = false; }); state = State.WaitingForReset; } break; case RESET: state = State.Reseting; stateMachine = craneArmResetStateMachine.GenerateStateMachine(); Runtime.UpdateFrequency |= UpdateFrequency.Once; break; default: if (argument.Length == 0) { Echo("ERROR Missing argument"); } else { Echo("ERROR Unrecognized argument: " + argument); } break; } } if ((updateType & UpdateType.Once) == UpdateType.Once) { RunStateMachine(); } }