Drive Constructor
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.
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.
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_setup | The style of drive, such as TANK_TWO_ROTATION. |
DriveL | Left motor group. |
DriveR | Right motor group. |
gyro_port | IMU port. |
wheel_diameter | Wheel diameter in inches. |
wheel_ratio | External drive gear ratio. |
gyro_scale | Scale factor in degrees. |
DriveLF_port | Left front port for holonomic drives. |
DriveRF_port | Right front port for holonomic drives. |
DriveLB_port | Left back port for holonomic drives. |
DriveRB_port | Right back port for holonomic drives. |
ForwardTracker_port | Port for the forward tracker. |
ForwardTracker_diameter | Diameter in inches. |
ForwardTracker_center_distance | Horizontal distance in inches. |
SidewaysTracker_port | Port for the sideways tracker. |
SidewaysTracker_diameter | Diameter in inches. |
SidewaysTracker_center_distance | Vertical 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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
ZERO_TRACKER_NO_ODOM,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT1, -PORT2,
//LB: //RB:
PORT3, -PORT4,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
3,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
-2,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
1,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
5.5
);
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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
ZERO_TRACKER_ODOM,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT1, -PORT2,
//LB: //RB:
PORT3, -PORT4,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
3,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.25,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
1,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
5.5
);
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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
TANK_ONE_FORWARD_ENCODER,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT1, -PORT2,
//LB: //RB:
PORT3, -PORT4,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
5,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.25,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
1,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
5.5
);
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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
TANK_ONE_FORWARD_ROTATION,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT1, -PORT2,
//LB: //RB:
PORT3, -PORT4,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
PORT17,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.25,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
1,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
2.5
);
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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
TANK_ONE_SIDEWAYS_ENCODER,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT1, -PORT2,
//LB: //RB:
PORT3, -PORT4,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
3,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.25,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
5,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
2.5
);
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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
TANK_ONE_SIDEWAYS_ROTATION,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT1, -PORT2,
//LB: //RB:
PORT3, -PORT4,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
3,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.25,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
PORT17,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
2.5
);
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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
TANK_TWO_ENCODER,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT1, -PORT2,
//LB: //RB:
PORT3, -PORT4,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
3,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.25,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
5,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
2.5
);
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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
TANK_TWO_ROTATION,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT1, -PORT2,
//LB: //RB:
PORT3, -PORT4,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
PORT18,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.25,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
PORT17,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
2.5
);
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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
HOLONOMIC_TWO_ENCODER,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT15, -PORT17,
//LB: //RB:
PORT16, -PORT18,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
3,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.25,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
5,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
2.5
);
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 chassis(
//Pick your drive setup from the list below:
//ZERO_TRACKER_NO_ODOM
//ZERO_TRACKER_ODOM
//TANK_ONE_FORWARD_ENCODER
//TANK_ONE_FORWARD_ROTATION
//TANK_ONE_SIDEWAYS_ENCODER
//TANK_ONE_SIDEWAYS_ROTATION
//TANK_TWO_ENCODER
//TANK_TWO_ROTATION
//HOLONOMIC_TWO_ENCODER
//HOLONOMIC_TWO_ROTATION
//
//Write it here:
HOLONOMIC_TWO_ROTATION,
//Add the names of your Drive motors into the motor groups below, separated by commas, i.e. motor_group(Motor1,Motor2,Motor3).
//You will input whatever motor names you chose when you configured your robot using the sidebar configurer, they don't have to be "Motor1" and "Motor2".
//Left Motors:
motor_group(LeftFront, LeftBack),
//Right Motors:
motor_group(RightFront, RightBack),
//Specify the PORT NUMBER of your inertial sensor, in PORT format (i.e. "PORT1", not simply "1"):
PORT4,
//Input your wheel diameter. (4" omnis are actually closer to 4.125"):
4.125,
//External ratio, must be in decimal, in the format of input teeth/output teeth.
//If your motor has an 84-tooth gear and your wheel has a 60-tooth gear, this value will be 1.4.
//If the motor drives the wheel directly, this value is 1:
1.0,
//Gyro scale, this is what your gyro reads when you spin the robot 360 degrees.
//For most cases 360 will do fine here, but this scale factor can be very helpful when precision is necessary.
360,
/*---------------------------------------------------------------------------*/
/* PAUSE! */
/* */
/* The rest of the drive constructor is for robots using POSITION TRACKING. */
/* If you are not using position tracking, leave the rest of the values as */
/* they are. */
/*---------------------------------------------------------------------------*/
//If you are using ZERO_TRACKER_ODOM, you ONLY need to adjust the FORWARD TRACKER CENTER DISTANCE.
//FOR HOLONOMIC DRIVES ONLY: Input your drive motors by position. This is only necessary for holonomic drives, otherwise this section can be left alone.
//LF: //RF:
PORT15, -PORT17,
//LB: //RB:
PORT16, -PORT18,
//If you are using position tracking, this is the Forward Tracker port (the tracker which runs parallel to the direction of the chassis).
//If this is a rotation sensor, enter it in "PORT1" format, inputting the port below.
//If this is an encoder, enter the port as an integer. Triport A will be a "1", Triport B will be a "2", etc.
PORT8,
//Input the Forward Tracker diameter (reverse it to make the direction switch):
2.75,
//Input Forward Tracker center distance (a positive distance corresponds to a tracker on the right side of the robot, negative is left.)
//For a zero tracker tank drive with odom, put the positive distance from the center of the robot to the right side of the drive.
//This distance is in inches:
5.25,
//Input the Sideways Tracker Port, following the same steps as the Forward Tracker Port:
PORT9,
//Sideways tracker diameter (reverse to make the direction switch):
-2.75,
//Sideways tracker center distance (positive distance is behind the center of the robot, negative is in front):
2.5
);
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.