Process keyboard input - returns delta position, delta rotation, joint angle delta, and control flags
(dpos: float = 0.01, drot: float = 0.05, dangle: float = 0.02, joint_mode: bool = False)
| 271 | |
| 272 | |
| 273 | def process_input(dpos: float = 0.01, drot: float = 0.05, dangle: float = 0.02, joint_mode: bool = False): |
| 274 | """Process keyboard input - returns delta position, delta rotation, joint angle delta, and control flags""" |
| 275 | keys = pygame.key.get_pressed() |
| 276 | |
| 277 | if not hasattr(process_input, "tab_pressed"): |
| 278 | process_input.tab_pressed = False |
| 279 | process_input.c_pressed = False |
| 280 | process_input.j_pressed = False |
| 281 | process_input.left_pressed = False |
| 282 | process_input.right_pressed = False |
| 283 | |
| 284 | # In joint mode, arrow keys control joints |
| 285 | if joint_mode: |
| 286 | dangle_val = dangle * (keys[pygame.K_UP] - keys[pygame.K_DOWN]) |
| 287 | |
| 288 | prev_joint = False |
| 289 | if keys[pygame.K_LEFT] and not process_input.left_pressed: |
| 290 | prev_joint = True |
| 291 | process_input.left_pressed = True |
| 292 | elif not keys[pygame.K_LEFT]: |
| 293 | process_input.left_pressed = False |
| 294 | |
| 295 | next_joint = False |
| 296 | if keys[pygame.K_RIGHT] and not process_input.right_pressed: |
| 297 | next_joint = True |
| 298 | process_input.right_pressed = True |
| 299 | elif not keys[pygame.K_RIGHT]: |
| 300 | process_input.right_pressed = False |
| 301 | |
| 302 | return None, None, dangle_val, False, False, True, prev_joint, next_joint |
| 303 | |
| 304 | else: |
| 305 | # Normal mode: position and rotation control |
| 306 | dx = dpos * (keys[pygame.K_UP] - keys[pygame.K_DOWN]) |
| 307 | dy = dpos * (keys[pygame.K_LEFT] - keys[pygame.K_RIGHT]) |
| 308 | dz = dpos * (keys[pygame.K_e] - keys[pygame.K_d]) |
| 309 | |
| 310 | droll = drot * (keys[pygame.K_q] - keys[pygame.K_w]) |
| 311 | dpitch = drot * (keys[pygame.K_a] - keys[pygame.K_s]) |
| 312 | dyaw = drot * (keys[pygame.K_z] - keys[pygame.K_x]) |
| 313 | |
| 314 | return [dx, dy, dz], [droll, dpitch, dyaw], 0.0, False, False, False, False, False |
| 315 | |
| 316 | |
| 317 | def process_common_input(): |