Search requires an index. Run npm run build once, then restart dev.
Search needs internet. Offline lessons: use the sidebar or download a track under Reading preferences (Aa).
Control Hub & Expansion Hub
beginner35 min
Control Hub and Expansion Hub
The Control Hub runs your code and hosts WiFi for the Driver Station. The Expansion Hub adds motor, servo, and sensor ports when one hub is not enough.
// Example: Accessing hardware on both hubsDcMotor leftDrive = hardwareMap.get(DcMotor.class, "left_drive");DcMotor rightDrive = hardwareMap.get(DcMotor.class, "right_drive");Servo armServo = hardwareMap.get(Servo.class, "arm_servo");DistanceSensor distance = hardwareMap.get(DistanceSensor.class, "distance_sensor");// The names must match the configuration on the Driver Station.// Devices can be on either the Control Hub or Expansion Hub.
Configuring hardware in the Driver Station
In the Driver Station app, add each device and give it a name that matches your hardwareMap.get() calls.
Label all cables and ports for easy troubleshooting.
Double-check wiring before powering on.
Keep firmware up to date on both hubs.
Use clear, consistent device names in configuration.
Practice: Hardware Setup
Try these to reinforce your understanding:
Configure a new device on the Expansion Hub in the Driver Station app.
Write code to access a motor and a sensor on the Expansion Hub.
Ask your mentor to cause a wiring issue, then fix it.
Configure a new device in the Driver Station app
Configure a new device in the Driver Station app
// Steps to configure hardware in Driver Station:
//
// 1. Open Driver Station app on your phone/tablet
// 2. Tap 'Configure Robot' button
// 3. Tap 'New Configuration' or select existing config
// 4. Tap '+' to add a new device
// 5. Select device type (Motor, Servo, Sensor, etc.)
// 6. Choose the specific device (e.g., 'DcMotor', 'ColorSensor')
// 7. Enter a name (e.g., 'left_drive', 'color_sensor')
// 8. Select which hub it's connected to (Control Hub or Expansion Hub)
// 9. Select the port number (e.g., port 0, port 1)
// 10. Tap 'Done' to save the configuration
//
// Example configuration:
// - Device: DcMotor, Name: 'left_drive', Hub: Control Hub, Port: 0
// - Device: ColorSensor, Name: 'color_sensor', Hub: Expansion Hub, Port: 1
//
// Remember: Device names must match exactly in your code!
Write code to access a motor and a sensor
Write code to access a motor and a sensor
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.ColorSensor;
@TeleOp(name = "HardwareAccess")
public class HardwareAccess extends LinearOpMode {
// Declare hardware variables
private DcMotor driveMotor;
private ColorSensor colorSensor;
@Override
public void runOpMode() {
// Initialize hardware using hardwareMap
// Names must match your Driver Station configuration
driveMotor = hardwareMap.get(DcMotor.class, "drive_motor");
colorSensor = hardwareMap.get(ColorSensor.class, "color_sensor");
// Show initialization status
telemetry.addData("Status", "Hardware initialized");
telemetry.addData("Motor Name", "drive_motor");
telemetry.addData("Sensor Name", "color_sensor");
telemetry.update();
waitForStart();
while (opModeIsActive()) {
// Control motor with gamepad
double motorPower = -gamepad1.left_stick_y;
driveMotor.setPower(motorPower);
// Read sensor values
int red = colorSensor.red();
int green = colorSensor.green();
int blue = colorSensor.blue();
// Display data on Driver Station
telemetry.addData("Motor Power", motorPower);
telemetry.addData("Color Sensor", "R:%d G:%d B:%d", red, green, blue);
telemetry.update();
}
}
}