Skip to main content

Overview

The ControlModule class manages all motor actuators in the robotic arm system, including base rotation, shoulder, elbow, and gripper motors. Source: arm_system/vex_brain/src/main.py:169

Class Definition

ControlModule

class ControlModule:
    def __init__(self, sensor_module: SensorModule)
Initializes all motors with torque limits and sensor integration.
sensor_module
SensorModule
required
SensorModule instance for inertial feedback

Attributes

base_motor
Motor
Base rotation motor (PORT1, reversed)
shoulder_motor
Motor
Shoulder joint motor (PORT2, reversed, 95% torque limit)
elbow_motor
Motor
Elbow joint motor (PORT3, reversed, 95% torque limit)
gripper_motor
Motor
Gripper motor (PORT4, reversed)
sensor_module
SensorModule
Reference to sensor module for angle feedback
Torque Configuration:
  • Elbow: 95% max torque
  • Shoulder: 95% max torque
  • Base and Gripper: 100% max torque (default)

Methods

move_motor_to_angle

def move_motor_to_angle(self, motor: Motor, target: float, speed: int)
Moves the base motor to a target angle using inertial sensor feedback.
motor
Motor
required
Motor to control (typically base_motor)
target
float
required
Target angle in degrees (0-360)
speed
int
required
Rotation speed in RPM
Algorithm:
  1. Reads current angle from inertial sensor
  2. Calculates shortest rotation path (-180 to 180 degrees)
  3. Determines rotation direction (FORWARD or REVERSE)
  4. Spins motor until within 2° of target
  5. Stops motor with brake
Accuracy: ±2 degrees Source: arm_system/vex_brain/src/main.py:180

Example

control = ControlModule(sensor_module)

# Rotate base to 90 degrees at 30 RPM
control.move_motor_to_angle(control.base_motor, 90, 30)

# Rotate to 270 degrees (takes shortest path)
control.move_motor_to_angle(control.base_motor, 270, 40)

get_position

def get_position(self, motor: Motor) -> float
Returns current position of a motor.
motor
Motor
required
Motor to query
position
float
Current motor position in degrees
Source: arm_system/vex_brain/src/main.py:194

get_current

def get_current(self, motor: Motor) -> float
Returns current draw of a motor.
motor
Motor
required
Motor to query
current
float
Current draw in amperes
Usage: Detect stall conditions or grip force Source: arm_system/vex_brain/src/main.py:197

Example

# Check gripper current to detect object grasp
current = control.get_current(control.gripper_motor)
if current > 0.5:
    print("Object gripped!")
    control.gripper_motor.stop(HOLD)

general_stop

def general_stop(self)
Emergency stop for all motors. Stops: base_motor, shoulder_motor, elbow_motor, gripper_motor Stopping Mode: Brake (motors resist movement) Source: arm_system/vex_brain/src/main.py:200

check_motors

def check_motors(self) -> bool
Verifies all motors are installed and connected. Checked Motors:
  • base_motor (PORT1)
  • shoulder_motor (PORT2)
  • elbow_motor (PORT3)
  • gripper_motor (PORT4)
all_installed
bool
True if all motors installed, False otherwise
Source: arm_system/vex_brain/src/main.py:204

Motor Port Configuration

MotorPortFunctionReversedTorque Limit
base_motorPORT1Base rotationYes100%
shoulder_motorPORT2Shoulder liftYes95%
elbow_motorPORT3Elbow extensionYes95%
gripper_motorPORT4Gripper open/closeYes100%

Movement Control Patterns

Base Rotation

# Absolute angle control with inertial feedback
control.move_motor_to_angle(control.base_motor, target_angle, speed)

Arm Extension/Retraction

# Coordinated shoulder and elbow movement
control.shoulder_motor.spin(REVERSE, speed, RPM)
control.elbow_motor.spin(FORWARD, speed, RPM)

Gripper Control

# Current-based grip detection
control.gripper_motor.spin(REVERSE, 20, RPM)  # Close
if control.get_current(control.gripper_motor) > 0.5:
    control.gripper_motor.stop(HOLD)

Integration with SafetyModule

The SafetyModule uses ControlModule for safe movement operations:
class SafetyModule:
    def __init__(self, sensor: SensorModule, control: ControlModule):
        self.control_module = control
    
    def check_shoulder_safety(self, speed_forward: int, speed_reverse: int):
        if self.sensor_module.is_bumper_pressed():
            self.control_module.general_stop()
            # ... safety protocol

Complete Example

from vex import *

class ControlModule:
    def __init__(self, sensor_module):
        self.base_motor = Motor(Ports.PORT1, True)
        self.shoulder_motor = Motor(Ports.PORT2, True)
        self.elbow_motor = Motor(Ports.PORT3, True)
        self.gripper_motor = Motor(Ports.PORT4, True)
        self.sensor_module = sensor_module
        
        # Set torque limits
        self.elbow_motor.set_max_torque(95, PERCENT)
        self.shoulder_motor.set_max_torque(95, PERCENT)
    
    # ... methods ...

# Usage
sensor = SensorModule()
control = ControlModule(sensor)

# Check system
if control.check_motors():
    print("All motors ready")
    
    # Rotate base to 90 degrees
    control.move_motor_to_angle(control.base_motor, 90, 30)
    
    # Extend arm
    control.shoulder_motor.spin(REVERSE, 20, RPM)
    control.elbow_motor.spin(FORWARD, 40, RPM)
    wait(2, SECONDS)
    
    # Close gripper until object detected
    control.gripper_motor.spin(REVERSE, 20, RPM)
    while control.get_current(control.gripper_motor) < 0.5:
        wait(10, MSEC)
    control.gripper_motor.stop(HOLD)
    
    # Emergency stop
    control.general_stop()

Stopping Modes

Available Modes

  • COAST: Motor freewheels (no resistance)
  • BRAKE: Motor actively resists movement
  • HOLD: Motor maintains position with active control

Usage

# Stop with brake (default for general_stop)
motor.stop(BRAKE)

# Stop and hold position
motor.stop(HOLD)

# Stop and allow free movement
motor.stop(COAST)

Current Monitoring

Current draw indicates:
  • Low (less than 0.2A): Free movement
  • Medium (0.2-0.5A): Normal load
  • High (greater than 0.5A): Stall condition or object contact
Used for:
  • Gripper grip detection
  • Stall detection
  • Load monitoring

Build docs developers (and LLMs) love