Last active
February 16, 2018 02:41
-
-
Save cipher982/a405525bb0bb6406b201cdd8ade8f388 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define the (x,y) points we will use for the planner | |
vector<double> next_x_vals; | |
vector<double> next_y_vals; | |
// start with previous path points from above | |
for (int i = 0; i < prev_size; i++) | |
{ | |
next_x_vals.push_back(previous_path_x[i]); | |
next_y_vals.push_back(previous_path_y[i]); | |
} | |
// calculate how to break up spline points to travel at desired reference velocity | |
double target_x = 30.0; | |
double target_y = s(target_x); | |
double target_dist = sqrt(target_x * target_x + target_y * target_y); | |
double x_add_on = 0; | |
// fill up the rest of path planner after filling with previous points | |
for (int i = 1; i < 50 — prev_size; i++) // 50 points | |
{ | |
// ramp up speed | |
ref_vel += speed_diff; | |
if (ref_vel > max_vel) // until hitting limit | |
{ | |
ref_vel = max_vel; // then hold | |
} | |
else if (ref_vel < max_acl) // if hitting max acceleration | |
{ | |
ref_vel = max_acl; // keep at max acceleration | |
} | |
double N = target_dist / (0.02 * ref_vel / 2.24); | |
double x_point = x_add_on + target_x / N; | |
double y_point = s(x_point); | |
x_add_on = x_point; | |
double x_ref = x_point; | |
double y_ref = y_point; | |
// now rotate BACK to normal | |
x_point = x_ref * cos(ref_yaw) — y_ref * sin(ref_yaw); | |
y_point = x_ref * sin(ref_yaw) + y_ref * cos(ref_yaw); | |
x_point += ref_x; | |
y_point += ref_y; | |
next_x_vals.push_back(x_point); | |
next_y_vals.push_back(y_point); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment