static void Turning(EV3GyroSensor gyroSensor, int draaiGraden, Motor motorL, Motor motorR)
        {
            gyroSensor.Reset();
            sbyte draaiSnelheid    = 20;
            sbyte minDraaiSnelheid = -20;

            int graden     = 0;
            int counter    = 0;
            int updateTime = 8;

            if (draaiGraden > 0)                                                                                                                                                        //als hij naar rechts moet draaien dus een positief getal is
            {
                LcdConsole.WriteLine("GROTER ALS 0 ", draaiGraden);
                motorL.SetSpeed(draaiSnelheid);
                motorR.SetSpeed(minDraaiSnelheid);
                while (graden <= draaiGraden)                                                                                                                                   //terwijl het aantal graden dat hij gedraaid is kleiner is dan het aantal graden dat hij moet draaien
                {
                    LcdConsole.WriteLine("Gyro sensor: " + gyroSensor.ReadAsString());
                    graden = gyroSensor.Read();
                    Thread.Sleep(updateTime);
                    counter++;
                    if (counter > 500)
                    {
                        break;
                    }
                }
            }
            if (draaiGraden < 0)                                                                                                                                                    //als hij naar links moet draaien dus het aantal graden negatief is
            {
                LcdConsole.WriteLine("KLEINER ALS 0 ", draaiGraden);
                motorL.SetSpeed(minDraaiSnelheid);
                motorR.SetSpeed(draaiSnelheid);
                while (graden >= draaiGraden)                                                                                                                                   //terwijl het aantal graden dat hij gedraaid is groter is dan het aantal graden dat hij moet draaien
                {
                    LcdConsole.WriteLine("Gyro sensor: " + gyroSensor.ReadAsString());
                    graden = gyroSensor.Read();
                    Thread.Sleep(updateTime);
                    counter++;
                    if (counter > 500)
                    {
                        break;
                    }
                }
            }
            else
            {
                LcdConsole.WriteLine("IK KAN GEEN 0 GRADEN DRAAIEN " + gyroSensor.ReadAsString());
            }
            motorR.Brake();
            motorL.Brake();
            motorR.Off();
            motorL.Off();
            Thread.Sleep(1000);
        }
示例#2
0
        public static void Main(string[] args)
        {
            ManualResetEvent terminateProgram = new ManualResetEvent(false);

            GyroMode[]   modes   = { GyroMode.Angle, GyroMode.AngularVelocity };
            int          modeIdx = 0;
            ButtonEvents buts    = new ButtonEvents();
            var          gyro    = new EV3GyroSensor(SensorPort.In2, GyroMode.Angle);

            LcdConsole.WriteLine("Use gyro on port 1");
            LcdConsole.WriteLine("Up read value");
            LcdConsole.WriteLine("Down rotation count");
            LcdConsole.WriteLine("Left reset");
            LcdConsole.WriteLine("Enter change mode");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                terminateProgram.Set();
            };
            buts.UpPressed += () => {
                LcdConsole.WriteLine("Gyro sensor: " + gyro.ReadAsString());
            };
            buts.EnterPressed += () => {
                modeIdx   = (modeIdx + 1) % modes.Length;
                gyro.Mode = modes[modeIdx];
                LcdConsole.WriteLine("Mode: " + modes[modeIdx]);
            };
            buts.DownPressed += () => {
                LcdConsole.WriteLine("Rotation count: " + gyro.RotationCount());
            };
            buts.LeftPressed += () => {
                LcdConsole.WriteLine("Reset");
                gyro.Reset();
            };
            terminateProgram.WaitOne();
        }