### Initialization Routine Example (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/odom_general An example C++ initialization routine demonstrating the setup of boomerang movement parameters. It shows how to set the boomerang PID constants using pid_odom_boomerang_constants_set and then configure the dlead and distance thresholds for boomerang actions using odom_boomerang_dlead_set and odom_boomerang_distance_set respectively. This routine would typically be called once at the start of the program. ```c++ void initialize() { chassis.pid_odom_boomerang_constants_set(5, 0, 50); chassis.odom_boomerang_dlead_set(0.5); chassis.odom_boomerang_distance_set(12); } ``` -------------------------------- ### Autonomous Routine Example (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/odom_general An example C++ autonomous routine demonstrating the usage of various EZ-Template odometry and path functions. It includes resetting PID targets, IMU, and drive sensors, setting the initial robot position, configuring motor brake modes, and toggling PID drive and print functionalities. The example also shows how to retrieve default and set custom path smoothing constants, define a path using pid_odom_set, and print the path using odom_path_print. ```c++ void autonomous() { chassis.pid_targets_reset(); // Resets PID targets to 0 chassis.drive_imu_reset(); // Reset gyro position to 0 chassis.drive_sensor_reset(); // Reset drive sensors to 0 chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency chassis.pid_drive_toggle(false); // Disable the drive chassis.pid_print_toggle(false); // Disable movement printing // Print default smooth constants std::vector smooth_consts = chassis.odom_path_smooth_constants_get(); printf("Weight Smooth: %.2f Weight Data: %.2f Tolerance: %.2f\n", smooth_consts[0], smooth_consts[1], smooth_consts[2]); chassis.pid_odom_set({{{0_in, 24_in}, fwd, 110}, {{24_in, 24_in}, fwd, 110}}, false); chassis.odom_path_print(); // Print the full path to terminal // Print updated smooth constants chassis.odom_path_smooth_constants_set(0.5, 0.003, 0.0001); smooth_consts = chassis.odom_path_smooth_constants_get(); printf("Weight Smooth: %.2f Weight Data: %.2f Tolerance: %.2f\n", smooth_consts[0], smooth_consts[1], smooth_consts[2]); chassis.pid_odom_set({{{0_in, 24_in}, fwd, 110}, {{24_in, 24_in}, fwd, 110}}, false); chassis.odom_path_print(); // Print the full path to terminal } ``` -------------------------------- ### Get Robot Odometry Pose - C++ Source: https://ez-robotics.github.io/EZ-Template/docs/odom_general Retrieves the current pose (x, y, theta) of the robot. This function is fundamental for tracking the robot's position on the field. The example demonstrates how to fetch the pose and print its components after setting a new target pose. ```cpp pose odom_pose_get(); ``` ```cpp void autonomous() { chassis.pid_targets_reset(); // Resets PID targets to 0 chassis.drive_imu_reset(); // Reset gyro position to 0 chassis.drive_sensor_reset(); // Reset drive sensors to 0 chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency chassis.pid_odom_set({{24_in, 24_in, 45_deg}, fwd, 110}); chassis.pid_wait(); ez::pose c_pose = chassis.odom_pose_get(); printf("X: %.2f Y: %.2f T: %.2f\n", c_pose.x, c_pose.y, c_pose.theta); } ``` -------------------------------- ### Check for SD Card Installation Source: https://ez-robotics.github.io/EZ-Template/docs/util The `IS_SD_CARD` boolean constant indicates whether an SD card is currently installed in the robot. It returns `true` if an SD card is detected and `false` otherwise. This is useful for conditional logic that depends on persistent storage availability. ```cpp void initialize() { if (!ez::util::IS_SD_CARD) printf("No SD Card Found!\n"); } ``` ```cpp const bool IS_SD_CARD = pros::usd::is_installed(); ``` -------------------------------- ### Set and Get PID Target - C++ Source: https://ez-robotics.github.io/EZ-Template/docs/pid Sets the PID target to a specified goal position for a subsystem. It also includes a getter function to retrieve the current target value. The example demonstrates setting the target based on user input. ```C++ ez::PID liftPID{1, 0.003, 4, 100, "Lift"}; pros::Motor lift_motor(1); void opcontrol() { while (true) { if (master.get_digital(DIGITAL_L1)) { liftPID.target_set(500); printf("%.2f\n", liftPID.target_get()); // This prints 500 } else if (master.get_digital(DIGITAL_L2)) { liftPID.target_set(0); printf("%.2f\n", liftPID.target_get()); // This prints 0 } lift_motor.move(liftPID.compute(lift_motor.get_position())); pros::delay(ez::util::DELAY_TIME); } } ``` ```C++ double target_set(); ``` -------------------------------- ### C++: Pure Pursuits through Points with PID Odom PP Set Source: https://ez-robotics.github.io/EZ-Template/docs/odom_movements The `pid_odom_pp_set` function executes pure pursuits through a series of given points. It accepts a vector of `united_odom` poses. The example demonstrates resetting sensors and initiating a multi-point pursuit. ```cpp void pid_odom_pp_set(std::vector p_imovements); ``` ```cpp void autonomous() { chassis.pid_targets_reset(); // Resets PID targets to 0 chassis.drive_imu_reset(); // Reset gyro position to 0 chassis.drive_sensor_reset(); // Reset drive sensors to 0 chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency chassis.pid_odom_pp_set({{{0_in, 24_in}, fwd, 110}, {{24_in, 24_in}, fwd, 110}}); chassis.pid_wait(); } ``` -------------------------------- ### Create Slew Object (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/slew Creates a slew object with initial speed and distance constants. The robot starts at `min_speed` and reaches maximum speed after traveling `distance`. Requires the EZ-Template library. ```C++ ez::slew lift_Slew(100, 60); ``` -------------------------------- ### PID Drive Chain Forward Constant Setup Source: https://ez-robotics.github.io/EZ-Template/docs/drive_movements Configures the PID overshoot constant specifically for forward driving to maintain momentum into the next motion. The input value is provided in Okapi length units. ```cpp void initialize() { chassis.pid_drive_chain_forward_constant_set(3_in); } ``` ```cpp void pid_drive_chain_forward_constant_set(okapi::QLength input); ``` -------------------------------- ### Get Secondary Sensor Status - C++ Source: https://ez-robotics.github.io/EZ-Template/docs/pid Returns whether the secondary sensor is enabled or disabled. `true` indicates the secondary sensor is in use, while `false` means it is disabled. The example shows enabling the sensor. ```C++ ez::PID liftPID; void initialize() { liftPID.velocity_sensor_secondary_toggle_set(true); // Enable the secondary sensor } ``` ```C++ double velocity_sensor_secondary_get(); ``` -------------------------------- ### Initialize Drive Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Initializes the drive system by running `opcontrol_curve_sd_initialize()` and `drive_imu_calibrate()`. ```APIDOC ## Initialize Drive ### Description Initializes the drive system by running `opcontrol_curve_sd_initialize()` and `drive_imu_calibrate()`. ### Method void ### Endpoint initialize() ### Parameters None ### Request Example ```cpp void initialize() { chassis.initialize(); } ``` ### Response None ``` -------------------------------- ### Get Secondary Sensor Velocity Exit Threshold - C++ Source: https://ez-robotics.github.io/EZ-Template/docs/pid Retrieves the threshold for the secondary sensor's velocity. The velocity timer starts increasing when the secondary sensor is within this value. This is defaulted to `0.1` and is only utilized when the secondary sensor is enabled. ```C++ ez::PID liftPID; void initialize() { liftPID.velocity_sensor_secondary_toggle_set(true); // Enable the secondary sensor printf("%.2f\n",liftPID.velocity_sensor_secondary_exit_get()); // This prints 0.1 } ``` ```C++ double velocity_sensor_secondary_exit_get(); ``` -------------------------------- ### C++ PID Drive Movement Example Source: https://context7.com/context7/ez-robotics_github_io_ez-template/llms.txt Demonstrates basic forward and backward movement using PID control. Includes resetting PID targets, IMU, sensors, odometry, setting brake mode, and executing movements with optional slew rate limiting. Requires `chassis.pid_wait()` to ensure completion. ```cpp void autonomous() { chassis.pid_targets_reset(); chassis.drive_imu_reset(); chassis.drive_sensor_reset(); chassis.odom_xyt_set(0_in, 0_in, 0_deg); chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Drive 24 inches forward at speed 110 chassis.pid_drive_set(24_in, 110); chassis.pid_wait(); // Drive 24 inches backward with slew enabled chassis.pid_drive_set(-24_in, 110, true); chassis.pid_wait(); // Drive without heading correction chassis.pid_drive_set(12_in, 110, false, false); chassis.pid_wait(); } ``` -------------------------------- ### Get Main Sensor Velocity Exit Threshold - C++ Source: https://ez-robotics.github.io/EZ-Template/docs/pid Retrieves the threshold for the main sensor's velocity. This value determines when the velocity timer starts increasing. The default value is `0.1`. This function is used in conjunction with the secondary sensor. ```C++ ez::PID liftPID; void initialize() { liftPID.velocity_sensor_secondary_toggle_set(true); // Enable the secondary sensor printf("%.2f\n",liftPID.velocity_sensor_main_exit_get()); // This prints 0.05 } ``` ```C++ double velocity_sensor_main_exit_get(); ``` -------------------------------- ### Initialize Drive - C++ Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Initializes the robot's drive system by calling `opcontrol_curve_sd_initialize()` and `drive_imu_calibrate()`. This is a crucial first step before operating the drive. ```cpp void initialize() { chassis.initialize(); } ``` ```cpp void Drive::initialize(); ``` -------------------------------- ### Get Robot Odometry Theta - C++ Source: https://ez-robotics.github.io/EZ-Template/docs/odom_general Retrieves the current Theta (orientation) of the robot in degrees. This function is crucial for precise navigation and turning maneuvers. The example shows how to use it after resetting odometry and driving to a new position. ```cpp double odom_theta_get(); ``` ```cpp void autonomous() { chassis.pid_targets_reset(); // Resets PID targets to 0 chassis.drive_imu_reset(); // Reset gyro position to 0 chassis.drive_sensor_reset(); // Reset drive sensors to 0 chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency chassis.pid_odom_set({{24_in, 24_in, 45_deg}, fwd, 110}); chassis.pid_wait(); printf("X: %.2f Y: %.2f T: %.2f\n", chassis.odom_x_get(), chassis.odom_y_get(), chassis.odom_theta_get()); } ``` -------------------------------- ### Create PID Object Source: https://ez-robotics.github.io/EZ-Template/docs/pid Instantiates a PID object with specified constants for proportional (kP), integral (kI), and derivative (kD) control. Optional parameters include the error threshold for starting integral gain and a name for the PID instance. Default values are provided for parameters beyond kP. ```cpp ez::PID liftPID{1, 0.003, 4, 100, "Lift"}; ``` ```cpp PID(double p, double i = 0, double d = 0, double start_i = 0, std::string name = ""); ``` -------------------------------- ### Toggle and Get Secondary Sensor Status - C++ Source: https://ez-robotics.github.io/EZ-Template/docs/pid Toggles the secondary sensor for velocity exit calculations and provides a getter to check its status. The getter returns 1 if enabled and 0 if disabled. The example demonstrates toggling and printing the status. ```C++ ez::PID liftPID; void initialize() { printf("%i\n",liftPID.velocity_sensor_secondary_toggle_get()); // This prints 0 liftPID.velocity_sensor_secondary_toggle_set(true); // Enable the secondary sensor printf("%i\n",liftPID.velocity_sensor_secondary_toggle_get()); // This prints 1 } ``` ```C++ double velocity_sensor_secondary_toggle_get(); ``` -------------------------------- ### Initialize Autonomous Selector Source: https://ez-robotics.github.io/EZ-Template/docs/auton_selector Initializes the autonomous selector. If an SD card is present, it will load the autonomous configuration from the SD card. This is a prerequisite for using other autonomous selector functions. ```cpp void initialize() { ez::as::initialize(); } ``` ```cpp void initialize(); ``` -------------------------------- ### Get Minimum Swing Power (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/swing_movements This function returns the minimum power value applied to motors during swing motions when integral control (kI) and starting integral (startI) are enabled. It's used to ensure consistent movement even at low speeds. ```c++ int pid_swing_min_get(); ``` ```c++ void autonomous() { chassis.pid_targets_reset(); // Resets PID targets to 0 chassis.drive_imu_reset(); // Reset gyro position to 0 chassis.drive_sensor_reset(); // Reset drive sensors to 0 chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency chassis.pid_swing_min_set(30); printf("Swing Min: %i", chassis.pid_swing_min_get()); } ``` -------------------------------- ### Initialize Autonomous Selector - C++ Source: https://context7.com/context7/ez-robotics_github_io_ez-template/llms.txt Initializes the autonomous selector system, enabling LCD support for selecting autonomous routines. It can optionally be configured with external buttons for navigation and requires registering button callbacks for page up and page down functionality. ```cpp void initialize() { ez::as::initialize(); // Optional: Use external buttons for selection pros::adi::DigitalIn increase('A'); pros::adi::DigitalIn decrease('B'); ez::as::limit_switch_lcd_initialize(&increase, &decrease); // Register LCD button callbacks pros::lcd::register_btn0_cb(ez::as::page_down); pros::lcd::register_btn2_cb(ez::as::page_up); } ``` -------------------------------- ### Initialize Slew (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/slew Sets up the slew functionality, including enabling/disabling it, setting the maximum target speed, the target distance, and the current sensor value. Requires motor and PID objects. ```C++ PID lift_slew; pros::Motor lift(1); void initialize() { lift_slew.constants_set(100, 50); lift_slew.initialize(true, 127, 500, lift.get_position()); } ``` -------------------------------- ### Get Slew Output Speed (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/slew Returns the calculated maximum speed for the current iteration. This function should be called after `iterate()` to get the actual speed value to apply to the motor. ```C++ PID lift_slew; pros::Motor lift(1); void initialize() { lift_slew.constants_set(100, 50); lift_slew.initialize(true, 127, 500, lift.get_position()); } void autonomous() { while (lift.get_position() <= 500) { lift_slew.iterate(lift.get_position()); lift = lift_slew.output(); pros::delay(10); } lift = 0; } ``` -------------------------------- ### Create Tracking Wheel with ADI Encoder and 3-wire Expander Source: https://ez-robotics.github.io/EZ-Template/docs/tracking_wheels Initializes a tracking wheel using an ADI Encoder connected via a 3-wire expander. Specify the smart port for the expander and the ports for the encoder. Requires wheel diameter, distance to the robot's center, and optionally a gear ratio. ```cpp tracking_wheel(int smart_port, std::vector ports, double wheel_diameter, double distance_to_center = 0.0, double ratio = 1.0); ``` ```cpp ez::tracking_wheel right_tracker(1, {'C', 'D'}, 2.75, 4.0); ``` -------------------------------- ### PID Controller Constructor for Custom Mechanisms (C++) Source: https://context7.com/context7/ez-robotics_github_io_ez-template/llms.txt Initializes a PID controller for custom mechanisms such as lifts or arms. It takes proportional (kP), integral (kI), and derivative (kD) gains, along with a starting integral threshold and a name for the PID controller. This allows for precise control of mechanism positions. ```cpp // Create lift PID controller // kP = 1, kI = 0.003, kD = 4, start_i at error < 100 ez::PID liftPID{1, 0.003, 4, 100, "Lift"}; pros::Motor lift_motor(1); void opcontrol() { while (true) { if (master.get_digital(DIGITAL_L1)) { liftPID.target_set(500); } else if (master.get_digital(DIGITAL_L2)) { liftPID.target_set(0); } lift_motor.move(liftPID.compute(lift_motor.get_position())); pros::delay(ez::util::DELAY_TIME); } } ``` -------------------------------- ### Initialize Prototype (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/slew Prototype for the initialize function, which sets up the slew controller with parameters for operation. It takes boolean for enabled state, maximum speed, target distance, and current sensor value. ```C++ void initialize(bool enabled, double maximum_speed, double target, double current); ``` -------------------------------- ### Set PID Tuner Start I Increment (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/pid_tuner Sets the value by which the 'Start I' parameter of the PID Tuner will be incremented. This function is useful for fine-tuning the integral term of a PID controller during operation. It takes a double value representing the increment amount. ```cpp void opcontrol() { // This is preference to what you like to drive on chassis.drive_brake_set(MOTOR_BRAKE_COAST); chassis.pid_tuner_increment_start_i_set(5.0); while (true) { // PID Tuner // After you find values that you're happy with, you'll have to set them in auton.cpp if (!pros::competition::is_connected()) { // Enable / Disable PID Tuner if (master.get_digital_new_press(DIGITAL_X)) chassis.pid_tuner_toggle(); // Trigger the selected autonomous routine if (master.get_digital_new_press(DIGITAL_B)) autonomous(); chassis.pid_tuner_iterate(); // Allow PID Tuner to iterate } chassis.opcontrol_tank(); // Tank control pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME } } ``` ```cpp void pid_tuner_increment_start_i_set(double start_i); ``` -------------------------------- ### Drive Constructor with Integrated Encoders (Example 2) Source: https://ez-robotics.github.io/EZ-Template/docs/constructor Constructs a drive system using integrated motor encoders with an external gear ratio. Requires left and right motor ports, IMU port, wheel diameter, cartridge RPM, and the external gear ratio. ```cpp ez::Drive chassis( // These are your drive motors, the first motor is used for sensing! {1, 2, 3}, // Left Chassis Ports (negative port will reverse it!) {-4, -5, -6}, // Right Chassis Ports (negative port will reverse it!) 7, // IMU Port 4.125, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!) 600, // Cartridge RPM // External Gear Ratio (MUST BE DECIMAL) This is WHEEL GEAR / MOTOR GEAR // eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 84/36 which is 2.333 // eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 36/60 which is 0.6 2.333); ``` -------------------------------- ### Initialize Joystick Curves from SD Card (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/user_control Initializes the left and right joystick curves using settings stored on an SD card. It is recommended to run this function during the initialization phase of the program. ```cpp void initialize() { chassis.opcontrol_curve_sd_initialize(); } ``` ```cpp void opcontrol_curve_sd_initialize(); ``` -------------------------------- ### Set Robot Odometry Position - C++ Source: https://context7.com/context7/ez-robotics_github_io_ez-template/llms.txt Sets the robot's current position (X, Y coordinates) and heading (theta) for odometry. This function is essential for initializing the robot's starting pose or resetting it to a known location, especially before starting autonomous routines. It accepts distances in inches and angles in degrees. ```cpp void autonomous() { chassis.pid_targets_reset(); chassis.drive_imu_reset(); chassis.drive_sensor_reset(); // Start at origin facing 0 degrees chassis.odom_xyt_set(0_in, 0_in, 0_deg); chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Or start at specific position chassis.odom_xyt_set(24_in, 24_in, 90_deg); chassis.pid_odom_set({{48_in, 48_in}, fwd, 110}); chassis.pid_wait(); } ``` -------------------------------- ### Print EZ-Template Branding Source: https://ez-robotics.github.io/EZ-Template/docs/util This function, `print_ez_template`, displays the EZ-Template branding information on the terminal. It's a simple utility for project identification. ```cpp void initialize() { print_ez_template(); } ``` ```cpp void print_ez_template(); ``` -------------------------------- ### Get Left Motor Velocity Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Retrieves the current velocity of the left motor. ```APIDOC ## Get Left Motor Velocity ### Description The velocity of the left motor. ### Method int ### Endpoint drive_velocity_left() ### Parameters None ### Request Example ```cpp void opcontrol() { while (true) { chassis.opcontrol_tank(); printf("Left Velocity: %i \n", chassis.drive_velocity_left()); pros::delay(ez::util::DELAY_TIME); } } ``` ### Response #### Success Response (200) - **velocity** (int) - The velocity of the left motor. ``` -------------------------------- ### Get Right Motor Velocity Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Retrieves the current velocity of the right motor. ```APIDOC ## Get Right Motor Velocity ### Description The velocity of the right motor. ### Method int ### Endpoint drive_velocity_right() ### Parameters None ### Request Example ```cpp void opcontrol() { while (true) { chassis.opcontrol_tank(); printf("Right Velocity: %i \n", chassis.drive_velocity_right()); pros::delay(ez::util::DELAY_TIME); } } ``` ### Response #### Success Response (200) - **velocity** (int) - The velocity of the right motor. ``` -------------------------------- ### Print Formatted Text to LLEMU Screen Source: https://ez-robotics.github.io/EZ-Template/docs/util The `screen_print` function displays text on the LLEMU screen, automatically handling line breaks for text exceeding screen width and supporting newline characters (`\n`). It takes the text string and the starting line number as input. This is useful for displaying status messages or sensor readings. ```cpp void initialize() { ez::screen_print("hello, this is line 0\nthis is line 1"); } ``` ```cpp void screen_print(std::string text, int line) void initialize() { std::string 32char = 01234567890123456789012345678901; ez::print_to_screen(32char + "hello", 2); } ``` -------------------------------- ### Get Left Motor Current (mA) Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Retrieves the current (in milliamps) being drawn by the left motor. ```APIDOC ## Get Left Motor Current (mA) ### Description The current (in milliamps) of the left motor. ### Method double ### Endpoint drive_mA_left() ### Parameters None ### Request Example ```cpp void opcontrol() { while (true) { chassis.opcontrol_tank(); printf("Left mA: %i \n", chassis.drive_mA_left()); pros::delay(ez::util::DELAY_TIME); } } ``` ### Response #### Success Response (200) - **current** (double) - The current draw of the left motor in milliamps. ``` -------------------------------- ### Create Smoothed Path and Follow with Pure Pursuit (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/odom_movements Generates a new path with interpolated points, smooths its corners, and then follows it using the pure pursuit algorithm. The `slew_on` parameter enables gradual speed increase. ```cpp void pid_odom_smooth_pp_set(std::vector{odom} imovements, bool slew_on); ``` ```cpp void autonomous() { chassis.pid_targets_reset(); chassis.drive_imu_reset(); chassis.drive_sensor_reset(); chassis.odom_xyt_set(0_in, 0_in, 0_deg); chassis.drive_brake_set(MOTOR_BRAKE_HOLD); chassis.pid_odom_smooth_pp_set({{{0, 24}, fwd, 110}, {{24, 24}, fwd, 110}}, true); chassis.pid_wait(); } ``` -------------------------------- ### Get Right Motor Current (mA) Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Retrieves the current (in milliamps) being drawn by the right motor. ```APIDOC ## Get Right Motor Current (mA) ### Description The current (in milliamps) of the right motor. ### Method double ### Endpoint drive_mA_right() ### Parameters None ### Request Example ```cpp void opcontrol() { while (true) { chassis.opcontrol_tank(); printf("Right mA: %i \n", chassis.drive_mA_right()); pros::delay(ez::util::DELAY_TIME); } } ``` ### Response #### Success Response (200) - **current** (double) - The current draw of the right motor in milliamps. ``` -------------------------------- ### Initialize Master Controller Source: https://ez-robotics.github.io/EZ-Template/docs/util Declares the global master controller object, which is used to interface with the robot's primary controller for input and feedback. ```cpp extern pros::Controller master(); ``` -------------------------------- ### Get Left Sensor Position Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Retrieves the position of the left sensor in inches. This typically corresponds to the position of a tracking wheel or motor. ```APIDOC ## Get Left Sensor Position ### Description The position of the left sensor in inches. If you have two parallel tracking wheels, this will return tracking wheel position. Otherwise this returns motor position. ### Method int ### Endpoint drive_sensor_left() ### Parameters None ### Request Example ```cpp void opcontrol() { while (true) { chassis.opcontrol_tank(); printf("Left Sensor: %i \n", chassis.drive_sensor_left()); pros::delay(ez::util::DELAY_TIME); } } ``` ### Response #### Success Response (200) - **position** (int) - The position of the left sensor in inches. ``` -------------------------------- ### Configure Drive with ADI Encoders via Expander Source: https://ez-robotics.github.io/EZ-Template/docs/constructor Initializes the EZ-Template Drive class using ADI Encoders connected through a 3-wire port expander. This method requires specifying motor ports, IMU port, wheel diameter, encoder ticks per revolution, gear ratio, and the expander's smart port. It supports two parallel tracking wheels equidistant from the robot's center. ```cpp ez::Drive chassis( // These are your drive motors, the first motor is used for sensing! {1, 2, 3}, // Left Chassis Ports (negative port will reverse it!) {-4, -5, -6}, // Right Chassis Ports (negative port will reverse it!) 7, // IMU Port 4.125, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!) 360, // Ticks Per Rotation of your encoder. This is 360 for the red encoders // External Gear Ratio (MUST BE DECIMAL) This is WHEEL GEAR / SENSOR GEAR // eg. if your drive is 84:36 where the 36t is sensored, your RATIO would be 84/36 which is 2.333 // eg. if your drive is 36:60 where the 60t is sensored, your RATIO would be 36/60 which is 0.6 1.0, {1, 2}, // Left Tracking Wheel Ports (negative port will reverse it!) {-3, -4}, // Right Tracking Wheel Ports (negative port will reverse it!) 9); // 3 Wire Port Expander Smart Port ``` ```cpp Drive(std::vector left_motor_ports, std::vector right_motor_ports, int imu_port, double wheel_diameter, double ticks, double ratio, std::vector left_tracker_ports, std::vector right_tracker_ports, int expander_smart_port); ``` -------------------------------- ### Arcade Drive Control Setup - C++ Source: https://context7.com/context7/ez-robotics_github_io_ez-template/llms.txt Sets up arcade drive control for the robot, offering two modes: split arcade and single-stick arcade. In split arcade, the left stick controls forward/backward movement and the right stick controls turning. In single-stick arcade, the left stick handles both functions. ```cpp void opcontrol() { while (true) { // Left stick Y = forward/back, right stick X = turning chassis.opcontrol_arcade_standard(ez::SPLIT); // Or single stick arcade (left stick only) // chassis.opcontrol_arcade_standard(ez::SINGLE); pros::delay(ez::util::DELAY_TIME); } } ``` -------------------------------- ### Get Right Sensor Position Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Retrieves the position of the right sensor in inches. This typically corresponds to the position of a tracking wheel or motor. ```APIDOC ## Get Right Sensor Position ### Description The position of the right sensor in inches. If you have two parallel tracking wheels, this will return tracking wheel position. Otherwise this returns motor position. ### Method int ### Endpoint drive_sensor_right() ### Parameters None ### Request Example ```cpp void opcontrol() { while (true) { chassis.opcontrol_tank(); printf("Right Sensor: %i \n", chassis.drive_sensor_right()); pros::delay(ez::util::DELAY_TIME); } } ``` ### Response #### Success Response (200) - **position** (int) - The position of the right sensor in inches. ``` -------------------------------- ### Get Piston State Source: https://ez-robotics.github.io/EZ-Template/docs/piston Retrieves the current state of the piston (whether it is extended or retracted). This is useful for conditional logic within robot routines. ```C++ ez::Piston left_wing('A'); void autonomous() { left_wing.set(!left_wing.get()); } ``` ```C++ bool get(); ``` -------------------------------- ### Configure Drive with Rotation Sensors Source: https://ez-robotics.github.io/EZ-Template/docs/constructor Initializes the EZ-Template Drive class using Rotation Sensors. This method requires specifying motor ports, IMU port, wheel diameter, gear ratio, and the ports for the left and right rotation sensors. It supports two parallel tracking wheels equidistant from the robot's center. ```cpp ez::Drive chassis( // These are your drive motors, the first motor is used for sensing! {1, 2, 3}, // Left Chassis Ports (negative port will reverse it!) {-4, -5, -6}, // Right Chassis Ports (negative port will reverse it!) 7, // IMU Port 4.125, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!) // External Gear Ratio (MUST BE DECIMAL) This is WHEEL GEAR / SENSOR GEAR // eg. if your drive is 84:36 where the 36t is sensored, your RATIO would be 84/36 which is 2.333 // eg. if your drive is 36:60 where the 60t is sensored, your RATIO would be 36/60 which is 0.6 11.0, 8, // Left Rotation Port (negative port will reverse it!) -9); // Right Rotation Port (negative port will reverse it!) ``` ```cpp Drive(std::vector left_motor_ports, std::vector right_motor_ports, int imu_port, double wheel_diameter, double ratio, int left_rotation_port, int right_rotation_port); ``` -------------------------------- ### Speed Max Get Prototype (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/slew Prototype for the speed_max_get function, which returns the current maximum speed limit set for the slew. This is a read-only function. ```C++ double speed_max_get(); ``` -------------------------------- ### Tracking Wheel Constructor with ADI Encoder (C++) Source: https://context7.com/context7/ez-robotics_github_io_ez-template/llms.txt Initializes a tracking wheel using VEX V5 ADI Encoders. This constructor can be configured with ports directly connected to the brain or via a smart port expander. It requires the encoder ports, wheel diameter, and distance from the robot's center. This is an alternative method for setting up odometry tracking wheels. ```cpp // ADI encoder on ports A and B (reversed) ez::tracking_wheel right_tracker({-'A', -'B'}, 2.75, 4.0); // ADI encoder on 3-wire expander (smart port 1, ADI ports C and D) ez::tracking_wheel left_tracker(1, {'C', 'D'}, 2.75, 4.0); void initialize() { ez::ez_template_print(); pros::delay(500); chassis.odom_tracker_right_set(&right_tracker); chassis.odom_tracker_left_set(&left_tracker); } ``` -------------------------------- ### Injected Pure Pursuit Path Following (C++) Source: https://context7.com/context7/ez-robotics_github_io_ez-template/llms.txt Implements Pure Pursuit path following with automatically injected points to create smoother curves between waypoints. This function requires the chassis and its odometry to be initialized, and it takes a vector of waypoints with specified positions, forward direction, and speed. ```cpp void autonomous() { chassis.pid_targets_reset(); chassis.drive_imu_reset(); chassis.drive_sensor_reset(); chassis.odom_xyt_set(0_in, 0_in, 0_deg); chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Injected points create smoother curve between waypoints chassis.pid_odom_injected_pp_set({ {{0_in, 0_in}, fwd, 110}, {{24_in, 24_in}, fwd, 110}, {{48_in, 0_in}, fwd, 110} }); chassis.pid_wait(); } ``` -------------------------------- ### Get Maximum Slew Speed (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/slew Retrieves the currently set maximum speed for the slew controller. This can be used to check the current speed limit. ```C++ PID lift_slew; pros::Motor lift(1); void initialize() { lift_slew.constants_set(100, 50); lift_slew.initialize(true, 127, 500, lift.get_position()); } void autonomous() { while (lift.get_position() <= 500) { if (lift.get_position() < 100) lift_slew.speed_max_set(50); else lift_slew.speed_max_set(127); printf("%.2f", lift_slew.speed_max_get()); lift_slew.iterate(lift.get_position()); lift = lift_slew.output(); pros::delay(10); } lift = 0; } ``` -------------------------------- ### Get IMU Accelerometer Values (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Returns the combined X and Y accelerometer values from the IMU. This can be used for detecting linear motion or changes in acceleration. ```cpp void opcontrol() { while (true) { chassis.opcontrol_tank(); printf("Accel x + y: %f \n", chassis.drive_imu_accel_get()); pros::delay(ez::util::DELAY_TIME); } } ``` ```cpp double drive_imu_accel_get(); ``` -------------------------------- ### Create Piston Object (3-Wire Expander) Source: https://ez-robotics.github.io/EZ-Template/docs/piston Initializes a new Piston object connected via a 3-wire expander. It requires the ADI port, expander smart port, and an optional default state. ```C++ ez::Piston left_wing('A', 1); ``` ```C++ Piston(int input_port, int expander_smart_port, bool default_state = false); ``` -------------------------------- ### Create Tracking Wheel with ADI Encoder Source: https://ez-robotics.github.io/EZ-Template/docs/tracking_wheels Initializes a tracking wheel using an ADI Encoder connected to two ports. Allows for reversing the encoder direction by negating the port values. Requires wheel diameter, distance to the robot's center, and optionally a gear ratio. ```cpp tracking_wheel(std::vector ports, double wheel_diameter, double distance_to_center = 0.0, double ratio = 1.0); ``` ```cpp ez::tracking_wheel right_tracker({-'A', -'B'}, 2.75, 4.0); ``` -------------------------------- ### Get Wheel Diameter Source: https://ez-robotics.github.io/EZ-Template/docs/tracking_wheels Retrieves the diameter of the tracking wheel. This value is essential for converting rotational movement into linear distance. The function does not take any parameters. ```cpp double wheel_diameter_get(); ``` ```cpp ez::tracking_wheel right_tracker(1, 2.75, 4.0); void opcontrol() { while (true) { chassis.opcontrol_tank(); if (ez::as::page_blank_is_on(0)) { ez::screen_print(to_string(right_tracker.wheel_diameter_get()), 1); } pros::delay(ez::util::DELAY_TIME); } } ``` -------------------------------- ### Get IMU Scaler Value (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Retrieves the current IMU sensor scaling factor. This factor is multiplied by the IMU readings to adjust the definition of a 'degree'. ```cpp void turn_example() { chassis.drive_imu_scaler_set(2); printf("%.2f\n", chassis.drive_imu_scaler_get()); // Prints 2 // This will now turn to 45 real degrees chassis.pid_turn_set(90_deg, TURN_SPEED); chassis.pid_wait(); // This will turn to 22.5 real degrees chassis.pid_turn_set(45_deg, TURN_SPEED); chassis.pid_wait(); chassis.pid_turn_set(0_deg, TURN_SPEED); chassis.pid_wait(); } ``` ```cpp double drive_imu_scaler_get(); ``` -------------------------------- ### C++: Create and Smooth Path with PID Odom Set Source: https://ez-robotics.github.io/EZ-Template/docs/odom_movements The `pid_odom_set` function creates and smooths a path from given points. It supports gradual speed increase via `slew_on` if slew constants are set. It takes a vector of poses and a boolean for slew control. ```cpp void pid_odom_set(std::vector p_imovements, bool slew_on); ``` ```cpp void autonomous() { chassis.pid_targets_reset(); // Resets PID targets to 0 chassis.drive_imu_reset(); // Reset gyro position to 0 chassis.drive_sensor_reset(); // Reset drive sensors to 0 chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency chassis.pid_odom_set({{{0_in, 24_in}, fwd, 110}, {{24_in, 24_in}, fwd, 110}}, true); chassis.pid_wait(); } ``` -------------------------------- ### Get Right Drive Velocity - C++ Source: https://ez-robotics.github.io/EZ-Template/docs/set_and_get_drive Returns the current velocity of the right drive motor. This can be used for monitoring drive performance or implementing speed-based logic. ```cpp void opcontrol() { while (true) { chassis.opcontrol_tank(); printf("Right Velocity: %i \n", chassis.drive_velocity_right()); pros::delay(ez::util::DELAY_TIME); } } ``` ```cpp int drive_velocity_right(); ``` -------------------------------- ### Set PID Constants Source: https://ez-robotics.github.io/EZ-Template/docs/pid Updates the PID control constants (kP, kI, kD) and the integral start threshold. This allows dynamic adjustment of the PID controller's behavior without re-initializing the object. If only a subset of constants is provided, the others retain their previous values. ```cpp ez::PID liftPID; void initialize() { liftPID.constants_set(1, 0, 4); } ``` ```cpp void constants_set(double p, double i = 0, double d = 0, double p_start_i = 0); ``` -------------------------------- ### Drive Constructor with ADI Encoders Source: https://ez-robotics.github.io/EZ-Template/docs/constructor Constructs a drive system using ADI encoders for tracking. Requires drive motor ports, IMU port, wheel diameter, encoder ticks per revolution, gear ratio, and tracking wheel ports. ```cpp ez::Drive chassis( // These are your drive motors, the first motor is used for sensing! {1, 2, 3}, // Left Chassis Ports (negative port will reverse it!) {-4, -5, -6}, // Right Chassis Ports (negative port will reverse it!) 7, // IMU Port 4.125, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!) 360, // Ticks Per Rotation of your encoder. This is 360 for the red encoders // External Gear Ratio (MUST BE DECIMAL) This is WHEEL GEAR / SENSOR GEAR // eg. if your drive is 84:36 where the 36t is sensored, your RATIO would be 84/36 which is 2.333 // eg. if your drive is 36:60 where the 60t is sensored, your RATIO would be 36/60 which is 0.6 1.0, {1, 2}, // Left Tracking Wheel Ports (negative port will reverse it!) {-3, -4}); // Right Tracking Wheel Ports (negative port will reverse it!) ``` -------------------------------- ### Get Joystick Curve Toggle State (C++) Source: https://ez-robotics.github.io/EZ-Template/docs/user_control Retrieves the current state of the joystick curve adjustment toggle. It returns `true` if the feature is enabled and `false` if it is disabled. ```cpp void initialize() { printf("Enabled? %i\n", chassis.opcontrol_curve_buttons_toggle_get()); // Returns false chassis.opcontrol_curve_buttons_toggle(true); printf("Enabled? %i\n", chassis.opcontrol_curve_buttons_toggle_get()); // Returns true } ``` ```cpp bool opcontrol_curve_buttons_toggle_get(); ```