public bool Begin() { Rebug.Print("Opening BNO communications channel..."); _comPort.Open(); ConfigMode(); write_byte(Bno055Registers.Bno055PageIdAddr, 0); var bnoId = read_byte(Bno055Registers.Bno055ChipIdAddr); Rebug.Print("Read chip ID for BNO055: 0x" + bnoId.ToString("x")); if (bnoId != Bno055Id) { return(false); } //reset the device write_byte(Bno055Registers.Bno055SysTriggerAddr, 0x20, false); //sleep 650 ms after reset for chip to be ready(as suggested in datasheet) Thread.Sleep(650); //set to normal power mode write_byte(Bno055Registers.Bno055PwrModeAddr, (byte)Bno055PowerMode.PowerModeNormal); //default to external oscillator write_byte(Bno055Registers.Bno055SysTriggerAddr, 0x80); //enter normal operation mode OpMode(); return(true); }
public void TurnOff() { Rebug.Print("Sending signal to power off RICH detector"); _richPin.Write(true); Thread.Sleep(4000); _richPin.Write(false); }
private static void ThreadWorker() { while (true) { //Wait for pulse from ThreadPool, signifying a new work item has been queued // ReSharper disable once InconsistentlySynchronizedField ThreadSynch.WaitOne(); var workItem = new WorkItem(); lock (ThreadActions) { //pull the next work item off of the queue if (ThreadActions.Count > 0) { workItem = ThreadActions.Dequeue() as WorkItem; } //no pending actions - reset threads so they wait for next pulse. else { lock (ThreadSynch) ThreadSynch.Reset(); } } //if no action, go back to waiting. if (workItem?.Action == null) { continue; } //workItem.Action(); //FlightComputer.TriggerEvent(workItem.Loggable, ref workItem.PacketData); //if (workItem.Persistent) QueueWorkItem(workItem); //Debug.Print("Current Thread Queue count: " + ThreadActions.Count); //safe try { //try to execute, then trigger any events, then re-add to queue if repeatable. workItem.Action(); FlightComputer.TriggerEvent(workItem.Loggable, ref workItem.PacketData); if (workItem.Persistent) { QueueWorkItem(workItem); } } catch (Exception e) { Rebug.Print("ThreadPool: Unhandled error executing action - " + e.Message + e.InnerException); Rebug.Print("StackTrace: " + e.StackTrace); //maybe just reset the flight computer? } } }
public static byte[] CurrentTime() { var time = new byte[7]; I2CBus.GetInstance().ReadRegister(SlaveConfig, 0x00, time, TransactionTimeout); var realseconds = Tools.Bcd2Bin(new [] { time[0] }); var minutes = Tools.Bcd2Bin(new [] { time[1] }); var hours = Tools.Bcd2Bin(new [] { time[2] }); Rebug.Print("Current time: " + hours + ":" + minutes + ":" + realseconds + ", Freemem: " + Debug.GC(true) + ", Action Count: " + ThreadPool.ActionCount + ", Log count: " + FlightComputer.Logger.PendingItems); return(new[] { (byte)hours, (byte)minutes, (byte)realseconds }); }
private byte[] serial_send(byte[] command, int expectedLength, bool ack = true, int maxTries = 10, int tries = 0) { lock (Locker) { _comPort.Flush(); _comPort.Write(command, 0, command.Length); //If no ack needed, we're done. if (!ack) { return(null); } //wait for serial stream to fill with expected ack data Thread.Sleep(500); //bug THIS THIS SLOW... should wait until correct amount of data is ready to be read. var response = new byte[_comPort.BytesToRead]; var readCount = _comPort.Read(response, 0, response.Length); //If we timed out, throw an exception. if (readCount == 0) { Rebug.Print("Serial ACK timeout..."); } //if we didn't get an error code (0xEE07), we're done. if (response.Length > 0 && !(response[0] == 0xEE && response[1] == 0x07)) { return(response); } //if we tried 5 times to get a non-error ACK and didn't, throw an exception. if (++tries == maxTries) { throw new IOException("Exceeded max tries to acknowlege serial command without bus error."); } return(serial_send(command, expectedLength, maxTries: maxTries, tries: tries)); } }
private void OpMode() { Rebug.Print("BNO055 entering normal operation mode..."); SetMode(_mode); }
private void ConfigMode() { Rebug.Print("BNO055 entering configuration mode..."); SetMode(Bno055OpMode.OperationModeConfig); }
public static void Main() { var bus = new I2CBus(); var lcdProvider = new MCP23008LcdTransferProvider(bus); var lcd = new Lcd(lcdProvider); lcd.Begin(16, 2); lcd.Backlight = true; lcd.Write("Payload McPayload Face v1.0"); for (int i = 0; i < 12; i++) { lcd.ScrollDisplayLeft(); Thread.Sleep(200); } Thread.Sleep(1000); lcd.Clear(); LCDFinish(lcd, "ACC DemoSat 2016"); //THIS SECTION CREATES / INITIALIZES THE SERIAL LOGGER Debug.Print("Flight computer started successfully. Beginning INIT."); //Lcd = new LiquidCrystalI2C(0x01, 16, 2); //Lcd.write("Testing!"); lcd.Write("Starting logger."); var logger = new Logger(); Debug.Print("Starting logger."); logger.Start(); LCDFinish(lcd, "Done."); lcd.Write("Starting clock..."); Rebug.Print("Starting clock."); Clock.Instance.Start(); LCDFinish(lcd, "Done."); //THIS SECTION CREATES/INITIALIZES THE PRESSURE SENSOR //lcd.Write("Init BMP sensor."); //Rebug.Print("Initializing BMP Sensor "); //var bmploop = new PressureTempAltitudeUpdater(bus, delay: 1000); //LCDFinish(lcd); //THIS SECTION CREATES/INITIALIZES THE SERIAL BNO 100HZ UPDATER lcd.Write("Init BNO sensor..."); Rebug.Print("Initializing BNO Sensor "); var bno = new SerialBno(SerialPorts.COM1, 5000, 5000, SerialBno.Bno055OpMode.OperationModeNdof); var bnoloop = new SerialBnoUpdater(bno, delay: 1000); LCDFinish(lcd, "Done."); ////Starts up the expensive mag lcd.Write("Init exp. mag..."); Rebug.Print("Initializing expensive magnetometer on com3"); var expensiveMagLoop = new ExpensiveMagUpdater(delay: 1000); LCDFinish(lcd, "Done."); lcd.Write("Init calib disp."); Rebug.Print("Initializing BNO calibration display loop"); var printBnoCalib = new BNOCalibUpdate(bno, lcd, delay: 1000); LCDFinish(lcd, "Done."); //////THIS SECTION CREATES/INITIALIZES THE MAGNETOMETER UPDATER var mag_dump_size = 18432; lcd.Write("Init fast mag..."); Rebug.Print("Initializing fast mag dump collector with a size of " + mag_dump_size + "bytes."); var customMagLoop = new CustomMagUpdater(mag_dump_size, AnalogChannels.ANALOG_PIN_A0); LCDFinish(lcd, "Done."); //Thread.Sleep(5000); lcd.Write("Init complete..."); Rebug.Print("Flight computer INIT Complete. Continuing with boot."); LCDFinish(lcd, "Continuing boot."); //THIS SECTION INITIALIZES AND STARTS THE MEMORY MONITOR lcd.Write("Start memory monitor..."); Rebug.Print("Starting memory monitor..."); MemoryMonitor.Instance.Start(ref logger); LCDFinish(lcd, "Done."); ////THIS STARTS THE Mag dump update lcd.Write("Start f.mag loop..."); Rebug.Print("Starting fast mag dump..."); customMagLoop.Start(); LCDFinish(lcd, "Done."); ////THIS STARTS THE BNO SENSOR UPDATE lcd.Write("Start bno loop..."); Rebug.Print("Starting bno sensor updates..."); bnoloop.Start(); LCDFinish(lcd, "Done."); //THIS STARTS THE BNO SENSOR UPDATE //lcd.Write("Start bmp loop"); //Rebug.Print("Starting bmp sensor updates..."); //bmploop.Start(); //LCDFinish(lcd); //THIS STARTS THE EXPENSIVE MAG UPDATE lcd.Write("Start e.mag loop..."); Rebug.Print("Starting expensive mag updates..."); expensiveMagLoop.Start(); LCDFinish(lcd, "Done."); lcd.Write("Boot successful!"); LCDFinish(lcd, "Entering run state."); Rebug.Print("Flight computer boot successful."); printBnoCalib.Start(); }
public static void Main() { //THIS SECTION CREATES / INITIALIZES THE SERIAL LOGGER Debug.Print("Flight computer started successfully. Beginning INIT."); var logger = new Logger(); Debug.Print("Starting logger..."); logger.Start(); Rebug.Print("Starting stopwatch"); Clock.Instance.Start(); Rebug.Print("Recording time-sync packet"); var timeSync = new TimeSync(delay: 10000); timeSync.Run(); //Initializes the RICH on pin D7 Rebug.Print("Initializing RICH detector"); var rich = new Rich(); //THIS SECTION CREATES/INITIALIZES THE SERIAL BNO 100HZ UPDATER Rebug.Print("Initializing BNO Sensor "); var bnoloop = new SerialBnoUpdater(delay: 1000); //THIS SECTION CREATES/INITIALIZES THE GEIGER COUNTER UPDATER Rebug.Print("Initializing geiger counter collection data"); var geigerloop = new GeigerUpdater(delay: 10, size: 2048); //THIS SECTION CREATES/INITIALIZES THE GEIGER COUNTER UPDATER var accel_dump_size = 18432; Rebug.Print("Initializing fast accel dump collector with a size of " + accel_dump_size + "bytes."); var acceldumploop = new AccelUpdater(accel_dump_size); //Thread.Sleep(5000); Rebug.Print("Flight computer INIT Complete. Continuing with boot."); //THIS SECTION INITIALIZES AND STARTS THE MEMORY MONITOR Rebug.Print("Starting memory monitor..."); MemoryMonitor.Instance.Start(ref logger); //THIS STARTS THE Accel dump update Rebug.Print("Starting accel dumper..."); acceldumploop.Start(); //THIS STARTS THE BNO SENSOR UPDATE Rebug.Print("Starting bno sensor updates..."); bnoloop.Start(); //THIS STARTS THE Geiger UPDATE. Rebug.Print("Starting geiger counter data collection..."); geigerloop.Start(); //Starts the RICH detector Rebug.Print("Starting RICH detector"); rich.TurnOn(); Rebug.Print("Flight computer boot successful."); }
public bool Begin() { Rebug.Print("Starting up expensive mag!"); _comPort.Open(); return(true); }
public static void Main() { I2CBus bus = new I2CBus(); //THIS SECTION CREATES / INITIALIZES THE SERIAL LOGGER Debug.Print("Flight computer started successfully. Beginning INIT."); var logger = new Logger(); Debug.Print("Starting logger."); logger.Start(); Rebug.Print("Starting clock."); Clock.Instance.Start(); //var tracker = new LightTracker(PWMChannels.PWM_PIN_D5, PWMChannels.PWM_PIN_D10, // Cpu.AnalogChannel.ANALOG_2, Cpu.AnalogChannel.ANALOG_0, // Cpu.AnalogChannel.ANALOG_3, Cpu.AnalogChannel.ANALOG_1); var tracker = new LightTracker(PWMChannels.PWM_PIN_D5, Cpu.AnalogChannel.ANALOG_0, Cpu.AnalogChannel.ANALOG_1); tracker.Start(); //THIS SECTION CREATES/INITIALIZES THE PRESSURE SENSOR //lcd.Write("Init BMP sensor."); Rebug.Print("Initializing BMP Sensor "); var bmploop = new PressureTempAltitudeUpdater(bus, delay: 1000); //LCDFinish(lcd); //THIS SECTION CREATES/INITIALIZES THE SERIAL BNO 100HZ UPDATER Rebug.Print("Initializing BNO Sensor "); var bno = new SerialBno(SerialPorts.COM1, 5000, 5000, SerialBno.Bno055OpMode.OperationModeNdof); var bnoloop = new SerialBnoUpdater(bno, delay: 1000); Rebug.Print("Initializing BNO calibration display loop"); var printBnoCalib = new BNOCalibUpdate(bno, delay: 1000); //LCDFinish(lcd, "Done."); //Thread.Sleep(5000); //lcd.Write("Init complete..."); Rebug.Print("Flight computer INIT Complete. Continuing with boot."); //LCDFinish(lcd, "Continuing boot."); //THIS SECTION INITIALIZES AND STARTS THE MEMORY MONITOR //lcd.Write("Start memory monitor..."); Rebug.Print("Starting memory monitor..."); MemoryMonitor.Instance.Start(ref logger); //LCDFinish(lcd, "Done."); //LCDFinish(lcd, "Done."); ////THIS STARTS THE BNO SENSOR UPDATE //lcd.Write("Start bno loop..."); Rebug.Print("Starting bno sensor updates..."); bnoloop.Start(); //LCDFinish(lcd, "Done."); //THIS STARTS THE BNO SENSOR UPDATE //lcd.Write("Start bmp loop"); //TODO BNP180 discontinued... Update at later time Rebug.Print("Starting bmp sensor updates..."); bmploop.Start(); //LCDFinish(lcd); //lcd.Write("Boot successful!"); //LCDFinish(lcd,"Entering run state."); Rebug.Print("Flight computer boot successful."); printBnoCalib.Start(); }