Ejemplo n.º 1
0
        private void Running()
        {
            int factor = pistonDown.List.Count + pistonUp.List.Count;

            if (stators.IsEmpty)
            {
                Prepare();
            }

            switch (phase)
            {
            case Phase.None:
                phase = Phase.PistonDown;
                break;

            case Phase.PistonDown:
                drills.On();
                pistonDown.ForEach(delegate(IMyPistonBase block) {
                    if (slowDown)
                    {
                        block.Velocity = SPEED_MIN / factor;
                    }
                    else
                    {
                        block.Velocity = SPEED_MAX / factor;
                    }
                });
                pistonUp.ForEach(delegate(IMyPistonBase block) {
                    if (slowDown)
                    {
                        block.Velocity = -SPEED_MIN / factor;
                    }
                    else
                    {
                        block.Velocity = -SPEED_MAX / factor;
                    }
                });
                pistonDown.On();
                pistonUp.On();
                if (pistonDown.IsPositionMax() && pistonUp.IsPositionMin())
                {
                    phase = Phase.PistonUp;
                }
                break;

            case Phase.PistonUp:
                slowDown = false;
                pistonDown.ForEach(delegate(IMyPistonBase block) {
                    block.Velocity = -SPEED_MAX;
                });
                pistonUp.ForEach(delegate(IMyPistonBase block) {
                    block.Velocity = SPEED_MAX;
                });
                pistonDown.On();
                pistonUp.On();
                if (pistonDown.IsPositionMin() && pistonUp.IsPositionMax())
                {
                    phase = Phase.Bras;
                }
                break;

            case Phase.Bras:
                if (brasOut && pistonRayon.IsPositionMax())
                {
                    targetAngle += deltaAngle;
                    brasOut      = false;
                    phase        = Phase.Rotor;
                }
                else if (!brasOut && pistonRayon.IsPositionMin())
                {
                    targetAngle += deltaAngle;
                    brasOut      = true;
                    phase        = Phase.Rotor;
                }
                else
                {
                    if (brasOut)
                    {
                        targetRayon += Math.Min(deltaRayon, 10f);
                        if (targetRayon > 10f)
                        {
                            targetRayon = 10f;
                        }
                        phase = Phase.BrasOut;
                    }
                    else
                    {
                        targetRayon -= Math.Min(deltaRayon, 10f);
                        if (targetRayon < 0f)
                        {
                            targetRayon = 0f;
                        }
                        phase = Phase.BrasIn;
                    }
                }
                break;

            case Phase.BrasIn:
                pistonRayon.On();
                pistonRayon.ForEach(delegate(IMyPistonBase block) {
                    block.Velocity = -SPEED_MAX;
                });
                if (pistonRayon.IsPosition(targetRayon))
                {
                    pistonRayon.Off();
                    phase = Phase.PistonDown;
                }
                break;

            case Phase.BrasOut:
                pistonRayon.On();
                pistonRayon.ForEach(delegate(IMyPistonBase block) {
                    block.Velocity = SPEED_MAX;
                });
                if (pistonRayon.IsPosition(targetRayon))
                {
                    pistonRayon.Off();
                    phase = Phase.PistonDown;
                }
                break;

            case Phase.Rotor:
                stators.ForEach(delegate(IMyMotorStator block) {
                    block.TargetVelocityRPM = ANGLE_RPM_MIN;
                });
                stators.Unlock();
                if (stators.IsPositionMax())
                {
                    stateMachine = StateMachine.Stopping;
                    phase        = Phase.None;
                }
                else if (stators.IsPosition(targetAngle))
                {
                    stators.Lock();
                    phase = Phase.PistonDown;
                }
                break;
            }
        }
Ejemplo n.º 2
0
        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;
                }
            }
        }
Ejemplo n.º 3
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.º 4
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;
        }