Skip to content

Commit 3e5904c

Browse files
committed
forgot all the template notebooks
1 parent 0674a99 commit 3e5904c

7 files changed

Lines changed: 656 additions & 0 deletions

File tree

project/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!*ipynb
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "d777ed6c",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%load_ext autoreload\n",
11+
"%autoreload 2\n",
12+
"\n",
13+
"# Get parent directory and add to sys.path\n",
14+
"import os\n",
15+
"import sys\n",
16+
"\n",
17+
"parent_dir = os.path.dirname(os.getcwd())\n",
18+
"sys.path.append(parent_dir)\n",
19+
"\n",
20+
"# Require ipympl\n",
21+
"%matplotlib widget "
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "c9fb75e7",
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"# MPC import\n",
32+
"import numpy as np\n",
33+
"from LinearMPC.MPCVelControl import MPCVelControl\n",
34+
"from src.rocket import Rocket\n",
35+
"from src.vel_rocket_vis import RocketVis\n",
36+
"\n",
37+
"rocket_obj_path = os.path.join(parent_dir, \"Cartoon_rocket.obj\")\n",
38+
"rocket_params_path = os.path.join(parent_dir, \"rocket.yaml\")"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"id": "494f56e2",
45+
"metadata": {},
46+
"outputs": [],
47+
"source": [
48+
"Ts = 0.05\n",
49+
"sim_time = ...\n",
50+
"H = ...\n",
51+
"x0 = ... # initial state\n",
52+
"\n",
53+
"rocket = Rocket(Ts=Ts, model_params_filepath=rocket_params_path)\n",
54+
"mpc = MPCVelControl().new_controller(rocket, Ts, H)\n",
55+
"\n",
56+
"t_cl, x_cl, u_cl, t_ol, x_ol, u_ol, _ = rocket.simulate_control(\n",
57+
" mpc, sim_time, H, x0, method=\"linear\"\n",
58+
")\n",
59+
"\n",
60+
"vis = RocketVis(rocket, rocket_obj_path)\n",
61+
"vis.anim_rate = 1.0\n",
62+
"vis.animate(t_cl[:-1], x_cl[:, :-1], u_cl, T_ol=t_ol[..., :-1], X_ol=x_ol, U_ol=u_ol);"
63+
]
64+
}
65+
],
66+
"metadata": {
67+
"kernelspec": {
68+
"display_name": "Python 3",
69+
"language": "python",
70+
"name": "python3"
71+
},
72+
"language_info": {
73+
"codemirror_mode": {
74+
"name": "ipython",
75+
"version": 3
76+
},
77+
"file_extension": ".py",
78+
"mimetype": "text/x-python",
79+
"name": "python",
80+
"nbconvert_exporter": "python",
81+
"pygments_lexer": "ipython3",
82+
"version": "3.12.12"
83+
}
84+
},
85+
"nbformat": 4,
86+
"nbformat_minor": 5
87+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "d777ed6c",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%load_ext autoreload\n",
11+
"%autoreload 2\n",
12+
"\n",
13+
"# Get parent directory and add to sys.path\n",
14+
"import os\n",
15+
"import sys\n",
16+
"\n",
17+
"parent_dir = os.path.dirname(os.getcwd())\n",
18+
"sys.path.append(parent_dir)\n",
19+
"\n",
20+
"# Require ipympl\n",
21+
"%matplotlib widget "
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "c9fb75e7",
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"# MPC import\n",
32+
"import numpy as np\n",
33+
"from LinearMPC.MPCVelControl import MPCVelControl\n",
34+
"from src.rocket import Rocket\n",
35+
"from src.vel_rocket_vis import RocketVis\n",
36+
"\n",
37+
"rocket_obj_path = os.path.join(parent_dir, \"Cartoon_rocket.obj\")\n",
38+
"rocket_params_path = os.path.join(parent_dir, \"rocket.yaml\")"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"id": "494f56e2",
45+
"metadata": {},
46+
"outputs": [],
47+
"source": [
48+
"Ts = 0.05\n",
49+
"sim_time = 7\n",
50+
"H = 5.0\n",
51+
"x0 = ... # initial state\n",
52+
"x_target = ... # target state\n",
53+
"\n",
54+
"rocket = Rocket(Ts=Ts, model_params_filepath=rocket_params_path)\n",
55+
"mpc = MPCVelControl().new_controller(rocket, Ts, H)\n",
56+
"\n",
57+
"t_cl, x_cl, u_cl, t_ol, x_ol, u_ol, _ = rocket.simulate_control(\n",
58+
" mpc, sim_time, H, x0, x_target=x_target, method=\"linear\"\n",
59+
")\n",
60+
"\n",
61+
"vis = RocketVis(rocket, rocket_obj_path)\n",
62+
"vis.anim_rate = 1.0\n",
63+
"vis.animate(\n",
64+
" t_cl[:-1],\n",
65+
" x_cl[:, :-1],\n",
66+
" u_cl,\n",
67+
" Ref=x_target.reshape(-1, 1).repeat(u_cl.shape[1], axis=1),\n",
68+
" T_ol=t_ol[..., :-1],\n",
69+
" X_ol=x_ol,\n",
70+
" U_ol=u_ol,\n",
71+
");"
72+
]
73+
}
74+
],
75+
"metadata": {
76+
"kernelspec": {
77+
"display_name": "mpc2025",
78+
"language": "python",
79+
"name": "python3"
80+
},
81+
"language_info": {
82+
"codemirror_mode": {
83+
"name": "ipython",
84+
"version": 3
85+
},
86+
"file_extension": ".py",
87+
"mimetype": "text/x-python",
88+
"name": "python",
89+
"nbconvert_exporter": "python",
90+
"pygments_lexer": "ipython3",
91+
"version": "3.12.11"
92+
}
93+
},
94+
"nbformat": 4,
95+
"nbformat_minor": 5
96+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "d777ed6c",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%load_ext autoreload\n",
11+
"%autoreload 2\n",
12+
"\n",
13+
"# Get parent directory and add to sys.path\n",
14+
"import os\n",
15+
"import sys\n",
16+
"\n",
17+
"parent_dir = os.path.dirname(os.getcwd())\n",
18+
"sys.path.append(parent_dir)\n",
19+
"\n",
20+
"# Require ipympl\n",
21+
"%matplotlib widget "
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "c9fb75e7",
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"# MPC import\n",
32+
"from LinearMPC.MPCVelControl import MPCVelControl\n",
33+
"from PIControl.PIControl import PIControl\n",
34+
"import numpy as np\n",
35+
"from src.rocket import Rocket\n",
36+
"from src.vel_rocket_vis import RocketVis\n",
37+
"\n",
38+
"rocket_obj_path = os.path.join(parent_dir, \"Cartoon_rocket.obj\")\n",
39+
"rocket_params_path = os.path.join(parent_dir, \"rocket.yaml\")"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"id": "494f56e2",
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"Ts = 0.05\n",
50+
"sim_time = 20\n",
51+
"H = 5.0\n",
52+
"x0 = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 50, 100]) # initial state\n",
53+
"pos_target = np.array([0, 0, 10.0])\n",
54+
"\n",
55+
"rocket = Rocket(Ts=Ts, model_params_filepath=rocket_params_path)\n",
56+
"pos_controller = PIControl(pos_target)\n",
57+
"mpc = MPCVelControl().new_controller(rocket, Ts, H)\n",
58+
"\n",
59+
"t_cl, x_cl, u_cl, t_ol, x_ol, u_ol, ref = rocket.simulate_control(\n",
60+
" mpc, sim_time, H, x0, pos_control=pos_controller, method=\"linear\"\n",
61+
")\n",
62+
"\n",
63+
"vis = RocketVis(rocket, rocket_obj_path)\n",
64+
"vis.anim_rate = 1.0\n",
65+
"vis.animate(\n",
66+
" t_cl[:-1],\n",
67+
" x_cl[:, :-1],\n",
68+
" u_cl,\n",
69+
" Ref=ref[:, :-1],\n",
70+
" T_ol=t_ol[..., :-1],\n",
71+
" X_ol=x_ol,\n",
72+
" U_ol=u_ol,\n",
73+
");"
74+
]
75+
}
76+
],
77+
"metadata": {
78+
"kernelspec": {
79+
"display_name": "mpc2025",
80+
"language": "python",
81+
"name": "python3"
82+
},
83+
"language_info": {
84+
"codemirror_mode": {
85+
"name": "ipython",
86+
"version": 3
87+
},
88+
"file_extension": ".py",
89+
"mimetype": "text/x-python",
90+
"name": "python",
91+
"nbconvert_exporter": "python",
92+
"pygments_lexer": "ipython3",
93+
"version": "3.12.11"
94+
}
95+
},
96+
"nbformat": 4,
97+
"nbformat_minor": 5
98+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "d777ed6c",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%load_ext autoreload\n",
11+
"%autoreload 2\n",
12+
"\n",
13+
"# Get parent directory and add to sys.path\n",
14+
"import os\n",
15+
"import sys\n",
16+
"\n",
17+
"parent_dir = os.path.dirname(os.getcwd())\n",
18+
"sys.path.append(parent_dir)\n",
19+
"\n",
20+
"# Require ipympl\n",
21+
"%matplotlib widget "
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "c9fb75e7",
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"# MPC import\n",
32+
"from LinearMPC.MPCVelControl import MPCVelControl\n",
33+
"from PIControl.PIControl import PIControl\n",
34+
"import numpy as np\n",
35+
"from src.rocket import Rocket\n",
36+
"from src.vel_rocket_vis import RocketVis\n",
37+
"\n",
38+
"rocket_obj_path = os.path.join(parent_dir, \"Cartoon_rocket.obj\")\n",
39+
"rocket_params_path = os.path.join(parent_dir, \"rocket.yaml\")"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"id": "494f56e2",
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"Ts = 0.05\n",
50+
"sim_time = 20\n",
51+
"H = 5.0\n",
52+
"x0 = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 50, 100]) # initial state\n",
53+
"pos_target = np.array([0, 0, 10.0])\n",
54+
"\n",
55+
"rocket = Rocket(Ts=Ts, model_params_filepath=rocket_params_path)\n",
56+
"pos_controller = PIControl(pos_target)\n",
57+
"mpc = MPCVelControl().new_controller(rocket, Ts, H)\n",
58+
"\n",
59+
"t_cl, x_cl, u_cl, t_ol, x_ol, u_ol, ref = rocket.simulate_control(\n",
60+
" mpc, sim_time, H, x0, pos_control=pos_controller, method=\"nonlinear\"\n",
61+
")\n",
62+
"\n",
63+
"vis = RocketVis(rocket, rocket_obj_path)\n",
64+
"vis.anim_rate = 1.0\n",
65+
"vis.animate(\n",
66+
" t_cl[:-1],\n",
67+
" x_cl[:, :-1],\n",
68+
" u_cl,\n",
69+
" Ref=ref[:, :-1],\n",
70+
" T_ol=t_ol[..., :-1],\n",
71+
" X_ol=x_ol,\n",
72+
" U_ol=u_ol,\n",
73+
");"
74+
]
75+
}
76+
],
77+
"metadata": {
78+
"kernelspec": {
79+
"display_name": "mpc2025",
80+
"language": "python",
81+
"name": "python3"
82+
},
83+
"language_info": {
84+
"codemirror_mode": {
85+
"name": "ipython",
86+
"version": 3
87+
},
88+
"file_extension": ".py",
89+
"mimetype": "text/x-python",
90+
"name": "python",
91+
"nbconvert_exporter": "python",
92+
"pygments_lexer": "ipython3",
93+
"version": "3.12.11"
94+
}
95+
},
96+
"nbformat": 4,
97+
"nbformat_minor": 5
98+
}

0 commit comments

Comments
 (0)