void RunContinuousLogic() { quantity = DrillCount(); if (quantity > 10 && quantity > lastQuantity) { slowDown = true; } lastQuantity = quantity; Display(); if (quantity > 10000) { stateMachine = StateMachine.Waitting; } switch (stateMachine) { case StateMachine.Initializing: Initializing(); break; case StateMachine.Running: Running(); break; case StateMachine.RotorZero: RotorZero(); break; case StateMachine.Stopping: pistonUp.Off(); pistonDown.Off(); pistonRayon.Off(); stators.Lock(); drills.Off(); break; case StateMachine.Waitting: pistonUp.Off(); pistonDown.Off(); pistonRayon.Off(); stators.Lock(); drills.Off(); if (quantity == 0) { stateMachine = StateMachine.Running; } break; } }
public void Search() { BlockFilter <IMyDoor> block_filter_doors = BlockFilter <IMyDoor> .Create(program.Me, $"G:{GroupFilter}"); doors = BlockSystem <IMyDoor> .SearchByFilter(program, block_filter_doors); BlockFilter <IMyAirVent> block_filter_airvent = BlockFilter <IMyAirVent> .Create(program.Me, $"G:{GroupFilter}"); airvent = BlockSystem <IMyAirVent> .SearchByFilter(program, block_filter_airvent); BlockFilter <IMyTextPanel> block_filter_control = BlockFilter <IMyTextPanel> .Create(program.Me, $"G:{GroupFilter}"); control_panel = BlockSystem <IMyTextPanel> .SearchByFilter(program, block_filter_control); BlockFilter <IMyLightingBlock> block_filter_light = BlockFilter <IMyLightingBlock> .Create(program.Me, $"G:{GroupFilter}"); light = BlockSystem <IMyLightingBlock> .SearchByFilter(program, block_filter_light); BlockFilter <IMySoundBlock> block_filter_sound = BlockFilter <IMySoundBlock> .Create(program.Me, $"G:{GroupFilter}"); sound = BlockSystem <IMySoundBlock> .SearchByFilter(program, block_filter_sound); if (control_panel != null) { control_panel.ForEach(delegate(IMyTextPanel block) { block.ScriptBackgroundColor = Color.Black; }); } if (light != null) { light.ForEach(delegate(IMyLightingBlock block) { block.Color = program.MyProperty.GetColor("Airlock", "running_color"); }); light.Off(); } }
private void RunCommand(string argument) { if (argument != null) { commandLine.TryParse(argument); var command = commandLine.Argument(0); if (commandLine.ArgumentCount > 1) { string cycle = commandLine.Argument(1); int.TryParse(cycle, out Cycle); } else { Cycle = 1; } switch (command.ToLower()) { case "init": Init(); break; case "stop": LastMode = Mode; drills.Off(); Mode = ModeMachine.Stop; break; case "start": drills.On(); Mode = LastMode; if (Mode == ModeMachine.Down) { projector.On(); } break; case "lock": Stage = 0; Mode = ModeMachine.Lock; Sequence = new List <ActionMachine>(); Sequence.Add(ActionMachine.Start); Sequence.Add(ActionMachine.LockBottom); Sequence.Add(ActionMachine.LockTop); Sequence.Add(ActionMachine.Stop); Sequence.Add(ActionMachine.Terminated); break; case "lockbottom": Stage = 0; Mode = ModeMachine.LockBottom; Sequence = new List <ActionMachine>(); Sequence.Add(ActionMachine.Start); Sequence.Add(ActionMachine.LockBottom); Sequence.Add(ActionMachine.Stop); Sequence.Add(ActionMachine.Terminated); break; case "unlockbottom": Stage = 0; Mode = ModeMachine.UnlockBottom; Sequence = new List <ActionMachine>(); Sequence.Add(ActionMachine.Start); Sequence.Add(ActionMachine.UnlockBottom); Sequence.Add(ActionMachine.Stop); Sequence.Add(ActionMachine.Terminated); break; case "locktop": Stage = 0; Mode = ModeMachine.LockTop; Sequence = new List <ActionMachine>(); Sequence.Add(ActionMachine.Start); Sequence.Add(ActionMachine.LockTop); Sequence.Add(ActionMachine.Stop); Sequence.Add(ActionMachine.Terminated); break; case "unlocktop": Stage = 0; Mode = ModeMachine.UnlockTop; Sequence = new List <ActionMachine>(); Sequence.Add(ActionMachine.Start); Sequence.Add(ActionMachine.UnlockTop); Sequence.Add(ActionMachine.Stop); Sequence.Add(ActionMachine.Terminated); break; case "startwelder": Stage = 0; Mode = ModeMachine.LockTop; Sequence = new List <ActionMachine>(); Sequence.Add(ActionMachine.Start); Sequence.Add(ActionMachine.StartWelder); Sequence.Add(ActionMachine.Stop); Sequence.Add(ActionMachine.Terminated); break; case "stopwelder": Stage = 0; Mode = ModeMachine.UnlockTop; Sequence = new List <ActionMachine>(); Sequence.Add(ActionMachine.Start); Sequence.Add(ActionMachine.StopWelder); Sequence.Add(ActionMachine.Stop); Sequence.Add(ActionMachine.Terminated); break; case "down": Stage = 0; Mode = ModeMachine.Down; Sequence = new List <ActionMachine>(); Sequence.Add(ActionMachine.Start); Sequence.Add(ActionMachine.UnlockBottom); Sequence.Add(ActionMachine.StartWelder); Sequence.Add(ActionMachine.Down); Sequence.Add(ActionMachine.StopWelder); Sequence.Add(ActionMachine.LockBottom); Sequence.Add(ActionMachine.UnlockTop); Sequence.Add(ActionMachine.Up); Sequence.Add(ActionMachine.LockTop); Sequence.Add(ActionMachine.Stop); Sequence.Add(ActionMachine.Terminated); break; case "up": Stage = 0; Mode = ModeMachine.Up; Sequence = new List <ActionMachine>(); Sequence.Add(ActionMachine.Start); Sequence.Add(ActionMachine.UnlockTop); Sequence.Add(ActionMachine.Down); Sequence.Add(ActionMachine.LockTop); Sequence.Add(ActionMachine.UnlockBottom); Sequence.Add(ActionMachine.StartGrinder); Sequence.Add(ActionMachine.Up); Sequence.Add(ActionMachine.StopGrinder); Sequence.Add(ActionMachine.LockBottom); Sequence.Add(ActionMachine.Stop); Sequence.Add(ActionMachine.Terminated); break; case "reset": Mode = ModeMachine.Reset; Stage = 0; break; } } }
private void Staging(ActionMachine action) { bool closed = true; float position_target = 0f; float velocity = 0f; switch (action) { case ActionMachine.LockBottom: velocity = -MyProperty.locker_velocity; position_target = MyProperty.locker_position_min; bottom_mergers.On(); bottom_pistons.Velocity(velocity); WriteText($"Bottom mergers: On", true); WriteText($"Velocity: {velocity}", true); WriteText($"Target Position={position_target}", true); closed = true; bottom_pistons.ForEach(delegate(IMyPistonBase block) { WriteText($"Position={block.CurrentPosition}", true); }); if (bottom_pistons.IsLessPosition(position_target)) { Stage++; } break; case ActionMachine.UnlockBottom: closed = true; top_mergers.ForEach(delegate(IMyShipMergeBlock block) { if (!block.IsConnected) { closed = false; } }); if (!closed) { WriteText($"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", true); WriteText($"Security: Top mergers is Off", true); } else { velocity = MyProperty.locker_velocity; position_target = MyProperty.locker_position_max; bottom_mergers.Off(); bottom_pistons.Velocity(velocity); WriteText($"Bottom mergers: Off", true); WriteText($"Velocity: {velocity}", true); WriteText($"Target Position={position_target}", true); closed = true; bottom_pistons.ForEach(delegate(IMyPistonBase block) { WriteText($"Position={block.CurrentPosition}", true); }); if (bottom_pistons.IsMorePosition(position_target)) { Stage++; } } break; case ActionMachine.LockTop: velocity = -MyProperty.locker_velocity; position_target = MyProperty.locker_position_min; top_mergers.On(); top_pistons.Velocity(velocity); WriteText($"Bottom mergers: On", true); WriteText($"Velocity: {velocity}", true); WriteText($"Target Position={position_target}", true); closed = true; top_pistons.ForEach(delegate(IMyPistonBase block) { WriteText($"Position={block.CurrentPosition}", true); }); if (top_pistons.IsLessPosition(position_target)) { connector.Lock(); Stage++; } break; case ActionMachine.UnlockTop: closed = true; bottom_mergers.ForEach(delegate(IMyShipMergeBlock block) { if (!block.IsConnected) { closed = false; } }); if (!closed) { WriteText($"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", true); WriteText($"Security: Bottom mergers is Off", true); } else { velocity = MyProperty.locker_velocity; position_target = MyProperty.locker_position_max; top_mergers.Off(); top_pistons.Velocity(velocity); connector.Unlock(); WriteText($"Top mergers: Off", true); WriteText($"Connector: Unlock", true); WriteText($"Velocity: {velocity}", true); WriteText($"Target Position={position_target}", true); closed = true; top_pistons.ForEach(delegate(IMyPistonBase block) { WriteText($"Position={block.CurrentPosition}", true); }); if (top_pistons.IsMorePosition(position_target)) { Stage++; } } break; case ActionMachine.Down: levage_pistons.On(); WriteText($"Piston Levage: On", true); velocity = MyProperty.elevator_velocity_min; if (Mode == ModeMachine.Up) { velocity = MyProperty.elevator_velocity_max; } WriteText($"Piston Velocity: {velocity}", true); levage_pistons.Velocity(velocity); position_target = MyProperty.elevator_position_max; WriteText($"Target Position={position_target}", true); levage_pistons.ForEach(delegate(IMyPistonBase block) { WriteText($"Position={block.CurrentPosition}", true); }); //projector_count = projector.List[0].RemainingBlocks; if (levage_pistons.IsMorePosition(position_target)) { Stage++; } break; case ActionMachine.Up: levage_pistons.On(); WriteText($"Piston Levage: On", true); velocity = -MyProperty.elevator_velocity_max; if (Mode == ModeMachine.Up) { velocity = -MyProperty.elevator_velocity_min; } WriteText($"Piston Velocity: {velocity}", true); levage_pistons.Velocity(velocity); position_target = MyProperty.elevator_position_min; WriteText($"Target Position={position_target}", true); levage_pistons.ForEach(delegate(IMyPistonBase block) { WriteText($"Position={block.CurrentPosition}", true); }); //projector_count = projector.List[0].RemainingBlocks; if (levage_pistons.IsLessPosition(position_target + 0.1f)) { Stage++; } break; case ActionMachine.StartWelder: projector.On(); welders.On(); WriteText($"Welders: On", true); Stage++; break; case ActionMachine.StopWelder: welders.Off(); projector.Off(); WriteText($"Welders: Off", true); Stage++; break; case ActionMachine.StartGrinder: grinders.On(); //projector.On(); WriteText($"Grinders: On", true); Stage++; break; case ActionMachine.StopGrinder: grinders.Off(); //projector.Off(); WriteText($"Grinders: Off", true); Stage++; break; case ActionMachine.Terminated: Cycle -= 1; if (Cycle == 0) { Mode = ModeMachine.Stop; } Stage = 0; break; case ActionMachine.Start: MyProperty.Load(); light.On(); drills.On(); Stage++; break; case ActionMachine.Stop: projector.Off(); light.Off(); drills.Off(); Stage++; break; } }
void Running() { delta = max_power - last_power; switch (machine_state) { case StateMachine.Stopped: lat_stators.Off(); lat_stators.Lock(); lon_stators.Off(); lon_stators.Lock(); if (Math.Abs(delta) > MyProperty.Lat_Delta) { machine_state = StateMachine.TrakingLat; last_power = 0; } break; case StateMachine.TrakingLat: if (Math.Abs(delta) < MyProperty.Lat_Delta) { machine_state = StateMachine.TrakingLon; } else { if (delta < 0) { lat_state = lat_state == StateLat.Forward ? StateLat.Backward : StateLat.Forward; } lat_stators.ForEach(delegate(IMyMotorStator block) { if (lat_state == StateLat.Forward) { block.TargetVelocityRPM = MyProperty.Lat_Speed; } else { block.TargetVelocityRPM = -MyProperty.Lat_Speed; } }); lat_stators.On(); lat_stators.Unlock(); } break; case StateMachine.TrakingLon: if (Math.Abs(delta) < MyProperty.Lat_Delta) { machine_state = StateMachine.Stopped; } else { if (delta < 0) { lon_state = lon_state == StateLon.Forward ? StateLon.Backward : StateLon.Forward; } float factor = 1f; lon_stators.ForEach(delegate(IMyMotorStator block) { if (lon_state == StateLon.Forward) { block.TargetVelocityRPM = MyProperty.Lat_Speed * factor; } else { block.TargetVelocityRPM = -MyProperty.Lat_Speed * factor; } factor *= -1f; }); lon_stators.On(); lon_stators.Unlock(); } break; default: if (Math.Abs(delta) < MyProperty.Lat_Delta) { machine_state = StateMachine.Stopped; } else { machine_state = StateMachine.TrakingLat; } break; } last_power = max_power; }