def __init__(self, **kwargs):
        super().__init__(**kwargs)
        accelerometer.enable()
        gyroscope.enable()
        gravity.enable()
        self.cols = 2
        if os.path.isfile("prev_details.txt"):
            with open("prev_details.txt", "r") as f:
                d = f.read().split(",")
                prev_ip = d[0]
                prev_port = d[1]
                prev_username = d[2]
        else:
            prev_ip = ''
            prev_port = ''
            prev_username = ''

        self.add_widget(Label(text='IP:', font_size=60))
        self.ip = TextInput(text=prev_ip, multiline=False, font_size=40)
        self.add_widget(self.ip)
        self.add_widget(Label(text='Port:', font_size=60))
        self.port = TextInput(text=prev_port, multiline=False, font_size=40)
        self.add_widget(self.port)

        self.add_widget(Label(text='Username:', font_size=60))
        self.username = TextInput(text=prev_username,
                                  multiline=False,
                                  font_size=40)
        self.add_widget(self.username)

        self.join = Button(text="Join", font_size=60)
        self.join.bind(on_press=self.join_button)
        self.add_widget(Label())
        self.add_widget(self.join)
Ejemplo n.º 2
0
def get_gyroscope_activity():
    gyroscope.enable()
    sleep(0.2)
    i = 0
    asum = 0.0
    lastx = lasty = lastz = 0
    val = gyroscope.orientation[:3]
    if (not val == (None, None, None)):
        lastx = val[0]
        lasty = val[1]
        lastz = val[2]
        Logger.info("gyro-x: " + str(val[0]) + "  y: " + str(val[1]) + "  z: " + str(val[2]))

    while i < 5:
        val = gyroscope.orientation[:3]
        if (not val == (None, None, None)):
            asum += abs(val[0] - lastx) + abs(val[1] - lasty) + abs(val[2] - lastz)
            Logger.info("gyro-yeah! gyro-values:" + str(datetime.now()) + "; asum: " + str(round(asum,2)) + "; x: " + str(round(val[0],2)) + "  y: " + str(round(val[1],2)) + "  z: " + str(round(val[2],2)))
            lastx = val[0]
            lasty = val[1]
            lastz = val[2]
            i += 1
        else:
            Logger.info("gyro-no gyrosc-values at " + str(datetime.now()) + "; " + str(asum))

        sleep(0.1)
    Logger.info("gyrosum: " + str(round(asum,3)))

    gyroscope.disable()
    return asum, val
Ejemplo n.º 3
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self._request_android_permissions()
     self.camera = Camera(play=False, resolution=(640, 480))
     self.camera._camera.bind(on_texture=self.capture)
     if self.is_android():
         gyroscope.enable()
         Clock.schedule_interval(self.get_rotation, 1 / 10)
Ejemplo n.º 4
0
	def build(self):
		try:
			# Enable gyroscope
			gyroscope.enable()
			# Set timer who check for movements
			Clock.schedule_interval(self.on_moove, 1.0/5) #5 calls per second 1.0/5
		except:
			print 'failed to enable gyroscope'
		return AirGuitarBackground()
Ejemplo n.º 5
0
 def askForPermissions(self):
     if kivy.platform == 'android':
         #self.request_android_permissions2()
         print("trying ... gps ...")
         try:
             gps.configure( 
                 on_location=self.on_gps_location,
                 on_status=self.on_gps_status
                 )
             self.request_android_permissions1()
             print("    gps OK")
         except:
             print("no gps :(")
             
             
         print("trying ... accelerometers ...")
         try:
             accelerometer.enable()
             print("    accelerometers OK")
         except:
             print("no accelerometers")
             
             
         print("trying ... spacial orientation ...")
         try:
             spatialorientation.enable_listener()
             print("    spacial orientation OK")
         except:
             print("no spacial orientation")
             
         print("trying ... gravity ...")    
         try:
             gravity.enable()
             print("    gravity OK")
         except:
             print("no gravity")
             
             
             
         print("trying ... gyroscope ...")
         try:
             gyroscope.enable()
             print("    gyroscope OK")
         except:
             print("no gyroscope")
     
         print("trying ... compass calibrated...")
         try:
             compass.enable()
             print("    compass calibrated OK")
         except:
             print("no compass calibrated")
    def InitializeSensors(self):
        print "Intializing Sensors"
        #--- Accelerometer Data ---
        if UseAccelerometer:
            print "Enable Accelerometer"
            print accelerometer
            accelerometer.enable()
            print "Accelerometer Enabled"

        #--- Gyroscope Data ---
        if UseGyroscope:
            print "Enable Gyroscope"
            print gyroscope
            gyroscope.enable()
            print "Gyroscope Enabled"
Ejemplo n.º 7
0
    def pressed1(self):
        try:
            if not self.sensorEnabled:
                gyroscope.enable()
                Clock.schedule_interval(self.get_orientation, 1 / 20.)

                self.sensorEnabled = True
                self.ids.button1.text = "Stop"
            else:
                gyroscope.disable()
                Clock.unschedule(self.get_orientation)

                self.sensorEnabled = False
                self.ids.button1.text = "Start"
        except NotImplementedError:
            import traceback
            traceback.print_exc()
            self.ids.status.text =\
"Gyroscope is not supported for your   platform"
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        accelerometer.enable()
        gyroscope.enable()
        gravity.enable()
        self.cols = 1
        self.AcceX = ''
        self.AcceY = ''
        self.AcceZ = ''
        self.gryX = ''
        self.gryY = ''
        self.gryZ = ''
        self.graX = ''
        self.graY = ''
        self.graZ = ''

        self.event = Clock.schedule_interval(self.update, 1.0 / 10)
        self.event()
        self.add_widget(
            Label(text="SENDING ACCELEROMETER DATA...", font_size=60))
        self.add_widget(
            Label(text="Press STOP to stop sending accelerometer data",
                  font_size=30))

        self.stop = Button(text="STOP",
                           font_size=60,
                           size_hint_y=None,
                           height=100)
        self.stop.bind(on_press=self.stop_client)
        self.add_widget(self.stop)

        self.back = Button(text="Back",
                           font_size=60,
                           size_hint_y=None,
                           height=100)
        self.back.bind(on_press=self.backbutton)
        self.add_widget(self.back)
Ejemplo n.º 9
0
	def publish_terminal(self, terminal, _data_queue):
		terminal.insert_text("\n")
  
		if (platform == 'android') or (platform == 'ios'):
			try:
				vibrator.vibrate(1)
			except:
				pass

			#Accelerometer
			if self._data_object.get("sensor") == "Accelerometer":
				try:
					accelerometer.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								accelerometer.disable()
							except:
								pass
							break
					if None in accelerometer.acceleration:
						pass
					else:
						payload_hash = hashlib.md5(str(accelerometer.acceleration).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "(x, y, z): " + str(accelerometer.acceleration)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
							payload = "(x, y, z): " + str(accelerometer.acceleration)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
							time.sleep(0.1)
			#Compass
			elif self._data_object.get("sensor") == "Compass":
				try:
					compass.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								compass.disable()
							except:
								pass
							break
					if None in compass.field:
						pass
					else:
						payload_hash = hashlib.md5(str(compass.field).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "(x, y, z): " + str(compass.field)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
							payload = "(x, y, z): " + str(compass.field)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
							time.sleep(0.1)
			#GPS
			elif self._data_object.get("sensor") == "GPS":
				try:
					gps.configure(on_location=self.on_location, on_status=self.on_status)
					gps.start(1000, 0)
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								gps.stop()
							except:
								pass
							break
					if self.gps_location is None:
						pass
					else:
						payload_hash = hashlib.md5(str(self.gps_location).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = str(self.gps_location)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(3)
						else:
							payload = str(self.gps_location)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
							time.sleep(0.5)
			#Barometer
			elif self._data_object.get("sensor") == "Barometer":
				try:
					barometer.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								barometer.disable()
							except:
								pass
							break
					if barometer.pressure is None:
						pass
					else:
						payload_hash = hashlib.md5(str(barometer.pressure).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "hPa: " + str(barometer.pressure)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
							payload = "hPa: " + str(barometer.pressure)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
			#Gravity
			elif self._data_object.get("sensor") == "Gravity":
				try:
					gravity.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								gravity.disable()
							except:
								pass
							break
					if None in gravity.gravity:
						pass
					else:
						payload_hash = hashlib.md5(str(gravity.gravity).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "(x, y, z): " + str(gravity.gravity)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
							payload = "(x, y, z): " + str(gravity.gravity)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
			#Gyroscope
			elif self._data_object.get("sensor") == "Gyroscope":
				try:
					gyroscope.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								gyroscope.disable()
							except:
								pass
							break
					if None in gyroscope.rotation:
						pass
					else:
						payload_hash = hashlib.md5(str(gyroscope.rotation).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "(x, y, z): " + str(gyroscope.rotation)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
								payload = "(x, y, z): " + str(gyroscope.rotation)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
			else:
				pass
		else:
			while True:
				if _data_queue.empty() is False:
					qdata = _data_queue.get()
					if qdata == "exit":
						break
				payload = "time: " + str(time.strftime("%c", time.gmtime()))
				terminal.insert_text(payload + "\n")
				if (self._data_object.get("protocol") != "terminal"):
					try:
						terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
					except Exception as _exp:
						terminal.insert_text("Exception: " + str(_exp) + "\n")
						return
				time.sleep(2)
Ejemplo n.º 10
0
	def __init__(self,gui):
		self.gui = gui
		self.boat = {}

		self.sensorsList = []

		self.th = TimeHelper()
		self.fa = FileActions()
		
		self.playingFromFile = False
		self.FromFile = ""
		self.FromFileData = {}
		self.replayFps = 60
		
		self.filesToPlay = self.fa.getFileList( self.gui.workingFolderAdress )
		print("files to play --\ \n",str(self.filesToPlay))
		sPlaFroFil = Spinner(
			values = list(self.filesToPlay),
			text = "play from file:",
			size_hint = (None,None),
			size = (self.gui.btH*4,self.gui.btH)		
			)
		sPlaFroFil.bind(text=self.on_PlaFroFile)
		bl = self.gui.rl.ids.bl_sensorsPlaFroFil
		bl.add_widget(sPlaFroFil)
		
		print("new Spinner with updated list DONE")
		#self.wHeelBoat = waveCicleHolder(gui,'boat_heel')
		
		
		self.calibrateStep = 0
		self.recordToFile = "ready"
		self.toFileList = []
		
		self.mic = micData(gui)
		#self.mic.runIt()
		self.device = deviceSensors(gui)
		self.sensorsList.append( self.device )
		self.device.initSensors()
		
		
		self.gpsD = gpsData(gui, {
			'lat': self.gui.rl.ids.senLGpsLat,
			'lon': self.gui.rl.ids.senLGpsLon,
			'sog': self.gui.rl.ids.senLGpsSog,
			'lSRacSog': self.gui.rl.ids.lSRacSog,
			'lSRacSogMax': self.gui.rl.ids.lSRacSogMax,
			'lSRacSogAvg': self.gui.rl.ids.lSRacSogAvg,
			'cog': self.gui.rl.ids.senLGpsCog,
			'accur': self.gui.rl.ids.senLGpsAcc
			})
		self.sensorsList.append( self.gpsD )
		
		self.gyro = xyzData(gui, "gyro", [
			self.gui.rl.ids.senLGyrX,
			self.gui.rl.ids.senLGyrY,
			self.gui.rl.ids.senLGyrZ
			])
		self.sensorsList.append( self.gyro )
		
		self.gyroFlipt = xyzData(gui, "gyroFlipt",[
			self.gui.rl.ids.senLGyrCalX,
			self.gui.rl.ids.senLGyrCalY,
			self.gui.rl.ids.senLGyrCalZ
			])
		self.sensorsList.append( self.gyroFlipt )
		
		self.accel = xyzData(gui, "accel", [
			self.gui.rl.ids.senLAccX,
			self.gui.rl.ids.senLAccY,
			self.gui.rl.ids.senLAccZ
			])
		self.sensorsList.append( self.accel )
		
		self.spacialOrientation = xyzData(gui, "spacorientation", [
			self.gui.rl.ids.senLSpaOriX,
			self.gui.rl.ids.senLSpaOriY,
			self.gui.rl.ids.senLSpaOriZ
			])
		self.sensorsList.append( self.spacialOrientation )
		
		self.accelFlipt = xyzData(gui, "accelFlipt")
		self.sensorsList.append( self.accelFlipt )
		
		self.orientation = xyzData(gui, "orientation")
		self.sensorsList.append( self.orientation )
		
		self.comCal = xyzData(gui, "comCal", [
			self.gui.rl.ids.senLComCalX,
			self.gui.rl.ids.senLComCalY,
			self.gui.rl.ids.senLComCalZ
			])
		self.sensorsList.append( self.comCal )
		
		self.comCalAccelGyro = xyzData(gui, "comCalAccelGyro")
		self.sensorsList.append( self.comCalAccelGyro )
		
		if kivy.platform == 'android':
			#self.request_android_permissions2()
			print("trying ... gps ...")
			try:
				gps.configure( 
					on_location=self.on_gps_location,
					on_status=self.on_gps_status
					)
				self.request_android_permissions1()
				print("	gps OK")
			except:
				print("no gps :(")
				
				
			print("trying ... accelerometers ...")
			try:
				accelerometer.enable()
				print("	accelerometers OK")
			except:
				print("no accelerometers")
				
			print("trying ... spacial orientation ...")
			try:
				spatialorientation.enable_listener()
				print("	spacial orientation OK")
			except:
				print("no spacial orientation")
				
			print("trying ... gyroscope ...")
			try:
				gyroscope.enable()
				print("	gyroscope OK")
			except:
				print("no accelerometers")
		
			print("trying ... compass calibrated...")
			try:
				compass.enable()
				print("	compass calibrated OK")
			except:
				print("no compass calibrated")
Ejemplo n.º 11
0
 def start(self):
     super().start()
     if gyroscope_is_implemented:
         gyroscope.enable()
     self._gyroscope_is_enabled = True