Пример #1
0
 def test_clear_many(self):
     smokesignal.on(('foo', 'bar', 'baz'), self.fn)
     smokesignal.clear('foo', 'bar')
     assert smokesignal.receivers == {
         'foo': set(),
         'bar': set(),
         'baz': set([self.fn]),
     }
Пример #2
0
 def test_clear_many(self):
     smokesignal.on(('foo', 'bar', 'baz'), self.fn)
     smokesignal.clear('foo', 'bar')
     assert smokesignal.receivers == {
         'foo': set(),
         'bar': set(),
         'baz': set([self.fn]),
     }
Пример #3
0
    def test_clear_many(self):
        smokesignal.on(('foo', 'bar', 'baz'), self.callback)
        assert len(smokesignal._receivers['foo']) == 1
        assert len(smokesignal._receivers['bar']) == 1
        assert len(smokesignal._receivers['baz']) == 1

        smokesignal.clear('foo', 'bar')
        assert len(smokesignal._receivers['foo']) == 0
        assert len(smokesignal._receivers['bar']) == 0
        assert len(smokesignal._receivers['baz']) == 1
Пример #4
0
    def test_clear_many(self):
        smokesignal.on(('foo', 'bar', 'baz'), self.callback)
        assert len(smokesignal._receivers['foo']) == 1
        assert len(smokesignal._receivers['bar']) == 1
        assert len(smokesignal._receivers['baz']) == 1

        smokesignal.clear('foo', 'bar')
        assert len(smokesignal._receivers['foo']) == 0
        assert len(smokesignal._receivers['bar']) == 0
        assert len(smokesignal._receivers['baz']) == 1
Пример #5
0
	def attachEvents(self, mic):
        ## clear all signals
		smokesignal.clear()
		text = ""
		@smokesignal.on('say')
		def onSay(args):
			print "Info from Nav"
			infoFromNav = eval(args.get('payload'))
			print infoFromNav
			infotosay = infoFromNav["text"]
			print infotosay
			print "Info from Nav before Mic"
			mic.say(infotosay)
Пример #6
0
    def attachEvents(self):
        smokesignal.clear()

        @smokesignal.on('sonarData')
        def sonardata(args):
            payload = eval(args.get("payload"))
            
            strSonarLeft = self.convertStr(payload['1'])
            self.sonarLeft = int(strSonarLeft)
            
            strSonarRight = self.convertStr(payload['2'])
            self.sonarRight = int(strSonarRight)

            self.sendAlert(self.checkForObstacle())
Пример #7
0
    def attachEvents(self):
        smokesignal.clear()

        @smokesignal.on('sonarData')
        def sonardata(args):
            payload = eval(args.get("payload"))

            strSonarLeft = self.convertStr(payload['1'])
            self.sonarLeft = int(strSonarLeft)

            strSonarRight = self.convertStr(payload['2'])
            self.sonarRight = int(strSonarRight)

            self.sendAlert(self.checkForObstacle())
Пример #8
0
    def test_clear_no_args_clears_all(self):
        smokesignal.on(('foo', 'bar', 'baz'), self.fn)
        assert smokesignal.receivers == {
            'foo': set([self.fn]),
            'bar': set([self.fn]),
            'baz': set([self.fn]),
        }

        smokesignal.clear()
        assert smokesignal.receivers == {
            'foo': set(),
            'bar': set(),
            'baz': set(),
        }
Пример #9
0
    def test_clear_no_args_clears_all(self):
        smokesignal.on(('foo', 'bar', 'baz'), self.fn)
        assert smokesignal.receivers == {
            'foo': set([self.fn]),
            'bar': set([self.fn]),
            'baz': set([self.fn]),
        }

        smokesignal.clear()
        assert smokesignal.receivers == {
            'foo': set(),
            'bar': set(),
            'baz': set(),
        }
Пример #10
0
    def attachEvents(self):
        
        """Configure event callbacks to attach to daemon on start.

        All events must be a series of event functions.
        
        1:345 2:60
        Do not call this externally!
        """
        ## clear all signals
        smokesignal.clear()
        
        @smokesignal.on('sonarData')
        def sonardata(args):
            threshold=70
            if(currentsoundtime-triggersoundtime>self.sendAlertInterval):
                self.sendflag=1
            else
                self.sendflag=0
            #1-proceed #2-stop #3 step right #4 step left     
            if(self.state ==1): #proceed state
                
                payload =eval(args.get("payload"))
                leftvalue= payload["1"]
                rightvalue=payload["2"]
                leftvalue=int(leftvalue.rstrip('\u0'))
                rightvalue=int(rightvalue.rstrip('\u0')) 
                
                if((leftvalue <= threshold) OR(rightvalue <= threshold)):
                    self.state=2 #stop state
                    currentsoundtime=datetime.datetime.now().time()
                     
                    if(self.sendflag==1):
                         
                        self._dispatcherClient.send(9002, 'say', {'text': 'stop'})
                        triggersoundtime=datetime.datetime.now().time() # when it sends
                     
                else
                    
					self.state=1 # proceed state
				    self._dispatcherClient.send(9002, 'say', {'text': 'proceed'})
                    triggersoundtime=datetime.datetime.now().time() # when it sends
Пример #11
0
	def attachEvents(self):
		"""Configure event callbacks to attach to daemon on start.

		All events must be a series of event functions.

		Do not call this externally!
		"""
		## clear all signals
		smokesignal.clear()

		@smokesignal.on('newPath')
		def onNewPath(args):
			logging.debug('Event triggered: Request for new path.')
			nodeTo = args.get('to')
			if ((nodeTo == None)):
				logging.error('Received no start / end nodes')
				return
			self.getPathTo(nodeTo)


		@smokesignal.on('obstacle')
		def onObstacle(args):
			##TODO: Implement obstacle detection
			pass
Пример #12
0
    def test_clear(self):
        smokesignal.on('foo', self.fn)
        assert smokesignal.receivers['foo'] == set([self.fn])

        smokesignal.clear('foo')
        assert smokesignal.receivers['foo'] == set()
Пример #13
0
    def test_clear(self):
        smokesignal.on('foo', self.callback)
        assert len(smokesignal._receivers['foo']) == 1

        smokesignal.clear('foo')
        assert len(smokesignal._receivers['foo']) == 0
Пример #14
0
	def attachEvents(self):
		"""Configure event callbacks to attach to daemon on start.

		All events must be a series of event functions.

		Do not call this externally!
		"""
		## clear all signals
		smokesignal.clear()

		@smokesignal.on('newPath')
		def onNewPath(args):
			logging.debug('Event triggered: Request for new path.')
			nodeFrom = json.loads(args.get('payload')).get('from')
			nodeTo = json.loads(args.get('payload')).get('to')
			if ((nodeTo == None) or (nodeFrom == None)):
				logging.error('Received no start / end nodes')
				return

			# DEPRECATED ------
			## reset current location
			# self.setPosBySUID(str(nodeFrom))
			# /DEPRECATED ------

			## Get new path
			self.getPathTo(nodeFrom, nodeTo)


		# @smokesignal.on('obstacle')
		# def onObstacle(args):
		# 	response = int(json.loads(args.get('payload')).get('status'))
		# 	if (response == 0):
		# 		self.obstacle = None
		# 		return # Do not set collision locked
		# 	elif (response == 1):
		# 		self.obstacle = 'FRONT'
		# 	elif (response == 2):
		# 		self.obstacle = 'LEFT'
		# 	elif (response == 3):
		# 		self.obstacle = 'RIGHT'

		# 	# If collision, set to true
		# 	self.collisionLocked = True


		@smokesignal.on('point')
		def onPoint(args):
			"""Update location based on interprocess posting
			by cruncher
			"""
			locInfo = json.loads(args.get('payload'))
			x = locInfo.get('x')
			y = locInfo.get('y')
			z = locInfo.get('z')
			angle = locInfo.get('ang')
			self.__model['currLoc'] = Point.fromParam(
				x=x, 
				y=y,
				z=z, 
				orientation=angle)
			# logging.info(
			# 	'[ NAV ] Internal pos is currently: (x=%s y=%s z=%s ang=%s)' % 
			# 	(x,y,z,angle) )


		@smokesignal.on('reset')
		def onReset(args):
			"""If navigation needs to be reset during routing, 
			use this 
			"""
			self._dispatcherClient.send(9002, 'say', {'text': 'Nav reset.'})
			self._resetNavParams() # Reset all navigation params and await new path
			logging.debug('Nav has been RESET.')


		@smokesignal.on('pause')
		def onPause(args):
			""" Pause navigation.  Useful for stairs / etc. 
			"""
			self.toPause = True
			self._dispatcherClient.send(9002, 'say', {'text': 'Nav paused.'})
			logging.debug('Nav is PAUSED.')


		@smokesignal.on('unpause')
		def onPause(args):
			""" Unpause navigation.  Useful for stairs / etc. 
			"""
			self.toPause = False
			self._dispatcherClient.send(9002, 'say', {'text': 'Nav resumed.'})
			logging.debug('Nav is RESUMED.')


		@smokesignal.on('checkNavigation')
		def onPause(args):
			""" Unpause navigation.  Useful for stairs / etc. 
			"""
			isNavigating = self.isNavigating()
			self._dispatcherClient.send(9002, 'checkNavigation', {'isNavigating': isNavigating })
			logging.debug('Nav state checked.')
Пример #15
0
    def test_clear(self):
        smokesignal.on('foo', self.fn)
        assert smokesignal.receivers['foo'] == set([self.fn])

        smokesignal.clear('foo')
        assert smokesignal.receivers['foo'] == set()
Пример #16
0
    def test_clear(self):
        smokesignal.on('foo', self.callback)
        assert len(smokesignal._receivers['foo']) == 1

        smokesignal.clear('foo')
        assert len(smokesignal._receivers['foo']) == 0
Пример #17
0
	def attachEvents(self, mic):
		## clear all signals
		smokesignal.clear()
		text = ""
		@smokesignal.on('say')
		def onSay(args):	
			print "Info from Nav"
			infoFromNav = eval(args.get('payload'))
			print infoFromNav
			self.infotosay = infoFromNav["text"]

			try:
				if(self.infotosay != None and self.infotosay == 'Retrieved new path.'):
					self.OngoingNav = 1
					#self.speaker.say(self.infotosay)
				if self.infotosay != None and "Destination" in self.infotosay:
					self.OngoingNav = 0
					self.speaker.say(self.infotosay)
				# if self.infotosay != None and "reset" in self.infotosay:
				# 	self.OngoingNav = 0
				# if "paused" in self.infotosay:
				# 	self.OngoingNav = 0
				# if "resumed" in self.infotosay:
				# 	self.OngoingNav=1

				if self.infotosay != None and "Checkpoint" in self.infotosay:
					self.speaker.say(self.infotosay)

				print self.infotosay
			except:
				pass

		@smokesignal.on('cruncherAlert')
		def onSay(args):
			print "Info from Nav"
			try:
				if(self.OngoingNav == 1):
					os.system("sudo pkill -SIGTERM -f \"aplay\" ")

				infoFromCruncher = eval(args.get('payload'))
				print infoFromCruncher
				self.cruncherInfotosay = infoFromCruncher["text"]
				self.cruncherAlert = 1

				print self.cruncherInfotosay
			except:
				pass



		@smokesignal.on('obstacle')
		def onObstacle(args):
			try:
				response = int(json.loads(args.get('payload')).get('status'))
				if (response == 0):
					self.obstacle = None
					return
				elif (response == 1):
					self.obstacle = 'FRONT'
					self.collisionLocked = True
				elif (response == 2):
					self.obstacle = 'LEFT'
					self.collisionLocked = True
				elif (response == 3):
					self.obstacle = 'RIGHT'
					self.collisionLocked = True

				# If collision, set to true
				if(self.OngoingNav==1 and not self.collisionLocked):
					os.system("sudo pkill -SIGTERM -f \"aplay\" ")
				#self.collisionLocked = True
			except:
				pass

		@smokesignal.on('reset')
		def onObstacle(args):
			self.speaker.say("Voice reset")
			self.OngoingNav = 0 #clear ongoing nav