Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
da1996-04 committed Jun 17, 2024
1 parent 0e95730 commit 157b642
Show file tree
Hide file tree
Showing 12 changed files with 402 additions and 318 deletions.
58 changes: 0 additions & 58 deletions src/chapter3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1297,64 +1297,6 @@
"plt.show() "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"# x = casadi.SX.sym('x')\n",
"# dt = 0.1 \n",
"# times = np.arange(0, 2+dt, dt)\n",
"# X_t = [1] # 初期値\n",
"\n",
"\n",
"# options = {'t0':0, 'tf':dt} # 積分範囲(時刻)\n",
"# ode = {'x': x, 'ode': -2*x} # 常微分方程式\n",
"\n",
"# F = casadi.integrator('F', 'idas', ode, options)\n",
"\n",
"# for t in times[:-1]:\n",
"# res = F(x0=X_t[-1])\n",
"# X_t += res['xf'].toarray().tolist()[0]\n",
"\n",
"# Y_t = np.exp(-2*times) #真の解 \n",
"\n",
"# plt.plot(times, X_t, label=\"数値解\", color=\"blue\")\n",
"# plt.plot(times, Y_t, label=\"解析解\", color=\"red\")\n",
"# plt.legend()\n",
"# plt.savefig(\"images/chap3_integ.png\")\n",
"# plt.show() "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
5 changes: 3 additions & 2 deletions src/chapter4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
"metadata": {},
"outputs": [],
"source": [
"# ロトカ・ヴォルテラモデルのパラメータ\n",
"a = 0.06\n",
"b = 0.06\n",
"c = 0.024\n",
"d = 0.06\n",
"e = 0.06\n",
"f = 0.012\n",
"\n",
"# 予測ホライズン等\n",
"# 予測ホライズン\n",
"K = 30\n",
"\n",
"nu = 1 #制御変数の次元\n",
Expand Down Expand Up @@ -148,7 +149,7 @@
"plt.xlabel(\"Time\")\n",
"plt.ylabel(\"State\")\n",
"\n",
"plt.savefig(\"images/chap4_mpc_no_control.png\")\n",
"plt.savefig(\"images/chap4_mpc_no_control.pdf\")\n",
"plt.show()"
]
},
Expand Down
62 changes: 2 additions & 60 deletions src/chapter5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"metadata": {},
"outputs": [],
"source": [
"# 倒立振子のパラメータ\n",
"g = 9.81 #重力加速度\n",
"M = 1 #台車の質量\n",
"m = 0.2 #振子の質量\n",
Expand Down Expand Up @@ -67,7 +68,7 @@
"x_ref = casadi.DM([0,0,0,0])\n",
"u_ref = casadi.DM([0])\n",
"\n",
"total = nx*(K+1) + nu*K"
"total = nx*(K+1) + nu*K #最適化変数の次元"
]
},
{
Expand Down Expand Up @@ -360,65 +361,6 @@
"ani.save(\"images/chap5_cart_pole.gif\",writer=\"pillow\",fps=fps)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# import os\n",
"# import shutil\n",
"# import glob\n",
"# import natsort\n",
"# import cv2\n",
"# shutil.rmtree(\"./tmp\",ignore_errors=True)\n",
"# os.mkdir(\"./tmp\")\n",
"# for i in np.linspace(0,99,12):\n",
"# i = int(i)\n",
"# update_figure(i)\n",
"# fig.savefig(f\"./tmp/_frame_{i}.png\")\n",
"# paths = glob.glob(\"./tmp/*.png\")\n",
"# paths = natsort.natsorted(paths)\n",
"# paths = [cv2.imread(path) for path in paths]\n",
"# paths = np.stack(paths,axis=0)\n",
"# paths = paths.reshape((4,3) + paths[0].shape)\n",
"# paths = np.concatenate(paths,axis=1)\n",
"# paths = np.concatenate(paths,axis=1)\n",
"# cv2.imwrite(\"images/chap5_cart_pole_anim.png\",paths)\n",
"# shutil.rmtree(\"./tmp\",ignore_errors=True)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# import glob\n",
"# import natsort\n",
"# import cv2\n",
"# for i in np.linspace(0,199,12):\n",
"# i = int(i)\n",
"# update_figure(i)\n",
"# fig.savefig(f\"./tmp/_frame_{i}.png\")\n",
"# paths = glob.glob(\"./tmp/*.png\")\n",
"# paths = natsort.natsorted(paths)\n",
"# paths = [cv2.imread(path) for path in paths]\n",
"# paths = np.stack(paths,axis=0)\n",
"# paths = paths.reshape(4,3,600,1200,3)\n",
"# paths = np.concatenate(paths,axis=1)\n",
"# paths = np.concatenate(paths,axis=1)\n",
"# # paths = cv2.resize(paths,dsize=None,fx=1/3,fy=1/3)\n",
"# cv2.imwrite(\"images/chap5_cart_pole_anim.png\",paths)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
164 changes: 71 additions & 93 deletions src/chapter7_2d_quadrotor.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 157b642

Please sign in to comment.