Skip to main content

Overview

The Robot 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

class Robot:
    def __init__(self)
Initializes the Robot instance with communication manager, scan callback registration, and placement zones.

Attributes

serial_manager
CommunicationManager
Serial communication manager for VEX brain connection (port=‘/dev/ttyACM1’, baudrate=115200)
scan_results
list
List of detected objects from scanning operations
placement_zones
dict
Dictionary mapping object classes to placement zones with angle and distance:
  • apple: angle=90°, distance=200mm
  • orange: angle=180°, distance=200mm
  • bottle: angle=45°, distance=200mm
  • default: angle=270°, distance=200mm

Methods

def main_menu_loop(self)
Runs the main interactive menu loop for user commands. Menu Options:
  • [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
Source: arm_system/main.py:25

handle_scan_command

def handle_scan_command(self)
Executes the scanning command to detect objects in the environment. Process:
  1. Clears previous scan results
  2. Registers scan callback
  3. Sends scan_service message with speed=20
  4. Waits for scan completion (60s timeout)
  5. Processes and logs scan results
Source: arm_system/main.py:58

handle_pick_place_command

def handle_pick_place_command(self)
Executes pick and place operations on detected objects. Process:
  1. Validates scan results exist
  2. Presents interactive object selection menu
  3. Executes pick sequence (rotate base, move arm, close gripper, lift)
  4. Executes place sequence (rotate to placement zone, lower arm, open gripper, return home)
Source: arm_system/main.py:132

execute_movement

def execute_movement(self, message_type: str, movement_sequence: list)
Sends movement commands to the robotic arm and waits for confirmation.
message_type
str
required
Type of service message: ‘pick_service’ or ‘place_service’
movement_sequence
list
required
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)
Raises:
  • Exception - If movement fails or timeout occurs
Source: arm_system/main.py:217

Example

robot = Robot()
movement_plan = [
    {'joint': 'base', 'angle': 90, 'speed': 30},
    {'joint': 'arm', 'distance': 150, 'action': 'pick'},
    {'joint': 'gripper', 'action': 'close'},
    {'joint': 'arm', 'distance': 150, 'action': 'up'},
]
robot.execute_movement('pick_service', movement_plan)

get_current_angles

def get_current_angles(self) -> dict
Retrieves current joint angles from the VEX brain.
angles
dict
Dictionary containing current angles for all joints
Returns: dict or None if timeout/error occurs Timeout: 5 seconds Source: arm_system/main.py:203

run

def run(self)
Main entry point that connects to VEX brain and starts the main menu loop. Process:
  1. Connects to VEX brain via serial communication
  2. Starts main menu loop
  3. Handles keyboard interrupts gracefully
  4. Closes serial connection on exit
Source: arm_system/main.py:261

Example Usage

from arm_system.main import Robot

# Initialize robot
robot = Robot()

# Run main loop
robot.run()

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

Build docs developers (and LLMs) love