Пример #1
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;
        }