FTC Programming

Hardware Mapping

Connecting motors, servos, and other devices, in the code.

What is hardware mapping?

Hardware mapping is what gets your hardware to connect with your code. Without this, your robot won't move at all. To do this, you will need your phones and your code.

Creating a configuration

A configuration basically names your hardware. Hardware being your motors, servos, sensors, etc. First, make sure both of your phones are connected to each other. Then on either phone, press in the upper right hand corner and press "Configure Robot". Press "New". Select your expansion hub(For example: Expansion Hub 6) and press "Done". If not found, click "Scan", and search for the hub.

Motors

Let's add our motors. Click on "Motors", and you will see a motors 0-3. Each expansion/control hub has four motor ports, labeled 0, 1, 2, and 3. In port 0, press "Nothing", select the motor type(Ours is the REV Robotics 40:1 HD Hex). Then type in "left_drive". In port 1, select the same motor and write "right_drive". In port 2, select the "REV Robotics Core Hex" and write "arm_motor". We will only use three out of the four motors. Press "Done", and we will go on.

Servos

Adding servos is the exact same. Click on "Servos", and you will see six servo inputs. We will only use one, so for port 0, select "Servo" and write "claw_servo".

Connecting the code to the hardware

Finally, keep pressing "Done" and click save. Name your configuration "robot" and back out of configuration settings. Then, open OnBot and go to your TeleOp file. Then, add the code below.

public void runOpMode() {
    leftDrive  = hardwareMap.get(DcMotor.class, "left_drive");
    rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
    armMotor = hardwareMap.get(DcMotor.class, "arm_motor");
    clawServo = hardwareMap.get(Servo.class, "claw_servo");

What exactly does that do?

In our first new line, we said that our leftDrive motor was equal to the hardwareMap getting a motor named "left_drive". This sounds like a lot, so let's simplify it: leftDrive is the same as "left_drive". What this does is tell the phone that the leftDrive we write about is the same as the "left_drive" we configured. The same goes for the other hardware. The only difference in the clawServo is that the phone is looking for a servo named "claw_servo" rather than a motor.

That's it!

We finished connecting all our our code with our hardware. If you want to use different hardware, just add more configurations and hardwareMaps. In the next lesson, we will be adding power to our motors.

chevron_up