Exemplo n.º 1
0
def handleCommand(cmd):
	global speed
	if cmd in DIGITS: # 0-9
		setSpeed(int(cmd)*255/9)
	if cmd in SPEED_COMMANDS.keys():
		setSpeed(speed + SPEED_COMMANDS[cmd])
	elif cmd in MOVE_COMMANDS.keys():
		if MOVE_COMMANDS[cmd] == 'stop':
			stopBot()
		else:
			print MOVE_COMMANDS[cmd]
			moveBot(MOVE_COMMANDS[cmd], speed)
	elif cmd == 'w':
		rockets.up()
	elif cmd == 'e':
		rockets.down()
        elif cmd == 'q':
                rockets.left()
        elif cmd == 'r':
                rockets.right()	
	elif cmd == 't':
		rockets.laser()
	elif cmd == 'y':
		rockets.fire()
	elif cmd == 'a':
		setDrive('A')
	elif cmd == 'b':
		setDrive('B')
Exemplo n.º 2
0
    def update(self, x, y, z, throttle, buttons, hat):
        #                self.x = x
        #                self.y = y
        #                self.z = z
        #                self.throttle = throttle
        #                self.buttons = buttons
        #                self.hat = hat

        now = time.time()
        self.tcnt = self.tcnt + 1
        self.tsum += now - self.last
        if self.tcnt == 100:
            #print self.tsum/self.tcnt
            self.tcnt = 0
            self.tsum = 0
        self.last = now

        if (abs(x) > self.minx):
            if (x > 0):
                controller.moveBot("right", int(x * 255 / 2))
            else:
                controller.moveBot("left", abs(int(x * 255 / 2)))
        else:
            controller.moveBot("right", 0)

        if (abs(y) > self.miny):
            if (y > 0):
                controller.moveBot("rev", int(y * 255))
            else:
                controller.moveBot("fwd", abs(int(y * 255)))
        else:
            controller.moveBot("fwd", 0)

        if (buttons[0]):
            rockets.fire()
        if (buttons[3]):
            rockets.laser()
        if (hat[1] > 0):
            rockets.up()
        if (hat[1] < 0):
            rockets.down()
        if (hat[0] > 0):
            rockets.right()
        if (hat[0] < 0):
            rockets.left()
Exemplo n.º 3
0
	def update(self,x,y,z,throttle,buttons,hat):
#                self.x = x
#                self.y = y
#                self.z = z
#                self.throttle = throttle
#                self.buttons = buttons
#                self.hat = hat

		now = time.time()
		self.tcnt = self.tcnt+1
		self.tsum += now - self.last
		if self.tcnt == 100:
			#print self.tsum/self.tcnt
			self.tcnt=0
			self.tsum=0
		self.last = now

		if (abs(x) > self.minx):
			if (x > 0):
				controller.moveBot("right",int(x*255/2))
			else:
				controller.moveBot("left",abs(int(x*255/2)))
		else:
			controller.moveBot("right",0)

                if (abs(y) > self.miny):
                        if (y > 0):
                                controller.moveBot("rev",int(y*255))
                        else:
                                controller.moveBot("fwd",abs(int(y*255)))
		else:
			controller.moveBot("fwd",0)

		if (buttons[0]):
			rockets.fire()
		if (buttons[3]):
			rockets.laser()
		if (hat[1] > 0):
			rockets.up()
		if (hat[1] < 0):
			rockets.down()
                if (hat[0] > 0):
                        rockets.right()
                if (hat[0] < 0):
                        rockets.left()