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

A Mechanism class that uses PID to control a motor group. Contains functions for moving to a relative or absolute angle both synchronously and asynchronously. More...

#include <Mechanism.h>

Public Member Functions

 Mechanism (vex::motor_group motors, float gear_ratio, std::string mech_id)
 Construct a new Mechanism object.
 
 Mechanism (vex::motor_group motors, float gear_ratio)
 
void spin (int velocity)
 Spins the motor group at the specified velocity. Negative values will spin the motors backwards.
 
void stop ()
 stops the motors using the default brake mode.
 
void waitUntilSettled ()
 Waits for the mechanism to finish motion.
 
void moveRelative (float position, float max_speed)
 Move the mechanism to a relative angle.
 
void moveRelativeAsync (float position, float max_speed)
 Move the mechanism to a relative angle asynchronously.
 
void moveAbsolute (float position, float max_speed)
 Move the mechanism to an absolute angle.
 
void moveAbsoluteAsync (float position, float max_speed)
 Move the mechanism to an absolute angle asynchronously.
 
float getPosition (vex::rotationUnits units)
 Get the position of the first motor in the group with the specified units.
 
void resetPosition ()
 Resets the encoders in the group to 0.
 
void setBrakeType (vex::brakeType type)
 Sets the brake type of the chassis.
 
void setPID (PID pid)
 Set a PID object to the mechanism.
 
void setOffset (float offset)
 Set the offset of the mechanism to add or subtract a constant angle.
 
void setMaxAcceleration (float max_accel)
 Set the max acceleration of the mechanism. 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 setBounds (float lower_bound, float upper_bound)
 Set the bounds of the mechanism, such that it is unable to spin past these points. This check is only done during driver control and does not affect PID motion.
 

Detailed Description

A Mechanism class that uses PID to control a motor group. Contains functions for moving to a relative or absolute angle both synchronously and asynchronously.

Constructor & Destructor Documentation

◆ Mechanism()

wpid::Mechanism::Mechanism ( vex::motor_group  motors,
float  gear_ratio,
std::string  mech_id 
)

Construct a new Mechanism object.

Parameters
motorsthe motors used on the mechanism
gear_ratiothe external gear ratio
mech_ida string identifier for the mechanism to use during logging

Member Function Documentation

◆ getPosition()

float Mechanism::getPosition ( vex::rotationUnits  units)

Get the position of the first motor in the group with the specified units.

Parameters
unitsthe rotation units to return
Returns
float the position of the motor

◆ moveAbsolute()

void Mechanism::moveAbsolute ( float  position,
float  max_speed 
)

Move the mechanism to an absolute angle.

Parameters
positionthe absolute angle to move to in degrees
max_speedthe max speed of the motors in velocityUnits::pct

◆ moveAbsoluteAsync()

void Mechanism::moveAbsoluteAsync ( float  position,
float  max_speed 
)

Move the mechanism to an absolute angle asynchronously.

Parameters
positionthe absolute angle to move to in degrees
max_speedthe max speed of the motors in velocityUnits::pct

◆ moveRelative()

void Mechanism::moveRelative ( float  position,
float  max_speed 
)

Move the mechanism to a relative angle.

Parameters
positionthe relative angle to move to in degrees
max_speedthe max speed of the motors in velocityUnits::pct

◆ moveRelativeAsync()

void Mechanism::moveRelativeAsync ( float  position,
float  max_speed 
)

Move the mechanism to a relative angle asynchronously.

Parameters
positionthe relative angle to move to in degrees
max_speedthe max speed of the motors in velocityUnits::pct

◆ setBounds()

void Mechanism::setBounds ( float  lower_bound,
float  upper_bound 
)

Set the bounds of the mechanism, such that it is unable to spin past these points. This check is only done during driver control and does not affect PID motion.

Parameters
lower_boundthe lowest encoder value the mechanism may move to in degrees
upper_boundthe highest encoder value the mechanism may move to in degrees

◆ setBrakeType()

void Mechanism::setBrakeType ( vex::brakeType  type)

Sets the brake type of the chassis.

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

◆ setMaxAcceleration()

void Mechanism::setMaxAcceleration ( float  max_accel)

Set the max acceleration of the mechanism. 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

◆ setOffset()

void Mechanism::setOffset ( float  offset)

Set the offset of the mechanism to add or subtract a constant angle.

Parameters
offsetthe offset in degrees

◆ setPID()

void Mechanism::setPID ( PID  pid)

Set a PID object to the mechanism.

Parameters
PIDa PID object

◆ spin()

void Mechanism::spin ( int  velocity)

Spins the motor group at the specified velocity. Negative values will spin the motors backwards.

Parameters
velocitythe velocity of the mechanism in velocityUnits::pct

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