def main(): console.alert('Motion Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') w = 512 h = 512 while True: sleep(0.1) current = motion.get_gravity() newMotion = [0, 0, 0] for i in range(len(current)): newMotion[i] = (current[i] * (10**3)) // 1 #print(newMotion) if newMotion[0] < 1001 and newMotion[0] > 900 and newMotion[ 1] > -50 and newMotion[1] < 50 and newMotion[ 2] > -50 and newMotion[2] < 50: canvas.set_size(w, h) canvas.set_fill_color(1, 0, 0) canvas.fill_ellipse(0, 0, w, h) if newMotion[0] > -1001 and newMotion[0] < -900 and newMotion[ 1] > -50 and newMotion[1] < 50 and newMotion[ 2] > -50 and newMotion[2] < 50: canvas.set_size(w, h) canvas.set_fill_color(0, 1, 0) canvas.fill_ellipse(0, 0, w, h) if newMotion[0] > -50 and newMotion[0] < 50 and newMotion[ 1] > -50 and newMotion[1] < 50 and newMotion[ 2] > -1001 and newMotion[2] < -900: canvas.set_size(w, h) canvas.set_fill_color(0, 0, 1) canvas.fill_ellipse(0, 0, w, h) motion.stop_updates() print('Capture finished, plotting...')
def run(self, sr=100.0, dur=3.0, cal_dur=1.0, co=0.0, target=0.0): mx_sl = 1.0/sr b = np.array([1.0,0.0,0.0]) a = np.array([0.0,0.0]) if co > 0.0 and co <= sr/2.0: a, b = calcFiltCoefs(co/sr) smpls = math.floor((cal_dur + dur)*sr) + 3 print smpls ti = np.zeros([smpls]) ar = np.zeros([smpls,3]) af = np.zeros([smpls,3]) vf = np.zeros([smpls,3]) idx = 2 motion.start_updates() ti[1]=time.time() ti[0]=ti[1] while time.time() - ti[1] < cal_dur: ti[idx] = time.time() ar[idx,:] = self.__collect() idx += 1 time.sleep(max([0,mx_sl - (time.time()-ti[idx-1])])) avg = np.average(ar[2:idx,:],axis=0) print 'Cal Done.', avg while ti[idx-1] - ti[1] < dur + cal_dur: ti[idx] = time.time() ar[idx,:] = self.__collect() - avg af[idx,:] = (b[0]*ar[idx]+b[1]*ar[idx-1]+b[2]*ar[idx-2,:] +a[0]*af[idx-1,:]+a[1]*af[idx-2,:]) vf[idx,:] = vf[idx-1,:] + 0.5*(af[idx,:]+af[idx-1,:])*(ti[idx]-ti[idx-1]) idx += 1 time.sleep(max([0,mx_sl - (time.time()-ti[idx-1])])) return ti[:idx], af[:idx,:], vf[:idx,:]
def setup(self): self.center = self.bounds.center() if use_motion: motion.start_updates() self.particles = [] for p in xrange(200): self.particles.append(Particle(self.size))
def main(): console.alert( 'Motion Plot', 'When you tap Continue, accelerometer (motion) data will be recorded for 5 seconds.', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') num_samples = 100 data = [] for i in range(num_samples): sleep(0.05) g = motion.get_gravity() data.append(g) motion.stop_updates() print('Capture finished, plotting...') x_values = [x * 0.05 for x in range(num_samples)] for i, color, label in zip(range(3), 'rgb', 'XYZ'): plt.plot(x_values, [g[i] for g in data], color, label=label, lw=2) plt.grid(True) plt.xlabel('t') plt.ylabel('G') plt.gca().set_ylim([-1.0, 1.0]) plt.legend() plt.show()
def setup(self): motion.start_updates() self.x = self.size.w * 0.5 self.y = self.size.h * 0.5 self.cx = self.x self.cy = self.y self.max = 0
def did_load(self): ht = self['helptext'] self.tv = self['tiltview'] ht.hidden = True ht.y = 100 c1 = self['color1'] setcolor(c1) ss = self['sensitivity'] ss.value = (gravsense - senserange[0]) / (senserange[1] - senserange[0]) self['scalev'].text = '{0:.2f}'.format(gravsense) dfc = self['difficulty'] dfc.action = self.setdiff dfc.selected_index = self.difficulty vis = self['visualize'] if vis: vis.value = False b = self['bubble'] b.image = ui.Image.named('Red_Circle').with_rendering_mode( ui.RENDERING_MODE_ORIGINAL) self.tv.ball = b motion.start_updates()
def setup(self): global scale self.background_color = 'white' self.measuringOn = False #am i taking in location coordinates? self.checkedOnce = 0 #counter for the mode (things happen sequentially so this works) # self.locations = [] #array of recorded coordinates #self.locations = [(40.4464,-79.9427),(40.4464,-79.9428),(40.4465,-79.9428),(40.4463,-79.9427),(40.4462,-79.9427),(40.4461,-79.9427),(40.446,-79.9427)] #self.locations = [(40.444,-79.9446),(40.444,-79.9445),(40.4441,-79.9446),(40.4441,-79.9447),(40.4442,-79.9447),(40.4443,-79.9447),(40.4444,-79.9447),(40.4444,-79.9448),(40.4445,-79.9447),(40.4446,-79.9447),(40.4446,-79.9446),(40.4447,-79.9446),(40.4448,-79.9446),(40.4449,-79.9445),(40.445,-79.9445)] #self.locations = [(40.444,-79.9446),(40.444,-79.9445),(40.4441,-79.9446),(40.4441,-79.9447),(40.4442,-79.9447),(40.4449,-79.9449)] self.locations = [(40.444, -79.9446), (40.444, -79.9445), (40.4441, -79.9446), (40.4441, -79.9447), (40.4442, -79.9447)] self.locationsLeft = [] self.needMore = False #need more values self.timerCount = 0 #timer to sync everything scale = self.size.w / 10 #scaling and UI Design self.MoreState = False #activate by pressing the bottom dot self.loopPrompt = False #if someone travels in a circle self.activator = False #a temporary solution to a significant problem self.loopPromptState = 0 #to save circled location or not self.currentLoc = None #self.query = 'safari-http://maps.apple.com/?q=%s,%s' #apple maps self.query = 'safari-https://www.google.com/maps/dir/' #google maps self.compassStat = False #compass in NSEW mode or degrees self.pathState = False self.radius = scale self.clipState = False motion.start_updates() #motion updates for compass location.start_updates() #location start updates
def main(): console.alert('Motion Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') w = 1000 h = 1200 while True: sleep(0.01) current = motion.get_gravity() newMotion = [0,0,0] for i in range(len(current)): newMotion[i] = (current[i]*(10**3))//1 #print(newMotion) x = newMotion[0]+500 y = newMotion[1]+500 z = newMotion[2]+1000 goalX = w/2 goalY = h/2 canvas.set_size(w, h) canvas.set_fill_color(0, 0, 0) canvas.fill_ellipse(goalX, goalY, 30, 30) if (abs(goalX-x) < 10 and abs(goalY-y) < 10): canvas.set_fill_color(0, 1, 0) canvas.fill_ellipse(x, y, 30, 30) else: canvas.set_fill_color(1, 0, 0) canvas.fill_ellipse(x, y, 30, 30) motion.stop_updates() print('Capture finished, plotting...')
def environ_data(sender): import motion import location motion.start_updates() location.start_updates() x = motion.get_attitude() environ['att'].text = str(x) + '\n' + environ['att'].text x = motion.get_gravity() environ['grav'].text = str(x) + '\n' + environ['grav'].text x = motion.get_user_acceleration() environ['acc'].text = str(x) + '\n' + environ['acc'].text x = motion.get_magnetic_field() environ['mag'].text = str(x) + '\n' + environ['mag'].text x = location.get_location() coord = {'latitude': x['latitude'], 'longitude': x['longitude']} print(coord) y = location.reverse_geocode(coord) print(y) environ['geo'].text = str(x) motion.stop_updates() location.stop_updates()
def main(): num_samples = 1000000 arrayA = [] arrayM = [] #arrayG = [] arrayP = [] arrayJ = [] arrayGPS = [] #GPS dataArray = [] CMAltimeter = ObjCClass('CMAltimeter') NSOperationQueue = ObjCClass('NSOperationQueue') if not CMAltimeter.isRelativeAltitudeAvailable(): print('This device has no barometer.') return altimeter = CMAltimeter.new() main_q = NSOperationQueue.mainQueue() altimeter.startRelativeAltitudeUpdatesToQueue_withHandler_( main_q, handler_block) motion.start_updates() location.start_updates() # GPS print("Logging start...") sleep(1.0) for i in range(num_samples): sleep(0.05) a = motion.get_user_acceleration() m = motion.get_magnetic_field() j = motion.get_attitude() gps = location.get_location() # GPS if a[1] > 0.8: break dataArray.append([relativeAltitude, a[2], m[0], m[1]]) arrayA.append(a) arrayM.append(m) arrayJ.append(j) arrayP.append(relativeAltitude) arrayGPS.append(gps) #GPS motion.stop_updates() location.stop_updates() # GPS altimeter.stopRelativeAltitudeUpdates() print("Logging stop and Saving start...") import pickle f = open('yokohama.serialize', 'wb') #pickle.dump([arrayA, arrayM, arrayP],f) pickle.dump([arrayA, arrayM, arrayJ, arrayP, arrayGPS], f) #GPS f.close print("Saving is finished.") x_values = [x * 0.05 for x in range(len(dataArray))] for i, color, label in zip(range(3), 'rgb', 'XYZ'): plt.plot(x_values, [g[i] for g in arrayM], color, label=label, lw=2) plt.grid(True) plt.xlabel('t') plt.ylabel('G') plt.gca().set_ylim([-100, 100]) plt.legend() plt.show()
def setup(self): global scale scale = self.size.w / 10 #motion start motion.start_updates() #pitch,roll,yaw self.R = scale self.Box = [[[W, L, -H]], [[-W, L, -H]], [[-W, -L, -H]], [[W, -L, -H]], [[W, L, H]], [[-W, L, H]], [[-W, -L, H]], [[W, -L, H]]] self.Box = np.array(self.Box)
def present(self, debug=False, *args, **kwargs): if debug: ui.View.present(self, *args, **kwargs) if self.superview: self.superview.right_button_items = [self.calibtn] else: self.right_button_items = [self.calibtn] motion.start_updates() ui.delay(self.update_touch, 0.01)
def compass(): motion.start_updates() while True: sleep(0.5) current = motion.get_magnetic_field() newMotion = [0, 0, 0, 0] for i in range(len(current)): newMotion[i] = (current[i] * (10**2)) // 1 print(newMotion) motion.stop_updates()
def setup(self): random.seed() self.background_color = 'midnightblue' self.text = scene.LabelNode("") self.text.position = self.size / 2 self.add_child(self.text) self.particles = [] for n in range(N): self.addParticle() motion.start_updates()
def setup(self): global scale scale = self.size.w / 10 #motion start motion.start_updates() #pitch,roll,yawメータの半径 self.R = scale #Boxの定義 後の計算の為arrayにしておく self.Box = [[[W, L, -H]], [[-W, L, -H]], [[-W, -L, -H]], [[W, -L, -H]], [[W, L, H]], [[-W, L, H]], [[-W, -L, H]], [[W, -L, H]]] self.Box = np.array(self.Box)
def launch(self): print('Starting silent camera...') self._session.startRunning() self._changeZoom(self._defeaultZoom[self.typeNum]) self.oldZoomScale = self._defeaultZoom[self.typeNum] self.currentZoomScale = self._defeaultZoom[self.typeNum] motion.start_updates() self.mainView.present( style='sheet', title_bar_color='black', hide_title_bar=True, orientations=['portrait']) self.mainView.wait_modal()
def update(self): motion.start_updates() time.sleep(0.3) g3 = motion.get_gravity() motion.stop_updates() # for g in g3: # print(round(g, 3), end = '\t') # print() self.isProne = g3[2] > 0.3 self.isLowBattery = self.device.batteryLevel() < 0.05
def thread(): console.alert('Begin Reading Motion', 'Altitude Change', 'Continue') motion.start_updates() altitudes = [] print('Capturing motion data...') main() while True: sleep(0.2) print(pressureRun()) motion.stop_updates() print('Capture finished, plotting...')
def setup(self): self.background_color = 'white' self.measuringOn = False #am i taking in location coordinates? self.checkedOnce = 0 #counter for the mode (things happen sequentially so this works) # self.locations = [] #array of recorded coordinates #self.locations = [(40.4464,-79.9427),(40.4464,-79.9428),(40.4465,-79.9428),(40.4463,-79.9427),(40.4462,-79.9427),(40.4461,-79.9427),(40.446,-79.9427)] #self.locations = [(40.444,-79.9446),(40.444,-79.9445),(40.4441,-79.9446),(40.4441,-79.9447),(40.4442,-79.9447),(40.4443,-79.9447),(40.4444,-79.9447),(40.4444,-79.9448),(40.4445,-79.9447),(40.4446,-79.9447),(40.4446,-79.9446),(40.4447,-79.9446),(40.4448,-79.9446),(40.4449,-79.9445),(40.445,-79.9445)] #self.locations = [(40.444,-79.9446),(40.444,-79.9445),(40.4441,-79.9446),(40.4441,-79.9447),(40.4442,-79.9447),(40.4449,-79.9449)] #self.locations = [(40.444,-79.9446),(40.444,-79.9445),(40.4441,-79.9446),(40.4441,-79.9447),(40.4442,-79.9447)] self.locations = [(40.429, -79.9594), (40.4288, -79.9598), (40.4285, -79.9601), (40.4284, -79.9605), (40.4281, -79.9608), (40.4279, -79.9612), (40.4277, -79.9616), (40.4275, -79.962), (40.4273, -79.9623), (40.4273, -79.9628), (40.4275, -79.9632), (40.4277, -79.9635), (40.4278, -79.9637), (40.4279, -79.9639), (40.4281, -79.9642), (40.4287, -79.965)] #self.locations = [(40.429,-79.9594),(40.4288,-79.9598),(40.4285,-79.9601),(40.4284,-79.9605),(40.4281,-79.9608),(40.4279,-79.9612),(40.4277,-79.9616),(40.4275,-79.962),(40.4273,-79.9623),(40.4273,-79.9628),(40.4275,-79.9632),(40.4277,-79.9635),(40.4278,-79.9637),(40.4279,-79.9639),(40.4281,-79.9642),(40.4287,-79.965),(40.4200,-79.965)] #self.locations = [(40.429,-79.9594),(40.4288,-79.9598)]#(40.4285,-79.9601),(40.4284,-79.9605)]#(40.4281,-79.9608),(40.4279,-79.9612),(40.4277,-79.9616),(40.4275,-79.962),(40.4273,-79.9623),(40.4273,-79.9628),(40.4275,-79.9632),(40.4277,-79.9635),(40.4278,-79.9637),(40.4279,-79.9639),(40.4281,-79.9642),(40.4287,-79.965),(40.4200,-79.965)] self.photoLocations = [] self.locationsLeft = [] self.needMore = False #need more values self.timerCount = 0 #timer to sync everything self.MoreState = False #activate by pressing the bottom dot self.loopPrompt = False #if someone travels in a circle self.activator = False #a temporary solution to a significant problem self.loopPromptState = 0 #to save circled location or not self.currentLoc = None #self.query = 'safari-http://maps.apple.com/?q=%s,%s' #apple maps self.query = 'safari-https://www.google.com/maps/dir/' #google maps self.compassStat = False #compass in NSEW mode or degrees self.pathState = False self.clipState = False self.photoCount = 0 self.imageMode = False self.imageModeOpen = False self.photoLibrary = None # self.photoLibraryName = self.photoLibrary.local_id #Organization/Design self.scale = self.size.w / 10 #scaling and UI Design self.centerX = self.size.w / 2 self.centerY = self.size.h / 2 self.centerX2 = self.size.w / 2 self.centerY2 = self.size.h * (1 / 2) - self.scale * 3.5 #updates start motion.start_updates() #motion updates for compass location.start_updates() #location start updates
def ios(rate=quantity(1, units.second)): """Retrieve motion information from an iOS device. This component requires the `motion` module provided by Pythonista. Parameters ---------- rate: time quantity, required Rate at which motion data will be retrieved. Yields ------ records: dict Records will contain information including the current acceleration due to gravity and the user, along with device attitude. """ import time import motion # pylint: disable=import-error rate = rate.to(units.seconds).magnitude motion.start_updates() try: while True: gravity = quantity(motion.get_gravity(), units.meters * units.seconds * units.seconds) acceleration = quantity(motion.get_user_acceleration(), units.meters * units.seconds * units.seconds) attitude = quantity(motion.get_attitude(), units.radians) record = dict() add_field(record, ("gravity", "x"), gravity[0]) add_field(record, ("gravity", "y"), gravity[1]) add_field(record, ("gravity", "z"), gravity[2]) add_field(record, ("acceleration", "x"), acceleration[0]) add_field(record, ("acceleration", "y"), acceleration[1]) add_field(record, ("acceleration", "z"), acceleration[2]) add_field(record, ("attitude", "roll"), attitude[0]) add_field(record, ("attitude", "pitch"), attitude[1]) add_field(record, ("attitude", "yaw"), attitude[2]) yield record time.sleep(rate) except GeneratorExit: motion.stop_updates()
def setup(self): global fig, ax1 #motionセンサスタート motion.start_updates() # data initial self.py = [pitch for i in range(0, 60)] # pitch array setup self.ry = [roll for i in range(0, 60)] # roll array setupr self.yy = [yaw for i in range(0, 60)] # yaw array setup self.xl = [i for i in range(0, 60)] # x_line # graph set up -------------------------# ymin = -180 ymax = 180 fig = plt.figure() # graphics setup ax1 = fig.add_subplot(111) # ax1.grid(True) # axis plt.ylim(ymin, ymax)
def setup(self): global scale self.background_color = 'white' self.measuringOn = False #am i taking in location coordinates? self.checkedOnce = 0 #counter for the mode (things happen sequentially so this works) self.locations = [] #array of recorded coordinates self.locationsReversed = [] #Useless? self.locationsLeft = [] self.timerCount = 0 #timer to sync everything scale = self.size.w / 10 #scaling and UI Design self.MoreState = False #activate by pressing the bottom dot #self.query = 'safari-http://maps.apple.com/?q=%s,%s' #apple maps self.query = 'safari-https://www.google.com/maps/dir/' #google maps self.compassStat = False #compass in NSEW mode or degrees self.radius = scale motion.start_updates() #motion updates for compass location.start_updates() #location start updates
def waitForLandscapeMode(): msg = 'Please, hold your phone in landscape mode' console.hud_alert(msg, duration=3) motion.start_updates() try: count = 0 while True: x, y, z = motion.get_gravity() count += 1 if count > 2: if abs(x) > abs(y): break else: console.hud_alert(msg, duration=2) time.sleep(0.5) finally: motion.stop_updates() time.sleep(1)
def main(): console.alert('Magentic Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') while True: sleep(0.5) current = motion.get_user_acceleration() newMotion = [0, 0, 0] for i in range(len(current)): newMotion[i] = (current[i] * (10**2)) // 1 x = newMotion[0] y = newMotion[1] z = newMotion[2] print(x, y, z) motion.stop_updates() print('Capture finished, plotting...')
def main(): console.alert('Magentic Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') while True: sleep(0.5) current = motion.get_attitude() newMotion = [0, 0, 0] for i in range(len(current)): newMotion[i] = (current[i] * (10**2)) // 1 roll = newMotion[0] pitch = newMotion[1] yaw = newMotion[2] print(roll, pitch, yaw) motion.stop_updates() print('Capture finished, plotting...')
async def gravity(self, instance, async_lib): motion.start_updates() try: while True: timestamp = time.time() gravity = motion.get_gravity() user_acceleration = motion.get_user_acceleration() attitude = motion.get_attitude() magnetic_field = motion.get_magnetic_field() await self.gravity.write(value=gravity, timestamp=timestamp) await self.user_acceleration.write(value=user_acceleration, timestamp=timestamp) await self.attitude.write(value=attitude, timestamp=timestamp) await self.magnetic_field.write(value=magnetic_field, timestamp=timestamp) await async_lib.library.sleep(0.01) finally: # TODO: put in @gravity.shutdown when in released version motion.stop_updates()
def main(): console.alert('Magentic Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') while True: sleep(0.05) current = motion.get_magnetic_field() newMotion = [0, 0, 0, 0] for i in range(len(current)): newMotion[i] = (current[i] // 1) x = newMotion[0] y = newMotion[1] z = newMotion[2] a = newMotion[3] print("X:" + str(x), "Y:" + str(y), "Z:" + str(z), "Acc:" + str(a)) motion.stop_updates() print('Capture finished, plotting...')
def main(): console.alert('Motion Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') num_samples = 100 w = 512 h = 512 for nums in range(num_samples): canvas.set_size(w, h) sleep(0.05) current = motion.get_gravity() newMotion = [0,0,0] for i in range(len(current)): newMotion[i] = (current[i]*(10**3))//1 print(newMotion) canvas.set_fill_color(1, 0, 0) canvas.fill_ellipse(0, 0, newMotion[1], newMotion[2]) motion.stop_updates() print('Capture finished, plotting...')
def Main(socket): print('Server Started') s.listen(1) c, addr = s.accept() print('Connection From: ' + str(addr)) motion.start_updates() while True: xaccel, yaccel, zaccel= motion.get_gravity() xrot, yrot, zrot= motion.get_attitude() message= str(xaccel)[:6] + ',' + str(yaccel)[:6] + ',' + str(zaccel)[:6] + ','+ str(xrot)[:6] + ',' + str(yrot)[:6] + ',' + str(zrot)[:6] print(message) try: c.send(str(message)) time.sleep(0.05) except: break c.close() Main(socket)
def main(): console.alert('Motion Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') while True: sleep(0.05) current = motion.get_gravity() newMotion = [0,0,0] for i in range(len(current)): newMotion[i] = (current[i]*(10**3))//1 #print(newMotion) if newMotion[0] < 1001 and newMotion[0] > 900 and newMotion[1] > -50 and newMotion[1] < 50 and newMotion[2] > -50 and newMotion[2] < 50: print("Position: Landscape Right") if newMotion[0] > -1001 and newMotion[0] < -900 and newMotion[1] > -50 and newMotion[1] < 50 and newMotion[2] > -50 and newMotion[2] < 50: print("Position: Landscape Left") if newMotion[0] > -50 and newMotion[0] < 50 and newMotion[1] > -50 and newMotion[1] < 50 and newMotion[2] > -1001 and newMotion[2] < -900: print("Position: Flat") motion.stop_updates() print('Capture finished, plotting...')
def main(): console.alert('Motion Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') w = 1000 h = 1200 goalX = w / 2 goalY = h / 2 moalX = w / 2 - 100 moalY = h / 2 - 100 while True: sleep(0.01) current = motion.get_gravity() newMotion = [0, 0, 0] for i in range(len(current)): newMotion[i] = (current[i] * (10**2)) // 1 #print(newMotion) x = newMotion[0] + 100 y = newMotion[1] + 100 z = newMotion[2] + 100 goalX += (x - 100) goalY += (y - 100) moalX += (x - 102) * 2 moalY += (y - 102) * 2 if goalX <= 0 or goalY <= 0 or goalX >= w or goalY >= h: goalX -= (x - 100) goalY -= (y - 100) if moalX <= 0 or moalY <= 0 or moalX >= w or moalY >= h: moalX -= (x - 102) * 2 moalY -= (y - 102) * 2 canvas.set_size(w, h) canvas.set_fill_color(0, 0, 0) canvas.fill_ellipse(goalX, goalY, 30, 30) canvas.set_fill_color(0, 0, 1) canvas.fill_ellipse(moalX, moalY, 30, 30) motion.stop_updates() print('Capture finished, plotting...')
def did_load(self): ht = self['helptext'] self.tv = self['tiltview'] ht.hidden = True ht.y = 100 c1 = self['color1'] setcolor(c1) ss = self['sensitivity'] ss.value = (gravsense - senserange[0]) / (senserange[1] - senserange[0]) self['scalev'].text = '{0:.2f}'.format(gravsense) dfc = self['difficulty'] dfc.action = self.setdiff dfc.selected_index = self.difficulty vis = self['visualize'] if vis: vis.value = False b = self['bubble'] b.image = ui.Image.named('Red_Circle').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL) self.tv.ball = b motion.start_updates()
def main(): console.alert('Motion Plot', 'When you tap Continue, accelerometer (motion) data will be recorded for 5 seconds.', 'Continue') motion.start_updates() sleep(0.2) print 'Capturing motion data...' num_samples = 100 data = [] for i in xrange(num_samples): sleep(0.05) g = motion.get_gravity() data.append(g) motion.stop_updates() print 'Capture finished, plotting...' x_values = [x*0.05 for x in xrange(num_samples)] for i, color, label in zip(range(3), 'rgb', 'XYZ'): plt.plot(x_values, [g[i] for g in data], color, label=label, lw=2) plt.grid(True) plt.xlabel('t') plt.ylabel('G') plt.gca().set_ylim([-1.0, 1.0]) plt.legend() plt.show()
def setup(self): global scale self.background_color = 'white' self.measuringOn = False self.textState = '' self.checkedOnce = 0 self.locations = [] self.locationsReversed = [] self.testCounter = 0 scale = self.size.w / 10 self.MoreState = False #self.query = 'safari-http://maps.apple.com/?q=%s,%s' self.query = 'safari-https://www.google.com/maps/dir/' #compass in NSEW mode or degrees self.compassStat = False #motion updates for compass motion.start_updates() #location start updates location.start_updates() self.radius = scale
def setup(self): self.center = self.bounds.center() if use_motion: motion.start_updates()
def update(self): motion.start_updates() px = motion.get_gravity() gx = px[0] * 50 self.x = min(max(self.x + gx, 20), self.scene.size.w - 20)
def update(self): motion.start_updates() gx = motion.get_gravity()[0] * 50 self.x = min(max(self.x + gx, 20), self.scene.size.w - (20 + image_width))
def setup(self): super(Advice, self).setup() self.answer = random.choice(choices) if use_motion: motion.start_updates()
def setup(self): self.label_node = scene.LabelNode('', ('Arial', 12), position=self.size*0.5, parent=self) motion.start_updates() self.orientation = '?'
import motion import time import numpy as np motion.start_updates() time.sleep(2) while True: mag_data = motion.get_magnetic_field() heading = (360.0 - np.arctan2(mag_data[1], mag_data[0]) * 180.0/np.pi) % 360 if mag_data[3] != -1: break # print 'Please calibrate the compass by moving the device...' time.sleep(0.5) print('\r\nMagnetometer successfully calibrated...') print('Data: \t {}'.format(motion.get_magnetic_field())) print('Heading: \t {:5.2f}'.format(heading)) motion.stop_updates()