FTCLayer Documentation
website·Indexed 30 days ago
https://ftclayer-docs.pages.dev/An open source project providing abstractions for FTC robots. Includes guides on installation via command line or OnBotJava, motor control (power, velocity, and run to position), encoder ticks, IMU orientation, and mecanum drivetrain implementation.
What's inside FTCLayer
- FTC Layer is an open-source project that provides abstractions over the base FTC SDK. Its primary goal is to make programming for FTC robots easier, simpler, and less time-consuming by reducing the complexity of the base SDK.
Overview of Mecanum Drivetrains
Mecanum drivetrains use four independently powered mecanum wheels. The rollers on these wheels are angled at 45 degrees relative to the axis of rotation, allowing the robot to strafe (move sideways) without turning. Because of this angle, mecanum robots cannot strafe as fast as they can drive forward.Understand motor ticks for position and velocity control
Motor encoders measure position and speed using 'ticks' rather than standard units like inches or centimeters. A tick represents a specific division of a single motor rotation. The number of ticks per rotation varies by motor manufacturer and must be verified via the manufacturer's documentation to accurately calculate distance or speed.
Commands that specifically utilize ticks include:
- Velocity control
- Go To Position
Control motors using direct Power
Direct power control adjusts the amount of electricity sent to the motor. This is the most basic form of motor control and does not rely on encoders for precision.Control motors using Run to Position
Run to Position uses motor encoders to move a motor to a specific location accurately and then hold that position by resisting movement. This behavior is similar to how a servo operates. It is the recommended method for controlling specific positions or creating movement boundaries.Control motors using Velocity
Velocity control uses encoders to maintain a consistent and accurate speed (e.g., rotations per second) rather than simply adjusting the electrical power. This results in more predictable movement than direct power control.Initialize and use the RevImu for robot orientation
The Internal Measurement Unit (IMU) allows a robot to measure speed, acceleration, and orientation. To track rotational data, you must instantiate a
RevImuobject.Hardware Requirement: Rev Hub IMUs are always located on I2C port 0; ensure the IMU is configured on port 0 in the I2C menu of the Control Hub.
Because the returned values depend on the physical orientation of the Control Hub on the robot, it is recommended to test all three orientation functions (heading, pitch, and roll) before finalizing your program logic.
import org.ftc17191.ftclayer.hardware.imu.RevImu; // Initialize the IMU RevImu imu = new RevImu(hardwareMap, "imu"); // Get orientation in degrees double heading = imu.getHeading(); double pitch = imu.getPitch(); double roll = imu.getRoll(); // Get orientation in radians double headingRad = imu.getHeadingRadians(); double pitchRad = imu.getPitchRadians(); double rollRad = imu.getRollRadians();Clone FTCLayer-quickstart using Git CLI
To set up the FTCLayer-quickstart project using the command line, ensure Git is installed and clone the repository from GitHub.git clone https://github.com/ftc17191/FTCLayer-quickstart.gitInitialize a MotorEx variable
To use a motor in ftclayer, import theMotorExclass and instantiate it by passing thehardwareMapand the motor's configuration ID.import com.ftc17191.ftclayer.hardware.motors.motorex.MotorEx; // Replace "motorid" with the ID specified in your configuration MotorEx motor = new MotorEx(hardwareMap, "motorid");Download FTCLayer-quickstart source code as a ZIP archive
Users without Git installed can download the FTCLayer-quickstart source code directly as a .zip archive from the master branch.Clone the FTCLayer Road Runner quickstart repository via GitHub CLI
If you have the GitHub CLI (gh) installed, you can clone the FTCLayer Road Runner quickstart repository using therepo clonecommand.gh repo clone ftc17191/FTCLayer-road-runner-quickstartInitialize and control a Mecanum drivetrain with FTC Layer
To use a mecanum drivetrain in FTC Layer, import theMecanumclass and instantiate it using the hardware map and the names of the four drive motors. Use thepowerDrivemethod within your robot's main loop to control forward movement, strafing, and turning via gamepad inputs.import org.ftc17191.ftclayer.drivetrain.mecanum.Mecanum; // Initialize with hardwareMap and motor IDs: front_right, front_left, back_right, back_left Mecanum mecanum = new Mecanum(hardwareMap, "front_right", "front_left", "back_right", "back_left"); // In the loop: // powerDrive(forward, strafe, turn) mecanum.powerDrive(gamepad1.left_stick_y, gamepad1.left_stick_x, gamepad1.right_stick_x);