Skip to content

Commit abb4d75

Browse files
author
Shunichi09
authored
Merge pull request #2 from Shunichi09/develop
Develop
2 parents 4b8ff4c + 2161162 commit abb4d75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2273
-7132
lines changed

.gitignore

Lines changed: 132 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,134 @@
1-
*.csv
2-
*.log
3-
*.pickle
4-
*.mp4
1+
# folders
2+
.vscode/
3+
.pytest_cache/
4+
result/
55

6-
.cache/
7-
.eggs/
6+
# Byte-compiled / optimized / DLL files
87
__pycache__/
9-
.pytest_cache
10-
cache/
8+
*.py[cod]
9+
*$py.class
10+
11+
# C extensions
12+
*.so
13+
14+
# Distribution / packaging
15+
.Python
16+
build/
17+
develop-eggs/
18+
dist/
19+
downloads/
20+
eggs/
21+
.eggs/
22+
lib/
23+
lib64/
24+
parts/
25+
sdist/
26+
var/
27+
wheels/
28+
pip-wheel-metadata/
29+
share/python-wheels/
30+
*.egg-info/
31+
.installed.cfg
32+
*.egg
33+
MANIFEST
34+
35+
# PyInstaller
36+
# Usually these files are written by a python script from a template
37+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
38+
*.manifest
39+
*.spec
40+
41+
# Installer logs
42+
pip-log.txt
43+
pip-delete-this-directory.txt
44+
45+
# Unit test / coverage reports
46+
htmlcov/
47+
.tox/
48+
.nox/
49+
.coverage
50+
.coverage.*
51+
.cache
52+
nosetests.xml
53+
coverage.xml
54+
*.cover
55+
*.py,cover
56+
.hypothesis/
57+
.pytest_cache/
58+
59+
# Translations
60+
*.mo
61+
*.pot
62+
63+
# Django stuff:
64+
*.log
65+
local_settings.py
66+
db.sqlite3
67+
db.sqlite3-journal
68+
69+
# Flask stuff:
70+
instance/
71+
.webassets-cache
72+
73+
# Scrapy stuff:
74+
.scrapy
75+
76+
# Sphinx documentation
77+
docs/_build/
78+
79+
# PyBuilder
80+
target/
81+
82+
# Jupyter Notebook
83+
.ipynb_checkpoints
84+
85+
# IPython
86+
profile_default/
87+
ipython_config.py
88+
89+
# pyenv
90+
.python-version
91+
92+
# pipenv
93+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
95+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
96+
# install all needed dependencies.
97+
#Pipfile.lock
98+
99+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
100+
__pypackages__/
101+
102+
# Celery stuff
103+
celerybeat-schedule
104+
celerybeat.pid
105+
106+
# SageMath parsed files
107+
*.sage.py
108+
109+
# Environments
110+
.env
111+
.venv
112+
env/
113+
venv/
114+
ENV/
115+
env.bak/
116+
venv.bak/
117+
118+
# Spyder project settings
119+
.spyderproject
120+
.spyproject
121+
122+
# Rope project settings
123+
.ropeproject
124+
125+
# mkdocs documentation
126+
/site
127+
128+
# mypy
129+
.mypy_cache/
130+
.dmypy.json
131+
dmypy.json
132+
133+
# Pyre type checker
134+
.pyre/

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: python
2+
3+
python:
4+
- 3.7
5+
6+
install:
7+
- pip install --upgrade pip setuptools wheel
8+
- pip install coveralls
9+
10+
script:
11+
- coverage run --source=PythonLinearNonlinearControl setup.py test
12+
13+
after_success:
14+
- coveralls

LICENSE

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Shunichi Sekiguchi
3+
Copyright (c) 2020 Shunichi Sekiguchi
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

PythonLinearNonlinearControl/__init__.py

Whitespace-only changes.

PythonLinearNonlinearControl/common/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import numpy as np
2+

PythonLinearNonlinearControl/configs/__init__.py

Whitespace-only changes.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import numpy as np
2+
3+
class FirstOrderLagConfigModule():
4+
# parameters
5+
ENV_NAME = "FirstOrderLag-v0"
6+
TYPE = "Linear"
7+
TASK_HORIZON = 1000
8+
PRED_LEN = 10
9+
STATE_SIZE = 4
10+
INPUT_SIZE = 2
11+
DT = 0.05
12+
# cost parameters
13+
R = np.eye(INPUT_SIZE)
14+
Q = np.eye(STATE_SIZE)
15+
Sf = np.eye(STATE_SIZE)
16+
# bounds
17+
INPUT_LOWER_BOUND = np.array([-0.5, -0.5])
18+
INPUT_UPPER_BOUND = np.array([0.5, 0.5])
19+
# DT_INPUT_LOWER_BOUND = np.array([-0.5 * DT, -0.5 * DT])
20+
# DT_INPUT_UPPER_BOUND = np.array([0.25 * DT, 0.25 * DT])
21+
DT_INPUT_LOWER_BOUND = None
22+
DT_INPUT_UPPER_BOUND = None
23+
24+
def __init__(self):
25+
"""
26+
"""
27+
# opt configs
28+
self.opt_config = {
29+
"Random": {
30+
"popsize": 5000
31+
},
32+
"CEM": {
33+
"popsize": 500,
34+
"num_elites": 50,
35+
"max_iters": 15,
36+
"alpha": 0.3,
37+
"init_var":1.,
38+
"threshold":0.001
39+
},
40+
"MPPI":{
41+
"beta" : 0.6,
42+
"popsize": 5000,
43+
"kappa": 0.9,
44+
"noise_sigma": 0.5,
45+
},
46+
"iLQR":{
47+
},
48+
"cgmres-NMPC":{
49+
},
50+
"newton-NMPC":{
51+
},
52+
}
53+
54+
@staticmethod
55+
def input_cost_fn(u):
56+
""" input cost functions
57+
Args:
58+
u (numpy.ndarray): input, shape(input_size, )
59+
or shape(pop_size, input_size)
60+
Returns:
61+
cost (numpy.ndarray): cost of input, none or shape(pop_size, )
62+
"""
63+
return (u**2) * np.diag(FirstOrderLagConfigModule.R)
64+
65+
@staticmethod
66+
def state_cost_fn(x, g_x):
67+
""" state cost function
68+
Args:
69+
x (numpy.ndarray): state, shape(pred_len, state_size)
70+
or shape(pop_size, pred_len, state_size)
71+
g_x (numpy.ndarray): goal state, shape(state_size, )
72+
or shape(pop_size, state_size)
73+
Returns:
74+
cost (numpy.ndarray): cost of state, none or shape(pop_size, )
75+
"""
76+
return ((x - g_x)**2) * np.diag(FirstOrderLagConfigModule.Q)
77+
78+
@staticmethod
79+
def terminal_state_cost_fn(terminal_x, terminal_g_x):
80+
"""
81+
Args:
82+
terminal_x (numpy.ndarray): terminal state,
83+
shape(state_size, ) or shape(pop_size, state_size)
84+
terminal_g_x (numpy.ndarray): terminal goal state,
85+
shape(state_size, ) or shape(pop_size, state_size)
86+
Returns:
87+
cost (numpy.ndarray): cost of state, none or shape(pop_size, )
88+
"""
89+
return ((terminal_x - terminal_g_x)**2) \
90+
* np.diag(FirstOrderLagConfigModule.Sf)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from .first_order_lag import FirstOrderLagConfigModule
2+
from .two_wheeled import TwoWheeledConfigModule
3+
4+
def make_config(args):
5+
"""
6+
Returns:
7+
config (ConfigModule class): configuration for the each env
8+
"""
9+
if args.env == "FirstOrderLag":
10+
return FirstOrderLagConfigModule()
11+
elif args.env == "TwoWheeledConst" or args.env == "TwoWheeled":
12+
return TwoWheeledConfigModule()
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import numpy as np
2+
3+
class TwoWheeledConfigModule():
4+
# parameters
5+
ENV_NAME = "TwoWheeled-v0"
6+
TYPE = "Nonlinear"
7+
TASK_HORIZON = 1000
8+
PRED_LEN = 10
9+
STATE_SIZE = 3
10+
INPUT_SIZE = 2
11+
DT = 0.01
12+
# cost parameters
13+
R = np.eye(INPUT_SIZE)
14+
Q = np.eye(STATE_SIZE)
15+
Sf = np.eye(STATE_SIZE)
16+
# bounds
17+
INPUT_LOWER_BOUND = np.array([-1.5, 3.14])
18+
INPUT_UPPER_BOUND = np.array([1.5, 3.14])
19+
20+
def __init__(self):
21+
"""
22+
"""
23+
# opt configs
24+
self.opt_config = {
25+
"Random": {
26+
"popsize": 5000
27+
},
28+
"CEM": {
29+
"popsize": 500,
30+
"num_elites": 50,
31+
"max_iters": 15,
32+
"alpha": 0.3,
33+
"init_var":1.,
34+
"threshold":0.001
35+
},
36+
"MPPI":{
37+
"beta" : 0.6,
38+
"popsize": 5000,
39+
"kappa": 0.9,
40+
"noise_sigma": 0.5,
41+
},
42+
"iLQR":{
43+
},
44+
"NMPC-CGMRES":{
45+
},
46+
"NMPC-Newton":{
47+
},
48+
}
49+
50+
@staticmethod
51+
def input_cost_fn(u):
52+
""" input cost functions
53+
Args:
54+
u (numpy.ndarray): input, shape(input_size, )
55+
or shape(pop_size, input_size)
56+
Returns:
57+
cost (numpy.ndarray): cost of input, none or shape(pop_size, )
58+
"""
59+
return (u**2) * np.diag(TwoWheeledConfigModule.R) * 0.1
60+
61+
@staticmethod
62+
def state_cost_fn(x, g_x):
63+
""" state cost function
64+
Args:
65+
x (numpy.ndarray): state, shape(pred_len, state_size)
66+
or shape(pop_size, pred_len, state_size)
67+
g_x (numpy.ndarray): goal state, shape(state_size, )
68+
or shape(pop_size, state_size)
69+
Returns:
70+
cost (numpy.ndarray): cost of state, none or shape(pop_size, )
71+
"""
72+
return ((x - g_x)**2) * np.diag(TwoWheeledConfigModule.Q)
73+
74+
@staticmethod
75+
def terminal_state_cost_fn(terminal_x, terminal_g_x):
76+
"""
77+
Args:
78+
terminal_x (numpy.ndarray): terminal state,
79+
shape(state_size, ) or shape(pop_size, state_size)
80+
terminal_g_x (numpy.ndarray): terminal goal state,
81+
shape(state_size, ) or shape(pop_size, state_size)
82+
Returns:
83+
cost (numpy.ndarray): cost of state, none or shape(pop_size, )
84+
"""
85+
return ((terminal_x - terminal_g_x)**2) \
86+
* np.diag(TwoWheeledConfigModule.Sf)

PythonLinearNonlinearControl/controllers/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)