Overview
TheRobot class is the main controller for the robotic arm system. It manages serial communication, handles user commands, coordinates scanning, and executes pick and place operations.
Source: arm_system/main.py:8
Class Definition
Robot
Attributes
Serial communication manager for VEX brain connection (port=‘/dev/ttyACM1’, baudrate=115200)
List of detected objects from scanning operations
Dictionary mapping object classes to placement zones with angle and distance:
apple: angle=90°, distance=200mmorange: angle=180°, distance=200mmbottle: angle=45°, distance=200mmdefault: angle=270°, distance=200mm
Methods
main_menu_loop
[c]- Check service (verify sensors and motors)[s]- Safety service (execute safety protocols)[n]- Scan service (scan environment for objects)[p]- Pick & place service (pick and place detected objects)[q]- Exit program
arm_system/main.py:25
handle_scan_command
- Clears previous scan results
- Registers scan callback
- Sends scan_service message with speed=20
- Waits for scan completion (60s timeout)
- Processes and logs scan results
arm_system/main.py:58
handle_pick_place_command
- Validates scan results exist
- Presents interactive object selection menu
- Executes pick sequence (rotate base, move arm, close gripper, lift)
- Executes place sequence (rotate to placement zone, lower arm, open gripper, return home)
arm_system/main.py:132
execute_movement
Type of service message: ‘pick_service’ or ‘place_service’
List of movement commands, each containing:
joint: str - Joint name (‘base’, ‘arm’, ‘gripper’)angle: int - Target angle for base rotation (optional)distance: int - Target distance for arm movement (optional)action: str - Action to perform (‘pick’, ‘place’, ‘up’, ‘close’, ‘open’)speed: int - Movement speed in RPM (optional)
Exception- If movement fails or timeout occurs
arm_system/main.py:217
Example
get_current_angles
Dictionary containing current angles for all joints
dict or None if timeout/error occurs
Timeout: 5 seconds
Source: arm_system/main.py:203
run
- Connects to VEX brain via serial communication
- Starts main menu loop
- Handles keyboard interrupts gracefully
- Closes serial connection on exit
arm_system/main.py:261
Example Usage
Error Handling
The Robot class implements comprehensive error handling:- Movement Failures: Triggers safety protocol via
handle_movement_failure() - Scan Timeout: Logs error after 60 seconds
- Communication Errors: Closes connection and exits
- Keyboard Interrupt: Graceful shutdown with resource cleanup