Advertisement
Guest User

Untitled

a guest
Dec 25th, 2013
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from L3GD20 import L3GD20
  4. import time
  5. import numpy
  6. import matplotlib.pylab as plt
  7.  
  8. # Communication object
  9. s = L3GD20(busId = 1, slaveAddr = 0x6b, ifLog = False, ifWriteBlock=False)
  10.  
  11. # Preconfiguration
  12. s.Set_PowerMode("Normal")
  13. s.Set_AxisX_Enabled(True)
  14. #s.Set_AxisY_Enabled(False)
  15. #s.Set_AxisZ_Enabled(True)
  16. s.Set_DataRateAndBandwidth(95, 12.5)
  17. s.Set_FifoMode_Value("Bypass")
  18. s.CalibrateZ()
  19. s.Init();
  20. plotEnabled = False
  21. if plotEnabled:
  22.     plt.subplot(111)
  23.  
  24.  
  25. # Read values loop
  26. starttime = time.time()         # this is our start time
  27. t = 0
  28. x = 0
  29. prev_z = 0
  30. tmax = 10
  31. T = []
  32. Z = []
  33. gyroXangle = 9.9
  34. while t < tmax:
  35. #    while s.Get_AxisDataAvailable_Value()[2] == 0:
  36. #        time.sleep(0.001)
  37. #    t = time.time() - starttime
  38.     timer = time.time();
  39.  
  40.     x = s.Get_CalOutX_Value()
  41. #    z = s.Get_CalOutZ_Value()
  42. #    T.append(t)
  43. #    Z.append(z)
  44. #    if z != prev_z:
  45. #        print (z);
  46. #        prev_z = z
  47.  
  48.     xrate = x * 0.020;
  49.  
  50.     gyroXangle += xrate;
  51.  
  52.     print "Gyro X Raw %5i " % x + " Gyro X Turn Rate = %5f " % xrate + " Gyro X Angle %5f" % gyroXangle;
  53.  
  54.     while ((time.time()-timer)< 0.020):
  55.         time.sleep(0.00001)
  56.     print "loopTime %f " % (time.time()-timer),
  57.  
  58.  
  59. if plotEnabled:
  60.     plt.plot(T, Z, 'ro')
  61.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement