Keyboard client for object and robot control
| 84 | |
| 85 | |
| 86 | class ObjectKeyboardClient: |
| 87 | """Keyboard client for object and robot control""" |
| 88 | |
| 89 | def __init__( |
| 90 | self, |
| 91 | entity_names: list[str], |
| 92 | entity_types: list[str], |
| 93 | entity_joints: dict[str, list[str]], # entity_name -> list of joint names |
| 94 | width: int = 550, |
| 95 | height: int = 650, |
| 96 | title: str = "Object/Robot Control", |
| 97 | ): |
| 98 | pygame.init() |
| 99 | self.screen = pygame.display.set_mode((width, height)) |
| 100 | pygame.display.set_caption(title) |
| 101 | self.clock = pygame.time.Clock() |
| 102 | self.font = pygame.font.Font(None, 28) |
| 103 | self.small_font = pygame.font.Font(None, 22) |
| 104 | self.tiny_font = pygame.font.Font(None, 18) |
| 105 | |
| 106 | self.entity_names = entity_names # All entities (objects + robots) |
| 107 | self.entity_types = entity_types # 'object' or 'robot' |
| 108 | self.entity_joints = entity_joints # joint names for each entity |
| 109 | self.selected_idx = 0 |
| 110 | |
| 111 | # Joint control mode |
| 112 | self.joint_mode = False |
| 113 | self.selected_joint_idx = 0 |
| 114 | |
| 115 | self.instructions = [ |
| 116 | "=== Object/Robot Control ===", |
| 117 | "", |
| 118 | " Movement:", |
| 119 | " UP - Move +X", |
| 120 | " DOWN - Move -X", |
| 121 | " LEFT - Move +Y", |
| 122 | " RIGHT - Move -Y", |
| 123 | " e - Move +Z", |
| 124 | " d - Move -Z", |
| 125 | "", |
| 126 | " Rotation:", |
| 127 | " q - Roll +", |
| 128 | " w - Roll -", |
| 129 | " a - Pitch +", |
| 130 | " s - Pitch -", |
| 131 | " z - Yaw +", |
| 132 | " x - Yaw -", |
| 133 | "", |
| 134 | " Joint Control (when in joint mode):", |
| 135 | " UP - Increase angle", |
| 136 | " DOWN - Decrease angle", |
| 137 | " LEFT - Previous joint", |
| 138 | " RIGHT - Next joint", |
| 139 | "", |
| 140 | " Control:", |
| 141 | " TAB - Switch entity", |
| 142 | " j - Toggle joint mode", |
| 143 | " c - Save poses", |