class RobotManualDriveState(UnlockState): SERVO_SPEED = 0.175 WHEEL_SPEED = 100 def __init__(self): super(RobotManualDriveState, self).__init__() self.sc = StreamClient('128.197.61.111', 21567) self.frame = None self.ready = True def process_command(self, command): cmds = {} if command.decision == 1: cmds['wheels'] = [self.WHEEL_SPEED, self.WHEEL_SPEED] elif command.decision == 2: cmds['wheels'] = [-self.WHEEL_SPEED, -self.WHEEL_SPEED] elif command.decision == 3: cmds['wheels'] = [self.WHEEL_SPEED / 2, -self.WHEEL_SPEED / 2] elif command.decision == 4: cmds['wheels'] = [-self.WHEEL_SPEED / 2, self.WHEEL_SPEED / 2] if command.selection: cmds['wheels'] = [0, 0] if len(cmds) > 0: self.sc.set('bri/command', json.dumps(cmds)) if self.ready: try: data = self.sc.get('bri/create/video.jpg') buffer = io.BytesIO(data) self.frame = pyglet.image.load('video.jpg', buffer) except: pass self.ready = not self.ready
class RobotManualDriveState(UnlockState): SERVO_SPEED = 0.175 WHEEL_SPEED = 100 def __init__(self): super(RobotManualDriveState, self).__init__() self.sc = StreamClient('128.197.61.111', 21567) self.frame = None self.ready = True def process_command(self, command): cmds = {} if command.decision == 1: cmds['wheels'] = [self.WHEEL_SPEED, self.WHEEL_SPEED] elif command.decision == 2: cmds['wheels'] = [-self.WHEEL_SPEED, -self.WHEEL_SPEED] elif command.decision == 3: cmds['wheels'] = [self.WHEEL_SPEED/2, -self.WHEEL_SPEED/2] elif command.decision == 4: cmds['wheels'] = [-self.WHEEL_SPEED/2, self.WHEEL_SPEED/2] if command.selection: cmds['wheels'] = [0, 0] if len(cmds) > 0: self.sc.set('bri/command', json.dumps(cmds)) if self.ready: try: data = self.sc.get('bri/create/video.jpg') buffer = io.BytesIO(data) self.frame = pyglet.image.load('video.jpg', buffer) except: pass self.ready = not self.ready
class RobotGridState(GridState): """ The Hierarchy Grid is a 2D grid interface for selecting targets arranged in a hierarchical fashion. The grid contains 2 or more layers, where certain tiles in the grid correspond to descend/ascend actions and the rest are target actions. The grid is laid our radially, with (0, 0) corresponding to the center. 1) Create a square grid of tiles 2) Each tile's state is its label and action 3) On layer change, set tile states accordingly """ def __init__(self, grid_radius): super(RobotGridState, self).__init__() self.radius = grid_radius self.state = (0, 0) self.state_change = None self.sc = StreamClient('128.197.61.111', 21567) def handle_state_change(self, new_state, change): if new_state and abs(new_state[0]) <= self.radius and abs( new_state[1]) <= self.radius: self.state = new_state self.state_change = GridStateChange(*change) def process_selection(self): """ Determine and execute current tile's associated action """ target = None print(self.state) if self.state == (0, 1): target = '0' elif self.state == (-1, 0): target = '1' elif self.state == (1, 0): target = '2' elif self.state == (0, -1): target = '3' if target is not None: self.sc.set('bri/target', target)
class RobotGridState(GridState): """ The Hierarchy Grid is a 2D grid interface for selecting targets arranged in a hierarchical fashion. The grid contains 2 or more layers, where certain tiles in the grid correspond to descend/ascend actions and the rest are target actions. The grid is laid our radially, with (0, 0) corresponding to the center. 1) Create a square grid of tiles 2) Each tile's state is its label and action 3) On layer change, set tile states accordingly """ def __init__(self, grid_radius): super(RobotGridState, self).__init__() self.radius = grid_radius self.state = (0, 0) self.state_change = None self.sc = StreamClient("128.197.61.111", 21567) def handle_state_change(self, new_state, change): if new_state and abs(new_state[0]) <= self.radius and abs(new_state[1]) <= self.radius: self.state = new_state self.state_change = GridStateChange(*change) def process_selection(self): """ Determine and execute current tile's associated action """ target = None print(self.state) if self.state == (0, 1): target = "0" elif self.state == (-1, 0): target = "1" elif self.state == (1, 0): target = "2" elif self.state == (0, -1): target = "3" if target is not None: self.sc.set("bri/target", target)
def __init__(self, grid_radius): super(RobotGridState, self).__init__() self.radius = grid_radius self.state = (0, 0) self.state_change = None self.sc = StreamClient('128.197.61.111', 21567)
def __init__(self): super(RobotManualDriveState, self).__init__() self.sc = StreamClient('128.197.61.111', 21567) self.frame = None self.ready = True
def __init__(self, grid_radius): super(RobotGridState, self).__init__() self.radius = grid_radius self.state = (0, 0) self.state_change = None self.sc = StreamClient("128.197.61.111", 21567)