Beispiel #1
0
def keyboard_controller_thread(q, route_start_time):
  print("keyboard waiting for input")
  kb = KBHit()
  while 1:
    c = kb.getch()
    if c == 'm':  # Move forward by 1m
      q.send_pyobj(SeekRelativeTime(60))
    elif c == 'M':  # Move backward by 1m
      q.send_pyobj(SeekRelativeTime(-60))
    elif c == 's':  # Move forward by 10s
      q.send_pyobj(SeekRelativeTime(10))
    elif c == 'S':  # Move backward by 10s
      q.send_pyobj(SeekRelativeTime(-10))
    elif c == 'G':  # Move backward by 10s
      q.send_pyobj(SeekAbsoluteTime(0.))
    elif c == "\x20":  # Space bar.
      q.send_pyobj(TogglePause())
    elif c == "\n":
      try:
        seek_time_input = input('time: ')
        seek_time = absolute_time_str(seek_time_input, route_start_time)

        # If less than 60, assume segment number
        if seek_time < 60:
          seek_time *= 60

        q.send_pyobj(SeekAbsoluteTime(seek_time))
      except Exception as e:
        print("Time not understood: {}".format(e))
Beispiel #2
0
class Keyboard:
    def __init__(self):
        self.kb = KBHit()
        self.axis_increment = 0.05  # 5% of full actuation each key press
        self.axes_map = {'w': 'gb', 's': 'gb', 'a': 'steer', 'd': 'steer'}
        self.axes_values = {'gb': 0., 'steer': 0.}

    def update(self):
        key = self.kb.getch().lower()
        self.cancel = False
        if key == 'r':
            self.axes_values = {ax: 0. for ax in self.axes_values}
        elif key == 'c':
            self.cancel = True
        elif key in self.axes_map:
            axis = self.axes_map[key]
            incr = self.axis_increment if key in ['w', 'a'
                                                  ] else -self.axis_increment
            self.axes_values[axis] = clip(self.axes_values[axis] + incr, -1, 1)
        else:
            return False
        return True