当前位置: 首页>>代码示例>>C#>>正文


C# ILogger.Flush方法代码示例

本文整理汇总了C#中ILogger.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# ILogger.Flush方法的具体用法?C# ILogger.Flush怎么用?C# ILogger.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILogger的用法示例。


在下文中一共展示了ILogger.Flush方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Controller

        public Controller(MotorMixer mixer, AxesController pid, Gyro gyro, Accelerometer accelerometer, Radio radio, ControllerLoopSettings loopSettings, MotorSettings motorSettings, ILogger logger)
        {
            TelemetryData telemetryData = new TelemetryData();
            long previousTime = DateTime.Now.Ticks;
            long lastRadioTime = 0;
            long lastSensorTime = 0;
            long lastControlTime = 0;
            long lastMotorTime = 0;
            long lastTelemetryTime = 0;

            bool systemArmed = false;

            Thread.Sleep(1000);
            gyro.Zero();
            accelerometer.Zero();

            while (true)
            {
                long currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastRadioTime + loopSettings.RadioLoopPeriod))
                {
                    lastRadioTime = currentTime;
                    radio.Update();
                    systemArmed = radio.Throttle > motorSettings.MinimumOutput;
                    if (!systemArmed)
                        logger.Flush();
                }

                currentTime = DateTime.Now.Ticks;
                if (systemArmed && (currentTime >= (lastSensorTime + loopSettings.SensorLoopPeriod)))
                {
                    lastSensorTime = currentTime;
                    gyro.Update();
                    accelerometer.Update();
                }

                currentTime = DateTime.Now.Ticks;
                if (systemArmed && (currentTime >= (lastControlTime + loopSettings.ControlAlgorithmPeriod)))
                {
                    lastControlTime = currentTime;
                    pid.Update(radio.Axes, gyro.Axes, (float) (currentTime - previousTime)/loopSettings.LoopUnit);
                    previousTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastMotorTime + loopSettings.MotorLoopPeriod))
                {
                    if (systemArmed)
                        mixer.Update(radio.Throttle, pid.Axes);
                    else
                        mixer.SetSafe();

                    lastMotorTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (systemArmed && (currentTime >= (lastTelemetryTime + loopSettings.TelemetryLoopPeriod)))
                {
                    telemetryData.Update(gyro.Axes, radio.Axes, pid.Axes, currentTime);
                    lastTelemetryTime = currentTime;
                    logger.Write(telemetryData);
                }

                if (!systemArmed)
                    pid.ZeroIntegral();
            }
        }
开发者ID:brandongrossutti,项目名称:DotCopter,代码行数:67,代码来源:Controller.cs

示例2: ControllerWithAccelerometerDebug

        public ControllerWithAccelerometerDebug(MotorMixer mixer, AxesController pid, Gyro gyro, Accelerometer accelerometer, Radio radio, ControllerLoopSettings loopSettings, MotorSettings motorSettings, ILogger logger)
        {
            long lastRadioTime = 0;
            long lastSensorTime = 0;
            long lastControlTime = 0;
            long lastMotorTime = 0;
            long lastTelemetryTime = 0;
            bool systemArmed = false;

            Thread.Sleep(1000);
            gyro.Zero();
            accelerometer.Zero();

            var serialPort = new SerialPort("COM1",115200);
            serialPort.Open();

            while (true)
            {
                long currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastRadioTime + loopSettings.RadioLoopPeriod))
                {
                    radio.Update();
                    systemArmed = radio.Throttle > motorSettings.MinimumOutput;
                    if (!systemArmed)
                        logger.Flush();
                    lastRadioTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastSensorTime + loopSettings.SensorLoopPeriod))
                {
                    gyro.Update();
                    accelerometer.Update();
                    lastSensorTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastControlTime + loopSettings.ControlAlgorithmPeriod))
                {
                    if (systemArmed)
                        pid.Update(radio.Axes, gyro.Axes, (float)(currentTime - lastControlTime) / loopSettings.LoopUnit);
                    lastControlTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastMotorTime + loopSettings.MotorLoopPeriod))
                {
                    if (systemArmed)
                        mixer.Update(radio.Throttle, pid.Axes);
                    else
                        mixer.SetSafe();

                    lastMotorTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastTelemetryTime + loopSettings.TelemetryLoopPeriod))
                {
                    byte[] buffer= new byte[12];

                    BitConverter.ToBytes(ref buffer, 0, accelerometer.Axes.Pitch);
                    BitConverter.ToBytes(ref buffer, 4, accelerometer.Axes.Roll);
                    BitConverter.ToBytes(ref buffer, 8, accelerometer.Axes.Yaw);

                    serialPort.Write(buffer, 0, buffer.Length);
                    lastTelemetryTime = currentTime;
                }
            }
        }
开发者ID:brandongrossutti,项目名称:DotCopter,代码行数:69,代码来源:ControllerWithAccelerometerDebug.cs

示例3: ControllerWithGyroDebug

        public ControllerWithGyroDebug(MotorMixer mixer, AxesController pid, Gyro gyro, Accelerometer accelerometer,Radio radio, ControllerLoopSettings loopSettings, MotorSettings motorSettings, ILogger logger)
        {
            long lastRadioTime = 0;
            long lastSensorTime = 0;
            long lastControlTime = 0;
            long lastMotorTime = 0;
            long lastTelemetryTime = 0;
            bool systemArmed = false;

            var serialPort = new SerialPort("COM1",115200);
            serialPort.Open();

            while (true)
            {
                long currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastRadioTime + loopSettings.RadioLoopPeriod))
                {
                    radio.Update();
                    systemArmed = radio.Throttle > motorSettings.MinimumOutput;
                    if (!systemArmed)
                        logger.Flush();
                    lastRadioTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastSensorTime + loopSettings.SensorLoopPeriod))
                {
                    gyro.Update();
                    lastSensorTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastControlTime + loopSettings.ControlAlgorithmPeriod))
                {
                    if (systemArmed)
                        pid.Update(radio.Axes, gyro.Axes, (float)(currentTime - lastControlTime) / loopSettings.LoopUnit);
                    lastControlTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastMotorTime + loopSettings.MotorLoopPeriod))
                {
                    if (systemArmed)
                        mixer.Update(radio.Throttle, pid.Axes);
                    else
                        mixer.SetSafe();

                    lastMotorTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastTelemetryTime + loopSettings.TelemetryLoopPeriod))
                {
                    Debug.Print(
                    //byte[] buffer = System.Text.Encoding.UTF8.GetBytes( //"\r" + currentTime +
                        //"\tR:" + radio.Axes.Pitch +);
                        "\rP:" + gyro.Axes.Pitch +
                        "\rR:" + gyro.Axes.Roll +
                        "\rY:" + gyro.Axes.Yaw
                        //"\tP" + pid.Axes.Pitch
                        );
                    //serialPort.Write(buffer, 0, buffer.Length);
                    lastTelemetryTime = currentTime;
                }
            }
        }
开发者ID:brandongrossutti,项目名称:DotCopter,代码行数:66,代码来源:ControllerWithGyroDebug.cs

示例4: ControllerWithLoopTimeDebug

        public ControllerWithLoopTimeDebug(MotorMixer mixer, AxesController pid, Gyro gyro, Radio radio, ControllerLoopSettings loopSettings, MotorSettings motorSettings, ILogger logger)
        {
            long lastRadioTime = 0;
            long lastSensorTime = 0;
            long lastControlTime = 0;
            long lastMotorTime = 0;
            long lastTelemetryTime = 0;

            float currentRadioFrequency = 0;
            float currentSensorFrequency = 0;
            float currentControlFrequency = 0;
            float currentMotorFrequency = 0;

            bool systemArmed = false;

            SerialPort serialPort = new SerialPort("COM1",115200);
            serialPort.Open();

            while (true)
            {
                long currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastRadioTime + loopSettings.RadioLoopPeriod))
                {
                    currentRadioFrequency = loopSettings.LoopUnit / (float)(currentTime - lastRadioTime);
                    radio.Update();
                    systemArmed = radio.Throttle > motorSettings.MinimumOutput;
                    if (!systemArmed)
                        logger.Flush();
                    lastRadioTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastSensorTime + loopSettings.SensorLoopPeriod))
                {
                    currentSensorFrequency = loopSettings.LoopUnit / (float)(currentTime - lastSensorTime);
                    gyro.Update();
                    lastSensorTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastControlTime + loopSettings.ControlAlgorithmPeriod))
                {
                    currentControlFrequency = loopSettings.LoopUnit / (float)(currentTime - lastControlTime);
                    if (systemArmed)
                        pid.Update(radio.Axes, gyro.Axes, (float)(currentTime - lastControlTime) / loopSettings.LoopUnit);
                    lastControlTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastMotorTime + loopSettings.MotorLoopPeriod))
                {
                    currentMotorFrequency = loopSettings.LoopUnit / (float)(currentTime - lastMotorTime);
                    if (systemArmed)
                        mixer.Update(radio.Throttle, pid.Axes);
                    else
                        mixer.SetSafe();

                    lastMotorTime = currentTime;
                }

                currentTime = DateTime.Now.Ticks;
                if (currentTime >= (lastTelemetryTime + loopSettings.TelemetryLoopPeriod))
                {
                    float currentTelemetryFrequency = loopSettings.LoopUnit / (float)(currentTime - lastTelemetryTime);

                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes( "\r" + currentTime +
                        "\tR: " + currentRadioFrequency +
                        "\tS: " + currentSensorFrequency +
                        "\tC: " + currentControlFrequency +
                        "\tM: " + currentMotorFrequency +
                        "\tT: " + currentTelemetryFrequency + "\t");
                    serialPort.Write(buffer, 0, buffer.Length);

                    lastTelemetryTime = currentTime;
                }
            }
        }
开发者ID:brandongrossutti,项目名称:DotCopter,代码行数:77,代码来源:ControllerWithLoopTimeDebug.cs


注:本文中的ILogger.Flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。