RIT VEXU Core API
Loading...
Searching...
No Matches
MotionController Class Reference

#include <motion_controller.h>

Inheritance diagram for MotionController:
Feedback

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)
 

Detailed Description

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

Author
Ryan McGee
Date
7/13/2022

Constructor & Destructor Documentation

◆ MotionController()

MotionController::MotionController ( m_profile_cfg_t & config)

Construct a new Motion Controller object.

Parameters
configThe 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

Member Function Documentation

◆ get()

double MotionController::get ( )
overridevirtual
Returns
the last saved result from the feedback controller

Implements Feedback.

◆ get_motion()

motion_t MotionController::get_motion ( ) const
Returns
The current postion, velocity and acceleration setpoints

◆ init()

void MotionController::init ( double start_pt,
double end_pt )
overridevirtual

Initialize the motion profile for a new movement This will also reset the PID and profile timers.

Parameters
start_ptMovement starting position
end_ptMovement ending posiiton

Implements Feedback.

◆ is_on_target()

bool MotionController::is_on_target ( )
overridevirtual
Returns
Whether or not the movement has finished, and the PID confirms it is on target

Implements Feedback.

◆ set_limits()

void MotionController::set_limits ( double lower,
double upper )
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

Parameters
lowerupper limit
upperlower limiet

Clamp the upper and lower limits of the output. If both are 0, no limits should be applied.

Parameters
lowerUpper limit
upperLower limit

Implements Feedback.

◆ tune_feedforward()

FeedForward::ff_config_t MotionController::tune_feedforward ( TankDrive & drive,
OdometryTank & odometry,
double pct = 0.6,
double duration = 2 )
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.

Parameters
driveThe tankdrive to operate on
odometryThe robot's odometry subsystem
pctMaximum velocity in percent (0->1.0)
durationAmount of time the robot should be moving for the test
Returns
A tuned feedforward object

◆ update()

double MotionController::update ( double sensor_val)
overridevirtual

Update the motion profile with a new sensor value.

Parameters
sensor_valValue from the sensor
Returns
the motor input generated from the motion profile

Implements Feedback.


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