WPID Library 5
Loading...
Searching...
No Matches
Public Member Functions | List of all members
wpid::HDrive Class Reference

An HDrive chassis class that inherits from the Tank class. Contains functions for strafing sideways, and moving diagonally along with all Tank related motion. Utilizes PID for all motion. More...

#include <HDrive.h>

Inheritance diagram for wpid::HDrive:
wpid::Tank wpid::Chassis

Public Member Functions

 HDrive (float track_width, float wheel_radius, float center_wheel_radius, vex::motor_group left, vex::motor_group right, vex::motor_group center, float drive_gear_ratio)
 Construct a new HDrive object.
 
void setStraightPID (PID pid) override
 Sets the straight PID object.
 
void setTurnPID (PID pid) override
 Sets the turning PID object.
 
void setStrafePID (PID pid)
 Sets the strafing PID object.
 
void spin (int left_velocity, int right_velocity, int center_velocity)
 Spin the entire chassis by specified velocities for each side of the chassis. Negative values spin the wheel backwards.
 
void spin (int sides, int center)
 Spin the entire chassis by specified velocities for each side of the chassis. Negative values spin the wheel backwards.
 
void straight (float distance, int max_speed) override
 Move the chassis forward a specific distance with PID. Chassis will always stay at or below the maximum speed.
 
void straightAsync (float distance, int max_speed) override
 Move the chassis forward asynchronously a specific distance with PID. Chassis will always stay at or below the maximum speed.
 
void turn (int target_angle, int max_speed) override
 Turn the chassis on the spot with PID. Chassis will always stay at or below the maximum speed.
 
void turnAsync (float target_angle, int max_speed) override
 Turn the chassis on the spot asynchronously with PID. Chassis will always stay at or below the maximum speed.
 
void strafe (float distance, int max_speed)
 Strafe the chassis sideways with PID. Chassis will always stay at or below the maximum speed.
 
void strafeAsync (float distance, int max_speed)
 Strafe the chassis sideways asynchronously with PID. Chassis will always stay at or below the maximum speed.
 
void diagonal (float straight_distance, float strafe_distance, int straight_max_speed)
 Move the chassis on a diagonal a specific distance with PID. Chassis will always stay at or below the maximum speed. The speed of the center wheel is calculated in the function as being proportional to the distance traveled. If the straight distance is 100, and center is 30, the center wheel will spin at 30% the speed of straight_max_speed.
 
void diagonalAsync (float straight_distance, float strafe_distance, int straight_max_speed)
 Move the chassis on a diagonal asynchronously a specific distance with PID. Chassis will always stay at or below the maximum speed. The speed of the center wheel is calculated in the function as being proportional to the distance traveled. If the straight distance is 100, and center is 30, the center wheel will spin at 30% the speed of straight_max_speed.
 
void stop () override
 Stops the chassis using the default brake mode.
 
void waitUntilSettled () override
 Waits for the robot to finish a motion.
 
float getLeftPosition (vex::rotationUnits units)
 Gets the current position of the left side of the chassis.
 
float getRightPosition (vex::rotationUnits units)
 Gets the current position of the right side of the chassis.
 
float getCenterPosition (vex::rotationUnits units)
 Gets the current position of the center wheel of the chassis.
 
void resetPosition () override
 Reset all encoders to 0.
 
void setBrakeType (vex::brakeType type)
 Sets the brake type of the chassis.
 
void setMaxAcceleration (float straight_max_accel, float c_max_accel)
 Set the max acceleration of the chassis. Every time the PID loop executes, it increments the speed of the mechanism by this value until the mechanism reaches it's maximum speed. Increase the value if the robot is ramping too slow, or decrease if it causes too much jerk.
 
void setOffset (float straight, float turn, float strafe)
 Set the offset for the straight and turn functions. This value is in inches, and will add to the input of each movement function.
 
void setTimeout (int timeout)
 Set the timeout to use for PID movement. If the timeout is exceeded, the system will stop regardless of the current error or speed. A value of -1 will disable timeouts.
 
void setMeasurementUnits (Conversion::measurement preferred_units)
 Set the measurement units for chassis values.
 
- Public Member Functions inherited from wpid::Tank
 Tank (float track_width, float wheel_radius, vex::motor_group left, vex::motor_group right, float drive_gear_ratio)
 Construct a new Tank object.
 
void setStraightPID (PID pid) override
 Sets the straight PID object.
 
void setTurnPID (PID pid) override
 Sets the turning PID constants.
 
void spin (int left_velocity, int right_velocity)
 Spin the entire chassis by specified velocities for each side of the chassis. Negative values spin the wheel backwards.
 
void spin (int velocity)
 Spin the entire chassis by specified velocities for both sides.
 
void straight (float distance, int max_speed) override
 Move the chassis forward a specific distance with PID. Chassis will always stay at or below the maximum speed.
 
void straightAsync (float distance, int max_speed) override
 Move the chassis forward asynchronously a specific distance with PID. Chassis will always stay at or below the maximum speed.
 
void turn (int target_angle, int max_speed) override
 Turn the chassis on the spot with PID. Chassis will always stay at or below the maximum speed.
 
void turnAsync (float target_angle, int max_speed) override
 Turn the chassis on the spot asynchronously with PID. Chassis will always stay at or below the maximum speed.
 
void stop () override
 Stops the chassis using the default brake mode.
 
void waitUntilSettled () override
 Waits for the robot to finish a motion.
 
float getLeftPosition (vex::rotationUnits units) override
 Gets the current position of the left side of the chassis.
 
float getRightPosition (vex::rotationUnits units) override
 Gets the current position of the right side of the chassis.
 
void resetPosition () override
 Reset the left and right encoders to 0.
 
void setBrakeType (vex::brakeType type) override
 Sets the brake type of the chassis by passing a brake type as a parameter.
 
void setMaxAcceleration (float max_accel)
 Set the max acceleration of the chassis. Every time the PID loop executes, it increments the speed of the mechanism by this value until the mechanism reaches it's maximum speed. Increase the value if the robot is ramping too slow, or decrease if it causes too much jerk.
 
void setOffset (float straight, float turn)
 Set the offset for the straight and turn functions. This value is in inches, and will add to the input of each movement function.
 
void setTimeout (int timeout)
 Set the timeout to use for PID movement. If the timeout is exceeded, the system will stop regardless of the current error or speed. A value of -1 will disable timeouts.
 
void setMeasurementUnits (Conversion::measurement preferred_units)
 Set the measurement units for chassis values.
 

Additional Inherited Members

- Protected Attributes inherited from wpid::Chassis
float track_width
 
float wheel_circumference
 
Mechanismleft
 
Mechanismright
 
PID pidStraight
 
PID pidTurn
 
float straight_offset = 0
 
float turn_offset = 0
 
Conversion::measurement measure_units = Conversion::measurement::in
 

Detailed Description

An HDrive chassis class that inherits from the Tank class. Contains functions for strafing sideways, and moving diagonally along with all Tank related motion. Utilizes PID for all motion.

Constructor & Destructor Documentation

◆ HDrive()

HDrive::HDrive ( float  track_width,
float  wheel_radius,
float  center_wheel_radius,
vex::motor_group  left,
vex::motor_group  right,
vex::motor_group  center,
float  drive_gear_ratio 
)

Construct a new HDrive object.

Parameters
track_widththe width between left and right
wheel_basethe distance from front to back of the wheel
wheel_radiusradius of the wheel
leftmotor group
rightmotor group
centermotor group
drive_gear_ratiothe internal gear-set of the drive train

Member Function Documentation

◆ diagonal()

void HDrive::diagonal ( float  straight_distance,
float  strafe_distance,
int  straight_max_speed 
)

Move the chassis on a diagonal a specific distance with PID. Chassis will always stay at or below the maximum speed. The speed of the center wheel is calculated in the function as being proportional to the distance traveled. If the straight distance is 100, and center is 30, the center wheel will spin at 30% the speed of straight_max_speed.

Parameters
straight_distancethe distance going forward or backwards in inches
strafe_distancethe distance going sideways in inches
straight_max_speedthe maximum speed the robot will travel in percent units

◆ diagonalAsync()

void HDrive::diagonalAsync ( float  straight_distance,
float  strafe_distance,
int  straight_max_speed 
)

Move the chassis on a diagonal asynchronously a specific distance with PID. Chassis will always stay at or below the maximum speed. The speed of the center wheel is calculated in the function as being proportional to the distance traveled. If the straight distance is 100, and center is 30, the center wheel will spin at 30% the speed of straight_max_speed.

Parameters
straight_distancethe distance going forward or backwards in inches
strafe_distancethe distance going sideways in inches
straight_max_speedthe maximum speed the robot will travel in percent units

◆ getCenterPosition()

float HDrive::getCenterPosition ( vex::rotationUnits  units)

Gets the current position of the center wheel of the chassis.

Parameters
unitthe rotation units you want to return
Returns
the position in the specified units

◆ getLeftPosition()

float HDrive::getLeftPosition ( vex::rotationUnits  units)
virtual

Gets the current position of the left side of the chassis.

Parameters
unitthe rotation units you want to return
Returns
the position in the specified units

Implements wpid::Chassis.

◆ getRightPosition()

float HDrive::getRightPosition ( vex::rotationUnits  units)
virtual

Gets the current position of the right side of the chassis.

Parameters
unitthe rotation units you want to return
Returns
the position in the specified units

Implements wpid::Chassis.

◆ resetPosition()

void HDrive::resetPosition ( )
overridevirtual

Reset all encoders to 0.

Implements wpid::Chassis.

◆ setBrakeType()

void HDrive::setBrakeType ( vex::brakeType  type)
virtual

Sets the brake type of the chassis.

Parameters
typeThe brake type can be set to coast, brake, or hold.

Implements wpid::Chassis.

◆ setMaxAcceleration()

void HDrive::setMaxAcceleration ( float  straight_max_accel,
float  c_max_accel 
)

Set the max acceleration of the chassis. Every time the PID loop executes, it increments the speed of the mechanism by this value until the mechanism reaches it's maximum speed. Increase the value if the robot is ramping too slow, or decrease if it causes too much jerk.

Parameters
max_accela value to increment to ramp the speed up in velocityUnits::pct

◆ setMeasurementUnits()

void HDrive::setMeasurementUnits ( Conversion::measurement  preferred_units)
virtual

Set the measurement units for chassis values.

Parameters
preferred_unitsthe user's measurement system

Implements wpid::Chassis.

◆ setOffset()

void HDrive::setOffset ( float  straight,
float  turn,
float  strafe 
)

Set the offset for the straight and turn functions. This value is in inches, and will add to the input of each movement function.

Parameters
straightthe distance to offset straight motion in distance units
turnthe angle to offset turns in degrees
strafethe distance to offset strafe motion in distance units

◆ setStrafePID()

void HDrive::setStrafePID ( PID  pid)

Sets the strafing PID object.

Parameters
pida PID object holding the constants for strafing sideways

◆ setStraightPID()

void HDrive::setStraightPID ( PID  pid)
overridevirtual

Sets the straight PID object.

Parameters
pida PID object holding the constants for driving straight

Implements wpid::Chassis.

◆ setTimeout()

void HDrive::setTimeout ( int  timeout)

Set the timeout to use for PID movement. If the timeout is exceeded, the system will stop regardless of the current error or speed. A value of -1 will disable timeouts.

Parameters
timeoutin milliseconds

◆ setTurnPID()

void HDrive::setTurnPID ( PID  pid)
overridevirtual

Sets the turning PID object.

Parameters
pida PID object holding the constants for turning on the spot

Implements wpid::Chassis.

◆ spin() [1/2]

void HDrive::spin ( int  left_velocity,
int  right_velocity,
int  center_velocity 
)

Spin the entire chassis by specified velocities for each side of the chassis. Negative values spin the wheel backwards.

Parameters
left_velocitythe left side velocity in percent units
right_velocitythe right side velocity in percent units
center_velocitythe center wheel velocity in percent units

◆ spin() [2/2]

void HDrive::spin ( int  sides,
int  center 
)

Spin the entire chassis by specified velocities for each side of the chassis. Negative values spin the wheel backwards.

Parameters
sidesthe side wheels' velocity in percent units
centerthe center wheel velocity in percent units

◆ stop()

void HDrive::stop ( )
overridevirtual

Stops the chassis using the default brake mode.

Implements wpid::Chassis.

◆ strafe()

void HDrive::strafe ( float  distance,
int  max_speed 
)

Strafe the chassis sideways with PID. Chassis will always stay at or below the maximum speed.

Parameters
distancethe distance to travel in inches
max_speedthe maximum speed in percent units

◆ strafeAsync()

void HDrive::strafeAsync ( float  distance,
int  max_speed 
)

Strafe the chassis sideways asynchronously with PID. Chassis will always stay at or below the maximum speed.

Parameters
distancethe distance to travel in inches
max_speedthe maximum speed in percent units

◆ straight()

void HDrive::straight ( float  distance,
int  max_speed 
)
overridevirtual

Move the chassis forward a specific distance with PID. Chassis will always stay at or below the maximum speed.

Parameters
distancethe distance in inches
max_speedthe maximum speed the robot will travel in percent units

Implements wpid::Chassis.

◆ straightAsync()

void HDrive::straightAsync ( float  distance,
int  max_speed 
)
overridevirtual

Move the chassis forward asynchronously a specific distance with PID. Chassis will always stay at or below the maximum speed.

Parameters
distancethe distance in inches
max_speedthe maximum speed the robot will travel in percent units

Implements wpid::Chassis.

◆ turn()

void HDrive::turn ( int  target_angle,
int  max_speed 
)
overridevirtual

Turn the chassis on the spot with PID. Chassis will always stay at or below the maximum speed.

Parameters
target_anglethe target angle in degrees
max_speedthe maximum speed in percent units

Implements wpid::Chassis.

◆ turnAsync()

void HDrive::turnAsync ( float  target_angle,
int  max_speed 
)
overridevirtual

Turn the chassis on the spot asynchronously with PID. Chassis will always stay at or below the maximum speed.

Parameters
target_anglethe target angle in degrees
max_speedthe maximum speed in percent units

Implements wpid::Chassis.

◆ waitUntilSettled()

void HDrive::waitUntilSettled ( )
overridevirtual

Waits for the robot to finish a motion.

Implements wpid::Chassis.


The documentation for this class was generated from the following files: