named variables as they should be
This commit is contained in:
parent
17707897d6
commit
f956c51d83
1 changed files with 6 additions and 6 deletions
|
|
@ -63,7 +63,7 @@ struct Setpoint {
|
||||||
// returns the position and velocity at the given time on a trapezoidal motion plan
|
// returns the position and velocity at the given time on a trapezoidal motion plan
|
||||||
// this could be baked if too computationally expensive
|
// this could be baked if too computationally expensive
|
||||||
// not fully fuzzed
|
// not fully fuzzed
|
||||||
struct Setpoint trapezoidal_planner(float max_vel, float, max_acc, float dist, float time) {
|
struct Setpoint trapezoidal_planner(float max_vel, float max_acc, float dist, float time) {
|
||||||
struct Setpoint setpoint = {0.0, 0.0};
|
struct Setpoint setpoint = {0.0, 0.0};
|
||||||
|
|
||||||
float time_accelerating = max_acc / max_vel;
|
float time_accelerating = max_acc / max_vel;
|
||||||
|
|
@ -71,7 +71,7 @@ struct Setpoint trapezoidal_planner(float max_vel, float, max_acc, float dist, f
|
||||||
|
|
||||||
if (2.0 * distance_while_accelerating > dist) {
|
if (2.0 * distance_while_accelerating > dist) {
|
||||||
// triangular
|
// triangular
|
||||||
float peak_velocity_time = sqrt(distance/max_acc);
|
float peak_velocity_time = sqrt(dist/max_acc);
|
||||||
float peak_velocity = max_acc * peak_velocity_time;
|
float peak_velocity = max_acc * peak_velocity_time;
|
||||||
|
|
||||||
if (time < peak_velocity_time) {
|
if (time < peak_velocity_time) {
|
||||||
|
|
@ -82,7 +82,7 @@ struct Setpoint trapezoidal_planner(float max_vel, float, max_acc, float dist, f
|
||||||
// slowing down
|
// slowing down
|
||||||
float time_decay = time - peak_velocity_time;
|
float time_decay = time - peak_velocity_time;
|
||||||
setpoint.velocity = peak_velocity - (time_decay * max_acc);
|
setpoint.velocity = peak_velocity - (time_decay * max_acc);
|
||||||
setpoint.position = (0.5 * A * peak_velocity_time * peak_velocity_time) // acceleration phase
|
setpoint.position = (0.5 * max_acc * peak_velocity_time * peak_velocity_time) // acceleration phase
|
||||||
+ peak_velocity * time_decay
|
+ peak_velocity * time_decay
|
||||||
- 0.5 * max_acc * time_decay * time_decay;
|
- 0.5 * max_acc * time_decay * time_decay;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -92,7 +92,7 @@ struct Setpoint trapezoidal_planner(float max_vel, float, max_acc, float dist, f
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// trapezoidal
|
// trapezoidal
|
||||||
float cruise_distance = distance - 2.0 * distance_while_accelerating;
|
float cruise_distance = dist - 2.0 * distance_while_accelerating;
|
||||||
float cruise_time = cruise_distance / max_vel;
|
float cruise_time = cruise_distance / max_vel;
|
||||||
float total_time = 2 * time_accelerating + cruise_time;
|
float total_time = 2 * time_accelerating + cruise_time;
|
||||||
if (time < time_accelerating) {
|
if (time < time_accelerating) {
|
||||||
|
|
@ -103,7 +103,7 @@ struct Setpoint trapezoidal_planner(float max_vel, float, max_acc, float dist, f
|
||||||
// cruising
|
// cruising
|
||||||
setpoint.velocity = max_vel;
|
setpoint.velocity = max_vel;
|
||||||
setpoint.position = distance_while_accelerating + max_vel * (time - time_accelerating);
|
setpoint.position = distance_while_accelerating + max_vel * (time - time_accelerating);
|
||||||
} else if (time < time_total) {
|
} else if (time < total_time) {
|
||||||
// slowing down
|
// slowing down
|
||||||
float time_decay = time - (time_accelerating + cruise_time);
|
float time_decay = time - (time_accelerating + cruise_time);
|
||||||
setpoint.velocity = max_vel - time_decay * max_acc;
|
setpoint.velocity = max_vel - time_decay * max_acc;
|
||||||
|
|
@ -113,7 +113,7 @@ struct Setpoint trapezoidal_planner(float max_vel, float, max_acc, float dist, f
|
||||||
} else {
|
} else {
|
||||||
//done
|
//done
|
||||||
setpoint.velocity = 0.0;
|
setpoint.velocity = 0.0;
|
||||||
setpoint.position = dest;
|
setpoint.position = dist;
|
||||||
setpoint.complete = true;
|
setpoint.complete = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue