Exemple #1
0
        private void Initializing()
        {
            switch (phase)
            {
            case Phase.None:
                targetRayon = 0f;
                targetAngle = ANGLE_MIN;
                phase       = Phase.PistonUp;
                break;

            case Phase.PistonUp:
                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.Rotor;
                }
                break;

            case Phase.Rotor:
                InitRotor();
                if (stators.IsPositionMin())
                {
                    stators.Lock();
                    phase = Phase.BrasIn;
                }
                break;

            case Phase.BrasIn:
                pistonRayon.On();
                pistonRayon.ForEach(delegate(IMyPistonBase block) {
                    block.Velocity = -SPEED_MAX;
                });
                if (pistonRayon.IsPositionMin())
                {
                    drills.Off();
                    phase        = Phase.None;
                    stateMachine = StateMachine.Stopped;
                }
                break;
            }
        }
Exemple #2
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;
            }
        }