public static void WriteLine(string format, params object[] args) { var message = string.Format(format, args); Console.WriteLine(message); LcdConsole.WriteLine(message); }
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(); } }
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(); }
public virtual void Eat() { //Make crunching sound MakeSound(DogSound.Crunching); fullness += 4; LcdConsole.WriteLine("Eating"); }
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()); } }
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(); }
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); }
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(); }
public void debug(string message) { if (CurrentLogger.Debug) { LcdConsole.WriteLine("[DEBUG] " + message); } }
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); }
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(); }
public static void Debug(String message) { if (level <= LEVEL_DEBUG) { LcdConsole.WriteLine("[D] " + message); } }
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(); }
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(); }
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; } } }
public static void Info(String message) { if (level <= LEVEL_INFO) { LcdConsole.WriteLine("[I] " + message); } }
public static void Warning(String message) { if (level <= LEVEL_WARNING) { LcdConsole.WriteLine("[W] " + message); } }
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(); }
// 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); } }
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); } }
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(); }
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); }
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); }
// 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); }
private static void Quit_OnEnterPressed() { LcdConsole.Clear(); LcdConsole.WriteLine("Terminating"); // Wait a bit Thread.Sleep(1000); TerminateMenu(); }
static void Log(string log) { // if (MonoBrickFirmware.Tools.PlatFormHelper.RunningPlatform == MonoBrickFirmware.Tools.PlatFormHelper.Platform.EV3) { LcdConsole.WriteLine("{0}", log); } //else //{ // Console.WriteLine(log); //} }
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); }
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; } }