Overview
The VEXCommunicationManager class handles serial communication on the VEX brain side, receiving commands from the Raspberry Pi and sending status updates.
Source: arm_system/vex_brain/src/main.py:26
Class Definition
CommunicationManager
Attributes
Serial port file handle (/dev/serial1)
Byte buffer for incoming message assembly
Message delimiter (newline character: b’\n’)
Methods
initialize
/dev/serial1 (read/write binary mode)
Raises:
Exception- If serial port cannot be opened
arm_system/vex_brain/src/main.py:32
Example
read_message
- Reads one byte at a time
- Accumulates bytes in buffer until newline delimiter
- Decodes buffer as UTF-8 string
- Parses JSON message
- Returns parsed dictionary
Parsed JSON message as dictionary, or None if:
- No complete message available
- JSON parsing fails
arm_system/vex_brain/src/main.py:38
Example
send_message
Message type identifier:
check_service- System check responsesafety_service- Safety protocol statusscan_service- Scan progress/completionpick_service- Pick movement statusplace_service- Place movement statuscurrent_angles- Joint angle dataerror- Error notification
Message payload data
Always returns True after sending
- Creates dictionary with ‘type’ and ‘data’ keys
- Serializes to JSON
- Encodes as UTF-8 bytes
- Appends newline delimiter
- Writes to serial port
arm_system/vex_brain/src/main.py:51
Example
Message Types
Incoming Messages (Raspberry Pi → VEX)
| Type | Data Fields | Description |
|---|---|---|
check_service | {} | Request system check |
safety_service | {} | Request safety protocol |
scan_service | speed: int | Start environment scan |
pick_service | joint, angle, distance, action, speed | Execute pick movement |
place_service | joint, angle, distance, action, speed | Execute place movement |
Outgoing Messages (VEX → Raspberry Pi)
| Type | Data Fields | Description |
|---|---|---|
check_service | state: str | System check result |
safety_service | state: str | Safety protocol status |
scan_service | state, angle, distance, size, objects | Scan progress/completion |
pick_service | joint, state, target_angle, actual_angle | Pick movement status |
place_service | joint, state | Place movement status |
current_angles | {joint: angle, ...} | Current joint angles |
error | msg: str | Error message |
Integration with RoboticServices
Complete Example
Error Handling
- Initialization Failure: Raises exception if serial port cannot be opened
- JSON Decode Error: Returns
Noneon malformed JSON - Buffer Management: Automatically resets buffer after message parsing