Hardware Map and Motors
Connect configuration names to Java objects safely.
Connect configuration names to Java objects safely.
In this lesson, you will:
The Robot Controller app stores names for motors, servos, and sensors. Java code asks the hardware map for those names, then controls the returned objects.
If the config says frontLeft but the code asks for leftFront, the robot will not initialize. Keep names boring, consistent, and written down.
Motors on opposite sides of many drivetrains are mounted as mirror images, so the same positive power can spin their wheels in opposite robot-relative directions. Reverse whichever side your physical build requires, then verify it on blocks. The goal is simple: positive power should mean robot-forward on every drive motor.
DriveHardware.javaJava
DcMotor frontLeft = hardwareMap.get(DcMotor.class, "frontLeft");
DcMotor frontRight = hardwareMap.get(DcMotor.class, "frontRight");
DcMotor backLeft = hardwareMap.get(DcMotor.class, "backLeft");
DcMotor backRight = hardwareMap.get(DcMotor.class, "backRight");
frontLeft.setDirection(DcMotor.Direction.REVERSE);
backLeft.setDirection(DcMotor.Direction.REVERSE);
waitForStart();
// Robot on blocks: test one wheel, then return it to zero.
if (opModeIsActive()) {
frontLeft.setPower(0.2);
sleep(500);
frontLeft.setPower(0.0);
}Check your understanding before moving on.
The string in hardwareMap.get(DcMotor.class, "frontLeft") must match what exactly?
Why is one side of the drivetrain usually set to REVERSE?
0 of 2 answered
Mark this lesson complete — “Gamepad Input and Edge Detection” is up next.