Skip to content

Commit 1e0c26c

Browse files
author
Shunichi09
committed
Add: Quick start guide
1 parent 4467644 commit 1e0c26c

File tree

11 files changed

+175
-19
lines changed

11 files changed

+175
-19
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from PythonLinearNonlinearControl.configs.cartpole \
2+
import CartPoleConfigModule # NOQA
3+
from PythonLinearNonlinearControl.configs.first_order_lag \
4+
import FirstOrderLagConfigModule # NOQA
5+
from PythonLinearNonlinearControl.configs.two_wheeled \
6+
import TwoWheeledConfigModule # NOQA
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from PythonLinearNonlinearControl.controllers.cem \
2+
import CEM # NOQA
3+
from PythonLinearNonlinearControl.controllers.mppi \
4+
import MPPI # NOQA
5+
from PythonLinearNonlinearControl.controllers.mppi_williams \
6+
import MPPIWilliams # NOQA
7+
from PythonLinearNonlinearControl.controllers.random \
8+
import RandomShooting # NOQA
9+
from PythonLinearNonlinearControl.controllers.ilqr \
10+
import iLQR # NOQA
11+
from PythonLinearNonlinearControl.controllers.ddp \
12+
import DDP # NOQA
13+
from PythonLinearNonlinearControl.controllers.mpc \
14+
import LinearMPC # NOQA
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from PythonLinearNonlinearControl.envs.cartpole \
2+
import CartPoleEnv # NOQA
3+
from PythonLinearNonlinearControl.envs.first_order_lag \
4+
import FirstOrderLagEnv # NOQA
5+
from PythonLinearNonlinearControl.envs.two_wheeled \
6+
import TwoWheeledConstEnv # NOQA
7+
from PythonLinearNonlinearControl.envs.two_wheeled \
8+
import TwoWheeledTrackEnv # NOQA
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from PythonLinearNonlinearControl.models.cartpole \
2+
import CartPoleModel # NOQA
3+
from PythonLinearNonlinearControl.models.first_order_lag \
4+
import FirstOrderLagModel # NOQA
5+
from PythonLinearNonlinearControl.models.two_wheeled \
6+
import TwoWheeledModel # NOQA
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from PythonLinearNonlinearControl.planners.const_planner \
2+
import ConstantPlanner # NOQA
3+
from PythonLinearNonlinearControl.planners.closest_point_planner \
4+
import ClosestPointPlanner # NOQA
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from PythonLinearNonlinearControl.plotters.animator \
2+
import Animator
3+
from PythonLinearNonlinearControl.plotters.plot_func \
4+
import plot_results

PythonLinearNonlinearControl/plotters/animator.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
class Animator():
1111
""" animation class
1212
"""
13-
def __init__(self, args, env):
13+
def __init__(self, env, args=None):
1414
"""
1515
"""
16-
self.env_name = args.env
17-
self.result_dir = args.result_dir
18-
self.controller_type = args.controller_type
16+
self.env_name = "Env"
17+
self.result_dir = "./result"
18+
self.controller_type = "controller"
19+
20+
if args is not None:
21+
self.env_name = args.env
22+
self.result_dir = args.result_dir
23+
self.controller_type = args.controller_type
1924

2025
self.interval = env.config["dt"] * 1000. # to ms
2126
self.plot_func = env.plot_func
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from PythonLinearNonlinearControl.runners.runner \
2+
import ExpRunner # NOQA

README.md

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
[![GitHub issues open](https://img.shields.io/github/issues/Shunichi09/PythonLinearNonlinearControl.svg)]()
44
[![Build Status](https://travis-ci.org/Shunichi09/PythonLinearNonlinearControl.svg?branch=master&service=github)](https://travis-ci.org/Shunichi09/PythonLinearNonlinearControl)
55

6-
# PythonLinearNonLinearControl
6+
# PythonLinearNonlinearControl
77

8-
PythonLinearNonLinearControl is a library implementing the linear and nonlinear control theories in python.
8+
PythonLinearNonlinearControl is a library implementing the linear and nonlinear control theories in python.
99
Due to use only basic libralies (scipy, numpy), this library is easy to extend for your own situations.
1010

1111
<div><img src="assets/concept.png" width="500"/></div>
@@ -78,7 +78,7 @@ All states and inputs of environments are continuous.
7878

7979
You could know abount our environmets more in [Environments.md](Environments.md)
8080

81-
# Usage
81+
# Installation
8282

8383
## To install this package
8484

@@ -104,16 +104,6 @@ or
104104
pip install -e .
105105
```
106106

107-
## Run Experiments
108-
109-
You can run the experiments as follows:
110-
111-
```
112-
python scripts/simple_run.py --env FirstOrderLag --controller CEM
113-
```
114-
115-
**figures and animations are saved in the ./result folder.**
116-
117107
# Basic concepts
118108

119109
When we design control systems, we should have **Model**, **Planner**, **Controller** and **Runner** as shown in the figure.
@@ -141,6 +131,71 @@ Runner runs the simulation.
141131

142132
Please, see more detail in each scripts.
143133

134+
# Getting started
135+
136+
## [QuickStart Guide](scripts/quickstart/quickstart.md)
137+
138+
This is a quickstart guide for users who just want to try PythonLinearNonlinearControl.
139+
If you have not installed PythonLinearNonLinearControl, please see the section of "how to setup" in README.md
140+
141+
When we design control systems, we should have Environment, Model, Planner, Controller and Runner.
142+
Therefore your script contains those Modules.
143+
144+
First, import each Modules from PythonLinearNonlinearControl.
145+
146+
```py
147+
from PythonLinearNonlinearControl import configs
148+
from PythonLinearNonlinearControl import envs
149+
from PythonLinearNonlinearControl import models
150+
from PythonLinearNonlinearControl import planners
151+
from PythonLinearNonlinearControl import controllers
152+
from PythonLinearNonlinearControl import runners
153+
```
154+
155+
Configs contains each modules configurations such as cost functions, prediction length, ...etc.
156+
157+
Then you can make each module. (This is example about CEM and CartPole env)
158+
159+
```py
160+
config = configs.CartPoleConfigModule()
161+
env = envs.CartPoleEnv()
162+
model = models.CartPoleModel(config)
163+
planner = controllers.CEM(config, model)
164+
runner = planners.ConstantPlanner(config)
165+
controller = runners.ExpRunner()
166+
```
167+
168+
The preparation for experiment has done!
169+
Please run the runner.
170+
171+
```py
172+
history_x, history_u, history_g = runner.run(env, controller, planner)
173+
```
174+
175+
You can get the results of history of state, history of input and history of goal.
176+
Use that histories to visualize the Animation or Figures.
177+
(Note FirstOrderEnv does not support animation)
178+
179+
```py
180+
# plot results
181+
plot_results(args, history_x, history_u, history_g=history_g)
182+
save_plot_data(args, history_x, history_u, history_g=history_g)
183+
184+
# create animation
185+
animator = Animator(args, env)
186+
animator.draw(history_x, history_g)
187+
```
188+
189+
## Run Experiments
190+
191+
You can run the experiments as follows:
192+
193+
```
194+
python scripts/simple_run.py --env CartPole --controller CEM --save_anim 1
195+
```
196+
197+
**figures and animations are saved in the ./result folder.**
198+
144199
# Old version
145200

146201
If you are interested in the old version of this library, that was not a library just examples, please see [v1.0](https://github.com/Shunichi09/PythonLinearNonlinearControl/tree/v1.0)
@@ -168,4 +223,4 @@ author = {Shunichi Sekiguchi},
168223
title = {PythonLinearNonlinearControl},
169224
note = "\url{https://github.com/Shunichi09/PythonLinearNonlinearControl}",
170225
}
171-
```
226+
```

scripts/quickstart/quickstart.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# PythonLinearnNonlinearControl Quickstart Guide
2+
3+
This is a quickstart guide for users who just want to try PythonLinearNonlinearControl.
4+
If you have not installed PythonLinearNonLinearControl, please see the section of "how to setup" in README.md
5+
6+
When we design control systems, we should have Environment, Model, Planner, Controller and Runner.
7+
Therefore your script contains those Modules.
8+
9+
First, import each Modules from PythonLinearNonlinearControl.
10+
11+
```py
12+
from PythonLinearNonlinearControl import configs
13+
from PythonLinearNonlinearControl import envs
14+
from PythonLinearNonlinearControl import models
15+
from PythonLinearNonlinearControl import planners
16+
from PythonLinearNonlinearControl import controllers
17+
from PythonLinearNonlinearControl import runners
18+
```
19+
20+
Configs contains each modules configurations such as cost functions, prediction length, ...etc.
21+
22+
Then you can make each module. (This is example about CEM and CartPole env)
23+
24+
```py
25+
config = configs.CartPoleConfigModule()
26+
env = envs.CartPoleEnv()
27+
model = models.CartPoleModel(config)
28+
planner = controllers.CEM(config, model)
29+
runner = planners.ConstantPlanner(config)
30+
controller = runners.ExpRunner()
31+
```
32+
33+
The preparation for experiment has done!
34+
Please run the runner.
35+
36+
```py
37+
history_x, history_u, history_g = runner.run(env, controller, planner)
38+
```
39+
40+
You can get the results of history of state, history of input and history of goal.
41+
Use that histories to visualize the Animation or Figures.
42+
(Note FirstOrderEnv does not support animation)
43+
44+
```py
45+
# plot results
46+
plot_results(args, history_x, history_u, history_g=history_g)
47+
save_plot_data(args, history_x, history_u, history_g=history_g)
48+
49+
# create animation
50+
animator = Animator(args, env)
51+
animator.draw(history_x, history_g)
52+
```

0 commit comments

Comments
 (0)