Ejemplo n.º 1
0
        // METHOD: VelocityController
        //--------------------------------------------------------------------------------------
        /// <summary>
        /// Determine and issue the next power command (control train speed)
        /// </summary>
        //--------------------------------------------------------------------------------------
        private int VelocityController()
        {
            // If there has been a brake failure, set the emergency brake and do not issue a power command.
            if (EmergencyBrake || m_brakeFailure)
            {
                m_myTrain.SetEmergencyBrake(true, m_samplePeriod);
                return(1);
            }

            // Store values from the last iteration
            m_lastIntegral = m_currentIntegral;
            m_lastSample   = m_currentSample;

            // Calculate the error signal
            m_currentSample = m_setPoint - m_currentState.Speed;

            if (m_currentSample < 0)
            {
                m_myTrain.SetBrake(true, m_samplePeriod);
                return(2);
            }

            // Invoke the control law to calculate the next power command
            ControlLaw();

            // Issue the power command to the train if it's not waiting at a station
            if (!m_atStation && m_currentSample != 0)
            {
                m_myTrain.SetPower(m_powerCommand, m_samplePeriod);
                return(3);
            }

            return(0);
        }
Ejemplo n.º 2
0
 private void brakeBox_CheckedChanged(object sender, EventArgs e)
 {
     train.SetBrake(brakeBox.Checked, 0.1);
     powerTextBox.Text = train.GetPower().ToString();
 }