Skip to main content

Overview

The SensorModule class provides a unified interface to all VEX sensors including distance sensors, inertial sensor, bumper, touchled, and brain screen. Source: arm_system/vex_brain/src/main.py:63

Class Definition

SensorModule

class SensorModule:
    def __init__(self)
Initializes all VEX sensors and brain components.

Attributes

brain
Brain
VEX Brain for screen display
inertial
Inertial
Inertial sensor for heading/rotation measurement
gripper_distance
Distance
Distance sensor on gripper (PORT7)
touchled
Touchled
RGB LED indicator (PORT8)
base_distance
Distance
Distance sensor on base (PORT9) for scanning
bumper
Bumper
Bumper switch for safety limits (PORT10)

Methods

Screen Methods

clear_screen

def clear_screen(self)
Clears the VEX brain screen. Source: arm_system/vex_brain/src/main.py:72
def print_screen(self, text: str, coordinate_x: int, coordinate_y: int)
Prints text on the VEX brain screen at specified coordinates.
text
str
required
Text to display
coordinate_x
int
required
X coordinate (horizontal position)
coordinate_y
int
required
Y coordinate (vertical position)
Source: arm_system/vex_brain/src/main.py:75

Inertial Sensor Methods

get_angle

def get_angle(self) -> float
Returns current heading from inertial sensor.
angle
float
Current heading in degrees (0-360)
Source: arm_system/vex_brain/src/main.py:81

Distance Sensor Methods

get_distance

def get_distance(self, sensor: Distance) -> float
Returns distance measurement from specified distance sensor.
sensor
Distance
required
Distance sensor object (base_distance or gripper_distance)
distance
float
Distance to object in millimeters
Source: arm_system/vex_brain/src/main.py:84

Example

sensor = SensorModule()

# Get base distance
base_dist = sensor.get_distance(sensor.base_distance)
print(f"Base distance: {base_dist}mm")

# Get gripper distance
gripper_dist = sensor.get_distance(sensor.gripper_distance)
print(f"Gripper distance: {gripper_dist}mm")

get_object_size

def get_object_size(self, sensor: Distance) -> int
Returns raw object size measurement from distance sensor.
sensor
Distance
required
Distance sensor object
size
int
Raw object size value (sensor-specific units)
Source: arm_system/vex_brain/src/main.py:87

Bumper Methods

is_bumper_pressed

def is_bumper_pressed(self) -> bool
Checks if the bumper switch is currently pressed.
pressed
bool
True if bumper is pressed, False otherwise
Source: arm_system/vex_brain/src/main.py:90

LED Indicator Methods

set_color

def set_color(self, color: tuple)
Sets the RGB LED color.
color
tuple
required
RGB color tuple (red, green, blue) with values 0-255
Predefined Colors (LED_COLORS):
LED_COLORS = {
    'ERROR': (255, 0, 0),       # Red
    'WARNING': (255, 150, 0),   # Orange
    'READY': (0, 255, 0),       # Green
    'RUNNING': (0, 0, 255),     # Blue
    'INIT': (255, 255, 255)     # White
}
Source: arm_system/vex_brain/src/main.py:93

Example

sensor = SensorModule()

# Set to green (ready)
sensor.set_color((0, 255, 0))

# Set to red (error)
sensor.set_color((255, 0, 0))

# Use predefined colors
from main import LED_COLORS
sensor.set_color(LED_COLORS['RUNNING'])

System Check Methods

check_sensors

def check_sensors(self) -> bool
Verifies that all required sensors are installed and functional. Checked Sensors:
  • base_distance (PORT9)
  • gripper_distance (PORT7)
  • bumper (PORT10)
all_installed
bool
True if all sensors are installed, False otherwise
Source: arm_system/vex_brain/src/main.py:96

Port Configuration

SensorPortPurpose
gripper_distancePORT7Detect objects in gripper
touchledPORT8Visual status indicator
base_distancePORT9Scan environment for objects
bumperPORT10Safety limit switch
inertialDefaultBase rotation angle

Usage in RoboticServices

class RoboticServices:
    def __init__(self):
        self.sensor = SensorModule()
        # ... other components
    
    def run_service(self, service):
        if service == 'check':
            if self.sensor.check_sensors():
                self.sensor.set_color(LED_COLORS['READY'])
            else:
                self.sensor.set_color(LED_COLORS['ERROR'])

Complete Example

from vex import *

LED_COLORS = {
    'ERROR': (255, 0, 0),
    'WARNING': (255, 150, 0),
    'READY': (0, 255, 0),
    'RUNNING': (0, 0, 255),
    'INIT': (255, 255, 255)
}

class SensorModule:
    def __init__(self):
        self.brain = Brain()
        self.inertial = Inertial()
        self.gripper_distance = Distance(Ports.PORT7)
        self.touchled = Touchled(Ports.PORT8)
        self.base_distance = Distance(Ports.PORT9)
        self.bumper = Bumper(Ports.PORT10)
    
    # ... methods ...

# Usage
sensors = SensorModule()

# Check system
if sensors.check_sensors():
    sensors.set_color(LED_COLORS['READY'])
    sensors.print_screen("System Ready", 10, 10)
else:
    sensors.set_color(LED_COLORS['ERROR'])
    sensors.print_screen("Sensor Error", 10, 10)

# Monitor distance
while True:
    angle = sensors.get_angle()
    distance = sensors.get_distance(sensors.base_distance)
    
    sensors.clear_screen()
    sensors.print_screen(f"Angle: {angle:.1f}", 10, 20)
    sensors.print_screen(f"Distance: {distance}mm", 10, 40)
    
    if sensors.is_bumper_pressed():
        sensors.set_color(LED_COLORS['WARNING'])
    
    wait(100, MSEC)

Sensor Specifications

Distance Sensors

  • Range: 0-2000mm (varies by model)
  • Units: Millimeters (MM)
  • Update Rate: ~50Hz

Inertial Sensor

  • Range: 0-360 degrees
  • Accuracy: ±1 degree
  • Requires: Calibration on startup

Bumper Switch

  • Type: Digital on/off
  • Debounce: Hardware debounced

RGB LED

  • Colors: Full RGB (0-255 per channel)
  • Modes: Solid color, touch-sensitive

Build docs developers (and LLMs) love