Skip to content

Commit ca8f853

Browse files
committed
first release universal sampling method
1 parent 14e81aa commit ca8f853

File tree

15 files changed

+702
-9
lines changed

15 files changed

+702
-9
lines changed

.idea/dictionaries/atsushisakai.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PathPlanning/ModelPredictiveTrajectoryGenerator/lookuptable_generator.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import math
99
import model_predictive_trajectory_generator as planner
1010
import motion_model
11+
import pandas as pd
1112

1213

1314
def calc_states_list():
@@ -22,13 +23,12 @@ def calc_states_list():
2223
for iy in y:
2324
for ix in x:
2425
states.append([ix, iy, iyaw])
25-
# print(len(states))
26+
# print(len(states))
2627

2728
return states
2829

2930

3031
def search_nearest_one_from_lookuptable(tx, ty, tyaw, lookuptable):
31-
3232
mind = float("inf")
3333
minid = -1
3434

@@ -37,18 +37,33 @@ def search_nearest_one_from_lookuptable(tx, ty, tyaw, lookuptable):
3737
dx = tx - table[0]
3838
dy = ty - table[1]
3939
dyaw = tyaw - table[2]
40-
d = math.sqrt(dx**2 + dy**2 + dyaw**2)
40+
d = math.sqrt(dx ** 2 + dy ** 2 + dyaw ** 2)
4141
if d <= mind:
4242
minid = i
4343
mind = d
4444

45-
# print(minid)
45+
# print(minid)
4646

4747
return lookuptable[minid]
4848

4949

50-
def generate_lookup_table():
50+
def save_lookup_table(fname, table):
51+
mt = np.array(table)
52+
print(mt)
53+
# save csv
54+
df = pd.DataFrame()
55+
df["x"] = mt[:, 0]
56+
df["y"] = mt[:, 1]
57+
df["yaw"] = mt[:, 2]
58+
df["s"] = mt[:, 3]
59+
df["km"] = mt[:, 4]
60+
df["kf"] = mt[:, 5]
61+
df.to_csv(fname, index=None)
62+
63+
print("lookup table file is saved as " + fname)
5164

65+
66+
def generate_lookup_table():
5267
states = calc_states_list()
5368
k0 = 0.0
5469

@@ -58,11 +73,10 @@ def generate_lookup_table():
5873
for state in states:
5974
bestp = search_nearest_one_from_lookuptable(
6075
state[0], state[1], state[2], lookuptable)
61-
# print(bestp)
6276

6377
target = motion_model.State(x=state[0], y=state[1], yaw=state[2])
6478
init_p = np.matrix(
65-
[math.sqrt(state[0]**2 + state[1]**2), bestp[4], bestp[5]]).T
79+
[math.sqrt(state[0] ** 2 + state[1] ** 2), bestp[4], bestp[5]]).T
6680

6781
x, y, yaw, p = planner.optimize_trajectory(target, k0, init_p)
6882

@@ -71,7 +85,9 @@ def generate_lookup_table():
7185
lookuptable.append(
7286
[x[-1], y[-1], yaw[-1], float(p[0]), float(p[1]), float(p[2])])
7387

74-
print("finish lookuptable generation")
88+
print("finish lookup table generation")
89+
90+
save_lookup_table("lookuptable.csv", lookuptable)
7591

7692
for table in lookuptable:
7793
xc, yc, yawc = motion_model.generate_trajectory(
32.5 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
x,y,yaw,s,km,kf
2+
1.0,0.0,0.0,1.0,0.0,0.0
3+
0.9734888894493215,-0.009758406565994977,0.5358080146312756,0.9922329557399788,-0.10222538550473198,3.0262632253145982
4+
10.980728996433243,-0.0003093605787364978,0.522622783944529,11.000391678142623,0.00010296091030877934,0.2731556687244648
5+
16.020309241920156,0.0001292339008200291,0.5243399938698222,16.100019813021202,0.00013263212395994706,0.18999138959173634
6+
20.963495745193626,-0.00033031017429944326,0.5226120033275024,21.10082901143343,0.00011687467551566884,0.14550546012583987
7+
6.032553475650599,2.008504211720188,0.5050517859971599,6.400329805864408,0.1520002249689879,-0.13105940607691127
8+
10.977487445230075,2.0078696810700034,0.5263634407901872,11.201040572298973,0.04895863722280565,0.08356555007223682
9+
15.994057699325753,2.025659106131227,0.5303858891065698,16.200300421483128,0.0235708657178127,0.10002225103921249
10+
20.977228843605943,2.0281289825388513,0.5300376140865567,21.20043308669372,0.013795675421657671,0.09331700188063087
11+
25.95453914157977,1.9926432818499131,0.5226203078411618,26.200880299840527,0.00888830054451281,0.0830622000626594
12+
0.9999999999999999,0.0,0.0,1.0,0.0,0.0
13+
5.999999999670752,5.231312388722274e-05,1.4636120911014667e-05,5.996117185283419,4.483756968024291e-06,-3.4422519205046243e-06
14+
10.999749470720566,-0.011978787043239986,0.022694802592583763,10.99783855994015,-0.00024209503125174496,0.01370491008661795
15+
15.999885224357776,-0.018937230084507616,0.011565580878015763,15.99839381389597,-0.0002086399372890716,0.005267247862667496
16+
20.999882688881286,-0.030304200126461317,0.009117836885732596,20.99783120184498,-0.00020013159571184735,0.0034529188783636866
17+
25.999911270030413,-0.025754431694664327,0.0074809531598503615,25.99674782258235,-0.0001111138115390646,0.0021946603965658368
18+
10.952178818975062,1.993067260835455,0.0045572480669707136,11.17961498195845,0.04836813285436623,-0.19328716251760758
19+
16.028306009258,2.0086286208315407,0.009306594796759554,16.122411866381054,0.02330689045417979,-0.08877002085985948
20+
20.971603115419715,1.9864158336174966,0.007016819403167119,21.093006725076872,0.013439123130720928,-0.05238318300611623
21+
25.997019676818372,1.9818581321430093,0.007020172975955249,26.074021794586585,0.00876496148602802,-0.03362579291686346
22+
16.017903482982604,4.009490840390534,-5.293114796312698e-05,16.600937712976638,0.044543450568614244,-0.17444651314466567
23+
20.98845988414163,3.956600199823583,-0.01050744134070728,21.40149119463485,0.02622674388276059,-0.10625681152519345
24+
25.979448381017914,3.9968223055054977,-0.00012819253386682928,26.30504721211744,0.017467093413146118,-0.06914750106424669
25+
25.96268055563514,5.9821266846168,4.931311239565056e-05,26.801388563459287,0.025426008913226557,-0.10047663078001536
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*,cover
46+
.hypothesis/
47+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
# Django stuff:
53+
*.log
54+
local_settings.py
55+
56+
# Flask stuff:
57+
instance/
58+
.webassets-cache
59+
60+
# Scrapy stuff:
61+
.scrapy
62+
63+
# Sphinx documentation
64+
docs/_build/
65+
66+
# PyBuilder
67+
target/
68+
69+
# IPython Notebook
70+
.ipynb_checkpoints
71+
72+
# pyenv
73+
.python-version
74+
75+
# celery beat schedule file
76+
celerybeat-schedule
77+
78+
# dotenv
79+
.env
80+
81+
# virtualenv
82+
venv/
83+
ENV/
84+
85+
# Spyder project settings
86+
.spyderproject
87+
88+
# Rope project settings
89+
.ropeproject
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Atsushi Sakai
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# matplotrecorder
2+
A simple Python module for recording matplotlib animation
3+
4+
It can generate a matplotlib animation movie (mp4, gif, etc.)
5+
6+
This tool use "convert" command of ImageMagick.
7+
8+
# Sample gif
9+
10+
![matplotrecorder/animation.gif at master · AtsushiSakai/matplotrecorder](https://github.com/AtsushiSakai/matplotrecorder/blob/master/animation.gif)
11+
12+
# Requrements
13+
14+
- [ImageMagic](https://www.imagemagick.org/script/index.php)
15+
16+
17+
# How to use
18+
19+
Call save_frame() at each animation iteration,
20+
21+
And then, call savemovie() for movie generation.
22+
23+
A sample code:
24+
25+
26+
import matplotrecorder
27+
28+
print("A sample recording start")
29+
import math
30+
31+
time = range(50)
32+
33+
x1 = [math.cos(t / 10.0) for t in time]
34+
y1 = [math.sin(t / 10.0) for t in time]
35+
x2 = [math.cos(t / 10.0) + 2 for t in time]
36+
y2 = [math.sin(t / 10.0) + 2 for t in time]
37+
38+
for ix1, iy1, ix2, iy2 in zip(x1, y1, x2, y2):
39+
plt.plot(ix1, iy1, "xr")
40+
plt.plot(ix2, iy2, "xb")
41+
plt.axis("equal")
42+
plt.pause(0.1)
43+
44+
matplotrecorder.save_frame() # save each frame
45+
46+
# generate movie
47+
matplotrecorder.save_movie("animation.mp4", 0.1)
48+
# matplotrecorder.save_movie("animation.gif", 0.1) #gif is ok.
49+
50+
51+
52+
# License
53+
54+
MIT
55+
56+
# Author
57+
58+
Atsushi Sakai ([@Atsushi_twi](https://twitter.com/Atsushi_twi))
59+

PathPlanning/StateLatticePlanner/matplotrecorder/__init__.py

Whitespace-only changes.
311 KB
Loading

0 commit comments

Comments
 (0)