예제 #1
0
        public static void WriteLine(string format, params object[] args)
        {
            var message = string.Format(format, args);

            Console.WriteLine(message);
            LcdConsole.WriteLine(message);
        }
예제 #2
0
        public static void Display()
        {
            LcdConsole.Clear();

            // http://stackoverflow.com/questions/105031/how-do-you-get-total-amount-of-ram-the-computer-has
            // http://stackoverflow.com/questions/3896685/simplest-possible-performance-counter-example
            foreach (var pcCategory in PerformanceCounterCategory.GetCategories())
            {
                LcdConsole.Clear();
                LcdConsole.WriteLine(pcCategory.CategoryName);
                int lineNum = 1;
                int pageNum = 1;
                foreach (var performanceCounter in pcCategory.GetCounters())
                {
                    LcdConsole.WriteLine(performanceCounter.CounterName);
                    LcdConsole.WriteLine("{0}", performanceCounter.RawValue);
                    if ((++lineNum % 5) == 0)
                    {
                        LcdConsole.WriteLine("-----{0} page {1}", pcCategory.CategoryName, pageNum++);
                        EV3KeyPad.ReadKey();
                    }
                }
                LcdConsole.WriteLine("-----End of {0}", pcCategory.CategoryName);
                EV3KeyPad.ReadKey();
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
            ManualResetEvent terminateProgram = new ManualResetEvent(false);
            var          soundSensor          = new NXTSoundSensor(SensorPort.In1);
            ButtonEvents buts = new ButtonEvents();

            LcdConsole.WriteLine("Use sound on port1");
            LcdConsole.WriteLine("Up sensor value");
            LcdConsole.WriteLine("Enter read raw");
            LcdConsole.WriteLine("Down change mode");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                terminateProgram.Set();
            };
            buts.UpPressed += () => {
                LcdConsole.WriteLine("Sensor value:" + soundSensor.ReadAsString());
            };
            buts.EnterPressed += () => {
                LcdConsole.WriteLine("Sensor raw value:" + soundSensor.ReadRaw());
            };
            buts.DownPressed += () => {
                if (soundSensor.Mode == SoundMode.SoundDB)
                {
                    soundSensor.Mode = SoundMode.SoundDBA;
                }
                else
                {
                    soundSensor.Mode = SoundMode.SoundDB;
                }
                LcdConsole.WriteLine("Sensor mode is now: " + soundSensor.Mode);
            };
            terminateProgram.WaitOne();
        }
예제 #4
0
 public virtual void Eat()
 {
     //Make crunching sound
     MakeSound(DogSound.Crunching);
     fullness += 4;
     LcdConsole.WriteLine("Eating");
 }
예제 #5
0
        public static void Main(string[] args)
        {
            //The MSSensorMUXBase allows you to use the Mindsensors Multiplexer almost like every other sensor
            //The easiest way to use sensors is the following:
            MSSensorMUXBase GyroSensor = new MSSensorMUXBase(SensorPort.In1, MSSensorMUXPort.C1);

            //But that is a general way to use them that doesn't allow to use the TouchSensor and doesn't specify
            //the number of modes of the Sensor. It's better to use the following way:
            MSSensorMUXBase IRSensor = new MSSensorMUXBase(SensorPort.In1, MSSensorMUXPort.C3, IRMode.Remote);

            //You can see that you can use the Modes of the different sensors the same way like when you use them
            //without Multiplexer.

            //The EV3 Touchsensor needs to be traited a bit different:
            MSSensorMUXBase TouchSensor = new MSSensorMUXBase(SensorPort.In1, MSSensorMUXPort.C2, MSSensorMUXMode.TouchMode);

            while (true)
            {
                System.Threading.Thread.Sleep(500);

                //You can either read one, two, four or eight bytes at once from the sensor.
                //Normally one byte is enough but there are times when you want to read more.
                //Refer to http://mindsensors.com/index.php?module=documents&JAS_DocumentManager_op=downloadFile&JAS_File_id=1394
                //(Supported Sensors) for the suggested length for the different modes
                LcdConsole.WriteLine(Convert.ToString(GyroSensor.Read()) + ", " +
                                     Convert.ToString(TouchSensor.ReadOneByte()) + ", " + IRSensor.ReadAsString());
            }
        }
예제 #6
0
파일: Program.cs 프로젝트: thaiEv3/monoev3
        public static void Main(string[] args)
        {
            ManualResetEvent terminateProgram = new ManualResetEvent(false);

            UltraSonicMode[] modes = { UltraSonicMode.Centimeter, UltraSonicMode.Inch, UltraSonicMode.Listen };
            int          modeIdx   = 0;
            ButtonEvents buts      = new ButtonEvents();
            var          sensor    = new EV3UltrasonicSensor(SensorPort.In1, modes[modeIdx]);

            LcdConsole.WriteLine("Use sonic on port1");
            LcdConsole.WriteLine("Up change mode");
            LcdConsole.WriteLine("Enter read");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                terminateProgram.Set();
            };
            buts.UpPressed += () => {
                modeIdx     = (modeIdx + 1) % modes.Length;
                sensor.Mode = modes[modeIdx];
                LcdConsole.WriteLine("Mode: " + modes[modeIdx]);
            };
            buts.EnterPressed += () => {
                LcdConsole.WriteLine(sensor.ReadAsString());
            };
            terminateProgram.WaitOne();
        }
예제 #7
0
        private static void OutPerformanceCounterValue(string categoryName, string counterName)
        {
            var pc = new PerformanceCounter(categoryName, counterName);

            LcdConsole.WriteLine("{0} ({1})", counterName, categoryName);
            LcdConsole.WriteLine("{0:N0}", pc.RawValue);
        }
예제 #8
0
        public static void Main(string[] args)
        {
            ButtonEvents buts = new ButtonEvents();
            bool         run  = true;

            buts.EscapePressed += () =>
            {
                run = false;
            };

            MotorSync   motori = new MotorSync(MotorPort.OutB, MotorPort.OutD);
            EV3IRSensor ir     = new EV3IRSensor(SensorPort.In3, IRMode.Proximity);

            Thread bg = new Thread(Scan);

            bg.Start();
            while (run && ir.Read() > 80)
            {
                LcdConsole.WriteLine(ir.Read().ToString());
                Thread.Sleep(200);
            }
            bg.Abort();
            motori.Brake();
            motori.Off();
        }
예제 #9
0
 public void debug(string message)
 {
     if (CurrentLogger.Debug)
     {
         LcdConsole.WriteLine("[DEBUG] " + message);
     }
 }
예제 #10
0
        public static void Main(string[] args)
        {
            Vehicle vehicle = new Vehicle(MotorPort.OutA, MotorPort.OutD);

            const int speed     = 40;
            const int moveSteps = 2000;           //You need to adjust this
            const int spinSteps = 500;            //You need to adjust this

            vehicle.ReverseLeft  = false;         //You might need to adjust this
            vehicle.ReverseRight = false;         //You might need to adjust this
            LcdConsole.WriteLine("Use Motor on A");
            LcdConsole.WriteLine("Use Motor on D");
            //Make a square
            for (int i = 0; i < 4; i++)
            {
                LcdConsole.WriteLine("Spin left");
                vehicle.SpinLeft(speed, spinSteps, true);
                LcdConsole.WriteLine("Move forward");
                vehicle.Forward(speed, moveSteps, true);
            }
            vehicle.Off();

            Thread.Sleep(3000);
            LcdConsole.WriteLine("Make a soft turn to the left");
            vehicle.TurnLeftForward(speed, 50, moveSteps, false);
        }
예제 #11
0
파일: Program.cs 프로젝트: thaiEv3/monoev3
        public static void Main(string[] args)
        {
            EventWaitHandle stopped = new ManualResetEvent(false);

            ColorMode[]  modes   = { ColorMode.Color, ColorMode.Reflection, ColorMode.Ambient, ColorMode.Blue };
            int          modeIdx = 0;
            var          sensor  = new EV3ColorSensor(SensorPort.In1);
            ButtonEvents buts    = new ButtonEvents();

            LcdConsole.WriteLine("Use color on port1");
            LcdConsole.WriteLine("Up read value");
            LcdConsole.WriteLine("Down raw value");
            LcdConsole.WriteLine("Enter change mode");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                stopped.Set();
            };
            buts.UpPressed += () => {
                LcdConsole.WriteLine("Sensor value: " + sensor.ReadAsString());
            };
            buts.DownPressed += () => {
                LcdConsole.WriteLine("Raw sensor value: " + sensor.ReadRaw());
            };
            buts.EnterPressed += () => {
                modeIdx     = (modeIdx + 1) % modes.Length;
                sensor.Mode = modes[modeIdx];
                LcdConsole.WriteLine("Sensor mode is set to: " + modes[modeIdx]);
            };
            stopped.WaitOne();
        }
예제 #12
0
 public static void Debug(String message)
 {
     if (level <= LEVEL_DEBUG)
     {
         LcdConsole.WriteLine("[D] " + message);
     }
 }
예제 #13
0
        public static void Main(string[] args)
        {
            ManualResetEvent   terminateProgram = new ManualResetEvent(false);
            ButtonEvents       buts             = new ButtonEvents();
            HiTecCompassSensor compass          = new HiTecCompassSensor(SensorPort.In1);
            HiTecColorSensor   colorSensor      = new HiTecColorSensor(SensorPort.In2);
            HiTecTiltSensor    tilt             = new HiTecTiltSensor(SensorPort.In3);

            LcdConsole.WriteLine("Use compass on port1");
            LcdConsole.WriteLine("Use color on port2");
            LcdConsole.WriteLine("Use tilt on port3");
            LcdConsole.WriteLine("Up read compass");
            LcdConsole.WriteLine("Down read tilt");
            LcdConsole.WriteLine("Enter read color");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                terminateProgram.Set();
            };
            buts.UpPressed += () => {
                LcdConsole.WriteLine("Compass sensor: " + compass.ReadAsString());
            };
            buts.EnterPressed += () => {
                LcdConsole.WriteLine("Color sensor: " + colorSensor.ReadAsString());
                LcdConsole.WriteLine("Color index: " + colorSensor.ReadColorIndex());
            };
            buts.DownPressed += () => {
                LcdConsole.WriteLine("Tilt : " + tilt.ReadAsString());
            };
            terminateProgram.WaitOne();
        }
예제 #14
0
파일: Program.cs 프로젝트: jschmutz/monoev3
        public static void Main(string[] args)
        {
            ButtonEvents buts        = new ButtonEvents();
            var          tokenSource = new CancellationTokenSource();
            var          token       = tokenSource.Token;

            var dialog = new InfoDialog("Attach distance sensor", false);

            dialog.Show();
            var sensor = SensorAttachment.Wait <MSAngleSensor>(token);           //wait for sensor to attached on any port

            LcdConsole.WriteLine("Up reset angle");
            LcdConsole.WriteLine("Down read RMP");
            LcdConsole.WriteLine("Enter read angle");
            LcdConsole.WriteLine("Left read raw");
            LcdConsole.WriteLine("Esc. terminate");

            buts.EscapePressed += () => {
                tokenSource.Cancel();
            };
            buts.EnterPressed += () => {
                LcdConsole.WriteLine("Angle: " + sensor.ReadAngle().ToString());
            };
            buts.UpPressed += () => {
                LcdConsole.WriteLine("Reset angle");
                sensor.ResetAngle();
            };
            buts.DownPressed += () => {
                LcdConsole.WriteLine("Read RPM: " + sensor.ReadRPM().ToString());
            };
            buts.LeftPressed += () => {
                LcdConsole.WriteLine("Read raw: " + sensor.ReadRAW().ToString());
            };
            token.WaitHandle.WaitOne();
        }
예제 #15
0
        void MotorPollThread()
        {
            try
            {
                while (true)
                {
                    // take all pending comamnds
                    IRobotCommand command = null;
                    if (_commands.TryTake(out command, Timeout.Infinite, _cancel))
                    {
                        // do it!
                        command.Do(this);

                        // anything to do after a command executed?
                        PostCommand();
                    }
                }
            }
            catch (OperationCanceledException)
            {
                // normal exception when thread is stopped
            }
            catch (Exception ex)
            {
                //
                while (ex != null)
                {
                    LcdConsole.WriteLine(ex.Message);
                    ex = ex.InnerException;
                }
                throw;
            }
        }
        static void DriveToColor(sbyte speed, string Color, Motor motorR, Motor motorL, EV3ColorSensor sensor)
        {
            int i = 0;

            LcdConsole.WriteLine("zoeken naar" + sensor.ReadAsString() + "en " + Color);
            Thread.Sleep(1000);
            motorL.SetSpeed(speed);
            motorR.SetSpeed(speed);
            while (Color != sensor.ReadAsString())
            {
                LcdConsole.WriteLine("Sensor ẁaarde:" + sensor.ReadAsString());

                if (Color == (sensor.ReadAsString()))
                {
                    LcdConsole.WriteLine("Sensor ẁaarde:" + sensor.ReadAsString());
                    LcdConsole.WriteLine("GEVONDEN  " + sensor.ReadAsString());
                    motorR.Off();
                    motorL.Off();
                    break;
                }
                Thread.Sleep(50);                                                                                                                                                   // wacht voor zoveel miliseconde voor de volgende loop
                i++;
                if (i > 60)                                                                                                                                                         // als 5000 miliseconden voorbij zijn stop
                {
                    LcdConsole.WriteLine("heeft de kleur niet kunnen vinden");
                    motorR.Off();
                    motorL.Off();
                    break;
                }
            }
        }
예제 #17
0
 public static void Info(String message)
 {
     if (level <= LEVEL_INFO)
     {
         LcdConsole.WriteLine("[I] " + message);
     }
 }
예제 #18
0
 public static void Warning(String message)
 {
     if (level <= LEVEL_WARNING)
     {
         LcdConsole.WriteLine("[W] " + message);
     }
 }
예제 #19
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();
        }
예제 #20
0
        // Algoritam trazenja
        static bool Search()
        {
            LcdConsole.WriteLine("Trazenje predmeta...");
            lMotor.ResetTacho();             // Resetuje tacho motora zbog okretanja na kraju
            rMotor.ResetTacho();
            Thread movement = new Thread(SearchMove);

            movement.IsBackground = true;             // Background thread se gasi kada se main zavrsi
            movement.Start();

            progress = 0;
            while (ir.Read() > C.irScanTreshold && progress < tableLenght)
            {
                LcdConsole.WriteLine(ir.Read().ToString());
                if (color.Read() == 0)
                {
                    movement.Abort();
                    motors.Brake();
                    throw new Exception("Vrednost senzora za boju je 0!");
                }
                Thread.Sleep(200);
            }

            movement.Abort();
            motors.Brake();
            Thread.Sleep(C.motorBrakeSleepTime);
            if (progress == tableLenght)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #21
0
파일: Main.cs 프로젝트: AlfaOne/LegoV3
        public static void RijBepaaldeAfstand(int i)
        {
            Motor motor  = new Motor(MotorPort.OutA);
            Motor motorB = new Motor(MotorPort.OutB);

            motor.ResetTacho();

            int n = 1;

            while (n < 6)
            {
                motor.SetSpeed(25);
                motorB.SetSpeed(25);
                int distance = motor.GetTachoCount();
                int afstand  = distance;

                if (afstand < (i))
                {
                    motor.Off();
                    motorB.Off();
                    n = 8;
                }
                LcdConsole.WriteLine("Afstand: " + afstand);
            }
        }
예제 #22
0
파일: Program.cs 프로젝트: thaiEv3/monoev3
        public static void Main(string[] args)
        {
            ManualResetEvent terminateProgram = new ManualResetEvent(false);
            var          lightSensor          = new NXTLightSensor(SensorPort.In1);
            ButtonEvents buts = new ButtonEvents();

            LcdConsole.WriteLine("Use light on port1");
            LcdConsole.WriteLine("Up value ");
            LcdConsole.WriteLine("Down change mode");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                terminateProgram.Set();
            };
            buts.UpPressed += () => {
                LcdConsole.WriteLine("Sensor value:" + lightSensor.ReadAsString());
            };
            buts.DownPressed += () => {
                if (lightSensor.Mode == LightMode.Ambient)
                {
                    lightSensor.Mode = LightMode.Relection;
                }
                else
                {
                    lightSensor.Mode = LightMode.Ambient;
                }
                LcdConsole.WriteLine("Sensor mode is now: " + lightSensor.Mode);
            };
            terminateProgram.WaitOne();
        }
예제 #23
0
파일: Main.cs 프로젝트: AlfaOne/LegoV3
        public static int Gyroscope()
        {
            MonoBrickFirmware.Sensors.EV3GyroSensor Gyroskoopje = new MonoBrickFirmware.Sensors.EV3GyroSensor(MonoBrickFirmware.Sensors.SensorPort.In2);
            int graden = Gyroskoopje.Read();

            LcdConsole.WriteLine("Graden: " + graden);
            return(graden);
        }
예제 #24
0
파일: Main.cs 프로젝트: AlfaOne/LegoV3
        public static int SensorAfstand()
        {
            MonoBrickFirmware.Sensors.EV3UltrasonicSensor UltraSensor = new MonoBrickFirmware.Sensors.EV3UltrasonicSensor(MonoBrickFirmware.Sensors.SensorPort.In1);
            int distance = UltraSensor.Read();

            LcdConsole.WriteLine("Distance: " + distance);
            return(distance);
        }
예제 #25
0
 // Algoritam podizanja predmeta
 static void Pickup()
 {
     LcdConsole.WriteLine("Predmet pronadjen");
     ArmMove(ArmPosition.Open);
     motorWH = motors.StepSync(C.pickupForwardSpeed, 0, (uint)(ir.Read() * C.stepsPerCm), true);
     motorWH.WaitOne();
     ArmMove(ArmPosition.Lifted);
 }
예제 #26
0
 private static void Quit_OnEnterPressed()
 {
     LcdConsole.Clear();
     LcdConsole.WriteLine("Terminating");
     // Wait a bit
     Thread.Sleep(1000);
     TerminateMenu();
 }
예제 #27
0
 static void Log(string log)
 {
     // if (MonoBrickFirmware.Tools.PlatFormHelper.RunningPlatform == MonoBrickFirmware.Tools.PlatFormHelper.Platform.EV3)
     {
         LcdConsole.WriteLine("{0}", log);
     }
     //else
     //{
     //    Console.WriteLine(log);
     //}
 }
예제 #28
0
        public virtual void ControlEyes(DogEyes eyes)
        {
            //use enum for picking the right image file
            this.eyes = eyes;
            LcdConsole.WriteLine(eyes.ToString());
            Bitmap bmpEyes = Bitmap.FromResouce(Assembly.GetExecutingAssembly(), eyes.ToString() + ".bitmap");

            Lcd.Instance.Clear();
            Lcd.Instance.DrawBitmap(bmpEyes, new Point((int)(Lcd.Width - bmpEyes.Width) / 2, 10));
            Lcd.Instance.Update();
        }
        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);
        }
예제 #30
0
        void ScanPollThread()
        {
            try
            {
                Motor xmotor = Motors[RobotSetup.XPort];
                Motor ymotor = Motors[RobotSetup.YPort];

                float xratio = RatioSettings[RobotSetup.XPort];
                float yratio = RatioSettings[RobotSetup.YPort];

                int prevx = -1;
                int prevy = -1;
                while (true)
                {
                    _scanWait.WaitOne();

                    // capture motor positions
                    int x = xmotor.GetTachoCount();
                    int y = ymotor.GetTachoCount();
                    if (prevx != x || prevy != y)
                    {
                        // send a data point
                        RGBColor color = _colorSensor.ReadRGB();

                        // a bit of formatting
                        SendData(string.Format("PIX;{0};{1};{2};{3:#.##};{4:#.##}\0", new object[] { color.Red, color.Green, color.Blue, x / xratio, y / yratio }));

                        //
                        // LcdConsole.WriteLine(string.Format("{0:#.##}:{1:#.##} = {2}", x / xratio, y / yratio, color.ToString()));

                        prevx = x;
                        prevy = y;
                    }
                    if (_scanDelay > 0)
                    {
                        Thread.Sleep(_scanDelay);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                // normal exception when thread is stopped
            }
            catch (Exception ex)
            {
                //
                while (ex != null)
                {
                    LcdConsole.WriteLine(ex.Message);
                    ex = ex.InnerException;
                }
                throw;
            }
        }