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

An Tank chassis class that inherits from the Chassis virtual class. Contains functions for moving forwards and backwards, and on the spot turns. Utilizes PID for all motion. More...

#include <Tank.h>

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

Public Member Functions

 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 Tank chassis class that inherits from the Chassis virtual class. Contains functions for moving forwards and backwards, and on the spot turns. Utilizes PID for all motion.

Constructor & Destructor Documentation

◆ Tank()

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.

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

Member Function Documentation

◆ getLeftPosition()

float Tank::getLeftPosition ( vex::rotationUnits  units)
overridevirtual

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

Parameters
unitstypically using rotationUnits::deg
Returns
float

Implements wpid::Chassis.

◆ getRightPosition()

float Tank::getRightPosition ( vex::rotationUnits  units)
overridevirtual

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

Parameters
unitstypically using rotationUnits::deg
Returns
float

Implements wpid::Chassis.

◆ resetPosition()

void Tank::resetPosition ( )
overridevirtual

Reset the left and right encoders to 0.

Implements wpid::Chassis.

◆ setBrakeType()

void Tank::setBrakeType ( vex::brakeType  type)
overridevirtual

Sets the brake type of the chassis by passing a brake type as a parameter.

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

Implements wpid::Chassis.

◆ setMaxAcceleration()

void Tank::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.

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

◆ setMeasurementUnits()

void Tank::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 Tank::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.

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

◆ setStraightPID()

void Tank::setStraightPID ( PID  pid)
overridevirtual

Sets the straight PID object.

Parameters
pida PID object holding the constants for driving straight

Implements wpid::Chassis.

◆ setTimeout()

void Tank::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 Tank::setTurnPID ( PID  pid)
overridevirtual

Sets the turning PID constants.

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

Implements wpid::Chassis.

◆ spin() [1/2]

void Tank::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.

Parameters
left_velocitythe left side velocity in percent units
right_velocitythe right side velocity in percent units

◆ spin() [2/2]

void Tank::spin ( int  velocity)

Spin the entire chassis by specified velocities for both sides.

Parameters
velocitythe velocity in percent units

◆ stop()

void Tank::stop ( )
overridevirtual

Stops the chassis using the default brake mode.

Implements wpid::Chassis.

◆ straight()

void Tank::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 Tank::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 Tank::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 Tank::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 Tank::waitUntilSettled ( )
overridevirtual

Waits for the robot to finish a motion.

Implements wpid::Chassis.


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