def poll_th(): #data polling thread is main thread #setup gyro and altimeter alt = BMP180.BMP180(POWER_ON_ALT) #motion = LSM9DS0.LSM9DS0() gyro = LSM9DS0.LSM9DS0_GYRO() accel = LSM9DS0.LSM9DS0_ACCEL() f_log = open(DATA_LOG, 'a') f_log.write("starting log\n") last_measure = POWER_ON_ALT #sensors are up, start the xbee thread start_new_thread(xbee_th, ()) while True: try: dict['time'] = datetime.datetime.utcnow() dict['agl'] = alt.read_agl() dict['temp'] = alt.read_temperature() last_measure = dict['agl'] (x, y, z) = accel.read_accel() dict['a_x'] = x dict['a_y'] = y dict['a_z'] = z (x, y, z) = gyro.read() dict['g_x'] = x dict['g_y'] = y dict['g_z'] = z (x, y, z) = accel.read_magnetometer() dict['m_x'] = x dict['m_y'] = y dict['m_z'] = z dict['new_dat_flag'] = 1 f_log.write(str(dict) + "\n") except IOError as e: try: logging.exception('Got I2C exception on main handler' + str(dict['time'])) alt = BMP180.BMP180(last_measure) accel = LSM9DS0.LSM9DS0_ACCEL() gyro = LSM9DS0.LSM9DS0_GYRO() except: logging.exception('Gotexception on recovery attempt') except KeyboardInterrupt: break except: logging.exception('Got an exception on main handler')
import LSM9DS0 from time import sleep import sys import datetime f_log = open('/home/osu_rocketry/python/high_rev.out', 'r') while True: try: gyro = LSM9DS0.LSM9DS0_GYRO(LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_2000DPS) (x, y, z) = gyro.read() accel = LSM9DS0.LSM9DS0_ACCEL(LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_2000DPS) (x_mag, y_mag, z_mag) = accel.read_magnetometer() t = datetime.datetime.utcnow() dat = str(t) + "x: " + str(x) + " y: " + str(y) + " z: " + str(z) dat_mag = str(t) + "x_mag:" + str(x_mag) + "y_mag:" + str(y_mag) + "z_mag:" + str(z_mag) print "Gyro:" print dat print "Magnetometer:" print dat_mag sleep(1) f_log.write(dat) except KeyboardInterrupt: f_log.close() sys.exit() except IOError: i = 1
def poll_th(): #data polling thread is main thread #setup gyro and altimeter alt = BMP180.BMP180(POWER_ON_ALT) #motion = LSM9DS0.LSM9DS0() gyro = LSM9DS0.LSM9DS0_GYRO( LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_2000DPS) accel = LSM9DS0.LSM9DS0_ACCEL() f_log = open(DATA_LOG, 'a') f_log.write("starting log\n") #sensor are up, start the xbee and gps threads start_new_thread(xbee_th, ()) start_new_thread(gps_th, ()) # start_new_thread(log_th, ()) while True: try: trx_data['time'] = datetime.datetime.utcnow() trx_data['agl'] = alt.read_agl() trx_data['temp'] = alt.read_temperature() (x, y, z) = accel.read_accel() trx_data['a_x'] = x trx_data['a_y'] = y trx_data['a_z'] = z (x, y, z) = gyro.read() trx_data['g_x'] = x trx_data['g_y'] = y trx_data['g_z'] = z f_log.write(str(trx_data) + "\n") except IOError as e: try: logging.exception('Got I2C exception on main handler' + str(trx_data['time'])) err_lock.acquire() trx_data['xbee_errors'] += 1 error_trace['error'] += e + '\n' err_lock.release() alt = BMP180.BMP180(trx_data['agl']) accel = LSM9DS0.LSM9DS0_ACCEL() gyro = LSM9DS0.LSM9DS0_GYRO( LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_2000DPS) except: logging.exception('Gotexception on recovery attempt') err_lock.acquire() trx_data['xbee_errors'] += 1 error_trace[ 'error'] += 'error in recovery attempt of ' + e + '\n' err_lock.release() except KeyboardInterrupt: break except: logging.exception('Got an exception on main handler')
def poll_th(): #data polling thread is main thread #setup gyro and altimeter alt = BMP180.BMP180(POWER_ON_ALT) #motion = LSM9DS0.LSM9DS0() gyro = LSM9DS0.LSM9DS0_GYRO( LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_2000DPS) accel = LSM9DS0.LSM9DS0_ACCEL() f_log = open(DATA_LOG, 'a') f_log.write("starting log\n") last_measure = POWER_ON_ALT #sensor are up, start the xbee and gps threads start_new_thread(xbee_th, ()) start_new_thread(gps_th, ()) #start_new_thread(log_th, ()) #for servo testing #remove this part after testing #TODO #start_new_thread(nav_th, ()) while True: try: dict['time'] = datetime.datetime.utcnow() temp_agl = alt.read_agl() if abs(dict['agl'] - last_measure) < 60: dict['agl'] = temp_agl dict['temp'] = alt.read_temperature() #act on altimeter, in case accel fails in some way if (dict['agl'] > MIN_ALT) and (last_measure > MIN_ALT) and (not dict['arm_cut']): dict['arm_cut'] = 1 f_log.write("armed cutter\n") if dict['arm_cut'] and (not dict['start_cut']): if dict['agl'] <= CHUTE_DEPLOY and last_measure <= CHUTE_DEPLOY: dict['start_cut'] = 1 start_new_thread(nav_th, ()) last_measure = temp_agl (x, y, z) = accel.read_accel() dict['a_x'] = x dict['a_y'] = y dict['a_z'] = z (x, y, z) = gyro.read() dict['g_x'] = x dict['g_y'] = y dict['g_z'] = z (x, y, z) = accel.read_magnetometer() dict['m_x'] = x dict['m_y'] = y dict['m_z'] = z dict['new_dat_flag'] = 1 f_log.write(str(dict) + "\n") except IOError as e: try: logging.exception('Got I2C exception on main handler' + str(dict['time'])) err_lock.acquire() dict['xbee_errors'] += 1 error_trace['error'] += e + '\n' err_lock.release() alt = BMP180.BMP180(last_measure) accel = LSM9DS0.LSM9DS0_ACCEL() gyro = LSM9DS0.LSM9DS0_GYRO() except: logging.exception('Gotexception on recovery attempt') err_lock.aqcuire() dict['xbee_errors'] += 1 error_trace[ 'error'] += 'error in recovery attempt of ' + e + '\n' err_lock.release() except KeyboardInterrupt: break except: logging.exception('Got an exception on main handler')
#RTC = DS3231( 0x68, "DS3231") #BotTempAddr = 0x4F #TopTempAddr = 0x4B #InertialAddr = 0x1D # SAGAN MODULE from PCF85263A import * RTC = PCF85263A( 0x51, "PCF85263A") BotTempAddr = 0x48 TopTempAddr = 0x49 InertialAddr = 0x1E #One object for each sensor on the device BotTemp = LM75B(BotTempAddr, "LM75B") TopTemp = LM75B(TopTempAddr, "LM75B") Inertial = LSM9DS0(InertialAddr, "LSM9DSO") Barometer = BME280( 0x76, "BME280") IR_RGB_ALS = APDS_9250( 0x52, "APDS-9250") UV = VEML6070( 0x38, "VEML6070") Arducam = Camera() #Generic sensor information class, describes the sensor class SenInfo: Sensor = None Parameters = None #Defines the class def __init__(self, Sensor, Parameters): self.Sensor = Sensor self.Parameters = Parameters
import LSM9DS0 g = LSM9DS0.LSM9DS0_GYRO() #that is it! isn't it so cool! :)
def poll_th(): #data polling thread is main thread #setup gyro and altimeter alt = BMP180.BMP180(POWER_ON_ALT) gyro = LSM9DS0.LSM9DS0_GYRO(LSM9DS0.LSM9DS0_GYRODR_95HZ | LSM9DS0.LSM9DS0_GYRO_CUTOFF_1, LSM9DS0.LSM9DS0_GYROSCALE_2000DPS) accel = LSM9DS0.LSM9DS0_ACCEL() f_log = open(DATA_LOG, 'a') f_log.write("starting log\n") agl_arr = [0] * 10 i = 0 #sensor are up, start the xbee and gps threads start_new_thread(xbee_th, ()) start_new_thread(gps_th, ()) #start_new_thread(log_th, ()) #for servo testing #remove this part after testing #TODO #start_new_thread(nav_th, ()) while True: try: dict['time'] = datetime.datetime.utcnow() dict['agl'] = round(alt.read_agl(), 2) dict['temp'] = alt.read_temperature() #act on altimeter, in case accel fails in some way agl_arr[i] = dict['agl'] agl_avg = sum(agl_arr)/10 dict['agl_avg'] = agl_avg i += 1 if i == 10: i = 0 if PAYLOAD == 1: if (agl_avg > MIN_ALT) and (not dict['arm_cut']): dict['arm_cut'] = 1 f_log.write("armed cutter\n") if dict['arm_cut'] and (not dict['start_cut']): if agl_avg <= CHUTE_DEPLOY: dict['start_cut'] = 1 start_new_thread(nav_th, ()) (x, y, z) = accel.read_accel() dict['a_x'] = round(x, 5) dict['a_y'] = round(y, 5) dict['a_z'] = round(z, 5) (x, y, z) = gyro.read() dict['g_x'] = round(x, 5) dict['g_y'] = round(y, 5) dict['g_z'] = round(z, 5) (x, y, z) = accel.read_magnetometer() dict['m_x'] = round(x, 5) dict['m_y'] = round(y, 5) dict['m_z'] = round(z, 5) #dict['new_dat_flag'] = 1 f_log.write(str(dict) + "\n") #f_log.write("track:" + str(dict['track']) + " speed:" + str(dict['speed']) + "\n") except IOError as e: try: logging.exception('Got I2C exception on main handler' + str(dict['time'])) err_lock.acquire() dict['xbee_errors'] += 1 error_trace['error'] += e + '\n' err_lock.release() alt = BMP180.BMP180(last_measure) accel = LSM9DS0.LSM9DS0_ACCEL() gyro = LSM9DS0.LSM9DS0_GYRO() except: logging.exception('Gotexception on recovery attempt') err_lock.aqcuire() dict['xbee_errors'] += 1 error_trace['error'] += 'error in recovery attempt of ' + e + '\n' err_lock.release() except KeyboardInterrupt: break except: logging.exception('Got an exception on main handler')