Search
K

Example Code and Configuration

Configuration

Before getting started with programming we needed to create a configuration file. Below is an overview of how the robot is configured for the teleop code to function as expected:
Port Type
Port Number
Device Type
Name
Motor
0
REV Robotics Ultraplanetary HD Hex Motor
frontLeft
Motor
1
REV Robotics Ultraplanetary HD Hex Motor
frontRight
Motor
2
REV Robotics Ultraplanetary HD Hex Motor
backLeft
Motor
3
REV Robotics Ultraplanetary HD Hex Motor
backRight

Configuration file download

To put this configuration file on your robot, drag this file into the "FIRST" folder of your Control Hub's file system.
MecanumTest.xml
669B
Text
For more in-depth information on the configuration process check out Hello Robot - Configuration!

Gamepad Layout:

Gamepad Input
Function
Right Joystick - Left/Right
Strafe Left/Right
Left Joystick - Forward/Backward
Forward/Backward
Left Joystick - Left/Right
Turn Counter-Clockwise/Clockwise
More information on programming gamepads for use with your robot can be found at Hello Robot - Using Gamepads.

Programming Teleop - Blocks

This section makes the assumption that you have learned some of the FTC programming basics by going through the Hello Robot guide. If you have not gone through this guide please walk through it before proceeding.
In Hello Robot- Basics of Programming Drivetrains we covered how to program arcade drive with one joystick. For this example, we will be programming arcade drive using two joysticks to allow for strafing on the right stick. Remember this is just one way mecanum can be programmed!
Full code:
mecanumdemo.blk
9KB
Binary

Initialization:

For this program, when it is first initialized the lefthand motors will be set to run in reverse.

Moving Forward and Back:

For a mecanum drivetrain all 4 motors will be given a command to follow when the left joystick is moved forward/back.

Strafing:

For this example, strafing is controlled by the right stick's X-axis allowing the robot to slide left and right as the diagnol wheels move in opposite directions.

Turning:

For this demo, turning is controlled by moving the left stick back and forth along it's X-axis.