Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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...')
Ejemplo n.º 3
0
def motion_color():
    if not main_view.on_screen:
        motion.stop_updates()
        sys.exit(999)
    color = motion.get_attitude()
    main_view.background_color = color
    ui.delay(motion_color, .1)
Ejemplo n.º 4
0
def motion_color(): 
    if not main_view.on_screen : 
        motion.stop_updates()
        sys.exit(999)
    color=  motion.get_attitude()
    main_view.background_color = color
    ui.delay(motion_color, .1)
Ejemplo n.º 5
0
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...')
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
 def close(self):
     print('Stop running...')
     motion.stop_updates()
     self.mainView.close()
     self._session.stopRunning()
     self._delegate.release()
     self._session.release()
     self._output.release()
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
    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
Ejemplo n.º 11
0
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...')
Ejemplo n.º 12
0
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()
Ejemplo n.º 13
0
 def shutDown(self):
   motion.stop_updates()
   self.g.remove_all_gestures(self.main_view)
   self.myCameraNode.removeAllActions()
   self.pipeNode.removeAllParticleSystems()
   self.smokeHandle.removeAllParticleSystems()
   self.scnView.scene.physicsWorld.removeAllBehaviors()
   self.scnView.scene.paused = True
   
   for aView in self.main_view.subviews:
     self.main_view.remove_subview(aView)
     
   self.scnView.removeFromSuperview()
   
   self.main_view.close()
   ui.delay(self.exit, 2.0)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
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...')
Ejemplo n.º 16
0
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...')
Ejemplo n.º 17
0
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...')
Ejemplo n.º 18
0
	def game_over(self):
		motion.stop_updates()
		self.player.dead = True
		self.touch_disabled = True
		play_effect('Laser_4')
		t = TextLayer('Game Over', GAME_FONT, 100)
		ts = TextLayer('Tap to Play Again', GAME_FONT, 50)
		ts.frame.center(self.size.w / 2, self.size.h - 630)
		t.frame.center(self.bounds.center())
		self.delay(2.0, partial(self.__setattr__, 'touch_disabled', False))
		t.scale_x, t.scale_y = 0.0, 0.0
		ts.scale_x, ts.scale_y = 0.0, 0.0
		t.animate('scale_x', 1.0, 1.0, curve=curve_bounce_out)
		t.animate('scale_y', 1.0, 1.0, curve=curve_bounce_out)
		ts.animate('scale_x', 1.0, 1.0, curve=curve_bounce_out)
		ts.animate('scale_y', 1.0, 1.0, curve=curve_bounce_out)
		self.effects_layer.add_layer(t)
		self.effects_layer.add_layer(ts)
		self.high_score('P1', int(self.score))
Ejemplo n.º 19
0
 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()
Ejemplo n.º 20
0
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...')
Ejemplo n.º 21
0
 def game_over(self):
     motion.stop_updates()
     self.player.dead = True
     self.touch_disabled = True
     play_effect('Laser_4')
     t = TextLayer('Game Over', GAME_FONT, 100)
     ts = TextLayer('Tap to Play Again', GAME_FONT, 50)
     ts.frame.center(self.size.w / 2, self.size.h - 630)
     t.frame.center(self.bounds.center())
     self.delay(2.0, partial(self.__setattr__, 'touch_disabled', False))
     t.scale_x, t.scale_y = 0.0, 0.0
     ts.scale_x, ts.scale_y = 0.0, 0.0
     t.animate('scale_x', 1.0, 1.0, curve=curve_bounce_out)
     t.animate('scale_y', 1.0, 1.0, curve=curve_bounce_out)
     ts.animate('scale_x', 1.0, 1.0, curve=curve_bounce_out)
     ts.animate('scale_y', 1.0, 1.0, curve=curve_bounce_out)
     self.effects_layer.add_layer(t)
     self.effects_layer.add_layer(ts)
     self.switch_back()
     username = root_view['namefield'].text.strip() or 'Player 1'
     self.high_score(username, int(self.score))
Ejemplo n.º 22
0
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...')
Ejemplo n.º 23
0
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...')
Ejemplo n.º 24
0
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()
Ejemplo n.º 25
0
 def will_close(self):
     ui.cancel_delays()
     motion.stop_updates()
Ejemplo n.º 26
0
 def will_close(self):
     motion.stop_updates()
     self['startbutton'].title = 'Resume'
     if ms:
         ms.resumegame()
Ejemplo n.º 27
0
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()
Ejemplo n.º 28
0
            print("\n+++++++  Escape velocity !  +++++++")
            break

        gravx, gravy, gravz = motion.get_gravity()  # device orientation

        if gravz > 0.3:  # quit if user turns device screen downwards
            show_earth(1, 1, 0)  # show yellow Earth
            break

        if gravx > 0.8:  # output info if tipped to landscape
            print(f"{moonunits:6.2f} moonu @ {velocity:7.0f} mps")

    simtime += dtime
    iters += 1

motion.stop_updates()
logfile.close()

stoptime = time.process_time()
elapsedtime = stoptime - starttime
if elapsedtime == 0:
    elapsedtime = 1.0
itrate = int(iters / elapsedtime)
plotrate = int(plots / elapsedtime)

print()
print(f"{setupnum}: {inz.description}\n",
      f"{iters} iterations in {int(elapsedtime)} process seconds\n",
      f"avg.ips={itrate}   last.ips={ips}   max.ips={maxips}\n",
      f"plot.rate={plotrate}    orbits={orbits}\n")
print(f"{moonunits:6.2f} moonu @ {velocity:7.0f} mps")
Ejemplo n.º 29
0
	def will_close(self):
		# This will be called when a presented view is about to be dismissed.
		# You might want to save data here.
		location.stop_updates()
		motion.stop_updates()
Ejemplo n.º 30
0
 def stop(self):
     location.stop_updates()
     motion.stop_updates()
Ejemplo n.º 31
0
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 = 1400

    while True:
        sleep(0.01)
        canvas.set_size(w, h)
        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] + 1000
        y = newMotion[1] + 1000
        z = newMotion[2] + 1000
        goalX = w / 2
        goalY = h / 2

        #bottom
        if (abs(x - 1000) < 500 and abs(y - 1000) < 600 and abs(z - 0) < 500):
            canvas.set_fill_color(1, 0, 0)
            canvas.draw_text("bottom",
                             x - 500,
                             y - 400,
                             font_name='Courier New',
                             font_size=50.0)
        #top
        if (abs(x - 1000) < 500 and abs(y - 1000) < 600
                and abs(z - 2000) < 500):
            canvas.set_fill_color(0, 0, 1)
            canvas.draw_text("top",
                             1500 - x,
                             1700 - y,
                             font_name='Courier New',
                             font_size=50.0)
        #right
        if (abs(x - 0) < 500 and abs(y - 1000) < 600 and abs(z - 1000) < 500):
            canvas.set_fill_color(0, 0, 1)
            canvas.draw_text("right",
                             500 - x,
                             1500 - y,
                             font_name='Courier New',
                             font_size=50.0)
        #left
        if (abs(x - 2000) < 500 and abs(y - 1000) < 600
                and abs(z - 1000) < 500):
            canvas.set_fill_color(0, 0, 1)
            canvas.draw_text("left",
                             x - 1500,
                             1500 - y,
                             font_name='Courier New',
                             font_size=50.0)
        #front
        if (abs(x - 1000) < 500 and abs(y - 0) < 600 and abs(z - 1000) < 500):
            canvas.set_fill_color(0, 0, 1)
            canvas.draw_text("front",
                             500 - y,
                             1500 - z,
                             font_name='Courier New',
                             font_size=50.0)
        #back
        if (abs(x - 1000) < 500 and abs(y - 2000) < 600
                and abs(z - 1000) < 500):
            canvas.set_fill_color(0, 0, 1)
            canvas.draw_text("back",
                             y - 1500,
                             z - 500,
                             font_name='Courier New',
                             font_size=50.0)

        # if (z > 1000):
        # 	canvas.set_fill_color(0, 0, 1)
        # 	canvas.draw_text("top", 1500-x, 1700-y, font_name='Courier New', font_size=50.0)

    motion.stop_updates()
    print('Capture finished, plotting...')
Ejemplo n.º 32
0
 def stop(self):
     motion.stop_updates()
Ejemplo n.º 33
0
 def will_close(self):
     ui.cancel_delays()
     motion.stop_updates()
Ejemplo n.º 34
0
 def did_stop(self):
     motion.stop_updates()
Ejemplo n.º 35
0
def read_data(sender):
	import motion, location
	import time, datetime
	import io
	import numpy as np
	import matplotlib.pyplot as plt
	
	val = view['switch1'].value
	if val==True:
		motion.start_updates()
			
		y=0
		nx = np.empty(1)
		ny = np.empty(1)
		nz = np.empty(1)
		view['mag'].text = ''
		view['accel'].text = ''
		view['gyro'].text = ''
		view['gravity'].text = ''
		
		while (y<=100):
			time.sleep(.05)
			x = motion.get_attitude()
			view['gyro'].text = str(x) + '\n' + view['gyro'].text
			x = motion.get_gravity()
			view['gravity'].text = str(x) + '\n' + view['gravity'].text
			x = motion.get_user_acceleration()
			nx = np.append(nx,x[0])
			ny = np.append(ny,x[1])
			nz = np.append(nz,x[2])
			view['accel'].text = str(x) + '\n' + view['accel'].text
			x = motion.get_magnetic_field()
			view['mag'].text = str(x) + '\n' + view['mag'].text
			y +=1
			view['y'].text = str(y) + 'measurements'
				
		motion.stop_updates()	
		plt.plot(nx)
		plt.show()
		plt.savefig('x.tif')
		plt.close()
		plt.plot(ny)
		plt.show()
		plt.savefig('y.tif')
		plt.close()
		plt.plot(nz)
		plt.show()
		plt.savefig('z.tif')
		plt.close()
		medianx = np.median(nz)
		stdx = np.std(nz)
		apex = np.amax(np.absolute(nz))
		print (apex)
		print (stdx)
		if apex >= stdx*2:
			if apex > stdx*5:
				view['fell'].text = 'Fall'
			else:
				view['fell'].text = 'Trip'
					
		fname = 'motion' + str(datetime.datetime.now()).split('.')[1] + '.txt'
		with open(fname, 'w') as fo:
			fo.write('gyro\n')
			fo.write(view['gyro'].text)
			fo.write('gravity\n')
			fo.write(view['gravity'].text)
			fo.write('accel\n')
			fo.write(view['accel'].text)
			fo.write('mag\n')
			fo.write(view['mag'].text)
	else:
		view['mag'].text = ''
		view['accel'].text = ''
		view['gyro'].text = ''
		view['gravity'].text = ''
		view['y'].text = str(0)
Ejemplo n.º 36
0
 def stop(self):
     if use_motion:
         motion.stop_updates()
Ejemplo n.º 37
0
 def will_close(self):
   motion.stop_updates()
   self['startbutton'].title = 'Resume'
   if ms :
     ms.resumegame()
Ejemplo n.º 38
0
 def stop(self):
     motion.stop_updates()