Overview
TheCommunicationManager class handles all serial communication between the Raspberry Pi and VEX brain, including message passing, callback registration, and real-time object detection coordination.
Source: arm_system/communication/serial_manager.py:16
Class Definition
CommunicationManager
Serial port device path for VEX brain connection
Serial communication baud rate
Camera device index for image capture
Attributes
PySerial connection object
Connection status flag
Event signaled when scanning is complete
Event signaled when movement commands are received
Event signaled when angle data is received
Dictionary mapping message types to callback functions
Dictionary tracking status of each joint movement
Dictionary storing current joint angles
Camera manager instance for image capture
Image processor with YOLO detection model (confidence threshold: 0.45)
Methods
connect
True if connection successful, False otherwise
- Timeout: 10 seconds
- Write timeout: 10 seconds
- Background thread: Daemon mode
arm_system/communication/serial_manager.py:52
close
- Sets stop event
- Joins read thread (1.0s timeout)
- Closes serial port
- Updates connection status
arm_system/communication/serial_manager.py:76
send_message
Message type identifier:
check_service- Verify sensors and motorssafety_service- Execute safety protocolsscan_service- Start environment scanpick_service- Execute pick movementplace_service- Execute place movementget_angles- Request current joint angles
Message payload data
True if message sent successfully, False otherwise
arm_system/communication/serial_manager.py:87
Example
register_callback
Message type to listen for (e.g., ‘scan_service’)
Function to call when message is received. Set to
None to unregister.arm_system/communication/serial_manager.py:109
Example
wait_for_confirmation
Joint name to wait for: ‘base’, ‘arm’, or ‘gripper’
Maximum wait time in seconds
True if movement completed successfully, False if error or timeout
arm_system/communication/serial_manager.py:210
wait_for_angles_response
Maximum wait time in seconds
True if angles received, False if timeout
arm_system/communication/serial_manager.py:226
Threading & Events
The CommunicationManager uses threading for non-blocking communication:Background Read Thread
Continuously reads from serial port and processes incoming messages. Source:arm_system/communication/serial_manager.py:112
Event System
- scan_complete_event: Set when scan finishes
- movement_event: Set when movement status updates
- angles_event: Set when angle data received
Message Processing
Incoming messages are automatically processed based on type:Supported Message Types
| Type | Description | Events Triggered |
|---|---|---|
check_service | System check status | None |
safety_service | Safety protocol status | Updates safety_status |
scan_service | Scan progress/detection | scan_complete_event, launches detection thread |
pick_service | Pick movement status | movement_event |
place_service | Place movement status | movement_event |
current_angles | Joint angle data | angles_event |
arm_system/communication/serial_manager.py:132
Object Detection Integration
When a scan detection occurs, the CommunicationManager:- Captures image via CameraManager
- Runs YOLO inference via ImageProcessor
- Updates detection data with class, confidence, timestamp, and image path
- Invokes registered callback with complete data
arm_system/communication/serial_manager.py:174