def run(self):
        #i2c connection setup
        i2c = busio.I2C(board.SCL, board.SDA)
        sensor = adafruit_bno055.BNO055(i2c)
        #File path for sensordata.txt (writes in local directory)
        working_directory = os.getcwd()
        filepath = working_directory + '/sensordata.txt'
        
        print(filepath)
        print()
        f = open(filepath,'w+')

        while True:
            is_killed = self._kill.is_set()
            if is_killed:
                break;
   # print('Temperature: {} degrees C'.format(sensor.temperature))
   # print('Accelerometer (m/s^2): {}'.format(sensor.accelerometer))
   # print('Magnetometer (microteslas): {}'.format(sensor.magnetometer))
   # print('Gyroscope (deg/sec): {}'.format(sensor.gyroscope))
   # 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))
   # print()
   
            #This is timestamp of the sensor reading(isn't usesd currently)
            a = str(int(round(time.time()*1000)))
            
            #Writing sensor data to the sensor file.
            f.write("{} \n".format(sensor.acceleration))
        print("being Killed")
        f.write("STOP\n")
        print("Stop")
Exemplo n.º 2
0
    def run(self):

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

        working_directory = os.getcwd()
        filepath = working_directory + '/sensordata.txt'

        print(filepath)
        print()
        f = open(filepath, 'w+')

        while True:
            is_killed = self._kill.is_set()
            if is_killed:
                break
# print('Temperature: {} degrees C'.format(sensor.temperature))
# print('Accelerometer (m/s^2): {}'.format(sensor.accelerometer))
# print('Magnetometer (microteslas): {}'.format(sensor.magnetometer))
# print('Gyroscope (deg/sec): {}'.format(sensor.gyroscope))
# 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))
# print()

            time.sleep(1)
            print(strftime("%d %b %Y %H:%M:%S \n", gmtime()))

            f.write(strftime("%d %b %Y %H:%M:%S \n ", gmtime()))
        print("being Killed")
Exemplo n.º 3
0
 def __init__(self) -> None:
     """
     Sets up sensor.
     Arguments: nothing
     Returns: nothing
     """
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.sensor = adafruit_bno055.BNO055(self.i2c)
Exemplo n.º 4
0
def IMU():
    i2c = busio.I2C(board.SCL, board.SDA)
    time.sleep(1)
    sensor = adafruit_bno055.BNO055(i2c)
    sensor.euler[0]  # initialise euler vectors
    sensor.euler[1]
    sensor.euler[2]

    return sensor
Exemplo n.º 5
0
 def __init__(self, i2c):
     try:
         self.sensor = adafruit_bno055.BNO055(i2c)
     except:
         self.status = 1
     self.quaternion = None
     self.temperature = None
     time.sleep(0.5)  #Needs a few ticks to wake
     self.update()
Exemplo n.º 6
0
    def __init__(self):
        import adafruit_bno055
        from busio import I2C
        import board

        self._i2c = I2C(board.SCL, board.SDA)
        self._sensor = adafruit_bno055.BNO055(self._i2c)
        # turn on "compass mode"
        self._sensor.mode = adafruit_bno055.COMPASS_MODE
Exemplo n.º 7
0
	def __init__(self):
		self.i2c = busio.I2C(board.SCL, board.SDA)
		self.sensor = adafruit_bno055.BNO055(self.i2c)
		#self.last_acceleration = None
		self.last_acceleration = (0,0,0)
		self.bad_readings = 0
		self.failed = False
		self.last_tilt = 0
		self.bogus_readings = 0
Exemplo n.º 8
0
    def __init__(self):
        Thread.__init__(self)
        self.daemon = True
        self.lock = threading.Lock()

        self.gpgga_info = "$GPGGA,"
        self.ser = serial.Serial("/dev/ttyS0")  # Open port with baud rate

        self.arduinoAdr = 0x08  # Adres of the Arduino
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.sensor = adafruit_bno055.BNO055(self.i2c, 0x29)

        self.start()
Exemplo n.º 9
0
    def __init__(self):
        #Constants
        self.delay_time = .001

        #I2C Initialization
        self.i2c = busio.I2C(board.SCL, board.SDA)

        #BNO Initialization
        self.bno = adafruit_bno055.BNO055(i2c)
        #self.bno.use_external_crystal = True

        #MPL Initialization
        self.mpl = adafruit_mpl3115a2.MPL3115A2(i2c)
        self.mpl._ctrl_reg1 = adafruit_mpl3115a2._MPL3115A2_CTRL_REG1_OS1 |adafruit_mpl3115a2._MPL3115A2_CTRL_REG1_ALT
        time.sleep(1)
        self.zero_mpl()

        self.led = LED(21)

        #Initialize ADXL
        self.adxl = adafruit_adxl34x.ADXL345(i2c)
        self.adxl.range = adafruit_adxl34x.Range.RANGE_16_G
        self.adxl.data_rate = adafruit_adxl34x.DataRate.RATE_100_HZ

        #Initialize file and write header
        self.filename = self.gen_filename()
        with open(filename,'w') as f:
            f.write("Time ms,")
            #f.write("BNO X Acceleration m/s^2,")
            #f.write("BNO Y Acceleration m/s^2,")
            #f.write("BNO Z Acceleration m/s^2,")
            #f.write("BNO Gyro X rad/s,")    
            #f.write("BNO Gyro Y rad/s,")    
            #f.write("BNO Gyro Z rad/s,")    
            f.write("BNO Euler Angle X,")    
            f.write("BNO Euler Angle Y,")    
            f.write("BNO Euler Angle Z,")    
            #f.write("BNO Magnetometer X,")    
            #f.write("BNO Magnetometer Y,")    
            #f.write("BNO Magnetometer Z,")    
            #f.write("BNO Gravity X,")    
            #f.write("BNO Gravity Y,")    
            #f.write("BNO Gravity Z,")    
            f.write("Altitude m,")    
            f.write("ADXL X Acceleration,")    
            f.write("ADXL Y Acceleration,")    
            f.write("ADXL Z Acceleration,")    
            f.write("\n") 
Exemplo n.º 10
0
	def __init__(self, i2c, path):
		self.address = 0x29
		self.REFRESH_RATE = 1
		self.i2c = i2c
		self.name = "BNO05501"
		self.DATA_PATH = path
		self.sensor = adafruit_bno055.BNO055(i2c, self.address)

		millis = int(round(time.time() * 1000))
		self.ACCEL_f = open(self.DATA_PATH + "-" + self.name + "-ACCEL-" + time.strftime('%d-%m-%Y-%H-%M-%S', time.localtime()) + "." + str(millis) + ".csv", "a+")
		self.GYRO_f = open(self.DATA_PATH + "-" + self.name + "-GYRO-" + time.strftime('%d-%m-%Y-%H-%M-%S', time.localtime()) + "." + str(millis) + ".csv", "a+")
		self.MAG_f = open(self.DATA_PATH + "-" + self.name + "-MAG-" + time.strftime('%d-%m-%Y-%H-%M-%S', time.localtime()) + "." + str(millis) + ".csv", "a+")
		self.EULERA_f = open(self.DATA_PATH + "-" + self.name + "-EULERA-" + time.strftime('%d-%m-%Y-%H-%M-%S', time.localtime()) + "." + str(millis) + ".csv", "a+")
		self.QUATER_f = open(self.DATA_PATH + "-" + self.name + "-QUATER-" + time.strftime('%d-%m-%Y-%H-%M-%S', time.localtime()) + "." + str(millis) + ".csv", "a+")
		self.LINACCEL_f = open(self.DATA_PATH + "-" + self.name + "-LINACCEL-" + time.strftime('%d-%m-%Y-%H-%M-%S', time.localtime()) + "." + str(millis) + ".csv", "a+")
		self.GRAV_f = open(self.DATA_PATH + "-" + self.name + "-GRAV-" + time.strftime('%d-%m-%Y-%H-%M-%S', time.localtime()) + "." + str(millis) + ".csv", "a+")
Exemplo n.º 11
0
	def get_acceleration(self):
		try:
			if self.failed:
				self.sensor = adafruit_bno055.BNO055(self.i2c)
				self.failed = False
			acceleration = self.sensor.acceleration
			if self.sane_reading(acceleration):
				self.last_acceleration = acceleration	
				self.bad_readings = 0
				return acceleration
			else:
				return self.last_acceleration
		except Exception as e:
			print(e)
			if not self.failed:
				self.failed = True
			return 0,0,0
Exemplo n.º 12
0
    def __init__(self):
        # Pull private parameters only for BNO055
        period = rospy.get_param('~period')
        rate = rospy.Rate(1 / period)  #default 100 hz

        i2c = busio.I2C(board.SCL_1, board.SDA_1)
        sensor = adafruit_bno055.BNO055(i2c)

        pub = rospy.Publisher('BNO055', wheel_encoder_data, queue_size=10)

        deltaT = 0.0
        current_time = rospy.get_time()
        previous_time = current_time

        tick_count = 0
        total_tick_count = 0
        rospy.loginfo(rospy.get_caller_id() + ' began IMU Sensor:')

        while not rospy.is_shutdown():
            current_time = rospy.get_time()

            acceleration = sensor.linear_acceleration
            x_accel = acceleration[0]
            y_accel = acceleration[1]
            yaw = sensor.euler[2]

            deltaT += current_time - previous_time

            msg = imu_data()
            msg.linear_acceleration.x = x_accel
            msg.linear_acceleration.y = y_accel
            msg.angular_velocity.z = yaw
            msg.delta_t = deltaT
            msg.stamp = current_time
            msg.is_ready = True

            rospy.loginfo(rospy.get_caller_id() + ' x_accel: ' + str(x_accel) +
                          ' y_accel: ' + str(y_accel) + ' yaw: ' + yaw)

            pub.publish(msg)

            deltaT = 0

            previous_time = current_time
            rate.sleep()
Exemplo n.º 13
0
def setup(robot_config):
    global cs
    global i2c
    global sensor
    global kit
    global pid
    #global camServo

    kit = MotorKit()
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(18, GPIO.OUT)
    cs = GPIO.PWM(18, 50)
    cs.start(camServo)
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_bno055.BNO055(i2c)
    pid = pid_controller(kP, kI, kD, 0.0)
    resetHeading()
    stopMotors()
    stopServo()
    setLedMode(3)  #set LEDs to orange
Exemplo n.º 14
0
    def __init__(self,
                 period=0.025,
                 sensor_state_manager=None,
                 sensor_key=Sensor.KEY_BNO055):
        i2c = busio.I2C(
            board.SCL_1,
            board.SDA_1)  # Initialize I2C bus for the BNO055 IMU Sensor
        self.sensor = adafruit_bno055.BNO055(
            i2c)  # Initialize BNO055 IMU Sensor
        self.measured_value = None  # self.measured_value stores the latest IMU readings
        test = self.sensor.euler  # Calls the sensor for initial IMU reading to check that the sensor is in a ready state
        self.is_ready = True  # Initializes ready true since the test did receive a valid reading
        self.period = period  # Time period (in seconds) for one IMU measurement reading
        self.sensor_key = sensor_key  # Initialize sensor key to identify that future measurement readings originated from this BNO055 sensor

        self.observers = [
        ]  # Create tuple of observers that are waiting for and will receive measurement readings
        self.observers.append(
            sensor_state_manager
        )  # Append sensor_state_manager to receive measurement readings
Exemplo n.º 15
0
    def __init__(self):

        # ROS
        self.odom = Odometry()
        rospy.init_node('Localization', anonymous=True)
        self.odom_pub = rospy.Publisher('/odom', Odometry, queue_size=10)
        self.rate = rospy.Rate(10)  # 10 Hz

        # i2c device must be on Jetson's i2c bus 1
        i2c = busio.I2C(board.SCL, board.SDA)
        self.sensor = adafruit_bno055.BNO055(i2c)
        print("connected to IMU")

        # set up serial connection to GPS
        self.ser = serial.Serial("/dev/ttyACM0", 9600)
        print("connected to GPS")

        while not rospy.is_shutdown():
            self.update()
            self.odom_pub.publish(self.odom)
            self.rate.sleep()
Exemplo n.º 16
0
    def test_read_value(self):
        """
        Access all sensor values as per
        https://github.com/adafruit/Adafruit_CircuitPython_BNO055/blob/bdf6ada21e7552c242bc470d4d2619b480b4c574/examples/values.py
        Note I have not successfully run this test. Possibly a hardware issue with module I have.
        See https://forums.adafruit.com/viewtopic.php?f=60&t=131665
        """
        import board
        gc.collect()
        import adafruit_bno055
        gc.collect()
        i2c = I2C(board.SCL, board.SDA)
        sensor = adafruit_bno055.BNO055(i2c)

        self.assertTrue(9 <= sensor.gravity <= 11)
        self.assertTrue(sensor.temperature != 0)
        self.assertTrue(sensor.acceleration != (0, 0, 0))
        self.assertTrue(sensor.magnetometer != (0, 0, 0))
        self.assertTrue(sensor.gyroscope != (0, 0, 0))
        self.assertTrue(sensor.quaternion != (0, 0, 0, 0))
        sensor.euler
        sensor.linear_acceleration
Exemplo n.º 17
0
def run(ctx, param, value):
    if not value or ctx.resilient_parsing:
        return
    click.secho('Start running the AzatAI Techno Console:', fg='green')
    click.secho("AzatAI Techno Console Started!", fg='green')
    click.secho("Please Press Cntrl + Z to stop! \n WARN: Running code too much time may cause hardware problem!",
                fg='yellow')
    click.secho('INFO: The default see level pressure is: 1013.25', fg='blue')
    while True:
        i2c = I2C(SCL, SDA)
        orientation_sensor = adafruit_bno055.BNO055(i2c)
        light_sensor = SI1145.SI1145()
        gc.collect()
        bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)
        # change this to match the location's pressure (hPa) at sea level
        bme680.sea_level_pressure = 1013.25
        print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        click.secho('BME680:', fg='blue')
        print("\nTemperature: %0.1f C" % bme680.temperature)
        print("Gas: %d ohm" % bme680.gas)
        print("Humidity: %0.1f %%" % bme680.humidity)
        print("Pressure: %0.3f hPa" % bme680.pressure)
        print("Altitude = %0.2f meters" % bme680.altitude)
        click.secho('BNO055', fg='blue')
        print(orientation_sensor.temperature)
        print(orientation_sensor.euler)
        print(orientation_sensor.gravity)
        click.secho('SI1145', fg='blue')
        vis = light_sensor.readVisible()
        _IR = light_sensor.readIR()
        _UV = light_sensor.readUV()
        uvindex = _UV / 100.0
        print('Vis:'+str(vis))
        print("IR"+str(_IR))
        print("UV Index"+str(uvindex))
        time.sleep(3)
    ctx.exit()
Exemplo n.º 18
0
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(MQTT_SERVER, 1883, 60)

# initialize I2C bus and sensors for mma8451
i2c = busio.I2C(board.SCL, board.SDA)

# create the TCA9548A object and give it the I2C bus
tca = adafruit_tca9548a.TCA9548A(i2c)

# create each sensor using the TCA9548A channel instead of the I2C object
mma8451_1 = adafruit_mma8451.MMA8451(tca[0])  # MMA8451_1
mma8451_2 = adafruit_mma8451.MMA8451(tca[1])  # MMA8451_2
mma8451_3 = adafruit_mma8451.MMA8451(tca[2])  # MMA8451_3
bno055 = adafruit_bno055.BNO055(i2c)

# open files for each sensor
mma8451_1_File = open('/mnt/usb/mma8451_1.txt', 'w')
mma8451_2_File = open('/mnt/usb/mma8451_2.txt', 'w')
mma8451_3_File = open('/mnt/usb/mma8451_3.txt', 'w')
bno055_File = open('/mnt/usb/bno055.txt', 'w')


def data():
    x1, y1, z1 = mma8451_1.acceleration
    x2, y2, z2 = mma8451_2.acceleration
    x3, y3, z3 = mma8451_3.acceleration
    orientation_1 = mma8451_1.orientation
    orientation_2 = mma8451_2.orientation
    orientation_3 = MMA8451_3.orientation
Exemplo n.º 19
0
myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1)  # Infinite offline Publish queueing
myAWSIoTMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10)  # 10 sec
myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec

# Connect to AWS IoT
myAWSIoTMQTTClient.connect()

# Subscribe to control sensorDataTopic
myCallbackContainer = CallbackContainer(myAWSIoTMQTTClient)
myAWSIoTMQTTClient.subscribe(controlTopic, 1, myCallbackContainer.customCallback)
time.sleep(2)

# Create BNO055 device
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_bno055.BNO055(i2c)

# Setup MCP3008
## Create the spi bus
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
## Create the cs (chip select)
cs = digitalio.DigitalInOut(board.D5)
## Create the mcp object
mcp = MCP.MCP3008(spi, cs)
## Create an analog input channels
chan0 = AnalogIn(mcp, MCP.P0)
chan1 = AnalogIn(mcp, MCP.P1)
chan2 = AnalogIn(mcp, MCP.P2)
chan3 = AnalogIn(mcp, MCP.P3)
chan4 = AnalogIn(mcp, MCP.P4)
Exemplo n.º 20
0
def IMU():
    i2c = busio.I2C(board.SCL, board.SDA)
    time.sleep(1)
    sensor = adafruit_bno055.BNO055(i2c)
    return sensor
Exemplo n.º 21
0
    def __init__(self):

        # Load parameters
        subname = "janus"  #TODO unhardcode

        # Initalise I2C
        self.i2c = busio.I2C(board.SCL, board.SDA)

        # Initalise Depth Sensor
        self.C = initalizePressureSensor(self.i2c)

        self.pub_odom = rospy.Publisher('depth_odom',
                                        PoseWithCovarianceStamped,
                                        queue_size=1)
        self.pub_map = rospy.Publisher('depth_map',
                                       PoseWithCovarianceStamped,
                                       queue_size=1)

        self.pub_odom_data = PoseWithCovarianceStamped()
        self.pub_odom_data.pose.covariance = [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        ]
        self.pub_odom_data.header.frame_id = subname + "/description/depth_odom_frame"

        self.pub_map_data = PoseWithCovarianceStamped()
        self.pub_map_data.pose.covariance = [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        ]
        self.pub_map_data.header.frame_id = subname + "/description/depth_map_frame"

        # Initalise IMU
        self.imu = adafruit_bno055.BNO055(self.i2c)

        # Setup orientation
        self.imu.mode = adafruit_bno055.CONFIG_MODE
        #         AXIS_REMAP_CONFIG    AXIS_REMAP_SIGN
        # ADDRESS 0x41                 0x42
        # VALUE   0x21                 0x01
        self.imu._write_register(0x41, 0x24)
        self.imu._write_register(0x42, 0x03)
        self.imu.mode = adafruit_bno055.NDOF_MODE

        self.imu_pub = rospy.Publisher('imu', Imu, queue_size=1)

        self.imu_data = Imu()
        self.imu_data.header.frame_id = subname + "/description/imu_link"
        self.imu_data.orientation_covariance = [
            1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6
        ]
        self.imu_data.angular_velocity_covariance = [
            1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6
        ]
        self.imu_data.linear_acceleration_covariance = [
            1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6
        ]

        self.imu_temp_pub = rospy.Publisher('imu_temp_c',
                                            Float64,
                                            queue_size=1)
        self.imu_temp_data = Float64()

        # Initalise PWM Controller
        self.motor = ServoKit(channels=8)
        rospy.loginfo("Initalizing ECSs...")
        for motor_name in motor_map.keys():

            motor_id = motor_map[motor_name]

            rospy.loginfo(motor_name)
            # We have to shift the pulse range from (1100, 1900) because
            # the PCA9685 produces 1440uS pulses at 0.5 throttle using
            # the correct range
            self.motor.servo[motor_id].set_pulse_width_range(1160, 1960)
            time.sleep(0.2)

        self.motor_command_sub = rospy.Subscriber(
            'motor_controllers/pololu_control/command',
            Float64MultiArray,
            self.motor_command_callback,
            queue_size=1)

        # Initalize Battery Monitor
        # Create the ADC object using the I2C bus
        ads = ADS.ADS1115(self.i2c)

        # Create single-ended input on channel 0
        self.battery_monitor_channel = AnalogIn(ads, ADS.P0)

        self.bat_pub = rospy.Publisher('battery_voltage',
                                       Float64,
                                       queue_size=1)
        self.bat_data = Float64()

        # Start Battery Voltage Publisher
        battery_thread = threading.Thread(target=self.battery_publisher)
        battery_thread.start()

        # Setup Depth calibrator
        depth_offset_data = None
        try:
            with open("depth_offset.yaml", "r") as stream:
                depth_offset_data = yaml.safe_load(stream)
                rospy.set_param('/janus/depth_offset',
                                depth_offset_data['depth_offset'])
        except:
            rospy.logwarn("No depth saved!")

        # service to activate depth calibration
        s = rospy.Service('calibrate_depth', CalibrateDepth,
                          self.calibrate_depth)

        # Start Depth Publisher
        depth_thread = threading.Thread(target=self.depth_publisher)
        depth_thread.start()

        # Start IMU Publisher
        imu_thread = threading.Thread(target=self.imu_publisher)
        imu_thread.start()

        rospy.loginfo("Initalization Complete")

        # Run until we kill the core
        rospy.spin()
Exemplo n.º 22
0
 def __init__(self):
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.bno055 = adafruit_bno055.BNO055(self.i2c)
Exemplo n.º 23
0
import time
import logging
import sys
import board
import busio
import adafruit_bno055

import serial
uart = serial.Serial("/dev/ttyS0")
sensor = adafruit_bno055.BNO055(uart)

while True:
    print('Temperature: {} degrees C'.format(sensor.temperature))
    print('Accelerometer (m/s^2): {}'.format(sensor.accelerometer))
    print('Magnetometer (microteslas): {}'.format(sensor.magnetometer))
    print('Gyroscope (deg/sec): {}'.format(sensor.gyroscope))
    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))
    print()

    time.sleep(1)