Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from L3GD20 import L3GD20
- import time
- import numpy
- import matplotlib.pylab as plt
- # Communication object
- s = L3GD20(busId = 1, slaveAddr = 0x6b, ifLog = False, ifWriteBlock=False)
- # Preconfiguration
- s.Set_PowerMode("Normal")
- s.Set_AxisX_Enabled(True)
- #s.Set_AxisY_Enabled(False)
- #s.Set_AxisZ_Enabled(True)
- s.Set_DataRateAndBandwidth(95, 12.5)
- s.Set_FifoMode_Value("Bypass")
- s.CalibrateZ()
- s.Init();
- plotEnabled = False
- if plotEnabled:
- plt.subplot(111)
- # Read values loop
- starttime = time.time() # this is our start time
- t = 0
- x = 0
- prev_z = 0
- tmax = 10
- T = []
- Z = []
- gyroXangle = 9.9
- while t < tmax:
- # while s.Get_AxisDataAvailable_Value()[2] == 0:
- # time.sleep(0.001)
- # t = time.time() - starttime
- timer = time.time();
- x = s.Get_CalOutX_Value()
- # z = s.Get_CalOutZ_Value()
- # T.append(t)
- # Z.append(z)
- # if z != prev_z:
- # print (z);
- # prev_z = z
- xrate = x * 0.020;
- gyroXangle += xrate;
- print "Gyro X Raw %5i " % x + " Gyro X Turn Rate = %5f " % xrate + " Gyro X Angle %5f" % gyroXangle;
- while ((time.time()-timer)< 0.020):
- time.sleep(0.00001)
- print "loopTime %f " % (time.time()-timer),
- if plotEnabled:
- plt.plot(T, Z, 'ro')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement