Drive Constructor | JAR-Template (2024)

The JAR Template drive constructor can build drivetrains with no tracking wheels, but also supports tank and holonomic odometry, with either red optical encoders or V5 rotation sensors. Note that each constructor has the same prototype, and that every drive style requires a V5 inertial sensor.

caution

Do not try to add extra motor groups, sensors, or values to the constructor or to remove any that you do not need. The code will not compile. Follow the style of the examples, only filling in fields that are already present.

note

For odometry users using red optical encoders: the top wire of the encoder is always plugged in one port above the bottom wire, and it is the top wire that is indicated in VexCode. So putting the port as "3" means that the encoder is plugged into triports C and D on the brain with the top wire in port C and the bottom wire in port D. Likewise, putting the port as "5" means the encoder is plugged into ports E and F.

Drive Setup Examples

Drive constructor for the chassis. Even though there's only one constructor, there can be huge differences in implementation depending on the drive style selected.

Parameters
drive_setupThe style of drive, such as TANK_TWO_ROTATION.
DriveLLeft motor group.
DriveRRight motor group.
gyro_portIMU port.
wheel_diameterWheel diameter in inches.
wheel_ratioExternal drive gear ratio.
gyro_scaleScale factor in degrees.
DriveLF_portLeft front port for holonomic drives.
DriveRF_portRight front port for holonomic drives.
DriveLB_portLeft back port for holonomic drives.
DriveRB_portRight back port for holonomic drives.
ForwardTracker_portPort for the forward tracker.
ForwardTracker_diameterDiameter in inches.
ForwardTracker_center_distanceHorizontal distance in inches.
SidewaysTracker_portPort for the sideways tracker.
SidewaysTracker_diameterDiameter in inches.
SidewaysTracker_center_distanceVertical distance in inches.

ZERO_TRACKER_NO_ODOM

Note that for this drive setup, nothing needs to be edited after the gyro scale factor.

  • Prototype
  • Example
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);

ZERO_TRACKER_ODOM

For this drive setup, the only thing that needs to be edited after gyro scale factor is the Forward Tracker Center distance. Since this constructor uses the right side drive motor encoders to track position, Forward Tracker Center distance is just the distance from the center of your robot to the right set of wheels.

  • Prototype
  • Example
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);

TANK_ONE_FORWARD_ENCODER

This style of odometry has a single tracker measuring forward/backward movement. This typically makes sense if the robot has traction wheels, because it can't measure sideways movement. See the note above about optical encoder wiring.

  • Prototype
  • Example
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);

TANK_ONE_FORWARD_ROTATION

This style of odometry uses a V5 rotation sensor to measure forward/backward movement and assumes sideways slippage is minimal. This makes most sense on a drive with traction wheels.

  • Prototype
  • Example
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);

TANK_ONE_SIDEWAYS_ENCODER

This style of odometry uses the right side motor encoders to measure forward/backward movement and an optical encoder to measure sideways movement.

  • Prototype
  • Example
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);

TANK_ONE_SIDEWAYS_ROTATION

This style of odometry uses the right side motor encoders to measure forward/backward movement and a V5 rotation sensor to measure sideways movement.

  • Prototype
  • Example
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);

TANK_TWO_ENCODER

These tracking wheels must be perpendicular to each other. The Forward Tracker is parallel to the direction of travel, and the Sideways Tracker is perpendicular to the direction of travel. See the note above about optical encoder wiring.

  • Prototype
  • Example
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);

TANK_TWO_ROTATION

These tracking wheels must be perpendicular to each other. The Forward Tracker is parallel to the direction of travel, and the Sideways Tracker is perpendicular to the direction of travel. Remember to put the Forward and Sideways Tracker ports in "PORT1" format.

  • Prototype
  • Example
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);

HOLONOMIC_TWO_ENCODER

This setup only works with a four motor X-Drive or mecanum drive. These tracking wheels must be perpendicular to each other. The Forward Tracker is parallel to the direction of travel, and the Sideways Tracker is perpendicular to the direction of travel. See the note above about optical encoder wiring.

  • Prototype
  • Example
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);

HOLONOMIC_TWO_ROTATION

This setup only works with a four motor X-Drive or mecanum drive. These tracking wheels must be perpendicular to each other. The Forward Tracker is parallel to the direction of travel, and the Sideways Tracker is perpendicular to the direction of travel. Remember to put the Forward and Sideways Tracker ports in "PORT1" format.

  • Prototype
  • Example
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);

On Gyro Scale

Intuition

The gyro scale parameter is often the least intuitive parameter in the drive constructor, but it serves a particularly important purpose.

You may have noticed that V5 IMU sensors often display a bit of error. For example, even if you spin the robot around by a perfect 360 degrees, the sensor's output may say 358.5 every single time. Try it yourself. On most vex gyroscopes, you will get a consistent one or two degrees of error per rotation every time. This adds up, so a robot that reads 359 degrees after one spin will read 350 degrees after ten spins.

One solution is to keep trying new gyros until you find one that's as close to perfect as possible, and this is a lot of teams' go-to method. But I propose a new one. Just multiply the gyro's output by a small scale factor to make the robots rotation equal to 360 degrees every single time. This will negate the effect of the gyro's error and make your runs look good as new.

Usage

Open the devices menu and select your gyroscope. Ensure it reads 0 (or approximately 0), and spin the robot around a full rotation. Note the reading now displayed on the devices menu. If it is a bit less than 360, that's your number. If it is a bit more than 0, add 360 and that's your number. Input that number as the gyro scale in the drive constructor.

Drive Constructor | JAR-Template (2024)

References

Top Articles
Latest Posts
Article information

Author: Cheryll Lueilwitz

Last Updated:

Views: 6027

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Cheryll Lueilwitz

Birthday: 1997-12-23

Address: 4653 O'Kon Hill, Lake Juanstad, AR 65469

Phone: +494124489301

Job: Marketing Representative

Hobby: Reading, Ice skating, Foraging, BASE jumping, Hiking, Skateboarding, Kayaking

Introduction: My name is Cheryll Lueilwitz, I am a sparkling, clean, super, lucky, joyous, outstanding, lucky person who loves writing and wants to share my knowledge and understanding with you.