コード例 #1
0
def main():
    # Instantiate an AK8975 on I2C bus 0
    sensor = sensorObj.AK8975()

    ## Exit handlers ##
    # This function stops python from printing a stacktrace when you hit control-C
    def SIGINTHandler(signum, frame):
        raise SystemExit

    # This function lets you run code on exit
    def exitHandler():
        print "Exiting"
        sys.exit(0)

    # Register exit handlers
    atexit.register(exitHandler)
    signal.signal(signal.SIGINT, SIGINTHandler)

    sensor.init()

    x = sensorObj.new_floatp()
    y = sensorObj.new_floatp()
    z = sensorObj.new_floatp()

    while (1):
        sensor.update()
        sensor.getMagnetometer(x, y, z)
        print "Magnetometer:  MX: ", sensorObj.floatp_value(x),
        print " MY: ", sensorObj.floatp_value(y),
        print " MZ: ", sensorObj.floatp_value(z)

        print

        time.sleep(.5)
コード例 #2
0
def main():
    # Instantiate an MPU60X0 on I2C bus 0
    sensor = sensorObj.MPU60X0()

    ## Exit handlers ##
    # This function stops python from printing a stacktrace when you hit control-C
    def SIGINTHandler(signum, frame):
        raise SystemExit

    # This function lets you run code on exit
    def exitHandler():
        print("Exiting")
        sys.exit(0)

    # Register exit handlers
    atexit.register(exitHandler)
    signal.signal(signal.SIGINT, SIGINTHandler)

    UDP_IP = "192.168.0.10"
    UDP_PORT = 6001
    MESSAGE = ""

    sensor.init()

    x = sensorObj.new_floatp()
    y = sensorObj.new_floatp()
    z = sensorObj.new_floatp()

    print('start')
    while (1):
        sensor.update()
        sensor.getAccelerometer(x, y, z)
        #print("Accelerometer: AX: ", sensorObj.floatp_value(ax), end=' ')
        #print(" AY: ", sensorObj.floatp_value(ay), end=' ')
        #print(" AZ: ", sensorObj.floatp_value(az))

        MESSAGE = str(sensorObj.floatp_value(x)) + ' ' + str(
            sensorObj.floatp_value(y)) + ' ' + str(sensorObj.floatp_value(z))

        sensor.getGyroscope(x, y, z)
        #print("Gyroscope:     GX: ", sensorObj.floatp_value(x), end=' ')
        #print(" GY: ", sensorObj.floatp_value(y), end=' ')
        #print(" GZ: ", sensorObj.floatp_value(z))

        #print("Temperature:  ", sensor.getTemperature())
        #print()

        MESSAGE += ' ' + str(sensorObj.floatp_value(x)) + ' ' + str(
            sensorObj.floatp_value(y)) + ' ' + str(sensorObj.floatp_value(z))
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
        time.sleep(.1)
コード例 #3
0
    def RecieveData(self):

        GyrBias = self.GyrBias

        # Initialize the accumulative variables
        x = pyupm_mpu9150.new_floatp()
        y = pyupm_mpu9150.new_floatp()
        z = pyupm_mpu9150.new_floatp()
        ax = 0
        ay = 0
        az = 0
        gx = 0
        gy = 0
        gz = 0

        # Get the raw data
        for i in range(self.const.AVGTIME):
            self.update()

            # Acceleration Data
            self.getAccelerometer(x, y, z)
            ax += pyupm_mpu9150.floatp_value(x)
            ay += pyupm_mpu9150.floatp_value(y)
            az += pyupm_mpu9150.floatp_value(z)

            # Angular Speed Data
            self.getGyroscope(x, y, z)
            gx += pyupm_mpu9150.floatp_value(x)
            gy += pyupm_mpu9150.floatp_value(y)
            gz += pyupm_mpu9150.floatp_value(z)

            # Pause time for next sampling
            time.sleep(self.const.SAMPLETIME)

        Acc = np.array([ax, ay, az])
        Gyr = np.array([gx, gy, gz]) - GyrBias
        Acc = Acc * self.const.G / self.const.AVGTIME
        Gyr = Gyr / self.const.AVGTIME

        self.Acc = Acc
        self.Gyr = Gyr
コード例 #4
0
ファイル: mpu60x0.py プロジェクト: oronum/upm
def main():
    # Instantiate an MPU60X0 on I2C bus 0
    sensor = sensorObj.MPU60X0()

    ## Exit handlers ##
    # This function stops python from printing a stacktrace when you hit control-C
    def SIGINTHandler(signum, frame):
        raise SystemExit

    # This function lets you run code on exit
    def exitHandler():
        print "Exiting"
        sys.exit(0)

    # Register exit handlers
    atexit.register(exitHandler)
    signal.signal(signal.SIGINT, SIGINTHandler)

    sensor.init()

    x = sensorObj.new_floatp()
    y = sensorObj.new_floatp()
    z = sensorObj.new_floatp()

    while (1):
        sensor.update()
        sensor.getAccelerometer(x, y, z)
        print "Accelerometer: AX: ", sensorObj.floatp_value(x),
        print " AY: ", sensorObj.floatp_value(y),
        print " AZ: ", sensorObj.floatp_value(z)

        sensor.getGyroscope(x, y, z)
        print "Gyroscope:     GX: ", sensorObj.floatp_value(x),
        print " GY: ", sensorObj.floatp_value(y),
        print " GZ: ", sensorObj.floatp_value(z)

        print "Temperature:  ", sensor.getTemperature()
        print

        time.sleep(.5)
コード例 #5
0
ファイル: mpu9250.py プロジェクト: MotionCTL/edison-mpu9250

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)

sensor.init()

x = sensorObj.new_floatp()
y = sensorObj.new_floatp()
z = sensorObj.new_floatp()

while (1):
    sensor.update()
    sensor.getAccelerometer(x, y, z)
    print "Accelerometer: AX: ", sensorObj.floatp_value(x),
    print " AY: ", sensorObj.floatp_value(y),
    print " AZ: ", sensorObj.floatp_value(z)

    sensor.getGyroscope(x, y, z)
    print "Gyroscope:     GX: ", sensorObj.floatp_value(x),
    print " GY: ", sensorObj.floatp_value(y),
    print " GZ: ", sensorObj.floatp_value(z)

    sensor.getMagnetometer(x, y, z)
    print "Magnetometer:  MX: ", sensorObj.floatp_value(x),
    print " MY: ", sensorObj.floatp_value(y),
    print " MZ: ", sensorObj.floatp_value(z)

    print "Temperature:  ", sensor.getTemperature()
    print
コード例 #6
0
def main():
    """
    Initialization
    """
    # Instantiate an MPU60X0 on I2C bus 0
    sensor_1 = sensorObj.MPU60X0()

    ## Exit handlers ##
    # This function stops python from printing a stacktrace when you hit control-C
    def SIGINTHandler(signum, frame):
        raise SystemExit

    # This function lets you run code on exit
    def exitHandler():
        print("Exiting")
        sys.exit(0)

    # UDP Initialization
    UDP_IP = "192.168.0.105"
    UDP_PORT = 6001
    MESSAGE = ""
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    # Register exit handlers
    atexit.register(exitHandler)
    signal.signal(signal.SIGINT, SIGINTHandler)

    sensor_1.init()
    sensor_1.enableTemperatureSensor(False)
    if (not sensor_1.setDigitalLowPassFilter(20)):
        print("Failed to set up filter")
    #sensor_2.init()

    sensor_1.setAccelerometerScale(3)
    sensor_1.setGyroscopeScale(2)
    x = sensorObj.new_floatp()
    y = sensorObj.new_floatp()
    z = sensorObj.new_floatp()

    # Sample frequency
    sampleFreq = 5
    sampleTime = 1.0 / sampleFreq

    while (1):
        # Update the data in MPU
        sensor_1.update()
        """
        Get raw data from Accelerometer and Gyroscope
        """
        sensor_1.getAccelerometer(x, y, z)
        ax = sensorObj.floatp_value(x)
        ay = sensorObj.floatp_value(y)
        az = sensorObj.floatp_value(z)

        sensor_1.getGyroscope(x, y, z)
        gx = sensorObj.floatp_value(x)
        gy = sensorObj.floatp_value(y)
        gz = sensorObj.floatp_value(z)
        """
        Send out message to server
        """

        if (math.fabs(az) >= 0.02):
            Pitch = math.atan(ax / az) * (180 / math.pi)
            Roll = math.atan(ay / az) * (180 / math.pi)
        else:
            Pitch = 90
            Roll = 0
        MESSAGE = "{:.0f} {:.0f} 0 0".format(Pitch, Roll)
        sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
コード例 #7
0
ファイル: mpu9150.py プロジェクト: BiosPsucheZoe/upm
	sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)

sensor.init()

x = sensorObj.new_floatp()
y = sensorObj.new_floatp()
z = sensorObj.new_floatp()

while (1):
        sensor.update()
        sensor.getAccelerometer(x, y, z)
        print "Accelerometer: AX: ", sensorObj.floatp_value(x), 
        print " AY: ", sensorObj.floatp_value(y),
        print " AZ: ", sensorObj.floatp_value(z)

        sensor.getGyroscope(x, y, z)
        print "Gyroscope:     GX: ", sensorObj.floatp_value(x), 
        print " GY: ", sensorObj.floatp_value(y),
        print " GZ: ", sensorObj.floatp_value(z)

        sensor.getMagnetometer(x, y, z)
        print "Magnetometer:  MX: ", sensorObj.floatp_value(x), 
        print " MY: ", sensorObj.floatp_value(y),
        print " MZ: ", sensorObj.floatp_value(z)

        print "Temperature:  ", sensor.getTemperature()
        print
コード例 #8
0
ファイル: ak8975.py プロジェクト: BiosPsucheZoe/upm
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
	raise SystemExit

# This function lets you run code on exit
def exitHandler():
	print "Exiting"
	sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)

sensor.init()

x = sensorObj.new_floatp()
y = sensorObj.new_floatp()
z = sensorObj.new_floatp()

while (1):
        sensor.update()
        sensor.getMagnetometer(x, y, z)
        print "Magnetometer:  MX: ", sensorObj.floatp_value(x), 
        print " MY: ", sensorObj.floatp_value(y),
        print " MZ: ", sensorObj.floatp_value(z)

        print

	time.sleep(.5)
コード例 #9
0
def SIGINTHandler(signum, frame):
    raise SystemExit


# This function lets you run code on exit
def exitHandler():
    print "Exiting"
    sys.exit(0)


# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)

sensor.init()

x = sensorObj.new_floatp()
y = sensorObj.new_floatp()
z = sensorObj.new_floatp()

while (1):
    sensor.update()
    sensor.getMagnetometer(x, y, z)
    print "Magnetometer:  MX: ", sensorObj.floatp_value(x),
    print " MY: ", sensorObj.floatp_value(y),
    print " MZ: ", sensorObj.floatp_value(z)

    print

    time.sleep(.5)