def main(calibration, net_tables_server):
    """Output data from the BNO to Network Tables
    """
    logging.info("Starting network tables...")
    NetworkTables.initialize(server=net_tables_server)

    while not NetworkTables.isConnected():
        logging.info("Waiting for Network Tables to connect...")
        sleep(1)

    bno_table = NetworkTables.getTable("BNO055")
    logging.info("Connecting to BNO...")
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_bno055.BNO055_I2C(i2c)

    if calibration:
        set_calibration_data(calibration, sensor)

    logging.info("Initialization complete.")

    try:
        while True:
            write_bno_to_network_table(bno_table, sensor)
    except KeyboardInterrupt:
        logging.error("Interrupted!")

    NetworkTables.shutdown()
Esempio n. 2
0
    async def connect(
            self,
            url='/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0',
            baudrate=512000):

        # Position sensor
        t0 = time.time()
        self.reader, self.writer = await serial_asyncio.open_serial_connection(
            url=url, baudrate=baudrate)
        self.logger.info('connect: Positioning device connected.')
        await self.start_ranging()

        # Orientation sensor
        if self.config.use_bno055:
            self.logger.info('connect: Starting up orientation sensor.')
            i2c = board.I2C()
            i2c.init(board.SCL_1, board.SDA_1, 800)
            self.logger.info('connect: I2C initialized.')
            self.sensor = adafruit_bno055.BNO055_I2C(
                i2c)  # TODO: Why does this take so long here?
            self.logger.info(
                'connect: Orientation sensor connected. Reading initial calibrations from sensor.'
            )
            self.read_calibration_from_sensor()
            self.logger.info('connect: Sending stored calibrations to sensor.')
            await self.write_calibration_to_sensor(reset=True, restart=False)
            # asyncio.ensure_future(self._read_bno055())
            self.logger.info('connect: Orientation sensor started.')
            if self.cam is not None:
                self.logger.info(
                    'Camera is used for absolute orientation. Setting BNO055 to IMU mode'
                )
                self.sensor.mode = adafruit_bno055.IMUPLUS_MODE
        else:
            self.logger.info('connect: Orientation sensor is disabled.')
Esempio n. 3
0
    def __init__(self, config, queue, level):
        self._log = Logger("bno055", level)
        if config is None:
            raise ValueError("no configuration provided.")
        self._queue = queue

        self._config = config
        # config
        _config = self._config['ros'].get('bno055')
        self._loop_delay_sec = _config.get('loop_delay_sec')
        _i2c_device = _config.get('i2c_device')
        self._pitch_trim = _config.get('pitch_trim')
        self._roll_trim = _config.get('roll_trim')
        self._heading_trim = _config.get('heading_trim')
        self._error_range = 5.0  # permitted error between Euler and Quaternion (in degrees) to allow setting value, was 3.0
        self._rate = Rate(_config.get('sample_rate'))  # e.g., 20Hz

        # use `ls /dev/i2c*` to find out what i2c devices are connected
        self._bno055 = adafruit_bno055.BNO055_I2C(
            I2C(_i2c_device))  # Device is /dev/i2c-1
        # some of the other modes provide accurate compass calibration but are very slow to calibrate
        #       self._bno055.mode = BNO055Mode.COMPASS_MODE.mode
        #       self._bno055.mode = BNO055Mode.NDOF_FMC_OFF_MODE.mode

        self._counter = itertools.count()
        self._thread = None
        self._enabled = False
        self._closed = False
        self._heading = 0.0  # we jauntily default at zero so we don't return a None
        self._pitch = None
        self._roll = None
        self._is_calibrated = Calibration.NEVER
        self._log.info('ready.')
Esempio n. 4
0
 def __init__(self, frequency: int = 1):
     i2c = I2C(SCL, SDA)
     self.sensor = adafruit_bno055.BNO055_I2C(i2c)
     self.sensor.mode = SENSOR_MODES['NDOF']
     self.frequency = frequency
     self.calibration_cache = dict()
     self.acceleration_log = list()
Esempio n. 5
0
    def __init__(self) -> None:
        i2c = busio.I2C(board.SCL, board.SDA)
        self.__NineAxisSensor = adafruit_bno055.BNO055_I2C(i2c)

        self.__NineAxisSensor.gyro_mode = adafruit_bno055.GYRO_125_DPS
        self.__NineAxisSensor.accel_range = adafruit_bno055.ACCEL_2G
        self.__NineAxisSensor.magnet_mode = adafruit_bno055.MAGNET_ACCURACY_MODE
Esempio n. 6
0
    def __init__(self, config, queue, level):
        self._log = Logger("bno055", level)
        if config is None:
            raise ValueError("no configuration provided.")
        self._config = config
        self._queue = queue

        _config = self._config['ros'].get('bno055')
        self._quaternion_accept = _config.get(
            'quaternion_accept')  # permit Quaternion once calibrated
        self._loop_delay_sec = _config.get('loop_delay_sec')
        _i2c_device = _config.get('i2c_device')

        # use `ls /dev/i2c*` to find out what i2c devices are connected
        self._bno055 = adafruit_bno055.BNO055_I2C(
            I2C(_i2c_device))  # Device is /dev/i2c-1

        self._thread = None
        self._enabled = False
        self._closed = False
        self._heading = None
        self._pitch = None
        self._roll = None
        self._is_calibrated = False
        self._log.info('ready.')
Esempio n. 7
0
    def __init__(self, config, queue, level):
        self._log = Logger("bno055", level)
        if config is None:
            raise ValueError("no configuration provided.")
        self._config = config
        self._queue = queue

        #       # verbose will print some start-up info on the IMU sensors
        #       self._imu = IMU(gs=4, dps=2000, verbose=True)
        #       # setting a bias correction for the accel only; the mags/gyros are not getting a bias correction
        #       self._imu.setBias((0.1,-0.02,.25), None, None)

        _config = self._config['ros'].get('bno055')
        self._quaternion_accept = _config.get(
            'quaternion_accept')  # permit Quaternion once calibrated
        self._loop_delay_sec = _config.get('loop_delay_sec')
        _i2c_device = _config.get('i2c_device')
        self._pitch_trim = _config.get('pitch_trim')
        self._roll_trim = _config.get('roll_trim')
        self._heading_trim = _config.get('heading_trim')

        # use `ls /dev/i2c*` to find out what i2c devices are connected
        self._bno055 = adafruit_bno055.BNO055_I2C(
            I2C(_i2c_device))  # Device is /dev/i2c-1

        self._thread = None
        self._enabled = False
        self._closed = False
        self._heading = 0.0
        self._pitch = None
        self._roll = None
        self._is_calibrated = False
        self._h_max = 3.3  # TEMP
        self._h_min = 3.3  # TEMP
        self._log.info('ready.')
Esempio n. 8
0
    def __init__(self, config, level):
        self._log = Logger("bno055", level)
        if config is None:
            raise ValueError("no configuration provided.")

        self._config = config
        # config
        _config = self._config['ros'].get('bno055')
        self._bno_mode = BNO055Mode.from_name(_config.get('mode'))
        self._pitch_trim = _config.get('pitch_trim')
        self._roll_trim = _config.get('roll_trim')
        self._euler_heading_trim = _config.get('euler_heading_trim')
        self._quat_heading_trim = _config.get('quat_heading_trim')
        self._log.info('trim: heading: {:>5.2f}°(Euler) / {:>5.2f}°(Quat); pitch: {:>5.2f}°; roll: {:>5.2f}°'.format(\
                self._euler_heading_trim, self._quat_heading_trim, self._pitch_trim, self._roll_trim))
        self._error_range = 5.0  # permitted error between Euler and Quaternion (in degrees) to allow setting value, was 3.0
        # use `ls /dev/i2c*` to find out what i2c devices are connected
        _i2c_device = _config.get('i2c_device')
        self._bno055 = adafruit_bno055.BNO055_I2C(
            I2C(_i2c_device))  # Device is /dev/i2c-1
        # some of the modes provide accurate compass calibration but are very slow to calibrate
        #       self.set_mode(BNO055Mode.CONFIG_MODE)
        #       self._bno055.mode = BNO055Mode.COMPASS_MODE.mode
        #       self._bno055.mode = BNO055Mode.NDOF_FMC_OFF_MODE.mode
        self.set_mode(self._bno_mode)
        self._heading = 0.0
        #       self._pitch   = None
        #       self._roll    = None
        self._is_calibrated = Calibration.NEVER
        self._log.info('ready.')
Esempio n. 9
0
    def __init__(self):
        super().__init__("imu_node")

        self.imu_publisher = self.create_publisher(String, "imu_status", 10)
        self.timer_ = self.create_timer(1.0, self.publish_imu)
        self.get_logger().info("IMU status publisher has been started.")

        self.i2c = board.I2C()
        self.sensor = adafruit_bno055.BNO055_I2C(self.i2c)
Esempio n. 10
0
 def start(self):
     if started:
         return 1
     i2c = busio.I2C(board.SCL, board.SDA)
     try:
         self.bno = adafruit_bno055.BNO055_I2C(i2c)
         self.started = True
     except:
         raise RuntimeError("BNO not connected")
Esempio n. 11
0
 def __init__(self):
     super().__init__('node_encoder_publisher')
     
     self.imuPub = self.create_publisher(Float64, 'IMU', 10)
     timer_period = 0.010  # 10 milliseconds
     self.timer = self.create_timer(timer_period, self.timer_callback)               # IMU subscriber callback in every 10 milliseconds
     self.i2c = busio.I2C(board.SCL, board.SDA)					# Initialise Jetson NANO onboard IMU bus
     self.sensor = adafruit_bno055.BNO055_I2C(self.i2c)				# Initialise the BNO055 IMU with I2C port
     self.yaw = Float64()
     self.get_logger().info('Node IMU Publisher started')
Esempio n. 12
0
 def detect_motion_bno055(self):
     try:
         import board
         import busio
         import adafruit_bno055
         self.sensor_bno055 = adafruit_bno055.BNO055_I2C(
             busio.I2C(board.SCL, board.SDA))
         return True
     except:
         return False
Esempio n. 13
0
    def __init__(self, poll_delay=0.01):
        self.on = True
        self.poll_delay = poll_delay
        # optional, parameter p1
        i2c = I2C(6)  # Device is /dev/i2c-1
        self.sensor = adafruit_bno055.BNO055_I2C(i2c)

        self.heading = self.roll = self.pitch = self.sys = self.gyro = self.accel = self.mag = \
            self.ori_x = self.ori_y = self.ori_z = self.ori_w = self.temp_c = self.mag_x = self.mag_y = \
            self.mag_z = self.gyr_x = self.gyr_y = self.gyr_z = self.acc_x = self.acc_y = self.acc_z = \
            self.lacc_x = self.lacc_y = self.lacc_z = self.gra_x = self.gra_y = self.gra_z = 0
Esempio n. 14
0
def emitImuData():
    global i2c
    global sensor

    while True:

        try:
            xA, yA, zA = sensor.acceleration
            xL, yL, zL = sensor.linear_acceleration
            heading, roll, pitch = sensor.euler
            temp = temperature()
            xQ, yQ, zQ, wQ = sensor.quaternion
            sys, gyro, accel, mag = sensor.calibration_status

            data = {
                "accelX": xA,
                "accelY": yA,
                "accelZ": zA,
                "linAccelX": xL,
                "linAccelY": yL,
                "linAccelZ": zL,
                "gForce":
                math.sqrt((xL * xL) + (yL * yL) + (zL * zL)) / GRAVITY,
                "heading": heading,
                "roll": roll,
                "pitch": pitch,
                "temp": temp,
                "quatX":
                xQ,  #quatX and quatY seem to be reversed? x and y values will be swapped in javascript
                "quatY": yQ,
                "quatZ": zQ,
                "quatW": wQ,
                "calSys": sys,
                "calGyro": gyro,
                "calAccel": accel,
                "calMag": mag,
            }

            sio.emit('imuData', json.dumps(data))

        except Exception as ex:

            errorLog = obdUtils.createLogMessage(ERROR, SENSOR_TYPE,
                                                 type(ex).__name__, ex.args)
            print(errorLog)
            sio.emit(
                'log', json.dumps(errorLog)
            )  #will only work if exception is unrelated to node server connection
            i2c = board.I2C()  #try to reconnect to BNO055 sensor
            sensor = adafruit_bno055.BNO055_I2C(i2c)

            continue

        time.sleep(POLL_INTERVAL)
Esempio n. 15
0
 def __init__(self):
     print("BNO055 Constructor")
     super().__init__(self)
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.sensor = adafruit_bno055.BNO055_I2C(self.i2c)
     #self.sensor.mode = adafruit_bno055.COMPASS_MODE
     #self.sensor.mode = adafruit_bno055.IMUPLUS_MODE
     self.sensor.mode = adafruit_bno055.AMG_MODE
     #self.sensor.magnet_operation_mode = adafruit_bno055.MAGNET_ACCURACY_MODE
     super().initialize()
     pass
Esempio n. 16
0
def main(output_file):
    logging.info("Connecting to BNO...")
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_bno055.BNO055_I2C(i2c)

    sensor.mode = adafruit_bno055.NDOF_MODE

    logging.info("Starting calibration...")
    while not sensor.calibrated:
        print_status(sensor)
        sleep(0.5)

    output_calibration_data(output_file, sensor)
Esempio n. 17
0
    def __init__(self):
        self.IMU_ADDRESS = 0x29
        self.DRV_ADDRESS = 0x5A
        self.METER_ADDRESS = '0x40'
        self.DACL_ADDRESS = 0x62
        self.DACR_ADDRESS = 0x63

        self.i2c = busio.I2C(board.SCL, board.SDA)
        devices = self.scan_bus()
        print(devices)
        if len(devices) == 0: print('* No I/O device found')

        if str(self.IMU_ADDRESS) in devices:
            print('* Motion sensor detected')
            self.motion = adafruit_bno055.BNO055_I2C(self.i2c,
                                                     self.IMU_ADDRESS)
        else:
            self.motion = None

        if str(self.DRV_ADDRESS) in devices:
            haptic = adafruit_drv2605.DRV2605(self.i2c, self.DRV_ADDRESS)
            haptic.mode(0x03)  # Analog/PWM Mode
            haptic.use_LRM()
            print('* Haptic driver detected (and set to analog mode)')
        else:
            self.haptic = None

        if str(self.METER_ADDRESS) in devices:
            self.meter = INA219(0.1, 3)
            self.meter.configure(self.meter.RANGE_16V)
            print('* Current sensor detected')
        else:
            self.meter = None

        if str(self.DACL_ADDRESS) in devices:
            self.leftDAC = adafruit_mcp4725.MCP4725(self.i2c,
                                                    self.DACL_ADDRESS)
            print('* Left DAC detected')
        else:
            self.leftDAC = None

        if str(self.DACL_ADDRESS) in devices:
            self.rightDAC = adafruit_mcp4725.MCP4725(self.i2c,
                                                     self.DACR_ADDRESS)
            print('* Left DAC detected')
        else:
            self.rightDAC = None
def start():
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_bno055.BNO055_I2C(i2c)
    print('Temperature: {} degrees C'.format(sensor.temperature))
    print('Accelerometer: (m/s^2): {}'.format(sensor.acceleration))
    print('Magnetometer (microteslas): {}'.format(sensor.magnetic))
    print('Gyroscope (deg/sec): {}'.format(sensor.gyro))
    print('Euler angle: {}'.format(sensor.euler))
    print('Quaternion: {}'.format(sensor.quaternion))
    print('Linear acceleration (m/s^2): {}'.format(sensor.linear_acceleration))
    print('Gravity (m/s^2): {}'.format(sensor.gravity))

    average = 0
    outlier = 0
    for i in range(0, 1000):
        outlier = sensor.temperature
        if outlier < 20:
            print(outlier)
        average += outlier
    print(average / 1000)
Esempio n. 19
0
 def __init__(self):
     i2c = busio.I2C(board.SCL, board.SDA)
     self.sensor = adafruit_bno055.BNO055_I2C(i2c)
     #		self.gpsd = gps(mode=WATCH_ENABLE)
     self.Coord = None
     self.initialEuler = np.array([[None], [None], [None]])
     self.euler = None
     self.compAccel = None
     self.linAccel = None
     self.quaternion = None
     self.stopRecording = False
     self.initialCoord = None
     self.stopInitializingEuler = False
     self.initialEulerPrint = True
     self.calibrationValues = np.array([None, None, None, None])
     with open('calib.pickle', 'rb') as f:
         off_acc, off_mag, off_gyro, rad_acc, rad_mag = pickle.load(f)
     self.sensor.mode = adafruit_bno055.CONFIG_MODE
     self.sensor._write_register(0x55, off_acc)
     self.sensor._write_register(0x5B, off_mag)
     self.sensor._write_register(0x61, off_gyro)
     self.sensor._write_register(0x67, rad_acc)
     self.sensor._write_register(0x69, rad_mag)
     self.sensor.mode = adafruit_bno055.NDOF_MODE
Esempio n. 20
0
import _thread
import threading
from digitalio import DigitalInOut, Direction, Pull

DataQueue = queue.Queue()
PacketCount = 0

BackupFile = "/home/pi/BackUpData.txt"
BackupDataFile = ""
ErrorFile = "/home/pi/ErrorLog.txt"
ErrorDataFile = ""

try:
    i2c = busio.I2C(board.SCL, board.SDA)
    bmpSensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
    orientationSensor = adafruit_bno055.BNO055_I2C(i2c)
    CS = DigitalInOut(board.CE1)
    RESET = DigitalInOut(board.D25)
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
    rfm9x.tx_power = 23
    print('RFM9x: Detected')  # Inform UI

except RuntimeError as error:

    print('Sensor error: ' + error)  #Inform UI
    ErrorLog(error)
    CloseFiles()


def OpenAmplifier():
Esempio n. 21
0
import time
import board
import busio
import adafruit_bno055

import numpy as np
np.set_printoptions(linewidth=np.inf, precision=6, suppress=True)

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_bno055.BNO055_I2C(i2c)

sensor.mode = adafruit_bno055.IMUPLUS_MODE

tt = None

for i in range(1000000):
    t0 = time.clock()
    g = sensor.gyro
    t1 = time.clock()

    t = (t1 - t0)

    if tt is None:
        tt = t
    else:
        if t > tt:
            tt = t

    print(tt, t)
    # print(np.array(sensor._euler))
    # time.sleep(1.0/50.0)
Esempio n. 22
0
try:
    import time
    import RPi.GPIO as IO
    IO.setmode(IO.BCM)
    IO.setwarnings(False)
    import board
    import busio
    #set i2c connection - note that pins 2 (SDA) and 3 (SCL) are the only i2c connections on pi 3B+ model
    i2c = busio.I2C(board.SCL, board.SDA)
    import adafruit_bno055 as bno
    sensor = bno.BNO055_I2C(i2c)
except:
    print('Error initializing BNO055 sensor')

print('BNO055 sensor reading initialized')
time.sleep(1)

#set control pins on pi - note that 18 is the only hardware PWM pin on 3B+ model
PWM_CTRL = 18
PWM_FREQ = 100
DIR_CTRL = 15

#set tolerances on angles and velocities
TOL_EUL = 1  #degrees
TOL_VEL = 0.1  #rad/sec

try:
    IO.setup(PWM_CTRL, IO.OUT)
    IO.setup(DIR_CTRL, IO.OUT)

    IO.output(DIR_CTRL, IO.HIGH)
Esempio n. 23
0
    def __init__(self,
        _wheelspeed=True,
        _rpm=True,
        _gps=True,
        _imu=True,
        _engTemp=True,
        _camera=True,
        influxUrl='http://192.168.254.40:8086',
        influxToken="rc0LjEy36DIyrb1CX6rnUDeMJ0-ldW5Mps1KOwkSRrRhbRWDsGzPlNn6BOiyg96vWEKRMZ3xwsfZVgIAxL2gCw==",
        race='test5',
        units='standard'):
        """_args enables sensor type, on by default"""
        #influx config
        self.org = "rammers"
        self.bucket = race
        self.client = InfluxDBClient(url=influxUrl, token=influxToken)
        self.write_api = self.client.write_api(write_options=SYNCHRONOUS)

        self.units = units
        # self.unitCalc_temp = lambda x : x*9/5+32 if self.units == 'standard' else x
        self.lap = 0
        self.distance = 0
        self.speed = 0 #mph
        self.rpm = 0 #int
        self.engineTemp= 0
        self.airTemp = 0
        self.rpm_elapse = time.monotonic()
        self.wheel_elapse = time.monotonic()

        #timing
        self.current_sector = 1
        self.lapTime = 0
        self.lastLap = 0
        self.bestLap = 0
        self.sessionTime = time.monotonic()
        self.rider = 'default'
        self.sectorTime = time.monotonic()
        self.mapData = 0
        self.s1Time=0
        self.s2Time=0
        self.s3Time=0

        if _wheelspeed == True or _rpm == True:
            self.GPIO = GPIO
            self.GPIO.setmode(GPIO.BCM)
            self.GPIO.setwarnings(False)

        if _wheelspeed == True:
            self.GPIO.setup(17,GPIO.IN,GPIO.PUD_UP)
            self.GPIO.add_event_detect(17,GPIO.FALLING,callback=self.speedCalc,bouncetime=20)

        if _rpm == True:
            self.GPIO.setup(27,GPIO.IN,GPIO.PUD_DOWN)
            self.GPIO.add_event_detect(27,GPIO.RISING,callback=self.rpmCalc,bouncetime=2)

        if _imu == True:#IMU
            self.imu = adafruit_bno055.BNO055_I2C(busio.I2C(board.SCL, board.SDA))

        if _gps == True:
            uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=10)
            self.gps = adafruit_gps.GPS(uart, debug=False)
            self.gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0")
            self.gps.send_command(b"PMTK220,10000")

        if _engTemp == True: #thermocouple
            self.spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
            self.cs = digitalio.DigitalInOut(board.D5)
            self.max31855 = adafruit_max31855.MAX31855(self.spi, self.cs)

        self.sensorDict=dict()
        self.sensorThread = threading.Thread(target=self.call_sensorDict)
        self.sensorThread.start()
Esempio n. 24
0
def plant_detection():
    # Initilization of the script is now below...

    # Initialize the IMU
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_bno055.BNO055_I2C(i2c)

    # Initialize the LED
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(18, GPIO.OUT)  # Pin 18
    GPIO.output(18, GPIO.HIGH)

    # Initialize the last GPS location to nowhere
    GPS_last = [0, 0]

    # Set y acceleration low and high thresholds
    accLowThreshold = 5
    accHighThreshold = 20

    # Set timing thesholds to check for values over
    timeCheckLowHigh = 1
    timeCheckAV = 2

    # Set x angular velocity thresholds
    angVThreshold = 1.5

    # Finished initialization
    time.sleep(5)
    GPIO.output(18, GPIO.LOW)

    # Loop until off
    while True:

        # Get the latest GPS data
        GPS = get_lat_lng()

        # Initialize GPS location
        while (GPS == [0.0, 0.0]):
            GPIO.output(18, GPIO.HIGH)
            time.sleep(0.25)
            GPIO.output(18, GPIO.LOW)
            time.sleep(0.25)
            GPS = get_lat_lng()

        print("GPS: " + str(GPS))
        print("Accelerometer: " + str(sensor.acceleration))
        print("Gyroscope: " + str(sensor.gyro))
        print()

        # Has a plant just occured?
        plant = False

        # Are we DENSITY meters away from our last plant?
        if distance(GPS[0], GPS[1], GPS_last[0], GPS_last[1]) >= density:
            # Turn LED off to signify ready to plant
            GPIO.output(18, GPIO.LOW)
        else:
            # Turn LED on to signify in bad range
            GPIO.output(18, GPIO.HIGH)

        # Check if the acceleration is below the initial threshold
        if sensor.acceleration[1] < accLowThreshold:

            # If the acceleration is below the threshold, loop until it isn't
            while sensor.acceleration[1] < accLowThreshold:
                continue

            # Sets an end time to check for a planting instance until
            t_end_lh = time.time() + timeCheckLowHigh

            # Loop until the end time
            while time.time() < t_end_lh:

                # Did a plant just occur?
                if plant == True:
                    break

                # Check if the acceleration is above a threshold
                if sensor.acceleration[1] > accHighThreshold:

                    # If the acceleration is above the threshold, loop until it isn't
                    while sensor.acceleration[1] > accHighThreshold:
                        continue

                    # Set a new time end to loop until to check the angular velocity over
                    t_end_av = time.time() + timeCheckAV

                    # Loop until the end time
                    while time.time() < t_end_av:

                        # If the angular velocity is above the threshold, a planting instance has occured!
                        if np.abs(sensor.gyro[0]) > angVThreshold:

                            # Calls on record location to record GPS location
                            GPS_last = record_location(datetime.datetime.now())

                            # Sets plant to true to return to top of loop
                            plant = True
                            break
 def __init__(self) -> None:
     self.BNO055 = adafruit_bno055.BNO055_I2C(board.I2C())
     self.calibrate()
Esempio n. 26
0
import time
import board
import busio
import adafruit_bno055

sensor = adafruit_bno055.BNO055_I2C(busio.I2C(board.SCL, board.SDA))


def imuEuler():
    raw = sensor.euler
    x = raw[0]
    y = raw[1]
    z = raw[2]
    return str(y)


def imuTemp():
    raw = sensor.temperature
    output = raw.split('.')[0]
    return raw


#
# class IMU:
#     def __init__(self):
#         self.sensor = adafruit_bno055.BNO055_I2C(busio.I2C(board.SCL, board.SDA))
#     def euler(self):
#         return self.sensor.euler
# while True:
#     print("Temperature: {} degrees C".format(sensor.temperature))
#     print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
Esempio n. 27
0
 def __init__(self, i2c):
     self.i2c = i2c
     self.sensor = adafruit_bno055.BNO055_I2C(self.i2c)
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import json
import threading
import time

import board
import busio
import flask

import adafruit_bno055

i2c = busio.I2C(board.SCL, board.SDA)

# Create the BNO sensor connection.
bno = adafruit_bno055.BNO055_I2C(i2c)

# Application configuration below.  You probably don't need to change these values.

# How often to update the BNO sensor data (in hertz).
BNO_UPDATE_FREQUENCY_HZ = 10

# Name of the file to store calibration data when the save/load calibration
# button is pressed.  Calibration data is stored in JSON format.
CALIBRATION_FILE = "calibration.json"

# BNO sensor axes remap values.  These are the parameters to the BNO.set_axis_remap
# function.  Don't change these without consulting section 3.4 of the datasheet.
# The default axes mapping below assumes the Adafruit BNO055 breakout is flat on
# a table with the row of SDA, SCL, GND, VIN, etc pins facing away from you.
# BNO_AXIS_REMAP = { 'x': BNO055.AXIS_REMAP_X,
Esempio n. 29
0
    def __init__(self):
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.sensor = adafruit_bno055.BNO055_I2C(self.i2c)

        self.linear_acceleration = [0.0, 0.0, 0.0]
        self.gyro = [0.0, 0.0, 0.0]
Esempio n. 30
0
 def __init__(self, tofPinArray, i2c):
     self.i2c = i2c
     self.initTofs(tofPinArray)
     self.dof = adafruit_bno055.BNO055_I2C(self.i2c)