private static void MagnetometerExample() { Console.WriteLine("\n\n"); Console.WriteLine("hmc5883l Interrupt Example."); Console.WriteLine("--------------------------"); var hmc5883l = new HMC5883L(Device.CreateI2cBus()); // Attach an interrupt handler. hmc5883l.FieldStrengthChanged += (s, e) => { Console.WriteLine($"X: {e.CurrentValue.X}, Y: {e.CurrentValue.Y}, Z: {e.CurrentValue.Z}"); }; hmc5883l.StartInternalPolling(TimeSpan.FromMilliseconds(200)); Console.WriteLine("Running first time"); Thread.Sleep(1000); Console.WriteLine("Stopping"); hmc5883l.StopInternalPolling(); Console.WriteLine("Waiting one second"); Thread.Sleep(1000); Console.WriteLine("Continuing"); hmc5883l.StartInternalPolling(TimeSpan.FromMilliseconds(200)); // Put Meadow to sleep as the interrupt handler will deal // with changes in orientation. Thread.Sleep(Timeout.Infinite); }
//Maximum refresh rate from the HMC3883L is 14ms in continuous measurement mode public CompassUpdater(int delay = 50) { _compass = new HMC5883L(1000); _workItem = new WorkItem(CompassUpdate, false, true, true); _compass.Connected(); _delay = delay; }
public WayPointNavigator( Gps.GpsInformation gpsInformation, HMC5883L compass, CommandProcessor.CommandProcessor commandProcessor) { this.gpsInformation = gpsInformation ?? throw new ArgumentNullException(nameof(gpsInformation)); this.compass = compass ?? throw new ArgumentNullException(nameof(compass)); this.gpsInformation.DataReceivedEventHandler += this.GpsInformation_DataReceivedEventHandler; this.commandProcessor = commandProcessor; }
private static void Run() { Log.AttachLogSink(new RS232Writer()); // get this in early Log.WriteLine("\n--- Logging Initialisation ---"); Log.AttachLogSink(new TextFileWriter("Logs", "Log")); Log.WriteLine("\n--- AeroDataLogger: Boot Sequence Start ---"); MPU6050Device mpu6050 = new MPU6050Device(); // initalise this before the compass! MS5611Baro baro = new MS5611Baro(); HMC5883L compass = new HMC5883L(); // Wait for user to start the recording... var controller = new Controller(); Log.WriteLine("Initialisation successful! Waiting to begin recording...\n"); controller.NotifyReady(); while (!controller.Recording) { Thread.Sleep(100); } ; // Recording begins... Log.WriteLine("Starting data capture."); AccelerationAndGyroData inertialResult; RawData rawMagnetrometry; double temp = 0; double pressure = 0; using (var fileDataSink = new FileDataSink()) { var dataSinks = new IDataSink[] { fileDataSink, new DebuggerDataSink() }; DataHandler dataHandler = new DataHandler(dataSinks); dataHandler.WriteHeader(new[] { "Ax", "Ay", "Az", "Rx", "Ry", "Rz", "Mx", "My", "Mz", "P" }); while (controller.Recording) { // Gather data from sensors inertialResult = mpu6050.GetSensorData(); baro.ReadTemperatureAndPressure(out temp, out pressure); rawMagnetrometry = compass.Raw; // Emit data to handlers dataHandler.HandleData(new object[] { inertialResult.Ax, inertialResult.Ay, inertialResult.Az, inertialResult.Rx, inertialResult.Ry, inertialResult.Rz, rawMagnetrometry.X, rawMagnetrometry.Y, rawMagnetrometry.Z, pressure }); Thread.Sleep(100); } } Log.WriteLine("Data capture stopped."); Log.WriteLine("Exiting.\n\n"); Log.Close(); }
private async void MainPage_OnLoaded(object sender, RoutedEventArgs e) { try { var gpio = await GpioController.GetDefaultAsync(); if (gpio == null) { throw new IOException("GPIO interface not found"); } this.UpdateControlModeonUi(null, null); this.WriteToOutputTextBlock("Setting up distance sensor..."); this.ultrasonicsensor = new HCSR04(Constants.TriggerPin, Constants.EchoPin); this.Speak("Initializing system"); this.displayManager = new DisplayManager(); await this.displayManager.Init(); this.displayManager.AppendImage(DisplayImages.Logo_24_32, 48, 1); await Task.Delay(500); this.displayManager.ClearDisplay(); this.displayManager.AppendText("Initializing system...", 0, 0); this.WriteToOutputTextBlock("Initializing Gps..."); this.InitializeGps(); this.WriteToOutputTextBlock("Initializing Compass..."); this.compass = new HMC5883L(MeasurementMode.Continuous); await this.compass.InitializeAsync(); this.compasstimer = new DispatcherTimer(); this.compasstimer.Interval = TimeSpan.FromMilliseconds(500); this.compasstimer.Tick += this.Compasstimer_Tick; this.compasstimer.Start(); this.displayManager.AppendText(">Connecting slave...", 5, 1); await this.InitializeArduinoAsync(); while (!this.isArduinoSlaveSetup) { this.WriteToOutputTextBlock("Searching I2C device..."); this.displayManager.AppendText(">Searching...", 10, 2); await Task.Delay(2000); } this.WriteToOutputTextBlock("Connected to I2C device..."); this.displayManager.AppendText(">>Done...", 10, 2); this.WriteToOutputTextBlock("Initializing video service..."); await this.InitializeVideoService(); this.WriteToOutputTextBlock("Initializing command processor..."); this.commandProcessor = new CommandProcessor.CommandProcessor( this.arduino, this.displayManager, this.playbackService, this.httpServer, this.panTiltServo, this.ultrasonicsensor); this.commandProcessor.NotifyUIEventHandler += this.NotifyUIEventHandler; await this.commandProcessor.InitializeAsync(); this.WriteToOutputTextBlock("Initializing Rfcomm Service..."); this.displayManager.AppendText(">Starting Rfcomm Svc...", 5, 3); this.InitializeRfcommServerAsync(); while (!this.isRfcommSetup) { await Task.Delay(2000); } this.displayManager.AppendText(">Started Rfcomm Svc...", 5, 3); this.WriteToOutputTextBlock("Initializing waypoint navigator..."); WayPointNavigator.WayPointNavigator wayPointNavigator = new WayPointNavigator.WayPointNavigator(this.gpsInformation, this.compass, this.commandProcessor); wayPointNavigator.NotifyUIEventHandler += this.NotifyUIEventHandler; this.WriteToOutputTextBlock("Initializing cloud device connection..."); var cloudDataProcessor = new CloudDataProcessor(this.commandProcessor, wayPointNavigator); cloudDataProcessor.NotifyUIEventHandler += this.NotifyUIEventHandler; await cloudDataProcessor.InitializeAsync(); this.displayManager.ClearDisplay(); this.displayManager.AppendText("Initialization complete!", 0, 0); await Task.Delay(1000); this.displayManager.ClearDisplay(); await this.panTiltServo.Center(); this.DisplayNetworkInfo(); this.displayManager.AppendImage(DisplayImages.BluetoothDisconnected, 0, 1); cloudDataProcessor.IsTelemetryActive = true; this.InitializeVoiceCommands(); this.WriteToOutputTextBlock("Initializing voice commands..."); this.voiceController.Initialize(); NetworkInformation.NetworkStatusChanged += this.NetworkInformation_NetworkStatusChanged; this.WriteToOutputTextBlock("Initialization complete..."); this.Speak("Initialization complete"); } catch (Exception ex) { this.WriteToOutputTextBlock("Error: " + ex.Message); this.isSystemInitialized = false; var msg = new MessageDialog(ex.Message); await msg.ShowAsync(); // this will show error message(if Any) this.displayManager.ClearDisplay(); this.displayManager.AppendImage(DisplayImages.Error, 0, 0); this.displayManager.AppendText("Initialization error!", 15, 0); } }