diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..3be1ce78a5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,187 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Python", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${file}", + "cwd": "${workspaceFolder}", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: Attach", + "type": "python", + "request": "attach", + "localRoot": "${workspaceFolder}", + "remoteRoot": "${workspaceFolder}", + "port": 3000, + "secret": "my_secret", + "host": "localhost" + }, + { + "name": "Python: Terminal (integrated)", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${file}", + "cwd": "", + "console": "integratedTerminal", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [] + }, + { + "name": "Python: Terminal (external)", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${file}", + "cwd": "", + "console": "externalTerminal", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [] + }, + { + "name": "Python: Django", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${workspaceFolder}/manage.py", + "cwd": "${workspaceFolder}", + "args": [ + "runserver", + "--noreload", + "--nothreading" + ], + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput", + "DjangoDebugging" + ] + }, + { + "name": "Python: Flask (0.11.x or later)", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config:python.pythonPath}", + "program": "fully qualified path fo 'flask' executable. Generally located along with python interpreter", + "cwd": "${workspaceFolder}", + "env": { + "FLASK_APP": "${workspaceFolder}/quickstart/app.py" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: Flask (0.10.x or earlier)", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config:python.pythonPath}", + "program": "${workspaceFolder}/run.py", + "cwd": "${workspaceFolder}", + "args": [], + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: PySpark", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "osx": { + "pythonPath": "${env:SPARK_HOME}/bin/spark-submit" + }, + "windows": { + "pythonPath": "${env:SPARK_HOME}/bin/spark-submit.cmd" + }, + "linux": { + "pythonPath": "${env:SPARK_HOME}/bin/spark-submit" + }, + "program": "${file}", + "cwd": "${workspaceFolder}", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: Module", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "module": "module.name", + "cwd": "${workspaceFolder}", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + }, + { + "name": "Python: Pyramid", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "cwd": "${workspaceFolder}", + "env": {}, + "envFile": "${workspaceFolder}/.env", + "args": [ + "${workspaceFolder}/development.ini" + ], + "debugOptions": [ + "RedirectOutput", + "Pyramid" + ] + }, + { + "name": "Python: Watson", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${workspaceFolder}/console.py", + "cwd": "${workspaceFolder}", + "args": [ + "dev", + "runserver", + "--noreload=True" + ], + "env": {}, + "envFile": "${workspaceFolder}/.env", + "debugOptions": [ + "RedirectOutput" + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..fe79ecfcec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.pythonPath": "/home/kai/env/bin/python3.4", + "files.associations": { + "array": "cpp", + "*.ipp": "cpp" + } +} diff --git a/PathPlanning/DynamicWindowApproach/dynamic_window_approach.py b/PathPlanning/DynamicWindowApproach/dynamic_window_approach.py index aa74a43154..91dc67c786 100644 --- a/PathPlanning/DynamicWindowApproach/dynamic_window_approach.py +++ b/PathPlanning/DynamicWindowApproach/dynamic_window_approach.py @@ -4,13 +4,26 @@ author: Atsushi Sakai (@Atsushi_twi) +local minimum is the natural disadvantage of this method, global planning can relieve it partly + +local minimum is also sensitive to the weights in cost function, we can adjust the weights online by some method, such as RL. + +0 is 0, inf is inf, don't use small or big value to replace, use boolean value or floa("Inf") + """ +import os +import sys import math import numpy as np import matplotlib.pyplot as plt + +## get directory of matplotrecorder +github_root = os.path.join(os.path.dirname(__file__), '../../../') +sys.path.append(github_root) + from matplotrecorder import matplotrecorder -matplotrecorder.donothing = True +matplotrecorder.DO_NOTHING = True class Config(): @@ -18,23 +31,32 @@ class Config(): def __init__(self): # robot parameter - self.max_speed = 1.0 # [m/s] + self.max_speed = 2.0 # [m/s] self.min_speed = -0.5 # [m/s] self.max_yawrate = 40.0 * math.pi / 180.0 # [rad/s] + self.max_accel = 0.2 # [m/ss] self.max_dyawrate = 40.0 * math.pi / 180.0 # [rad/ss] + self.v_reso = 0.01 # [m/s] self.yawrate_reso = 0.1 * math.pi / 180.0 # [rad/s] + self.dt = 0.1 # [s] self.predict_time = 3.0 # [s] - self.to_goal_cost_gain = 1.0 - self.speed_cost_gain = 1.0 + + self.to_goal_cost_gain = 0.2 + self.speed_cost_gain = 0.45 + self.obs_cost_gain = 7.0 + self.robot_radius = 1.0 # [m] + self.goal_area = 0.3 # [m] def motion(x, u, dt): # motion model + ## TODO: real robot's state is sensed, not set by your control command + x[0] += u[0] * math.cos(x[2]) * dt x[1] += u[0] * math.sin(x[2]) * dt x[2] += u[1] * dt @@ -55,16 +77,15 @@ def calc_dynamic_window(x, config): x[3] + config.max_accel * config.dt, x[4] - config.max_dyawrate * config.dt, x[4] + config.max_dyawrate * config.dt] - # print(Vs, Vd) + # print(Vs, Vd) # [vmin,vmax, yawrate min, yawrate max] dw = [max(Vs[0], Vd[0]), min(Vs[1], Vd[1]), max(Vs[2], Vd[2]), min(Vs[3], Vd[3])] - # print(dw) + # print(dw) return dw - def calc_trajectory(xinit, v, y, config): x = np.array(xinit) @@ -82,9 +103,13 @@ def calc_trajectory(xinit, v, y, config): def calc_final_input(x, u, dw, config, goal, ob): xinit = x[:] - min_cost = 10000.0 + min_cost = float("Inf") min_u = u - min_u[0] = 0.0 + min_u[0] = 0.0 # real collision make the robot stop + # not necessary to keep a non-zero yawrate to escape from collision + # it will automatically change to a non-zero value + # this is the so called rotate away mode in original paper + # TODO: note that the inside of the current robot state should be forced to be collision free best_traj = np.array([x]) # evalucate all trajectory with sampled input in dynamic window @@ -92,11 +117,15 @@ def calc_final_input(x, u, dw, config, goal, ob): for y in np.arange(dw[2], dw[3], config.yawrate_reso): traj = calc_trajectory(xinit, v, y, config) - # calc cost - to_goal_cost = calc_to_goal_cost(traj, goal, config) - speed_cost = config.speed_cost_gain * \ - (config.max_speed - traj[-1, 3]) - ob_cost = calc_obstacle_cost(traj, ob, config) + ## TODO: normalization in cost + ## calc cost + ## dynamic window only consider one dt + ## but evaluation should be conducted on the whole trajectory + ## TODO: consider orientation relative to goal in goal cost + to_goal_cost = config.to_goal_cost_gain * calc_to_goal_cost(traj, goal, config) + speed_cost = config.speed_cost_gain * (config.max_speed - traj[-1, 3]) # TODO: neg. speed is penalized here, is this right? + ## TODO: do what the original paper says in obstacle cost + ob_cost = config.obs_cost_gain * calc_obstacle_cost(traj, ob, config) # print(ob_cost) final_cost = to_goal_cost + speed_cost + ob_cost @@ -126,13 +155,14 @@ def calc_obstacle_cost(traj, ob, config): dx = traj[ii, 0] - ox dy = traj[ii, 1] - oy - r = math.sqrt(dx**2 + dy**2) - if r <= config.robot_radius: + r = math.sqrt(dx**2 + dy**2) - config.robot_radius + if r <= 0 and ii != 0: # ignore the current state return float("Inf") # collisiton if minr >= r: minr = r + ## TODO: we should consider the distance between the margins of robot and obstacle return 1.0 / minr # OK @@ -142,7 +172,7 @@ def calc_to_goal_cost(traj, goal, config): dy = goal[0] - traj[-1, 0] dx = goal[1] - traj[-1, 1] goal_dis = math.sqrt(dx**2 + dy**2) - cost = config.to_goal_cost_gain * goal_dis + cost = goal_dis return cost @@ -166,20 +196,29 @@ def plot_arrow(x, y, yaw, length=0.5, width=0.1): def main(): print(__file__ + " start!!") # initial state [x(m), y(m), yaw(rad), v(m/s), omega(rad/s)] - x = np.array([0.0, 0.0, math.pi / 8.0, 0.0, 0.0]) + x = np.array([0.0, 0.0, math.pi / 2.0, 0.0, 0.0]) # goal position [x(m), y(m)] - goal = np.array([10, 10]) + goal = np.array([0, 20]) # obstacles [x(m) y(m), ....] - ob = np.matrix([[-1, -1], - [0, 2], - [4.0, 2.0], - [5.0, 4.0], - [5.0, 5.0], - [5.0, 6.0], - [5.0, 9.0], - [8.0, 9.0], - [7.0, 9.0], - [12.0, 12.0] + ob = np.matrix([[-4.0, 5.0], + [-4.0, 6.0], + [-4.0, 7.0], + [-4.0, 8.0], + [-4.0, 9.0], + [-4.0, 10.0], + [-3.0, 10.0], + [-2.0, 10.0], + [-1.0, 10.0], + [0.0, 10.0], + [1.0, 10.0], + [2.0, 10.0], + [3.0, 10.0], + [4.0, 10.0], + [5.0, 10.0], + [6.0, 10.0], + [7.0, 10.0], + [8.0, 10.0], + [9.0, 10.0] ]) u = np.array([0.0, 0.0]) @@ -187,6 +226,14 @@ def main(): traj = np.array(x) for i in range(1000): + print("################# STEP {} #################".format(i)) + + # if i == 330: + # config.to_goal_cost_gain = 0.0 + # config.speed_cost_gain = 0.0 + # config.obs_cost_gain = 999 + # print("################# escape ################# ") + plt.cla() u, ltraj = dwa_control(x, u, config, goal, ob) @@ -198,20 +245,30 @@ def main(): plt.plot(goal[0], goal[1], "xb") plt.plot(ob[:, 0], ob[:, 1], "ok") plot_arrow(x[0], x[1], x[2]) + + ## print v and yawrate + print("v = {:.5f}m/s\tyawrate = {:.5f}rad/s".format(x[3], x[4])) + + ## darw circle ((x[0], x[1]), config.robot_radius) + angles_circle = [kk * math.pi / 180.0 for kk in range(0, 360)] + cir_x = config.robot_radius * np.cos(angles_circle) + x[0] + cir_y = config.robot_radius * np.sin(angles_circle) + x[1] + plt.plot(cir_x, cir_y, '-r') + plt.axis("equal") plt.grid(True) plt.pause(0.0001) matplotrecorder.save_frame() # check goal - if math.sqrt((x[0] - goal[0])**2 + (x[1] - goal[1])**2) <= config.robot_radius: + if math.sqrt((x[0] - goal[0])**2 + (x[1] - goal[1])**2) <= config.goal_area: print("Goal!!") break print("Done") plt.plot(traj[:, 0], traj[:, 1], "-r") matplotrecorder.save_frame() - matplotrecorder.save_movie("animation.gif", 0.1) + matplotrecorder.save_movie("animation.gif", config.dt) plt.show() diff --git a/PathPlanning/DynamicWindowApproach/animation.gif b/PathPlanning/DynamicWindowApproach/results/0/animation.gif similarity index 100% rename from PathPlanning/DynamicWindowApproach/animation.gif rename to PathPlanning/DynamicWindowApproach/results/0/animation.gif diff --git a/PathPlanning/DynamicWindowApproach/results/1/1.png b/PathPlanning/DynamicWindowApproach/results/1/1.png new file mode 100644 index 0000000000..79a2711062 Binary files /dev/null and b/PathPlanning/DynamicWindowApproach/results/1/1.png differ diff --git a/PathPlanning/DynamicWindowApproach/results/1/animation.gif b/PathPlanning/DynamicWindowApproach/results/1/animation.gif new file mode 100644 index 0000000000..de13e92356 Binary files /dev/null and b/PathPlanning/DynamicWindowApproach/results/1/animation.gif differ diff --git a/PathPlanning/DynamicWindowApproach/results/1/animation.mp4 b/PathPlanning/DynamicWindowApproach/results/1/animation.mp4 new file mode 100644 index 0000000000..719acade89 Binary files /dev/null and b/PathPlanning/DynamicWindowApproach/results/1/animation.mp4 differ diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/lookuptable_generator.py b/PathPlanning/ModelPredictiveTrajectoryGenerator/lookuptable_generator.py index 57597a9d52..16d444cd80 100644 --- a/PathPlanning/ModelPredictiveTrajectoryGenerator/lookuptable_generator.py +++ b/PathPlanning/ModelPredictiveTrajectoryGenerator/lookuptable_generator.py @@ -2,6 +2,8 @@ Lookup Table generation for model predictive trajectory generator author: Atsushi Sakai + +The initial state is assumed to be (0, 0, 0) in this program. Other initial states can be rotated and translated to (0, 0, 0). """ from matplotlib import pyplot as plt import numpy as np @@ -37,7 +39,7 @@ def search_nearest_one_from_lookuptable(tx, ty, tyaw, lookuptable): dx = tx - table[0] dy = ty - table[1] dyaw = tyaw - table[2] - d = math.sqrt(dx ** 2 + dy ** 2 + dyaw ** 2) + d = math.sqrt(dx ** 2 + dy ** 2 + dyaw ** 2) # Euclidean norm if d <= mind: minid = i mind = d @@ -49,7 +51,7 @@ def search_nearest_one_from_lookuptable(tx, ty, tyaw, lookuptable): def save_lookup_table(fname, table): mt = np.array(table) - print(mt) + # print(mt) # save csv df = pd.DataFrame() df["x"] = mt[:, 0] @@ -58,25 +60,30 @@ def save_lookup_table(fname, table): df["s"] = mt[:, 3] df["km"] = mt[:, 4] df["kf"] = mt[:, 5] - df.to_csv(fname, index=None) + # df.to_csv(fname, index=None) + df.to_csv(fname) print("lookup table file is saved as " + fname) def generate_lookup_table(): - states = calc_states_list() + states = calc_states_list() # calculate target states k0 = 0.0 - # x, y, yaw, s, km, kf + # target_x, target_y, target_yaw -> s, km, kf lookuptable = [[1.0, 0.0, 0.0, 1.0, 0.0, 0.0]] - for state in states: + print("Lookup Table is being generated......") + + for idx, state in enumerate(states): bestp = search_nearest_one_from_lookuptable( state[0], state[1], state[2], lookuptable) target = motion_model.State(x=state[0], y=state[1], yaw=state[2]) + # init_p = np.matrix( + # [math.sqrt(state[0] ** 2 + state[1] ** 2), bestp[4], bestp[5]]).T init_p = np.matrix( - [math.sqrt(state[0] ** 2 + state[1] ** 2), bestp[4], bestp[5]]).T + [bestp[3], bestp[4], bestp[5]]).T x, y, yaw, p = planner.optimize_trajectory(target, k0, init_p) @@ -85,6 +92,10 @@ def generate_lookup_table(): lookuptable.append( [x[-1], y[-1], yaw[-1], float(p[0]), float(p[1]), float(p[2])]) + ## print percent of progress + percent = 100 * (idx + 1.0) / len(states) + print("Complete %{}...".format(percent)) + print("finish lookup table generation") save_lookup_table("lookuptable.csv", lookuptable) @@ -94,7 +105,10 @@ def generate_lookup_table(): table[3], table[4], table[5], k0) plt.plot(xc, yc, "-r") xc, yc, yawc = motion_model.generate_trajectory( - table[3], -table[4], -table[5], k0) + table[3], -table[4], -table[5], k0) # symmetrical, this is why target_yaw inlcude only -30 degree and exclude +30 degree + # similar for target_y, note that not for target_x + # also note that here change the sign of steering make the sign of target_yaw + # and target_y change at the same time plt.plot(xc, yc, "-r") plt.grid(True) diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/model_predictive_trajectory_generator.py b/PathPlanning/ModelPredictiveTrajectoryGenerator/model_predictive_trajectory_generator.py index 4d14a90b1a..b26dce96d7 100644 --- a/PathPlanning/ModelPredictiveTrajectoryGenerator/model_predictive_trajectory_generator.py +++ b/PathPlanning/ModelPredictiveTrajectoryGenerator/model_predictive_trajectory_generator.py @@ -2,22 +2,57 @@ Model trajectory generator author: Atsushi Sakai + +This sample program doesn't optimize the cost function in the original paper. + +The initial state is assumed to be (0, 0, 0) in this program. Other initial states can be rotated and translated to (0, 0, 0). + +the design of p can be improved, only two steer, v is connstant, no acceleration and deacceleration + +Jacobian: the calculation of Jacobian may be not right? (if steer limit is small, can't optimize!? or cost threshold too small?), +Jacobian: up and down at the starting of optimization is also a problem +Jacobian: what is the optimization's theory? +Jacobian: if the initial path is too long, can't optimize!? +Jacobian: what we are optimizing? +Jacobian: maybe local minimum cause the failure of optimization? +Jacobian: too close target also doesn't work, of cource this is partly related to the amplitude of steering, but the process is not too right """ +import os +import sys import numpy as np import matplotlib.pyplot as plt import math import motion_model +from colorama import init as clr_ama_init +from colorama import Fore +clr_ama_init(autoreset = True) # anto reset to default color if color not set + +## get directory of matplotrecorder +github_root = os.path.join(os.path.dirname(__file__), '../../../') +sys.path.append(github_root) + from matplotrecorder import matplotrecorder # optimization parameter -max_iter = 100 -h = np.matrix([0.5, 0.02, 0.02]).T # parameter sampling distanse +max_iter = 150 +h = np.matrix([0.5, 0.02, 0.02]).T # parameter sampling distance cost_th = 0.1 -matplotrecorder.donothing = True +matplotrecorder.DO_NOTHING = True show_graph = False +def limitP(p, cfg): + p[1, 0] = np.clip(p[1, 0], cfg.min_steer, cfg.max_steer) + p[2, 0] = np.clip(p[2, 0], cfg.min_steer, cfg.max_steer) + + return p + +def limitDp(dp, cfg, p): + dp[1, 0] = np.clip(dp[1, 0], cfg.min_steer - p[1, 0], cfg.max_steer - p[1, 0]) + dp[2, 0] = np.clip(dp[2, 0], cfg.min_steer - p[2, 0], cfg.max_steer - p[2, 0]) + + return dp def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"): u""" @@ -38,13 +73,15 @@ def calc_diff(target, x, y, yaw): def calc_J(target, p, h, k0): + ## change of x (R^3) is the function of p(R^3) + xp, yp, yawp = motion_model.generate_last_state( p[0, 0] + h[0, 0], p[1, 0], p[2, 0], k0) - dp = calc_diff(target, [xp], [yp], [yawp]) + dp = calc_diff(target, [xp], [yp], [yawp]) # Eq. (13) in paper xn, yn, yawn = motion_model.generate_last_state( p[0, 0] - h[0, 0], p[1, 0], p[2, 0], k0) dn = calc_diff(target, [xn], [yn], [yawn]) - d1 = np.matrix((dp - dn) / (2.0 * h[1, 0])).T + d1 = np.matrix((dp - dn) / (2.0 * h[1, 0])).T # Eq. (16) in paper xp, yp, yawp = motion_model.generate_last_state( p[0, 0], p[1, 0] + h[1, 0], p[2, 0], k0) @@ -70,9 +107,9 @@ def calc_J(target, p, h, k0): def selection_learning_param(dp, p, k0, target): mincost = float("inf") - mina = 1.0 - maxa = 2.0 - da = 0.5 + mina = 0.6 + maxa = 1.4 # for np.arange, can not reach max + da = 0.2 for a in np.arange(mina, maxa, da): tp = p[:, :] + a * dp @@ -103,6 +140,7 @@ def show_trajectory(target, xc, yc): def optimize_trajectory(target, k0, p): + mcfg = motion_model.ModelConfig() for i in range(max_iter): xc, yc, yawc = motion_model.generate_trajectory(p[0], p[1], p[2], k0) dc = np.matrix(calc_diff(target, xc, yc, yawc)).T @@ -110,42 +148,52 @@ def optimize_trajectory(target, k0, p): cost = np.linalg.norm(dc) if cost <= cost_th: + ## optimize success print("path is ok cost is:" + str(cost)) break J = calc_J(target, p, h, k0) try: - dp = - np.linalg.inv(J) * dc + dp = - np.linalg.inv(J) * dc # Eq. (14) in paper + dp = limitDp(dp, mcfg, p) except np.linalg.linalg.LinAlgError: - print("cannot calc path LinAlgError") + ## optimize fail + print(Fore.YELLOW + "cannot calc path LinAlgError") xc, yc, yawc, p = None, None, None, None break - alpha = selection_learning_param(dp, p, k0, target) + alpha = selection_learning_param(dp, p, k0, target) # choose learning rate p += alpha * np.array(dp) + p = limitP(p, mcfg) # print(p.T) if show_graph: show_trajectory(target, xc, yc) else: + ## optimize fail + ## if no break, enter here xc, yc, yawc, p = None, None, None, None - print("cannot calc path") + print(Fore.YELLOW + "cannot calc path") return xc, yc, yawc, p def test_optimize_trajectory(): + mcfg = motion_model.ModelConfig() # target = motion_model.State(x=5.0, y=2.0, yaw=math.radians(00.0)) - target = motion_model.State(x=5.0, y=2.0, yaw=math.radians(90.0)) + target = motion_model.State(x=1.0, y=0.0, yaw=math.radians(30.0)) k0 = 0.0 - init_p = np.matrix([6.0, 0.0, 0.0]).T + init_p_len = math.sqrt(target.x**2 + target.y**2) + init_p = np.matrix([init_p_len, 0.0, 0.0]).T + init_p = limitP(init_p, mcfg) x, y, yaw, p = optimize_trajectory(target, k0, init_p) + p = limitP(p, mcfg) show_trajectory(target, x, y) - matplotrecorder.save_movie("animation.gif", 0.1) + matplotrecorder.save_movie("animation.mp4", 0.1) # plt.plot(x, y, "-r") plot_arrow(target.x, target.y, target.yaw) plt.axis("equal") @@ -159,11 +207,11 @@ def test_trajectory_generate(): km = math.radians(30.0) kf = math.radians(-30.0) - # plt.plot(xk, yk, "xr") - # plt.plot(t, kp) - # plt.show() + # plt.plot(xk, yk, "xr") + # plt.plot(t, kp) + # plt.show() - x, y = motion_model.generate_trajectory(s, km, kf, k0) + x, y, _ = motion_model.generate_trajectory(s, km, kf, k0) plt.plot(x, y, "-r") plt.axis("equal") @@ -173,7 +221,7 @@ def test_trajectory_generate(): def main(): print(__file__ + " start!!") - # test_trajectory_generate() + # test_trajectory_generate() test_optimize_trajectory() diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/motion_model.py b/PathPlanning/ModelPredictiveTrajectoryGenerator/motion_model.py index b31d731956..17384339c5 100644 --- a/PathPlanning/ModelPredictiveTrajectoryGenerator/motion_model.py +++ b/PathPlanning/ModelPredictiveTrajectoryGenerator/motion_model.py @@ -1,6 +1,7 @@ import math import numpy as np import scipy.interpolate +import matplotlib.pyplot as plt # motion parameter L = 1.0 # wheel base @@ -16,6 +17,12 @@ def __init__(self, x=0.0, y=0.0, yaw=0.0, v=0.0): self.yaw = yaw self.v = v +class ModelConfig: + + def __init__(self): + self.min_steer = math.radians(-40.0) + self.max_steer = math.radians(40.0) + def pi_2_pi(angle): while(angle > math.pi): @@ -29,6 +36,13 @@ def pi_2_pi(angle): def update(state, v, delta, dt, L): + ## Ackermann model + ## limit amplitude + ## TODO: actual path length isn't equal to path length (s or p[0]) in parameterized control sequence (p)? + + model_cfg = ModelConfig() + delta = np.clip(delta, model_cfg.min_steer, model_cfg.max_steer) # steering min and max [rad] + state.v = v state.x = state.x + state.v * math.cos(state.yaw) * dt state.y = state.y + state.v * math.sin(state.yaw) * dt @@ -46,10 +60,10 @@ def generate_trajectory(s, km, kf, k0): kk = np.array([k0, km, kf]) t = np.arange(0.0, time, time / n) kp = scipy.interpolate.spline(tk, kk, t, order=2) - dt = float(time / n) + dt = float(time / n) # discretized by equal distance "ds" - # plt.plot(t, kp) - # plt.show() + # plt.plot(t, kp) + # plt.show() state = State() x, y, yaw = [state.x], [state.y], [state.yaw] @@ -78,5 +92,5 @@ def generate_last_state(s, km, kf, k0): state = State() - [update(state, v, ikp, dt, L) for ikp in kp] + [update(state, v, ikp, dt, L) for ikp in kp] # for class, no return is ok, this has been tested. return state.x, state.y, state.yaw diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/animation2.gif b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/0/animation2.gif similarity index 100% rename from PathPlanning/ModelPredictiveTrajectoryGenerator/animation2.gif rename to PathPlanning/ModelPredictiveTrajectoryGenerator/results/0/animation2.gif diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/k0animation.gif b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/0/k0animation.gif similarity index 100% rename from PathPlanning/ModelPredictiveTrajectoryGenerator/k0animation.gif rename to PathPlanning/ModelPredictiveTrajectoryGenerator/results/0/k0animation.gif diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/kn05animation.gif b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/0/kn05animation.gif similarity index 100% rename from PathPlanning/ModelPredictiveTrajectoryGenerator/kn05animation.gif rename to PathPlanning/ModelPredictiveTrajectoryGenerator/results/0/kn05animation.gif diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/lookuptable.png b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/0/lookuptable.png similarity index 100% rename from PathPlanning/ModelPredictiveTrajectoryGenerator/lookuptable.png rename to PathPlanning/ModelPredictiveTrajectoryGenerator/results/0/lookuptable.png diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/results/1/animation.gif b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/1/animation.gif new file mode 100644 index 0000000000..d2a7883676 Binary files /dev/null and b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/1/animation.gif differ diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/results/1/animation.mp4 b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/1/animation.mp4 new file mode 100644 index 0000000000..65be7d740c Binary files /dev/null and b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/1/animation.mp4 differ diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/results/2/animation.mp4 b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/2/animation.mp4 new file mode 100644 index 0000000000..e6b3af9f51 Binary files /dev/null and b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/2/animation.mp4 differ diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/lookuptable.csv b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/lookuptable.csv new file mode 100644 index 0000000000..ed1171e801 --- /dev/null +++ b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/lookuptable.csv @@ -0,0 +1,104 @@ +x,y,yaw,s,km,kf +1.0,0.0,0.0,1.0,0.0,0.0 +5.934183915194526,0.005405611332146738,0.5514520266182511,6.0,0.004365827717049513,0.5324282429269979 +10.969274192116142,0.03216071121115148,0.5493819212957336,11.000661862845583,0.0009399497626589406,0.28364246593382375 +15.94579103502118,0.03555018800694434,0.48807487892997536,16.007140502807186,0.0005655371642669476,0.1767655799081687 +20.95416262014933,0.046955608322188876,0.534339975385096,21.100379687851962,0.00044513207975985827,0.1474577637627991 +25.908865241713197,-0.012384398120037735,0.5193588602291844,26.107910115747732,6.199851140250445e-05,0.11765912164508979 +5.945747279038813,1.9590562091669046,0.517638668441123,6.312543943336395,0.1528613033555711,-0.11804270366817947 +10.977653810076534,2.0073571475798366,0.5262312225312316,11.202688358067665,0.048951803364724066,0.08355544937094767 +15.907573553457881,1.9748365587785348,0.5201426739804866,16.12570285645692,0.023327802848135563,0.0990533712226529 +20.977532394950202,2.027075674620532,0.5298010817437455,21.20212425288145,0.013792007019379266,0.09329829384322663 +25.94572698767402,2.025677459358005,0.528678153141794,26.200936432591117,0.009039525768775734,0.08383289991871018 +5.95990852961219,3.941060388037972,0.5323693326412191,7.5065412620116865,0.23177598606042482,-0.48257450643011246 +10.935884647118447,3.925370124215551,0.5068006963580796,11.808417839398922,0.08802610934843358,-0.09311976839250888 +15.952417762803327,3.9775236065103514,0.5198766857284765,16.60075955935451,0.04442226833579014,0.009951918859625267 +20.949087555318403,3.9940948490948003,0.5238093624227865,21.502281294208785,0.026454875983218443,0.039768176225094376 +25.985268455942407,4.016660219807042,0.5261824300175458,26.501662198568287,0.017481590315867546,0.048627417442342245 +5.97924611215104,5.9500654137079385,0.5370931053328587,9.308018129091295,0.24820988067134767,-0.6138815031889495 +11.029887109905536,5.964622548372629,0.4979648891556849,13.002553061864567,0.11441688874913211,-0.2231234874931787 +15.989215639588322,5.965673171119106,0.5133288440673606,17.403147450340132,0.06175740911797624,-0.06910069097022259 +20.970483915713434,5.977342589990561,0.5194936917077476,22.10066411645723,0.037838925396880295,-0.010227631827625573 +25.93082342700779,5.972937112084193,0.5216823291066396,26.90108441245977,0.02535774511747541,0.01474553148231285 +6.004728749524293,7.971997510978571,0.522820660295624,11.507234925211806,0.23646959035027065,-0.636676769786486 +10.965827964891812,7.944698640247776,0.5288305112808684,14.405314612395072,0.13008707469637584,-0.29373530466377706 +15.936143379989273,7.930464775985118,0.524642370499414,18.410856653889642,0.07530372487041755,-0.1287581784532251 +20.965162258270695,7.942946435675094,0.5149380641775931,22.905925418402315,0.047534917611530864,-0.0546998371842749 +25.9701051346819,7.970710048321492,0.5194346204670051,27.60059638234513,0.03245556867532292,-0.016751087853224586 +5.99013914239,9.965673147630298,0.5374906698523683,13.907128842934997,0.21741570009117225,-0.6064383409544339 +10.98052148510162,9.983014128462647,0.5307161812650916,16.20588701497373,0.1356436727565411,-0.3382860668017521 +16.031476186550417,9.942281738920256,0.5031905777370667,19.803130702616883,0.08397228170866237,-0.18075335188175684 +21.017729998698556,9.966901423121303,0.5124905755008868,24.000352901989118,0.05537507259203249,-0.09230295969694866 +25.940755548083505,9.920002489717708,0.5159824688426303,28.4050840303573,0.03863181923115752,-0.04514799663051309 +6.01302612184734,11.975672612665589,0.5233110935499182,16.506998456741183,0.1966009995549466,-0.5699064484075126 +10.999617614932653,11.981314969497422,0.5233488274974134,18.205708249597116,0.1351920531253496,-0.35970535479777493 +15.965440595463313,11.939667218575659,0.5271765548232162,21.308615341930427,0.0900760981263959,-0.20907795596297815 +21.00551572105455,11.917747906409005,0.5089483573924627,25.203887966491692,0.06136602152526883,-0.12296600895727972 +26.0022720147687,11.9530254718608,0.5147702244666441,29.505425256342157,0.04381936697848015,-0.07000303244821515 +1.047189675722912,13.969722827151239,0.5391101706919981,20.812958911675786,0.20748371809921923,-0.6401683985581305 +6.013020941274695,13.980226927883933,0.5234283532864134,19.204029242841038,0.17797853667449678,-0.5269238240747315 +10.994848377699613,13.917218176909216,0.5307095983315354,20.30777911183574,0.13178728804332976,-0.3621854400850839 +16.06713018814428,13.930758927275294,0.4981356239925087,23.102474647656077,0.09227688127603328,-0.23601851810797148 +20.954902639764526,13.930153243560216,0.5257166248098417,26.610630483144114,0.06597500393334328,-0.14402640117438303 +26.015461721905297,13.945391653149361,0.5128704389430422,30.705904668742022,0.04802964927670199,-0.09113855133464518 +1.0276276840001535,15.97521264134705,0.5368166290929105,23.910740487195902,0.18227521043745992,-0.569752825742308 +6.0357040634317745,15.9326924498329,0.5342589485444893,21.913418729870425,0.1617810534646692,-0.4852883338606933 +11.003632083132342,15.982729623803403,0.5234563553969972,22.706229176369558,0.12625951398130855,-0.3587793894776 +15.980283701178461,15.974007905686557,0.5285133370149352,25.006801073636026,0.09353607914412403,-0.24387818761652774 +20.963501220483074,15.932045796564047,0.5262556386798449,28.208370409178734,0.06884687139009235,-0.16184852807204098 +25.954566708145673,15.939710795417964,0.5251303371290894,32.00376163249387,0.05152015448877997,-0.10670024992489906 +1.0102855855867496,17.97908939009517,0.5351185364650618,27.00677056231159,0.16248635238417589,-0.5124629125588577 +5.991197853878843,17.976744834652358,0.5333416828096283,24.807593611535314,0.14764178417129628,-0.44846797159561813 +10.994854776378206,17.955905546296897,0.5307863398435816,25.10908889543992,0.12032598779817263,-0.34755677631489823 +15.986191435340405,17.917291883603518,0.5282323737398233,27.01190628221328,0.0927556838860843,-0.2504707482220659 +21.064409500600785,17.928762441968917,0.5044862533055923,30.00382679300119,0.07015760671635658,-0.1777818328125267 +25.962618329143424,17.944694664224894,0.5255710054553666,33.507658249041874,0.053977247788378244,-0.12083501407795985 +0.9999999999999999,0.0,0.0,1.0,0.0,0.0 +5.9996121147529635,0.00730929049373172,-0.04016757104872042,5.996792870451032,0.0002864504738219918,-0.0433286610355218 +10.999686154598917,-0.013246527379861444,0.02542201208530931,10.99092136807903,-0.00027174671528077494,0.015304601794634609 +15.999921755173412,-0.015974401494053728,0.009501951052983916,15.994350910320302,-0.00017683928255137296,0.004343822144805803 +20.999865351191875,-0.03319847294695509,0.009663654293547484,20.99100136883842,-0.00022006178980510388,0.0036855392330720493 +25.999867564251073,-0.04191720377669392,0.007913430867482894,25.989148275454486,-0.0001830536696644254,0.0025824399042456425 +5.952100129553903,1.9778464945327534,-0.03107351924056645,6.323896141120901,0.1530705954454068,-0.5978649824552916 +10.952344146457863,1.992260151157743,0.004172569722418373,11.177441626328559,0.04836641615798731,-0.19326095905805046 +16.02849691482329,2.0071012583632584,0.008548786999047172,16.116223585841446,0.02330598084400782,-0.0888390736513063 +20.97180567983339,1.984648268735215,0.0067309519348971785,21.086967679142997,0.013434437164992038,-0.05235572297760982 +25.99736702293876,1.9784967849643929,0.006979712145014468,26.06544930827501,0.008755545918577988,-0.033530501305256005 +10.935453773277805,3.965683306928956,0.008154294377782721,11.80388116383699,0.08886880047091393,-0.3385833051458505 +15.926636111946964,3.9746885810760655,0.003919863693058943,16.50472075483697,0.044665717816590095,-0.17374076638227892 +20.988211535034793,3.957896415640341,-0.010125219536219721,21.401607458148856,0.026235140421129836,-0.10618805394239166 +25.985620837457553,3.9578134064180754,-0.00914313088831196,26.30054227897991,0.017301177552678577,-0.07045081415177712 +10.970369922967693,5.988300531407694,0.009867910763688807,13.002854860052054,0.11548209060570723,-0.43739215537843784 +16.01875224981119,5.933042699839213,-0.02415142953131343,17.404430948165004,0.06135332753306763,-0.24795240546066102 +20.963597565242466,5.91955641888566,-0.014303946557529654,22.00653504555401,0.03763776370731319,-0.152216645161062 +25.972488075994065,5.9408149625139925,-0.009626526982450022,26.80558528296207,0.02523944465141781,-0.10196944067307973 +10.964959897904377,7.965054036754775,0.011763242119061185,14.508063641306126,0.12968168929746343,-0.4905958676797794 +15.97418470714956,7.994579085018131,0.006234293453112865,18.505922046409598,0.0753462289009922,-0.29218614286940786 +20.99601824559866,7.912482592869397,-0.018203447219137164,22.906133215439876,0.04731184105019175,-0.1909752142054268 +25.966383934972487,7.913829381946609,-0.01224617006905617,27.504765109324275,0.03234389854294942,-0.13049086684002664 +10.969134173040011,9.940332735358124,0.012891249402341633,16.31251897818367,0.13477893606522556,-0.5107483210238818 +15.99341595981961,9.990328961894047,0.00013932100337728237,19.90575912817816,0.08414790828182576,-0.3279089886455371 +20.96679302538247,9.986820506741104,0.004674761097046998,24.00727865692623,0.055616249438317306,-0.21774804434967535 +25.941902331672214,9.969282080340271,0.0034441445579561723,28.40511012829969,0.03881504072090396,-0.15266476306313967 +6.021387265124099,11.982584554803791,0.0619205367251186,16.807632400271277,0.19376349049457703,-0.6981317007977318 +10.978055479305647,11.971174051816263,0.012018418719579226,18.407379812244866,0.1341782485690368,-0.5092616898369976 +15.975525182408454,11.993577495261796,0.007467004371503862,21.505219245161303,0.08968698135931524,-0.3472766990624416 +20.96549643457338,11.980511052381956,0.0052444147732229884,25.302220154530886,0.06157444802296901,-0.2406694491660568 +25.953703755756163,11.973597439317075,0.0038229396719086234,29.50313647754905,0.043997517782207375,-0.17295345774509066 +6.0165336608823745,13.952107280107047,0.017430531922791037,19.610668909286897,0.17479324115073436,-0.6504808406230865 +10.993564813822987,13.917657524716438,0.013034187987974781,20.614125970500076,0.13019583708624366,-0.4967080460397468 +15.973434879881712,13.977597735935445,0.007959243395739744,23.30779254206784,0.09222221346693725,-0.3574646080513337 +20.970859212501967,13.98547236516948,0.005532903491342632,26.808041612485553,0.06575348990187455,-0.25734142418207917 +26.03581471613072,13.908897344375086,-0.018534119669600446,30.803643028824563,0.047797416328487136,-0.19221312068619223 +1.0628058924296457,15.984930849178589,0.018551885964324236,24.81534267554288,0.17609904286262462,-0.6578471506907968 +6.01962610936885,15.957570491711625,0.015509828050043348,22.51160003719807,0.15825763969556614,-0.5960207124638933 +11.008156936600685,15.908632907600232,0.012728793080601541,23.013028478847996,0.12462667450164781,-0.4772745140567172 +15.976273988698015,15.986680147056422,0.007846666865800225,25.308082572604224,0.09270099854647953,-0.35977902410825735 +20.954961154758088,15.929119185200921,0.006474182682246497,28.40896665795771,0.06849272704911687,-0.26800510926057863 +25.985860464061282,15.978545293919986,0.0002249129336966485,32.20170071598359,0.05133234241162024,-0.20248367036552462 +1.0079858111878683,17.99135843905021,0.014549187840126543,28.108487380717616,0.1567296513076089,-0.592361253858606 +5.995182546251699,17.981229571789623,0.01300492680865073,25.509101765362605,0.14408506171121896,-0.5475450175053673 +10.99256109126772,17.96396089500506,0.010759396656982077,25.610723074710805,0.11835766490426275,-0.455224799951496 +15.980714121403354,17.950968795069087,0.008369095811351257,27.41059404283746,0.09174908542307228,-0.35666362687139425 +20.960834081332603,17.91599620367308,0.006770598303988799,30.215200725543003,0.06998426392022473,-0.27426813569485314 +25.95412767133884,17.945700743778684,0.004909078296815111,33.70820574556154,0.053756122035816714,-0.21146781281706867 diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/lookuptable_Calc.csv b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/lookuptable_Calc.csv new file mode 100644 index 0000000000..1d4f4e0857 --- /dev/null +++ b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/lookuptable_Calc.csv @@ -0,0 +1,104 @@ +x,y,yaw,s,km,kf +1,0,0,1,0,0 +5.9341839152,0.0054056113,0.5514520266,6,0.0043658277,0.5324282429 +10.9692741921,0.0321607112,0.5493819213,11.0006618628,0.0009399498,0.2836424659 +15.945791035,0.035550188,0.4880748789,16.0071405028,0.0005655372,0.1767655799 +20.9541626201,0.0469556083,0.5343399754,21.1003796879,0.0004451321,0.1474577638 +25.9088652417,-0.0123843981,0.5193588602,26.1079101157,6.19985114025044E-005,0.1176591216 +5.945747279,1.9590562092,0.5176386684,6.3125439433,0.1528613034,-0.1180427037 +10.9776538101,2.0073571476,0.5262312225,11.2026883581,0.0489518034,0.0835554494 +15.9075735535,1.9748365588,0.520142674,16.1257028565,0.0233278028,0.0990533712 +20.977532395,2.0270756746,0.5298010817,21.2021242529,0.013792007,0.0932982938 +25.9457269877,2.0256774594,0.5286781531,26.2009364326,0.0090395258,0.0838328999 +5.9599085296,3.941060388,0.5323693326,7.506541262,0.2317759861,-0.4825745064 +10.9358846471,3.9253701242,0.5068006964,11.8084178394,0.0880261093,-0.0931197684 +15.9524177628,3.9775236065,0.5198766857,16.6007595594,0.0444222683,0.0099519189 +20.9490875553,3.9940948491,0.5238093624,21.5022812942,0.026454876,0.0397681762 +25.9852684559,4.0166602198,0.52618243,26.5016621986,0.0174815903,0.0486274174 +5.9792461122,5.9500654137,0.5370931053,9.3080181291,0.2482098807,-0.6138815032 +11.0298871099,5.9646225484,0.4979648892,13.0025530619,0.1144168887,-0.2231234875 +15.9892156396,5.9656731711,0.5133288441,17.4031474503,0.0617574091,-0.069100691 +20.9704839157,5.97734259,0.5194936917,22.1006641165,0.0378389254,-0.0102276318 +25.930823427,5.9729371121,0.5216823291,26.9010844125,0.0253577451,0.0147455315 +6.0047287495,7.971997511,0.5228206603,11.5072349252,0.2364695904,-0.6366767698 +10.9658279649,7.9446986402,0.5288305113,14.4053146124,0.1300870747,-0.2937353047 +15.93614338,7.930464776,0.5246423705,18.4108566539,0.0753037249,-0.1287581785 +20.9651622583,7.9429464357,0.5149380642,22.9059254184,0.0475349176,-0.0546998372 +25.9701051347,7.9707100483,0.5194346205,27.6005963823,0.0324555687,-0.0167510879 +5.9901391424,9.9656731476,0.5374906699,13.9071288429,0.2174157001,-0.606438341 +10.9805214851,9.9830141285,0.5307161813,16.205887015,0.1356436728,-0.3382860668 +16.0314761866,9.9422817389,0.5031905777,19.8031307026,0.0839722817,-0.1807533519 +21.0177299987,9.9669014231,0.5124905755,24.000352902,0.0553750726,-0.0923029597 +25.9407555481,9.9200024897,0.5159824688,28.4050840304,0.0386318192,-0.0451479966 +6.0130261218,11.9756726127,0.5233110935,16.5069984567,0.1966009996,-0.5699064484 +10.9996176149,11.9813149695,0.5233488275,18.2057082496,0.1351920531,-0.3597053548 +15.9654405955,11.9396672186,0.5271765548,21.3086153419,0.0900760981,-0.209077956 +21.0055157211,11.9177479064,0.5089483574,25.2038879665,0.0613660215,-0.122966009 +26.0022720148,11.9530254719,0.5147702245,29.5054252563,0.043819367,-0.0700030324 +1.0471896757,13.9697228272,0.5391101707,20.8129589117,0.2074837181,-0.6401683986 +6.0130209413,13.9802269279,0.5234283533,19.2040292428,0.1779785367,-0.5269238241 +10.9948483777,13.9172181769,0.5307095983,20.3077791118,0.131787288,-0.3621854401 +16.0671301881,13.9307589273,0.498135624,23.1024746477,0.0922768813,-0.2360185181 +20.9549026398,13.9301532436,0.5257166248,26.6106304831,0.0659750039,-0.1440264012 +26.0154617219,13.9453916531,0.5128704389,30.7059046687,0.0480296493,-0.0911385513 +1.027627684,15.9752126413,0.5368166291,23.9107404872,0.1822752104,-0.5697528257 +6.0357040634,15.9326924498,0.5342589485,21.9134187299,0.1617810535,-0.4852883339 +11.0036320831,15.9827296238,0.5234563554,22.7062291764,0.126259514,-0.3587793895 +15.9802837012,15.9740079057,0.528513337,25.0068010736,0.0935360791,-0.2438781876 +20.9635012205,15.9320457966,0.5262556387,28.2083704092,0.0688468714,-0.1618485281 +25.9545667081,15.9397107954,0.5251303371,32.0037616325,0.0515201545,-0.1067002499 +1.0102855856,17.9790893901,0.5351185365,27.0067705623,0.1624863524,-0.5124629126 +5.9911978539,17.9767448347,0.5333416828,24.8075936115,0.1476417842,-0.4484679716 +10.9948547764,17.9559055463,0.5307863398,25.1090888954,0.1203259878,-0.3475567763 +15.9861914353,17.9172918836,0.5282323737,27.0119062822,0.0927556839,-0.2504707482 +21.0644095006,17.928762442,0.5044862533,30.003826793,0.0701576067,-0.1777818328 +25.9626183291,17.9446946642,0.5255710055,33.507658249,0.0539772478,-0.1208350141 +1,0,0,1,0,0 +5.9996121148,0.0073092905,-0.040167571,5.9967928705,0.0002864505,-0.043328661 +10.9996861546,-0.0132465274,0.0254220121,10.9909213681,-0.0002717467,0.0153046018 +15.9999217552,-0.0159744015,0.0095019511,15.9943509103,-0.0001768393,0.0043438221 +20.9998653512,-0.0331984729,0.0096636543,20.9910013688,-0.0002200618,0.0036855392 +25.9998675643,-0.0419172038,0.0079134309,25.9891482755,-0.0001830537,0.0025824399 +5.9521001296,1.9778464945,-0.0310735192,6.3238961411,0.1530705954,-0.5978649825 +10.9523441465,1.9922601512,0.0041725697,11.1774416263,0.0483664162,-0.1932609591 +16.0284969148,2.0071012584,0.008548787,16.1162235858,0.0233059808,-0.0888390737 +20.9718056798,1.9846482687,0.0067309519,21.0869676791,0.0134344372,-0.052355723 +25.9973670229,1.978496785,0.0069797121,26.0654493083,0.0087555459,-0.0335305013 +10.9354537733,3.9656833069,0.0081542944,11.8038811638,0.0888688005,-0.3385833051 +15.9266361119,3.9746885811,0.0039198637,16.5047207548,0.0446657178,-0.1737407664 +20.988211535,3.9578964156,-0.0101252195,21.4016074581,0.0262351404,-0.1061880539 +25.9856208375,3.9578134064,-0.0091431309,26.300542279,0.0173011776,-0.0704508142 +10.970369923,5.9883005314,0.0098679108,13.0028548601,0.1154820906,-0.4373921554 +16.0187522498,5.9330426998,-0.0241514295,17.4044309482,0.0613533275,-0.2479524055 +20.9635975652,5.9195564189,-0.0143039466,22.0065350456,0.0376377637,-0.1522166452 +25.972488076,5.9408149625,-0.009626527,26.805585283,0.0252394447,-0.1019694407 +10.9649598979,7.9650540368,0.0117632421,14.5080636413,0.1296816893,-0.4905958677 +15.9741847071,7.994579085,0.0062342935,18.5059220464,0.0753462289,-0.2921861429 +20.9960182456,7.9124825929,-0.0182034472,22.9061332154,0.0473118411,-0.1909752142 +25.966383935,7.9138293819,-0.0122461701,27.5047651093,0.0323438985,-0.1304908668 +10.969134173,9.9403327354,0.0128912494,16.3125189782,0.1347789361,-0.510748321 +15.9934159598,9.9903289619,0.000139321,19.9057591282,0.0841479083,-0.3279089886 +20.9667930254,9.9868205067,0.0046747611,24.0072786569,0.0556162494,-0.2177480443 +25.9419023317,9.9692820803,0.0034441446,28.4051101283,0.0388150407,-0.1526647631 +6.0213872651,11.9825845548,0.0619205367,16.8076324003,0.1937634905,-0.6981317008 +10.9780554793,11.9711740518,0.0120184187,18.4073798122,0.1341782486,-0.5092616898 +15.9755251824,11.9935774953,0.0074670044,21.5052192452,0.0896869814,-0.3472766991 +20.9654964346,11.9805110524,0.0052444148,25.3022201545,0.061574448,-0.2406694492 +25.9537037558,11.9735974393,0.0038229397,29.5031364775,0.0439975178,-0.1729534577 +6.0165336609,13.9521072801,0.0174305319,19.6106689093,0.1747932412,-0.6504808406 +10.9935648138,13.9176575247,0.013034188,20.6141259705,0.1301958371,-0.496708046 +15.9734348799,13.9775977359,0.0079592434,23.3077925421,0.0922222135,-0.3574646081 +20.9708592125,13.9854723652,0.0055329035,26.8080416125,0.0657534899,-0.2573414242 +26.0358147161,13.9088973444,-0.0185341197,30.8036430288,0.0477974163,-0.1922131207 +1.0628058924,15.9849308492,0.018551886,24.8153426755,0.1760990429,-0.6578471507 +6.0196261094,15.9575704917,0.0155098281,22.5116000372,0.1582576397,-0.5960207125 +11.0081569366,15.9086329076,0.0127287931,23.0130284788,0.1246266745,-0.4772745141 +15.9762739887,15.9866801471,0.0078466669,25.3080825726,0.0927009985,-0.3597790241 +20.9549611548,15.9291191852,0.0064741827,28.408966658,0.068492727,-0.2680051093 +25.9858604641,15.9785452939,0.0002249129,32.201700716,0.0513323424,-0.2024836704 +1.0079858112,17.9913584391,0.0145491878,28.1084873807,0.1567296513,-0.5923612539 +5.9951825463,17.9812295718,0.0130049268,25.5091017654,0.1440850617,-0.5475450175 +10.9925610913,17.963960895,0.0107593967,25.6107230747,0.1183576649,-0.4552248 +15.9807141214,17.9509687951,0.0083690958,27.4105940428,0.0917490854,-0.3566636269 +20.9608340813,17.9159962037,0.0067705983,30.2152007255,0.0699842639,-0.2742681357 +25.9541276713,17.9457007438,0.0049090783,33.7082057456,0.053756122,-0.2114678128 diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/lookuptable_Calc_2.ods b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/lookuptable_Calc_2.ods new file mode 100644 index 0000000000..9083f30433 Binary files /dev/null and b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/lookuptable_Calc_2.ods differ diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/my_lookup_table.png b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/my_lookup_table.png new file mode 100644 index 0000000000..aa5fa724c5 Binary files /dev/null and b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/3/my_lookup_table.png differ diff --git a/PathPlanning/ModelPredictiveTrajectoryGenerator/results/4/lookuptable.csv b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/4/lookuptable.csv new file mode 100644 index 0000000000..33489771e3 --- /dev/null +++ b/PathPlanning/ModelPredictiveTrajectoryGenerator/results/4/lookuptable.csv @@ -0,0 +1,104 @@ +,x,y,yaw,s,km,kf +0,1.0,0.0,0.0,1.0,0.0,0.0 +1,5.93248606241041,0.04477335408603979,0.561326648158848,5.904418983174315,0.003635581107118673,0.5042475412347811 +2,10.97139558758923,0.04685384177199106,0.5454679523632097,11.00334932463324,0.0013404059716860524,0.28049162928143617 +3,15.91463435115268,0.045808336622304505,0.5361381718403999,16.005325143277854,0.0007150076396122978,0.19346622011066927 +4,20.954162466732427,0.046956363798501675,0.5343401647362965,21.10013557972375,0.00044428440287490453,0.14745269848591033 +5,25.908865325219594,-0.01238485036512426,0.5193587731949882,26.10821936927239,6.269330658165227e-05,0.11766328828318222 +6,5.952857738455988,1.9502677980709209,0.4983361898461735,6.3080235005857945,0.15206910132863133,-0.13169317797191382 +7,10.977652997421089,2.0073597273578585,0.5262318232147648,11.201694551195006,0.04894816231762309,0.08355064097574406 +8,15.900133660695607,1.9997012907193796,0.5266780189953999,16.103216446576536,0.023561770256890966,0.09996145895328014 +9,20.977532732159833,2.027074496221998,0.5298008199546806,21.20285602622561,0.013793608848683712,0.09330601003699736 +10,25.945729701821524,2.0256674333507045,0.528676293150669,26.206318212140953,0.009048091026951215,0.08387689878452288 +11,5.95989365163808,3.941072622750063,0.5323902383507471,7.511224553343554,0.23162626439951606,-0.48404577356924405 +12,10.93589821384132,3.925352596112569,0.5067838119799668,11.80071051519066,0.0880559738535562,-0.09271436943495406 +13,15.952417764781774,3.9775236384687394,0.5198766622359215,16.600637760896834,0.04442223214940138,0.0099529938833321 +14,20.949087579528594,3.9940947735691066,0.5238093536330594,21.50236551009194,0.026454953341878213,0.039768228671672484 +15,25.985268240355907,4.0166608903452135,0.5261825265475714,26.50081782816511,0.0174808186990068,0.048625007016577945 +16,5.979255449072514,5.950060385549822,0.5370825666181717,9.304897408249406,0.2483123724076069,-0.6129358195203664 +17,11.029887825243835,5.9646217963702775,0.49796430889412835,13.002268781644243,0.11441930953955544,-0.22309903377016116 +18,15.989215185312407,5.965673750246877,0.5133292091315987,17.40365989764349,0.06175639884233068,-0.06911397392346366 +19,20.97048401841735,5.977342504964486,0.5194935839247696,22.10013727566161,0.03783904655870495,-0.01022331847598236 +20,25.930823383603883,5.9729373036465745,0.5216823150109134,26.900607031034827,0.025357615093578208,0.014746540077955405 +21,6.004728789543921,7.971997496017458,0.5228206376036437,11.507222761055429,0.23646992589945529,-0.6366737572211348 +22,10.965825607538397,7.9447005027405755,0.528831986941112,14.40663142456893,0.1300736901435287,-0.2938630139571943 +23,15.936140411196247,7.93046804344976,0.52464407943386,18.413531995134736,0.07529440564052614,-0.12885769750602952 +24,20.965165229406956,7.942942666861402,0.5149362802616912,22.902561141729198,0.047538905997968034,-0.0546481698397432 +25,25.970105258849546,7.970709907417753,0.5194345362350604,27.600121193809024,0.03245571215907272,-0.0167480029434629 +26,5.9901382503462,9.965673417401618,0.5374914081962218,13.907695724433209,0.21740335382533213,-0.6065477360835893 +27,10.980522352966256,9.983013585494447,0.5307157258673572,16.20288544925058,0.13567497836368964,-0.3379977633480283 +28,16.03147218347369,9.94228551000832,0.5031925294273296,19.804711020565364,0.08396511031061892,-0.1808230216313134 +29,21.017727081712437,9.966904762790412,0.5124919539661417,24.003120503554147,0.05536977214144774,-0.09236018981494469 +30,25.940754125760467,9.920004287879216,0.5159831505748022,28.40669680561619,0.03863054572525547,-0.04516435197964391 +31,6.013026418970579,11.975672546680517,0.5233109239779965,16.506845815113536,0.1966036310551994,-0.5698834072019936 +32,10.999618069034977,11.98131473596233,0.5233486304594615,18.205216698968997,0.13519690421038705,-0.35966166215453443 +33,15.96544544259702,11.939663438832186,0.527174654424989,21.30533070697361,0.0900921670785234,-0.20892611050946855 +34,21.005520068406245,11.917743513595983,0.5089466131639474,25.201852664165415,0.061370956677566924,-0.12291669424542835 +35,26.002274639453574,11.953022413321714,0.514769192836982,29.50263681421407,0.04382266038913517,-0.06996677640517533 +36,1.0471906338566126,13.969722932158088,0.539109652151381,20.812754324923205,0.2074868569309694,-0.6401414599314111 +37,6.013016631498702,13.980227649857417,0.523430411856071,19.206795722572256,0.17794061122625904,-0.5272537103037491 +38,10.994836386020808,13.917223244716736,0.5307142007120365,20.310962550097262,0.13175898915920362,-0.3624375284245331 +39,16.067129477072108,13.930759417673334,0.4981358800960004,23.102666919519347,0.09227590401652133,-0.23602743768041612 +40,20.954905730840434,13.930150522551362,0.5257156343762146,26.608152218987236,0.06598169190337531,-0.14396173969465 +41,26.015465301644607,13.945387883588245,0.5128692226086865,30.703085413259387,0.04803381599016187,-0.09109598141373461 +42,1.0276312218981976,15.975213046117734,0.5368150007515399,23.909529597303923,0.1822896146803475,-0.5696296220691961 +43,6.0357053476871645,15.932692311445416,0.5342584630562058,21.91317149099456,0.16178378240891864,-0.4852646943429786 +44,11.003632236119643,15.98272957036228,0.5234563068638148,22.706068627903303,0.1262607813965495,-0.3587682164477665 +45,15.980284860782549,15.974007241901344,0.5285130356500495,25.005011249004507,0.09354479912149151,-0.2437990920310994 +46,20.963506201186025,15.932041935158137,0.5262542420707833,28.20474586098834,0.06885724314427988,-0.16175096156551064 +47,25.9545645238974,15.939712886536975,0.5251309085740978,32.00638425942628,0.05151579073787953,-0.1067433012134024 +48,1.0102811796364137,17.979088925242017,0.5351203627815457,27.0094790490419,0.16246067193562014,-0.5126820128261764 +49,5.991197301890051,17.976744892749753,0.5333419005375147,24.808291771837855,0.14763547617933154,-0.4485224197866932 +50,10.994857083198019,17.955904876891616,0.5307856685425895,25.10785789822634,0.12033449478904591,-0.3474821703657549 +51,15.98621055917561,17.917282344210758,0.5282271661503559,27.004756642677375,0.09278872662423435,-0.2501744857519473 +52,21.06441009426914,17.92876202536126,0.5044860887561218,30.003616600209913,0.07015822699616683,-0.17777615312783113 +53,25.962616945644598,17.94469585603458,0.5255713205633408,33.509243101861095,0.05397439479656563,-0.12086233675802045 +54,0.9999999999999999,0.0,0.0,1.0,0.0,0.0 +55,5.999638516755828,0.002145763578560201,-0.03955438103486121,5.901454699442083,0.00018040591429129135,-0.038979572152694986 +56,10.999704373496941,-0.011753002447328742,0.024810555073507615,10.994328597847979,-0.00023373014604302525,0.014831229804147139 +57,15.999786794731104,-0.025068443904961633,0.015864679605742633,15.99403410874661,-0.00027652909213202084,0.007175605638289395 +58,21.00000000000003,-2.9514423395470446e-22,8.776760613567232e-22,20.99918975465945,-1.415775110484139e-24,2.600812488912785e-22 +59,26.0000000000001,-3.0266903970903164e-23,2.797385997816466e-24,25.995879063777334,-1.3317551793362944e-25,1.1909300298029453e-24 +60,5.952508958012128,1.9770383036463155,-0.03085068599796998,6.307576440963514,0.15377112927243514,-0.5912693570519575 +61,10.946371680736087,2.023990990655425,0.027122675526372608,11.194612899459836,0.04904142236481999,-0.18537277954400272 +62,15.928580386835613,2.005084910949018,0.01766576884296867,16.094776253136057,0.023361977344289034,-0.08825565842819631 +63,21.068834673855772,2.018892872365515,0.016654750620985887,21.186280475648473,0.013544415261976191,-0.049959593336557126 +64,26.095546748024766,2.0056972685607874,0.014235175134816373,26.18644040448935,0.008797463240056293,-0.03219276955143403 +65,10.949128231620401,3.924508434518518,-0.024112995468350336,11.802950288562016,0.08794708475617515,-0.35016007797893817 +66,15.911042439885899,4.029210294474799,0.021072508555198845,16.5923137210505,0.04483912689858037,-0.173818030545946 +67,20.972122020260592,4.041136315862492,0.017145228736600446,21.489297356077607,0.026584898659407302,-0.10255732139592147 +68,26.071858158496777,4.0554700897865406,0.015674438172723557,26.481370030171835,0.01749453747199985,-0.06686855340110832 +69,10.994673419588775,5.936483724934604,-0.0336020716737723,13.001507222596576,0.1144863700499441,-0.45142728887870515 +70,16.019559439503862,5.931411869313231,-0.024303235927814023,17.400413145311624,0.06136370338964633,-0.24770400936766931 +71,20.920143888129115,6.056044224170263,0.018673365933935447,22.088424267850346,0.038259415018453036,-0.14915390515056787 +72,25.944771200937666,6.053155293660597,0.015337095488658683,26.885879550555792,0.025578256327662634,-0.09957729022276944 +73,10.964958985889444,7.96505525475518,0.011764044856306367,14.508622789657062,0.12967225711895444,-0.49067237327152163 +74,15.974185154102553,7.994578266379318,0.006233994363455567,18.503501517575295,0.07536532536778842,-0.2920321459993664 +75,20.970591205533008,7.976862179116774,0.0003032643475439252,22.901788288071057,0.047732480906087164,-0.18768743787864176 +76,25.94243950271542,7.987031087474341,0.0035545072296182447,27.587760397783118,0.032458723175920634,-0.1298798138817366 +77,10.969133524436847,9.94033341110301,0.012891674512308854,16.312707939140733,0.13477598889880063,-0.5107722183375754 +78,15.944532111405254,9.937439024480646,0.03899715195854861,19.803884407407562,0.08442795445544418,-0.3176801176122138 +79,20.96732452460839,9.986270557754835,0.004893733144002856,24.00250254459124,0.05563399650922351,-0.21750568024325487 +80,25.970616668076214,9.948269976163022,0.032626123526279846,28.402173487029874,0.03870814281167807,-0.14610592563367902 +81,6.021320695526516,11.982401622012084,0.06164049474889087,16.807174693787452,0.19377305680538612,-0.6981317007977318 +82,10.978053834096334,11.971175600327276,0.012019477148638123,18.40855398267583,0.1341620259594519,-0.5093931608322065 +83,15.975525151599077,11.993577533384167,0.007467019205741228,21.505337486109013,0.08968602697892114,-0.34728439720246584 +84,20.965496209803376,11.980511411470445,0.005244511785887064,25.302628852992093,0.06157250630169444,-0.24068507586809093 +85,25.992922686885503,11.91346007926575,0.0023151633647595475,29.500756243166943,0.043752811746211616,-0.17221067498191522 +86,6.0165284624859385,13.952109780178052,0.017433543304828894,19.611829356873717,0.1747740452060455,-0.650637124560814 +87,10.993561532687075,13.917660027105551,0.013035775387386164,20.614808309042196,0.1301876479627622,-0.49677431660050314 +88,15.973434197881728,13.97759847646533,0.007959545149409455,23.308595033454036,0.09221606528353282,-0.3575141827331485 +89,20.970861480653202,13.98546932426301,0.005532110102708997,26.803406772086127,0.06577571339868049,-0.2571626064259729 +90,26.035817289518832,13.90889264638572,-0.018535225407692042,30.80205590159011,0.0478023502072394,-0.19217370196164776 +91,1.0628047206780735,15.984931023043616,0.01855245005897556,24.81553608403634,0.17609648685066898,-0.6578679378077474 +92,6.0196269410399665,15.957570089538324,0.015509377795043605,22.51135694379849,0.15826085129958725,-0.5959946466859756 +93,11.008141114583767,15.908643439292039,0.012735367570205637,23.015894874227552,0.12459706590368232,-0.4775138773021154 +94,15.9762742453771,15.986679911930459,0.007846575559395608,25.307665028516144,0.09270396460649029,-0.3597551128931374 +95,20.954962022208424,15.929118120132417,0.006473872565325483,28.408551695787192,0.06849467894165985,-0.2679894056006025 +96,25.985859723627826,15.978546375600894,0.0002251347068684545,32.20302291351098,0.051328189131747526,-0.20251701926683538 +97,1.0079854746065235,17.991358523564113,0.014549350545550885,28.10867160169586,0.15672771188400475,-0.5923769864023686 +98,5.995182364340173,17.981229673807025,0.013005029050182623,25.509261051738427,0.14408335331668148,-0.5475588567924623 +99,10.992561635310912,17.963960566853896,0.010759192171854504,25.610467618756193,0.11835993188801539,-0.4552064868417598 +100,15.980718562056735,17.95096509272359,0.00836760979325911,27.40849176336775,0.09176273580090542,-0.35655363090278014 +101,20.96083763348477,17.915992341134356,0.006769473875027503,30.2138575823637,0.06999034099265891,-0.27421926068631297 +102,25.954122705230805,17.945707340331793,0.004910541470833769,33.71193134915777,0.05374445679345172,-0.21156153987142487 diff --git a/README.md b/README.md index b8715d9ea9..52a1ba37ff 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ Python codes for robotics algorithm. - matplotlib +- sudo apt-get install imagemagick (make matplotrecorder.py work normally when save .gif file) + +- install ffmpeg (google how to install and this is required if you want to save video such as .mp4 by matplotrecorder.py) + - [pyReedsShepp](https://github.com/ghliu/pyReedsShepp) (Only for reeds sheep path and RRTStarCar_reeds_sheep) - [cvxpy](https://cvxgrp.github.io/cvxpy/index.html) (Only for mix integer optimization based model predictive planning and control)