Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        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;
        }