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.

Tokens
2.2K
Snippets
14
Records
24
Agent score
75%

What's inside FTCLayer

  1. Overview of 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.
  2. 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.
  3. 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
  4. 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.
  5. 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.
  6. 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 RevImu object.

    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();
  7. Initialize a MotorEx variable

    To use a motor in ftclayer, import the MotorEx class and instantiate it by passing the hardwareMap and 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");
  8. Initialize and control a Mecanum drivetrain with FTC Layer

    To use a mecanum drivetrain in FTC Layer, import the Mecanum class and instantiate it using the hardware map and the names of the four drive motors. Use the powerDrive method 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);