JAR Template

website·Indexed 30 days ago

https://jacksonarearobotics.github.io/JAR-Template/

A C++ library for VexCode Pro V5 providing a framework for robotics development. It includes a drive class for chassis control with PID and odometry, a general-use PID class, and tools for writing autonomous routines.

Tokens
3.8K
Snippets
27
Records
34
Agent score
72%

What's inside JAR Template

  1. Overview of JAR Template for VEX Robotics

    JAR Template (Jackson Area Robotics Template) is a library designed for use with Vexcode Pro V5 and the VEX VS Code Extension. It provides a set of powerful tools for robot control and navigation, including:

    • Generic PID and Odometry classes
    • Holonomic drive support
    • Algorithms for driving to a specific point or pose
    • A basic Autonomous Selector
  2. Program user control in JAR Template

    Write driver control code within the void usercontrol() function located in \src\main.cpp. The JAR Template provides built-in support for tank, arcade, and holonomic drive for the chassis; however, any additional motors, mechanisms, or sensors must be programmed manually. Verify the setup by running the project and testing the drive and example autonomous routines.
  3. Create and register a new autonomous routine

    To add a new autonomous routine to the JAR-Template, you must declare the function, define its behavior, and map it to a selection case in the main control loop.

    1. Declare the function: Add the function prototype to \include\autons.h (e.g., void my_first_auton();).
    2. Define the behavior: Implement the logic in \src\autons.cpp using the function name declared in step 1.
    3. Set the display name: In \src\main.cpp, locate the void pre_auton() function. Find a case block (e.g., case 0:) and update the Brain.Screen.printAt text to the name you want displayed on the brain screen.
    4. Link the function to the case: In \src\main.cpp, locate the void autonomous() function. In the corresponding case block, call your auton function.
    5. Execution: If using case 0, the auton is the default. For other cases, tap the brain screen during the pre-auton phase to select the desired routine.
    // 1. In \include\autons.h
    void my_first_auton();
    
    // 2. In \src\autons.cpp
    void my_first_auton(){
        chassis.drive_distance(12);
        chassis.turn_to_angle(90);
        chassis.drive_distance(12);
        chassis.drive_distance(-12);
        chassis.turn_to_angle(0);
        chassis.drive_distance(-12);
    }
    
    // 3. In \src\main.cpp -> void pre_auton()
    case 0:
        Brain.Screen.printAt(5, 140, "My First Auton");
        break;
    
    // 4. In \src\main.cpp -> void autonomous()
    case 0:
        my_first_auton();
        break;
  4. Select a Drive Setup style for odometry

    Depending on the hardware used for tracking, select the appropriate drive_setup enum value. All setups use the same constructor prototype but interpret the parameters differently:
    Setup EnumDescription
    ZERO_TRACKER_NO_ODOMNo tracking wheels. No edits needed after gyro_scale.
    ZERO_TRACKER_ODOMUses right side motor encoders for position. ForwardTracker_center_distance is the distance from robot center to right wheels.
    TANK_ONE_FORWARD_ENCODERSingle optical encoder for forward/backward movement.
    TANK_ONE_FORWARD_ROTATIONSingle V5 rotation sensor for forward/backward movement.
    TANK_ONE_SIDEWAYS_ENCODERRight motor encoders for forward/backward; optical encoder for sideways.
    TANK_ONE_SIDEWAYS_ROTATIONRight motor encoders for forward/backward; V5 rotation sensor for sideways.
    TANK_TWO_ENCODERTwo perpendicular optical encoders (Forward and Sideways).
    TANK_TWO_ROTATIONTwo perpendicular V5 rotation sensors. Ports must be in "PORT1" format.
    HOLONOMIC_TWO_ENCODERHolonomic drive with two optical encoders.
  5. Initialize the Drive constructor for JAR Template

    The Drive constructor is used to build drivetrains with varying levels of tracking and odometry support. Every drive style requires a V5 inertial sensor. To ensure the code compiles, you must follow the provided examples exactly and only fill in the existing fields; do not add or remove parameters from the constructor.

    Optical Encoder Wiring Note: For red optical encoders, the top wire is plugged into the port indicated in VexCode, and the bottom wire is plugged into the port immediately below it. For example, port "3" corresponds to triports C (top) and D (bottom); port "5" corresponds to ports E (top) and F (bottom).

    Drive::Drive(
        enum::drive_setup drive_setup, 
        motor_group DriveL, 
        motor_group DriveR, 
        int gyro_port, 
        float wheel_diameter, 
        float wheel_ratio, 
        float gyro_scale, 
        int DriveLF_port, 
        int DriveRF_port, 
        int DriveLB_port, 
        int DriveRB_port, 
        int ForwardTracker_port, 
        float ForwardTracker_diameter, 
        float ForwardTracker_center_distance, 
        int SidewaysTracker_port, 
        float SidewaysTracker_diameter, 
        float SidewaysTracker_center_distance
    );
  6. Adjust drive constants using member variables

    To change drive constants (such as max voltage, PID gains, or timeouts) without using long overloaded method signatures, you can directly modify the member variables of the chassis object. Member variables persist across multiple function calls until they are manually changed or reset. This is the preferred method for maintaining readability when only a few parameters need to be adjusted.
    // Set a specific timeout and then perform a turn
    chassis.turn_timeout = 10000;
    chassis.turn_to_angle(90);
    
    // Set max voltage once; it will apply to all subsequent turns
    chassis.turn_max_voltage = 3;
    chassis.turn_to_angle(90);
    chassis.turn_to_angle(0);
  7. Configure a Holonomic drive with two rotation trackers

    The HOLONOMIC_TWO_ROTATION setup is designed specifically for four-motor X-Drives or Mecanum drives. This configuration requires two tracking wheels positioned perpendicular to each other: one Forward Tracker (parallel to the direction of travel) and one Sideways Tracker (perpendicular to the direction of travel). Ensure that the tracker ports are provided in "PORT1" format.