RIT VEXU Core API
|
#include <motion_controller.h>
Classes | |
struct | m_profile_cfg_t |
Public Member Functions | |
MotionController (m_profile_cfg_t &config) | |
Construct a new Motion Controller object. | |
void | init (double start_pt, double end_pt) override |
Initialize the motion profile for a new movement This will also reset the PID and profile timers. | |
double | update (double sensor_val) override |
Update the motion profile with a new sensor value. | |
double | get () override |
void | set_limits (double lower, double upper) override |
bool | is_on_target () override |
motion_t | get_motion () const |
Static Public Member Functions | |
static FeedForward::ff_config_t | tune_feedforward (TankDrive &drive, OdometryTank &odometry, double pct=0.6, double duration=2) |
Motion Controller class
This class defines a top-level motion profile, which can act as an intermediate between a subsystem class and the motors themselves
This takes the constants kS, kV, kA, kP, kI, kD, max_v and acceleration and wraps around a feedforward, PID and trapezoid profile. It does so with the following formula:
out = feedfoward.calculate(motion_profile.get(time_s)) + pid.get(motion_profile.get(time_s))
For PID and Feedforward specific formulae, see pid.h, feedforward.h, and trapezoid_profile.h
MotionController::MotionController | ( | m_profile_cfg_t & | config | ) |
Construct a new Motion Controller object.
config | The definition of how the robot is able to move max_v Maximum velocity the movement is capable of accel Acceleration / deceleration of the movement pid_cfg Definitions of kP, kI, and kD ff_cfg Definitions of kS, kV, and kA |
|
overridevirtual |
Implements Feedback.
motion_t MotionController::get_motion | ( | ) | const |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
Clamp the upper and lower limits of the output. If both are 0, no limits should be applied. if limits are applied, the controller will not target any value below lower or above upper
lower | upper limit |
upper | lower limiet |
Clamp the upper and lower limits of the output. If both are 0, no limits should be applied.
lower | Upper limit |
upper | Lower limit |
Implements Feedback.
|
static |
This method attempts to characterize the robot's drivetrain and automatically tune the feedforward. It does this by first calculating the kS (voltage to overcome static friction) by slowly increasing the voltage until it moves.
Next is kV (voltage to sustain a certain velocity), where the robot will record it's steady-state velocity at 'pct' speed.
Finally, kA (voltage needed to accelerate by a certain rate), where the robot will record the entire movement's velocity and acceleration, record a plot of [X=(pct-kV*V-kS), Y=(Acceleration)] along the movement, and since kA*Accel = pct-kV*V-kS, the reciprocal of the linear regression is the kA value.
drive | The tankdrive to operate on |
odometry | The robot's odometry subsystem |
pct | Maximum velocity in percent (0->1.0) |
duration | Amount of time the robot should be moving for the test |
|
overridevirtual |
Update the motion profile with a new sensor value.
sensor_val | Value from the sensor |
Implements Feedback.