Exemplo n.º 1
0
 def process(self, code):
     logging.debug('Processing code: %s' % code)
     if code == Controller.MOVE_FORWARD:
         self.walle.move(Base.FORWARD)
     elif code == Controller.MOVE_BACKWARD:
         self.walle.move(Base.BACKWARD)
     elif code == Controller.TURN_LEFT:
         self.walle.turn(Base.TURN_LEFT)
     elif code == Controller.TURN_RIGHT:
         self.walle.turn(Base.TURN_RIGHT)
     elif code == Controller.HEAD_LEFT:
         self.walle.move_head(Base.TURN_LEFT)
     elif code == Controller.HEAD_RIGHT:
         self.walle.move_head(Base.TURN_RIGHT)
     elif code == Controller.LEFT_ARM_UP:
         self.walle.move_arm(Base.LEFT_ARM, Base.UP)
     elif code == Controller.LEFT_ARM_DOWN:
         self.walle.move_arm(Base.LEFT_ARM, Base.DOWN)
     elif code == Controller.RIGHT_ARM_UP:
         self.walle.move_arm(Base.RIGHT_ARM, Base.UP)
     elif code == Controller.RIGHT_ARM_DOWN:
         self.walle.move_arm(Base.RIGHT_ARM, Base.DOWN)
     elif code == Controller.SOUND_1:
         Voice.getInstance().playFile('../resources/wall-e.ogg')
     elif code == Controller.SOUND_2:
         Voice.getInstance().playFile('../resources/eve.ogg')
Exemplo n.º 2
0
 def processCommandByMyself(self, cmd):
     global timer, canceled
     if timer is not None and timer.isAlive():
         logging.info('Cancel timer')
         timer.cancel()
         canceled = time.time()
         Voice.getInstance().say('Таймер остановлен')
Exemplo n.º 3
0
 def processCommand(self, cmd):
     logging.debug('Core processing: %s' % cmd)
     res = self.processors.processCommand(cmd)
     if res == 0:
         Voice.getInstance().sayCachedNotClear()
     if res == 0:
         logging.warn('Failed to find any suitable processor for: %s' % cmd)
     screen.ScreenWrapper.getInstance().draw_walle_state()
Exemplo n.º 4
0
 def processCommandByMyself(self, cmd):
     global timer
     global started
     global canceled
     preTag = None
     total = 0
     for tag in cmd.tags:
         if tag.lower().startswith('час') and preTag is not None:
             try:
                 hour = int(preTag)
             except ValueError:
                 hour = 1
             logging.debug('Hour: %d' % hour)
             total += hour * 3600
         if tag.lower().startswith('минут') and preTag is not None:
             try:
                 min = int(preTag)
             except ValueError:
                 min = 1
             logging.debug('Min: %d' % min)
             total += min * 60
         elif tag.lower().startswith('секунд') and preTag is not None:
             try:
                 sec = int(preTag)
             except ValueError:
                 logging.error('Can\'t cast \'%s\' to int' % preTag)
                 return
             logging.debug('Sec: %d' % sec)
             total += sec
         preTag = tag
     if total > 0:
         if timer is not None and timer.isAlive():
             timer.cancel()
         timer = threading.Timer(total, action, args=[self])
         started = time.time()
         canceled = None
         timer.start()
         tick()
         logging.info('Start timer for %s' % secToString(total))
         Voice.getInstance().say('Таймер на %s запущен' % secToString(total))
     else:
         logging.debug('NOTHING')
Exemplo n.º 5
0
 def processCommandByMyself(self, cmd):
     global timer
     logging.debug('Checking timer state')
     if timer is None:
         logging.info('Timer not run')
         Voice.getInstance().say('Таймер не запущен')
     elif timer.isAlive():
         passed = time.time() - started
         logging.info('Timer is run for %d sec, left %d sec' % (timer.interval, timer.interval - passed))
         Voice.getInstance().say('Осталось %s' % secToString(timer.interval - passed))
     else:
         if canceled is None:
             logging.info('Timer not run. Last was scheduled for %d sec, and finished %d sec ago' % (
                 timer.interval, time.time() - started - timer.interval))
             screen.ScreenWrapper.getInstance().write(secToFormat(time.time() - started), size=25)
             Voice.getInstance().say('Таймер на %s завершился %s назад' % (
                 secToString(timer.interval), secToString(time.time() - started - timer.interval)))
         else:
             logging.info('Timer not run. Last was scheduled for %d sec, and canceled %d sec ago' % (
                 timer.interval, time.time() - canceled))
             Voice.getInstance().say('Таймер на %s был отменен %s назад' % (
                 secToString(timer.interval), secToString(time.time() - canceled)))
Exemplo n.º 6
0
def action(processor):
    logging.info('Time!!!: %s' % processor)
    screen.ScreenWrapper.getInstance().write('Timeout', size=30)
    Voice.getInstance().sayCachedTimeout()
Exemplo n.º 7
0
 def checkWeather(self, day):
     page = requests.get('http://www.meteoprog.ua/ru/weather/Odesa/#detail')
     tree = html.fromstring(page.text)
     s = self.prepareString(tree, day)
     logging.info(s)
     Voice.getInstance().say(s)
Exemplo n.º 8
0
    time.sleep(0.5)

    # move forward
    walle.move(Base.FORWARD)
    time.sleep(1)
    walle.move_arm(Base.LEFT_ARM, Base.DOWN)
    walle.move_arm(Base.RIGHT_ARM, Base.DOWN)
    time.sleep(1)

    # shake hand twice
    direction = Base.DOWN
    for i in range(0, 4):
        direction = not direction
        walle.move_arm(Base.RIGHT_ARM, direction)
        time.sleep(0.3)
    Voice.getInstance().playFile('../resources/wall-e.ogg')

    # screen demo
    frames = [["../resources/anim1/sc0.png", 1],
           ["../resources/anim1/sc1.png", 0.1],
           ["../resources/anim1/sc2.png", 0.5],
           ["../resources/anim1/sc1.png", 0.1],
           ["../resources/anim1/sc0.png", 1]]
    screen.ScreenWrapper.getInstance().play(frames)
    screen.ScreenWrapper.getInstance().draw_walle_state()

    # turn left
    walle.head.move(0)
    walle.turn(Base.TURN_LEFT, 0.5)
    time.sleep(0.2)
    walle.head.move(90)