Guest User

Untitled

a guest
Oct 31st, 2018
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. import RPi.GPIO as GPIO
  3. import sys
  4. sys.path.append('.')
  5. import RTIMU
  6.  
  7. class Compass:
  8.  
  9.     def __init__(self):
  10.  
  11.         self.SETTINGS_FILE = "RTIMULib"
  12.         s = RTIMU.Settings(self.SETTINGS_FILE)
  13.         self.imu = RTIMU.RTIMU(s)
  14.  
  15.  
  16.         if (not self.imu.IMUInit()):
  17.             print('IMU init failed.')
  18.             sys.exit(1)
  19.  
  20.         self.imu.setSlerpPower(0.02)
  21.         self.imu.setGyroEnable(True)
  22.         self.imu.setAccelEnable(True)
  23.         self.imu.setCompassEnable(True)
  24.  
  25.         print('IMU init successful.')
  26.         self.poll_interval = self.imu.IMUGetPollInterval()
  27.         print('poll interval: ', self.poll_interval)
  28.  
  29.  
  30.     def getReading(self):
  31.  
  32.         try:
  33.             while True:
  34.  
  35.                 if self.imu.IMURead():
  36.                     data = self.imu.getIMUData()
  37.                     fusion_pose = data['fusionPose']
  38.  
  39.                     time.sleep(self.poll_interval*1.0/1000.0)
  40.                     return(fusion_pose)
  41.  
  42.         except:
  43.             print('error in getting IMU reading')
RAW Paste Data Copied