NoU_Drivetrain

class NoU_Drivetrain

Controls the output of a two- or four-motor drivetrain.

Public Functions

NoU_Drivetrain(NoU_Motor *leftMotor, NoU_Motor *rightMotor)

Constructs a new NoU_Drivetrain using the specified two motors.

Parameters:
  • NoU_Motor* leftMotor – The motor on the left side of the drivetrain.

  • NoU_Motor* rightMotor – The motor on the right side of the drivetrain.

Example usage:

NoU_Motor leftMotor(1);
NoU_Motor rightMotor(2);
NoU_Drivetrain drivetrain(&leftMotor, &rightMotor);

Constructs a new drivetrain with the left motor on motor port 1 and the right motor on motor port 2.

Note

Robot builders often wire the two motors on each side of the drivetrain into the same terminal block in parallel, using two motor ports for a four-motor drivetrain. In this case, this constructor should be used, not the four-motor constructor, NoU_Drivetrain(NoU_Motor*, NoU_Motor*, NoU_Motor*, NoU_Motor*)().

NoU_Drivetrain(NoU_Motor *frontLeftMotor, NoU_Motor *frontRightMotor, NoU_Motor *rearLeftMotor, NoU_Motor *rearRightMotor)

Constructs a new NoU_Drivetrain using the specified four motors.

Parameters:
  • NoU_Motor* frontLeftMotor – The motor on the front-left side of the drivetrain.

  • NoU_Motor* frontRightMotor – The motor on the front-right side of the drivetrain.

  • NoU_Motor* rearLeftMotor – The motor on the rear-left side of the drivetrain.

  • NoU_Motor* rearRightMotor – The motor on the rear-right side of the drivetrain.

Example usage:

NoU_Motor frontLeftMotor(1);
NoU_Motor frontRightMotor(2);
NoU_Motor rearLeftMotor(3);
NoU_Motor rearRightMotor(4);
NoU_Drivetrain drivetrain(&frontLeftMotor, &frontRightMtoor, &rearLeftMotor, &rearRightMotor);

Constructs a new drivetrain with the front left motor on motor port 1, the front right motor on motor port 2, the rear left motor on motor port 3, and the rear right motor on motor port 4.

Note

Robot builders often wire the two motors on each side of the drivetrain into the same terminal block in parallel, using two motor ports for a four-motor drivetrain. In this case, the two-motor constructor should be used, NoU_Drivetrain(NoU_Motor*, NoU_Motor*)().

void tankDrive(float leftPower, float rightPower)

Tank drive applies the specified output power directly to the left and right motors, after adjustments from setMinimumOutput(), setMaximumOutput(), setInputExponent(), and setInputDeadband(). This gives direct control over each side of the drivetrain.

Parameters:
  • float leftPower-1…1. The percentage of power to apply to the left side of the drivetrain.

  • float rightPower-1…1. The percentage of power to apply to the right side of the drivetrain.

Example usage:

drivetrain.tankDrive(-0.7, 0.5);

Sets the left side of the drivetrain to go in reverse at 70% power and the right side to go forward at 50% power.

See also

If unsure of which style of drivetrain control to use, curvature drive (curvatureDrive()) is usually recommended.

void arcadeDrive(float throttle, float rotation, boolean invertedReverse = false)

Arcade drive takes the provided throttle and adjusts the power delivered to each side of the drivetrain based on the provided rotation value. This allows control over the robot’s speed and rotation, similarly to many racing games, hence the name “arcade drive”.

Parameters:
  • float throttle-1…1. The percentage of throttle to apply to the drivetrain.

  • float rotation-1…1. The amount by which the throttle should be adjusted for the two sides of the drivetrain in order to produce a turning effect. When going forward, a positive rotation value produces a clockwise rotation.

  • bool invertedReverse – Whether turning should be inverted while driving in reverse. When this is set to false (default), the drivetrain’s orientation will turn in the same direction for the same value of rotation, regardless of whether throttle is positive or negative. In other words, when invertedReverse is false, the curve the drivetrain travels when going forward is mirrored from the curve it travels going backwards, assuming rotation is held constant. When invertedReverse is true, the curve the drivetrain travels when going forward is the same one it travels when going backwards, keeping the center of rotation on the same side of the robot whether throttle is positive or negative.

Example usage:

drivetrain.arcadeDrive(0.7, 0.5);

Sets the drivetrain to go forward at 70% throttle while turning to the right.

drivetrain.arcadeDrive(-0.7, 0.5, false);

Sets the drivetrain to go backwards at 70% throttle while turning to the right, causing the drivetrain to veer to its left side. The curve the drivetrain travels is the mirror image of the curve traveled by the first example.

drivetrain.arcadeDrive(-0.7, 0.5, true);

Sets the drivetrain to go backwards at 70% throttle while turning to the left, causing the drivetrain to veer to its right side. The curve the drivetrain travels is the same one as in the first example, only in reverse.

See also

When using arcade drive, for the same value of rotation, the drivetrain will traverse a much tighter arc when throttle is small compared to when it is large. Curvature drive (curvatureDrive()), on the other hand, keeps the radius of the arc constant for the same value of rotation, regardless of throttle. Most drivers prefer this, so curvature drive is usually recommended.

See also

This method is based on WPILib’s implementation of arcade drive (Java, C++) for FIRST Robotics Competition.

void curvatureDrive(float throttle, float rotation, boolean isQuickTurn = true)

When using arcade drive (see arcadeDrive()), for the same value of rotation, the drivetrain will traverse a much tighter arc when throttle is small compared to when it is large. Curvature drive is similar to arcade drive, but instead, regardless of the throttle value, the drivetrain traverses an arc with the same radius for the same value of rotation. In other words, rather than directly applying a differential to the power applied to the two sides of the drivetrain, the rotation value is the ratio of power applied to the two sides of the drivetrain.

Parameters:
  • float throttle-1…1. The percentage of throttle to apply to the drivetrain.

  • float rotation-1…1. The ratio of power between the two sides of the drivetrain. When going forward, a positive rotation value produces a clockwise rotation.

  • bool isQuickTurn – If enabled (default), the drivetrain will operate in arcade drive when throttle is below 20%. If disabled, because rotation controls the ratio of power applied to the sides of the drivetrain rather than the differential, a high rotation value with a throttle of 0 will produce no motion rather than turning the robot in place. For this reason, it is recommended that quick turn remains enabled for most applications.

Note

When compared to arcade drive, curvature drive acts as if invertedReverse is always true, meaning the robot will traverse the same curve for the same value of rotation, regardless of whether throttle is positive or negative.

See also

This method is based on WPILib’s implementation of curvature drive (Java, C++) for FIRST Robotics Competition.

Example usage:

drivetrain.curvatureDrive(0.7, 0.4);

Sets the drivetrain to go forward at 70% throttle while turning to the right. The left side of the drivetrain is set to 70% power, while the right side is set to 0.4 times that, 28% power.

void holonomicDrive(float xVelocity, float yVelocity, float rotation)
void setMinimumOutput(float minimumOutput)
void setMaximumOutput(float maximumOutput)
void setInputExponent(float inputExponent)
void setInputDeadband(float inputDeadband)