TrapezoidalProfile
The velocity units must be in (inches/seconds) and the acceleration units in (inches/seconds2) Otherwise, the code will not work as expected.
Constructor
TrapezoidalProfile()
Trapezoidal profile constructor. Create a new trapezoidal profile.
- Prototype
- Example
TrapezoidalProfile(float max_velocity, float max_acceleration);
void autonomous(){
lightning::TrapezoidalProfile profile (5,1); //5 inches/second, 1 inches/second^2
}
Parameters | |
---|---|
max_velocity | What would be the maximum profile velocity?. |
max_acceleration | What would be the maximum profile accleration? . |
Functions
update()
Updates the trapezoidal profile giving the target and the sample time.
- Prototype
- Example
void update(const float target, float sample_time_sec);
lightning::TrapezoidalProfile profile (5,1); //5 inches/second, 1 inches/second^2
void autonomous(){
//target= 48 inches.
//sample_time_sec = .01 seconds.
profile.update(48,.01);
}
Parameters | |
---|---|
target | How many distance you would travel in inches. |
sample_time_sec | The update rate in secconds. . |
reset()
Resets the trapezoidal profile.
The function erases and clean all the profile.
- Prototype
- Example
void reset();
void autonomous(){
lightning::TrapezoidalProfile profile (5,1); //5 inches/second, 1 inches/second^2
profile.update(48,.01); // 48 inches , .01 sec
/*
USING THE PROFILE during autonomous
*/
//When we finish using the profile
profile.reset();
}
is_ready()
Checks if the profile its ready to use.
- Prototype
- Example
bool is_ready() const;
void autonomous(){
lightning::TrapezoidalProfile profile (5,1); //5 inches/second, 1 inches/second^2
profile.update(48,.01); // 48 inches , .01 sec
if(profile.is_ready()){
/*
MAKE THINGS
*/
}
}
Setters
set_parameters()
Sets the main parameters for the profile.
- Prototype
- Example
void set_parameters(const float max_velocity, const float max_acceleration);
lightning::TrapezoidalProfile profile (5,1); //5 inches/second, 1 inches/second^2
void autonomous(){
profile.set_parameters(10,2); //10 inches/second, 2 inches/second^2
}
Parameters | |
---|---|
max_velocity | What would be the maximum profile velocity?. |
max_acceleration | What would be the maximum profile accleration? . |
set_max_velocity()
Sets the maximum profile velocity.
- Prototype
- Example
void set_max_velocity(const float max_velocity);
lightning::TrapezoidalProfile profile (5,1); //5 inches/second, 1 inches/second^2
void autonomous(){
profile.set_max_velocity(10); //5 inches/second
}
Parameters | |
---|---|
max_velocity | What would be the maximum profile velocity?. |
set_max_acceleration()
Sets the maximum profile acceleration.
- Prototype
- Example
void set_max_acceleration(const float max_acceleration);
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.set_max_velocity(10); //10 inches/second
profile.set_max_acceleration(2); //2 inches/second^2
}
Parameters | |
---|---|
max_acceleration | What would be the maximum profile accleration? . |
Getters
get_velocity_at()
Gets the desired velocity giving a point.
- Prototype
- Example
float get_velocity_at(int index) const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
float velocity = profile.get_velocity_at(5) //getting the velocity at index 5.
}
Parameters | |
---|---|
index | Index the profile index. |
Returns: The desired velocity.
get_max_velocity()
Gets the maximum profile velocity.
- Prototype
- Example
float get_max_velocity() const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
float max_velocity = profile.get_max_velocity();
}
Returns: The maximum velocity.
get_max_acceleration()
Gets the maximum profile acceleration.
- Prototype
- Example
float get_max_acceleration() const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
float max_acceleration = profile.get_max_acceleration();
}
Returns: The maximum acceleration.
get_accel_time()
Gets the acceleration time.
- Prototype
- Example
float get_accel_time() const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
float accel_time = profile.get_accel_time();
}
Returns: The acceleration time.
get_accel_distance()
Gets the acceleration distance (acceleration phase).
- Prototype
- Example
float get_accel_distance() const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
float accel_distance = profile.get_accel_distance();
}
Returns: The acceleration time.
get_desaccel_distance()
Gets the desacceleration distance (desacceleration phase).
- Prototype
- Example
float get_desaccel_distance() const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
float desaccel_distance = profile.get_desaccel_distance();
}
Returns: Gets the desacceleration time.
get_velocity_constant_distance()
Gets the constant velocity distance (constant acceleration phase).
- Prototype
- Example
float get_velocity_constant_distance() const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
float velocity_constant_distance = profile.get_velocity_constant_distance();
}
Returns: Gets the constant velocity distance.
get_time_to_arrived()
Gets the time to arrive.
- Prototype
- Example
float get_time_to_arrived() const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
float time_to_arrived = profile.get_time_to_arrived(); // in seconds
}
Returns: The time to arrive in seconds.
get_size()
Returns the profile size.
- Prototype
- Example
std::size_t get_size() const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
int profile_size = profile.get_size();
}
Returns: The current profile size.
get_velocities()
Return a vector with the desired velocities using the trapezoidal profile.
- Prototype
- Example
std::vector<float> get_velocities() const;
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
//Saving the profile velocities to a new vector.
std::vector<float> profile_velocities = profile.get_velocities();
}
Returns: Desired velocities vector.
Operators
std::ostream &operator <<
Prints the desired velocities of a TrapezoidalProfile
object in Integrated Terminal.
- Prototype
- Example
std::ostream &operator<<(std::ostream &os,const TrapezoidalProfile &profile);
lightning::TrapezoidalProfile profile (5,1);
void autonomous(){
profile.update(48,.01); // 48 inches , .01 sec
//Printing velocities
std::cout<<profile;
}