Exemplo n.º 1
0
__author__ = 'ivanbahdanau'


#!/usr/bin/env python

import sys

import smbus
import bitify.python.sensors.imu as imu
from bitify.python.utils.i2cutils import i2c_raspberry_pi_bus_number


bus = smbus.SMBus(i2c_raspberry_pi_bus_number())
imu_controller = imu.IMU(bus, 0x69, 0x53, 0x1e, "IMU")
imu_controller.set_compass_offsets(41, 136, 9)


if len(sys.argv) >= 2 and sys.argv[1] == 'stat':
    print "pitch,roll,yaw,axelX,axelY,axelZ"
    for i in range(0, 5000):
        ( pitch, roll, yaw, axel_x, axel_y, axel_z) = imu_controller.read_pitch_roll_yaw_with_speeds()
        result = "%.2f %.2f %.2f %.2f %.2f %.2f" % (roll, pitch, yaw, axel_x, axel_y, axel_z)
        print result
else:
    (pitch, roll, yaw, axel_x, axel_y, axel_z) = imu_controller.read_pitch_roll_yaw_with_speeds()
    print "position:"
    print "   pitch = %.3f" % (pitch)
    print "   roll = %.3f" % (roll)
    print "   yaw = %.3f" % (yaw)
    print "====================================="
Exemplo n.º 2
0
    def read_scaled_accel_y(self):
        '''Return the SCALED Y accelerometer value'''
        return self.accel_scaled_y

    def read_scaled_accel_z(self):
        '''Return the SCALED Z accelerometer value'''
        return self.accel_scaled_z

    def read_pitch(self):
        '''Calculate the current pitch value in radians'''
        x = self.read_scaled_accel_x()
        y = self.read_scaled_accel_y()
        z = self.read_scaled_accel_z()
        return self.read_x_rotation(x, y, z)

    def read_roll(self):
        '''Calculate the current roll value in radians'''
        x = self.read_scaled_accel_x()
        y = self.read_scaled_accel_y()
        z = self.read_scaled_accel_z()
        return self.read_y_rotation(x, y, z)


if __name__ == "__main__":
    bus = smbus.SMBus(I2CUtils.i2c_raspberry_pi_bus_number())
    adxl345 = ADXL345(bus, 0x53, "accel")
    adxl345.read_raw_data()
    print adxl345.read_scaled_accel_x()
    print adxl345.read_scaled_accel_y()
    print adxl345.read_scaled_accel_z()
Exemplo n.º 3
0
#!/usr/bin/env python

import web  # web.py
import smbus

import bitify.python.sensors.imu as imu
from bitify.python.utils.i2cutils import i2c_raspberry_pi_bus_number

urls = (
    '/', 'index'
)

bus = smbus.SMBus(i2c_raspberry_pi_bus_number())
imu_controller = imu.IMU(bus, 0x69, 0x53, 0x1e, "IMU")

imu_controller.set_compass_offsets(9, -10, -140)

app = web.application(urls, globals())

class index:
    def GET(self):
        (pitch, roll, yaw) = imu_controller.read_pitch_roll_yaw()
        result = "%.2f %.2f %.2f" % (pitch, roll, yaw)
        return result

if __name__ == "__main__":
    app.run()
Exemplo n.º 4
0
    def read_scaled_accel_y(self):
        '''Return the SCALED Y accelerometer value'''
        return self.accel_scaled_y

    def read_scaled_accel_z(self):
        '''Return the SCALED Z accelerometer value'''
        return self.accel_scaled_z

    
    def read_pitch(self):
        '''Calculate the current pitch value in radians'''
        x = self.read_scaled_accel_x()
        y = self.read_scaled_accel_y()
        z = self.read_scaled_accel_z()
        return self.read_x_rotation(x, y, z)

    def read_roll(self):
        '''Calculate the current roll value in radians'''
        x = self.read_scaled_accel_x()
        y = self.read_scaled_accel_y()
        z = self.read_scaled_accel_z()
        return self.read_y_rotation(x, y, z)

if __name__ == "__main__":
    bus = smbus.SMBus(I2CUtils.i2c_raspberry_pi_bus_number())
    adxl345=ADXL345(bus, 0x53, "accel")
    adxl345.read_raw_data()
    print adxl345.read_scaled_accel_x()
    print adxl345.read_scaled_accel_y()
    print adxl345.read_scaled_accel_z()