Overview
TheSensorModule class provides a unified interface to all hardware sensors on the VEX IQ robotic arm. It manages the Brain, inertial sensor, distance sensors, bumper, and touch LED, offering convenient methods for reading sensor data and controlling outputs.
Source: ~/workspace/source/arm_controller/src/main.py:76
Constructor
__init__()
Initializes all sensor hardware components with their port configurations.
VEX Brain controller with screen and button interface
3-axis gyroscope for angle and rotation measurements. Requires calibration before use.
Distance sensor on gripper (Port 7). Measures object distance in gripper proximity.Port:
Ports.PORT7RGB LED with touch sensitivity (Port 10). Used for status indication.Port:
Ports.PORT10Distance sensor on rotating base (Port 11). Primary sensor for environmental scanning.Port:
Ports.PORT11Mechanical bumper switch (Port 12). Safety sensor for shoulder collision detection.Port:
Ports.PORT12main.py:77
Brain Screen Methods
clear_screen()
Clears all content from the VEX Brain display.
main.py:86
print_screen(text: str, coordinate_x: int, coordinate_y: int)
Displays text at specified screen coordinates.
Text string to display on screen
Horizontal pixel position (0 = left edge)
Vertical pixel position (0 = top edge)
- VEX IQ Brain: 228×128 pixels
- Origin (0,0) at top-left corner
main.py:89
Inertial Sensor Methods
calibrate_intertial_sensor()
Calibrates the inertial sensor. Robot must remain stationary during calibration.
- On robot startup
- After significant temperature changes
- If angle readings drift
- After physical impacts
main.py:93
get_angle()
Returns the current heading angle from the inertial sensor.
Current heading angle in degrees (0-360°)
0°: Initial calibration position- Increases with clockwise rotation
- Wraps around at 360°
- Tracking rotation during environmental scans
- Calculating object angular positions
- Returning to specific orientations
main.py:96
Distance Sensor Methods
get_base_distance()
Reads distance from the base-mounted distance sensor.
Distance to nearest object in millimeters (mm)
- Range: 20-2000mm (typical)
- Accuracy: ±3mm
- Returns large value if no object detected
- Minimum: ~20mm
- Optimal: 50-300mm (used for object detection)
- Maximum: ~2000mm
main.py:100
get_base_object_size()
Returns the raw size measurement from base distance sensor.
Raw size value (0-400 typical)
- Higher values indicate larger objects
- Unitless metric (not physical dimensions)
- Used for relative size comparison
0: No object detected1-100: Small object (bottle cap, pen)100-200: Medium object (cup, bottle)200+: Large object (box, container)
main.py:103
get_gripper_distance()
Reads distance from the gripper-mounted distance sensor.
Distance in millimeters from gripper sensor to nearest object
- Range: 20-200mm (shorter range than base sensor)
- Used to verify object grip
- Confirming object capture
- Fine-tuning gripper approach
- Verifying gripper is empty
main.py:106
Bumper Methods
is_bumper_pressed()
Checks if the mechanical bumper switch is pressed.
True: Bumper is currently pressed (collision detected)False: Bumper is not pressed (normal state)
- Safety checks during shoulder movement
- Emergency stop trigger
- Collision avoidance validation
main.py:110
Touch LED Methods
set_color(color: tuple)
Sets the RGB color of the touch LED for status indication.
RGB color tuple
(red, green, blue)- Each component: 0-255
(0, 0, 0): Off(255, 255, 255): White
main.py:114
Hardware Verification
check_sensors()
Verifies that all critical sensors are properly installed and responsive.
Returns
True if all sensors installed, False if any sensor missing or unresponsive- Base distance sensor (Port 11)
- Gripper distance sensor (Port 7)
- Bumper switch (Port 12)
- Brain (always available)
- Inertial sensor (always available)
- Touch LED (always available)
main.py:119
Port Configuration Summary
| Sensor | Port | Type | Purpose |
|---|---|---|---|
| Gripper Distance | PORT7 | Distance | Gripper proximity detection |
| Touch LED | PORT10 | Touchled | Status indication |
| Base Distance | PORT11 | Distance | Environmental scanning |
| Bumper | PORT12 | Bumper | Collision safety |
| Inertial | Internal | Inertial | Angle measurement |
| Brain | Internal | Brain | Display and control |
Sensor Data Flow
The sensor data flows through the system as follows:Usage Examples
Complete Sensor Initialization
Object Detection Loop
Safety Monitoring
Related Classes
- RoboticServices - Main orchestrator that uses sensor data
- ControlModule - Motor control coordinated with sensors
- CommunicationManager - Sends sensor data to Raspberry Pi