diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..3ee9ad1 --- /dev/null +++ b/_config.yml @@ -0,0 +1,2 @@ +plugins: + - jekyll-sitemap diff --git a/google6c54bbb9fe6d9d62.html b/google6c54bbb9fe6d9d62.html new file mode 100644 index 0000000..d418707 --- /dev/null +++ b/google6c54bbb9fe6d9d62.html @@ -0,0 +1 @@ +google-site-verification: google6c54bbb9fe6d9d62.html \ No newline at end of file diff --git a/readme.md b/readme.md index d828b85..8849019 100644 --- a/readme.md +++ b/readme.md @@ -1,37 +1,73 @@ # 書籍『PythonとCasADiで学ぶモデル予測制御』サポートサイト このページは書籍『PythonとCasADiで学ぶモデル予測制御』に関する情報を公開するページです。 +### 書籍の購入はこちら: +[Amazonで購入](https://amzn.asia/d/8TwVTO3) + +[版元ドットコム](https://www.hanmoto.com/bd/isbn/9784065356111) + [](https://amzn.asia/d/8TwVTO3) ## Google Colabへのリンク +ここでは、本書の各章に対応するGoogle Colabノートブックへのリンクを提供します。以下のリンクから直接実行可能です。 + +### 3章 CasADi入門 +- **3.3~3.7** [CasADiの基本](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter3.ipynb) + +### 4章 離散時間のモデル予測制御 +- **4.6** [ロトカ・ヴォルテラモデルに対するMPC](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter4.ipynb) + +### 5章 連続時間のモデル予測制御 +- **5.6** [倒立振子に対するMPC](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter5.ipynb) + +### 6章 モデル予測制御の実装に向けて +- **6.2.2** [直接的単一シューティング法と直接的多重シューティング法の比較](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_single_shooting.ipynb) +- **6.2.3** [直接的コロケーション法と直接的多重シューティング法の比較(計算速度)](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_collocation_cartpole.ipynb) +- **6.2.3** [直接的コロケーション法と直接的多重シューティング法の比較(硬い状態方程式モデル)](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_collocation_stiff.ipynb) +- **6.4.1** [ウォームスタート](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_warm_start_experiment_solution_time.ipynb) +- **6.4.1** [反復回数の制限](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_limit_iteration.ipynb) + +### 7章 CasADiにおける最適化ソルバーの比較 +- **7.2** [マス・バネ・ダンバモデルを例に用いたIPOPTとOSQPの比較](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter7_mass_spring_damper.ipynb) +- **7.3** [2次元ドローンを例に用いたQPソルバーの比較](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter7_2d_quadrotor.ipynb) +- **7.4** [ゴム紐モデルを例に用いたNLPソルバーの比較](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter7_chain_of_masses.ipynb) + +### 8章 状態推定問題と移動ホライズン推定 +- **8.4** [リチウムイオン電池に対するMHE](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter8_LIB.ipynb) +- **8.5** [CSTRに対するMPCxMHE](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter8_CSTR.ipynb) -* 3章 CasADi入門 - * [CasADiの基本](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter3.ipynb) -* 4章 離散時間のモデル予測制御 - * [ロトカ・ヴォルテラモデルに対するMPC](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter4.ipynb) -* 5章 連続時間のモデル予測制御 - * [倒立振子に対するMPC](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter5.ipynb) -* 6章 モデル予測制御の実装に向けて - * [6章 直接的単一シューティング法と直接的多重シューティング法の比較](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_single_shooting.ipynb) - * [6章 直接的コロケーション法と直接的多重シューティング法の比較(計算速度)](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_collocation_cartpole.ipynb) - * [6章 直接的コロケーション法と直接的多重シューティング法の比較(硬い状態方程式モデル)](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_collocation_stiff.ipynb) - * [6章 ウォームスタート](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_warm_start_experiment_solution_time.ipynb) - * [6章 反復回数の制限](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter6_limit_iteration.ipynb) -* 7章 CasADiにおける最適化ソルバーの比較 - * [7章 マス・バネ・ダンバモデルを例に用いたIPOPTとOSQPの比較](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter7_mass_spring_damper.ipynb) - * [7章 2次元ドローンを例に用いたQPソルバーの比較](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter7_2d_quadrotor.ipynb) - * [7章 ゴム紐モデルを例に用いたNLPソルバーの比較](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter7_chain_of_masses.ipynb) -* 8章 状態推定問題と移動ホライズン推定 - * [8章 リチウムイオン電池に対するMHE](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter8_LIB.ipynb) - * [8章 CSTRに対するMPCxMHE](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapter8_CSTR.ipynb) -* B章 CasADi中級 - * [B章 acados(* Google Colabでの動作は行えません。)](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapterB_acados_getting_started.ipynb) - * [B章 codegen for func](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapterB_codegen_function_object.ipynb) - * [B章 codegen for solver](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapterB_codegen_solver_interface.ipynb) - * [B章 discrete](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapterB_discrete_actuator.ipynb) +### B章 CasADi中級 +- **B.2.2** [関数オブジェクトのCコード生成](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapterB_codegen_function_object.ipynb) +- **B.2.3** [ソルバーオブジェクトのCコード生成](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapterB_codegen_solver_interface.ipynb) +- **B.4** [acados(* Google Colabでの動作は行えません。)](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapterB_acados_getting_started.ipynb) +- **B.6** [ロトカ・ヴォルテラモデルに対する離散入力MPC](https://colab.research.google.com/github/proxima-technology/casadi_mpc_nyuumon/blob/master/src/chapterB_discrete_actuator.ipynb) + + +## 制御のアニメーション例 +本書では、以下のような制御のアニメーションを作成することができます。 + +### 倒立振子 + + +### 2次元ドローン + + +### ゴム紐 + ## リンク集 +### Amazon +[単行本](https://www.amazon.co.jp/Python%E3%81%A8CasADi%E3%81%A7%E5%AD%A6%E3%81%B6%E3%83%A2%E3%83%87%E3%83%AB%E4%BA%88%E6%B8%AC%E5%88%B6%E5%BE%A1-KS%E7%90%86%E5%B7%A5%E5%AD%A6%E5%B0%82%E9%96%80%E6%9B%B8-%E6%B7%B1%E6%B4%A5-%E5%8D%93%E5%BC%A5/dp/4065356113) + +### 版元ドットコム +[版元ドットコム](https://www.hanmoto.com/bd/isbn/9784065356111) + +### 参考資料 +[CasADi公式](https://web.casadi.org/) + +[サポートサイト](https://github.com/proxima-technology/casadi_mpc_nyuumon) + ### 著者発信の情報 |ソース |リンク |補足| diff --git a/src/chapterB_acados_getting_started.ipynb b/src/chapterB_acados_getting_started.ipynb index c8077a4..f26fac6 100644 --- a/src/chapterB_acados_getting_started.ipynb +++ b/src/chapterB_acados_getting_started.ipynb @@ -4,19 +4,7 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Collecting casadi==3.6.3\n", - " Downloading casadi-3.6.3-cp310-none-manylinux2014_x86_64.whl.metadata (1.8 kB)\n", - "Requirement already satisfied: numpy in /home/proxima/anaconda3/envs/work/lib/python3.10/site-packages (from casadi==3.6.3) (1.26.4)\n", - "Downloading casadi-3.6.3-cp310-none-manylinux2014_x86_64.whl (67.5 MB)\n", - "\u001b[2K \u001b[38;2;249;38;114m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[38;5;237m╺\u001b[0m\u001b[38;5;237m━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m34.6/67.5 MB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:10\u001b[0m:10\u001b[0m" - ] - } - ], + "outputs": [], "source": [ "# !pip install casadi\n", "!pip install casadi==3.6.3 # officially supported newest version by acados at the time of writing.\n", @@ -29,10 +17,10 @@ "import matplotlib.patches as patches\n", "from matplotlib.animation import FuncAnimation\n", "\n", - "os.makedirs('images',exist_ok=True)\n", - "if os.name == 'nt':\n", - " plt.rcParams['font.family'] = 'MS Gothic'\n", - "elif os.name == 'posix':\n", + "os.makedirs(\"images\",exist_ok=True)\n", + "if os.name == \"nt\":\n", + " plt.rcParams[\"font.family\"] = \"MS Gothic\"\n", + "elif os.name == \"posix\":\n", " !pip install japanize-matplotlib\n", "\n", "clear_output()" @@ -131,7 +119,7 @@ " cost = (casadi.dot(Q@x,x) + casadi.dot(R@u,u)) / 2\n", " return cost\n", "\n", - "def compute_final_cost(x):\n", + "def compute_terminal_cost(x):\n", " cost = casadi.dot(Q_f@x,x) / 2\n", " return cost" ] @@ -145,8 +133,8 @@ "def make_nlp():\n", " RK4 = make_RK4()\n", "\n", - " U = [casadi.SX.sym(f\"u_{i}\",nu) for i in range(K)]\n", - " X = [casadi.SX.sym(f\"x_{i}\",nx) for i in range(K+1)]\n", + " U = [casadi.SX.sym(f\"u_{k}\",nu) for k in range(K)]\n", + " X = [casadi.SX.sym(f\"x_{k}\",nx) for k in range(K+1)]\n", " G = []\n", "\n", " J = 0\n", @@ -155,7 +143,7 @@ " J += compute_stage_cost(X[k],U[k])*dt\n", " eq = X[k+1] - RK4(x=X[k],u=U[k])[\"x_next\"]\n", " G.append(eq)\n", - " J += compute_final_cost(X[-1])\n", + " J += compute_terminal_cost(X[-1])\n", "\n", " # option = {'print_time':False,'ipopt':{'print_level':0}}\n", " option = {} # printオプションを有効化\n", @@ -323,16 +311,16 @@ "Number of equality constraint Jacobian evaluations = 46\n", "Number of inequality constraint Jacobian evaluations = 0\n", "Number of Lagrangian Hessian evaluations = 44\n", - "Total seconds in IPOPT = 0.043\n", + "Total seconds in IPOPT = 0.037\n", "\n", "EXIT: Optimal Solution Found.\n", " S : t_proc (avg) t_wall (avg) n_eval\n", - " nlp_f | 2.98ms ( 15.60us) 290.62us ( 1.52us) 191\n", - " nlp_g | 15.27ms ( 79.94us) 1.49ms ( 7.82us) 191\n", - " nlp_grad_f | 1.01ms ( 24.51us) 107.45us ( 2.62us) 41\n", - " nlp_hess_l | 29.34ms (682.42us) 3.36ms ( 78.11us) 43\n", - " nlp_jac_g | 12.18ms (259.09us) 1.35ms ( 28.65us) 47\n", - " total | 437.09ms (437.09ms) 44.92ms ( 44.92ms) 1\n" + " nlp_f | 2.29ms ( 11.97us) 273.77us ( 1.43us) 191\n", + " nlp_g | 11.70ms ( 61.23us) 1.40ms ( 7.34us) 191\n", + " nlp_grad_f | 803.00us ( 19.59us) 101.46us ( 2.47us) 41\n", + " nlp_hess_l | 22.32ms (519.05us) 3.14ms ( 73.11us) 43\n", + " nlp_jac_g | 8.68ms (184.64us) 1.19ms ( 25.24us) 47\n", + " total | 291.19ms (291.19ms) 37.68ms ( 37.68ms) 1\n" ] } ], @@ -367,7 +355,7 @@ "\n", "def export_cart_pole_model() -> AcadosModel:\n", "\n", - " model_name = 'cart_pole'\n", + " model_name = \"cart_pole\"\n", " \n", " f = make_f()\n", " states = casadi.SX.sym(\"states\",nx)\n", @@ -423,20 +411,20 @@ "\n", "rm -f libacados_ocp_solver_cart_pole.so\n", "rm -f cart_pole_cost/cart_pole_cost_ext_cost_0_fun.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_fun.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac_hess.o acados_solver_cart_pole.o\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_0_fun.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac_hess.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_fun.o cart_pole_cost/cart_pole_cost_ext_cost_fun.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac_hess.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_e_fun.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac_hess.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o acados_solver_cart_pole.o acados_solver_cart_pole.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_model/cart_pole_expl_ode_fun.o cart_pole_model/cart_pole_expl_ode_fun.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_model/cart_pole_expl_vde_forw.o cart_pole_model/cart_pole_expl_vde_forw.c\n", - "cc -fPIC -std=c99 -O3 -I/home/hishinuma/acados/include -I/home/hishinuma/acados/include/acados -I/home/hishinuma/acados/include/blasfeo/include -I/home/hishinuma/acados/include/hpipm/include -c -o cart_pole_model/cart_pole_expl_vde_adj.o cart_pole_model/cart_pole_expl_vde_adj.c\n", - "cc -shared cart_pole_cost/cart_pole_cost_ext_cost_0_fun.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_fun.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac_hess.o acados_solver_cart_pole.o cart_pole_model/cart_pole_expl_ode_fun.o cart_pole_model/cart_pole_expl_vde_forw.o cart_pole_model/cart_pole_expl_vde_adj.o -o libacados_ocp_solver_cart_pole.so -L/home/hishinuma/acados/lib -lacados -lhpipm -lblasfeo -lm \\\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_0_fun.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac_hess.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_fun.o cart_pole_cost/cart_pole_cost_ext_cost_fun.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac_hess.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_e_fun.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac_hess.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o acados_solver_cart_pole.o acados_solver_cart_pole.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_model/cart_pole_expl_ode_fun.o cart_pole_model/cart_pole_expl_ode_fun.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_model/cart_pole_expl_vde_forw.o cart_pole_model/cart_pole_expl_vde_forw.c\n", + "/usr/lib/ccache/gcc -fPIC -std=c99 -O3 -I/home/proxima/acados/include -I/home/proxima/acados/include/acados -I/home/proxima/acados/include/blasfeo/include -I/home/proxima/acados/include/hpipm/include -c -o cart_pole_model/cart_pole_expl_vde_adj.o cart_pole_model/cart_pole_expl_vde_adj.c\n", + "/usr/lib/ccache/gcc -shared cart_pole_cost/cart_pole_cost_ext_cost_0_fun.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_0_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_fun.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_fun_jac_hess.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac.o cart_pole_cost/cart_pole_cost_ext_cost_e_fun_jac_hess.o acados_solver_cart_pole.o cart_pole_model/cart_pole_expl_ode_fun.o cart_pole_model/cart_pole_expl_vde_forw.o cart_pole_model/cart_pole_expl_vde_adj.o -o libacados_ocp_solver_cart_pole.so -L/home/proxima/acados/lib -lacados -lhpipm -lblasfeo -lm \\\n", "-L -l\n", "acados was compiled without OpenMP.\n" ] @@ -452,10 +440,10 @@ "ocp.model = model\n", "ocp.dims.N = K\n", "\n", - "ocp.cost.cost_type = 'EXTERNAL'\n", - "ocp.cost.cost_type_e = 'EXTERNAL'\n", + "ocp.cost.cost_type = \"EXTERNAL\"\n", + "ocp.cost.cost_type_e = \"EXTERNAL\"\n", "ocp.model.cost_expr_ext_cost = compute_stage_cost(model.x,model.u)\n", - "ocp.model.cost_expr_ext_cost_e = compute_final_cost(model.x)\n", + "ocp.model.cost_expr_ext_cost_e = compute_terminal_cost(model.x)\n", "\n", "ocp.constraints.lbu = np.array(u_lb)\n", "ocp.constraints.ubu = np.array(u_ub)\n", @@ -463,21 +451,21 @@ "\n", "ocp.constraints.x0 = state_init\n", "\n", - "ocp.solver_options.qp_solver = 'PARTIAL_CONDENSING_HPIPM'\n", + "ocp.solver_options.qp_solver = \"PARTIAL_CONDENSING_HPIPM\"\n", "ocp.solver_options.qp_solver_cond_N = 5\n", "\n", - "ocp.solver_options.hpipm_mode = 'SPEED'\n", - "# ocp.solver_options.hpipm_mode = 'BALANCE' \n", - "# ocp.solver_options.hpipm_mode = 'ROBUST' \n", + "ocp.solver_options.hpipm_mode = \"SPEED\"\n", + "# ocp.solver_options.hpipm_mode = \"BALANCE\"\n", + "# ocp.solver_options.hpipm_mode = \"ROBUST\"\n", "\n", - "# ocp.solver_options.hessian_approx = 'EXACT'\n", - "ocp.solver_options.hessian_approx = 'GAUSS_NEWTON' \n", + "# ocp.solver_options.hessian_approx = \"EXACT\"\n", + "ocp.solver_options.hessian_approx = \"GAUSS_NEWTON\"\n", "\n", - "ocp.solver_options.nlp_solver_type = 'SQP'\n", - "ocp.solver_options.ext_fun_compile_flags = '-O3'\n", + "ocp.solver_options.nlp_solver_type = \"SQP\"\n", + "ocp.solver_options.ext_fun_compile_flags = \"-O3\"\n", "\n", "ocp.solver_options.tf = T\n", - "ocp_solver = AcadosOcpSolver(ocp, json_file = 'acados_ocp.json')" + "ocp_solver = AcadosOcpSolver(ocp, json_file = \"acados_ocp.json\")" ] }, { @@ -489,7 +477,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'Tsim': 0.05, 'alpha_min': 0.05, 'alpha_reduction': 0.7, 'collocation_type': 'GAUSS_LEGENDRE', 'cost_discretization': 'EULER', 'custom_templates': [], 'custom_update_copy': True, 'custom_update_filename': '', 'custom_update_header_filename': '', 'eps_sufficient_descent': 0.0001, 'exact_hess_constr': 1, 'exact_hess_cost': 1, 'exact_hess_dyn': 1, 'ext_cost_num_hess': 0, 'ext_fun_compile_flags': '-O3', 'full_step_dual': 0, 'globalization': 'FIXED_STEP', 'globalization_use_SOC': 0, 'hessian_approx': 'GAUSS_NEWTON', 'hpipm_mode': 'SPEED', 'initialize_t_slacks': 0, 'integrator_type': 'ERK', 'levenberg_marquardt': 0.0, 'line_search_use_sufficient_descent': 0, 'model_external_shared_lib_dir': None, 'model_external_shared_lib_name': None, 'nlp_solver_ext_qp_res': 0, 'nlp_solver_max_iter': 100, 'nlp_solver_step_length': 1.0, 'nlp_solver_tol_comp': 1e-06, 'nlp_solver_tol_eq': 1e-06, 'nlp_solver_tol_ineq': 1e-06, 'nlp_solver_tol_stat': 1e-06, 'nlp_solver_type': 'SQP', 'print_level': 0, 'qp_solver': 'PARTIAL_CONDENSING_HPIPM', 'qp_solver_cond_N': 5, 'qp_solver_cond_ric_alg': 1, 'qp_solver_iter_max': 50, 'qp_solver_ric_alg': 1, 'qp_solver_tol_comp': None, 'qp_solver_tol_eq': None, 'qp_solver_tol_ineq': None, 'qp_solver_tol_stat': None, 'qp_solver_warm_start': 0, 'reg_epsilon': 0.0001, 'regularize_method': 'NO_REGULARIZE', 'shooting_nodes': [0.0, 0.05, 0.1, 0.15000000000000002, 0.2, 0.25, 0.3, 0.35, 0.39999999999999997, 0.44999999999999996, 0.49999999999999994, 0.5499999999999999, 0.6, 0.65, 0.7000000000000001, 0.7500000000000001, 0.8000000000000002, 0.8500000000000002, 0.9000000000000002, 0.9500000000000003, 1.0000000000000002], 'sim_method_jac_reuse': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'sim_method_newton_iter': 3, 'sim_method_newton_tol': 0.0, 'sim_method_num_stages': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], 'sim_method_num_steps': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 'tf': 1, 'time_steps': [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05]}\n" + "{'Tsim': 0.05, 'adaptive_levenberg_marquardt_lam': 5.0, 'adaptive_levenberg_marquardt_mu0': 0.001, 'adaptive_levenberg_marquardt_mu_min': 1e-16, 'alpha_min': 0.05, 'alpha_reduction': 0.7, 'as_rti_iter': 1, 'as_rti_level': 4, 'collocation_type': 'GAUSS_LEGENDRE', 'cost_discretization': 'EULER', 'custom_templates': [], 'custom_update_copy': True, 'custom_update_filename': '', 'custom_update_header_filename': '', 'eps_sufficient_descent': 0.0001, 'exact_hess_constr': 1, 'exact_hess_cost': 1, 'exact_hess_dyn': 1, 'ext_cost_num_hess': 0, 'ext_fun_compile_flags': '-O3', 'fixed_hess': 0, 'full_step_dual': 0, 'globalization': 'FIXED_STEP', 'globalization_use_SOC': 0, 'hessian_approx': 'GAUSS_NEWTON', 'hpipm_mode': 'SPEED', 'initialize_t_slacks': 0, 'integrator_type': 'ERK', 'levenberg_marquardt': 0.0, 'line_search_use_sufficient_descent': 0, 'log_primal_step_norm': False, 'model_external_shared_lib_dir': None, 'model_external_shared_lib_name': None, 'nlp_solver_ext_qp_res': 0, 'nlp_solver_max_iter': 100, 'nlp_solver_step_length': 1.0, 'nlp_solver_tol_comp': 1e-06, 'nlp_solver_tol_eq': 1e-06, 'nlp_solver_tol_ineq': 1e-06, 'nlp_solver_tol_stat': 1e-06, 'nlp_solver_type': 'SQP', 'num_threads_in_batch_solve': 1, 'print_level': 0, 'qp_solver': 'PARTIAL_CONDENSING_HPIPM', 'qp_solver_cond_N': 5, 'qp_solver_cond_ric_alg': 1, 'qp_solver_iter_max': 50, 'qp_solver_ric_alg': 1, 'qp_solver_tol_comp': None, 'qp_solver_tol_eq': None, 'qp_solver_tol_ineq': None, 'qp_solver_tol_stat': None, 'qp_solver_warm_start': 0, 'reg_epsilon': 0.0001, 'regularize_method': 'NO_REGULARIZE', 'rti_log_residuals': 0, 'shooting_nodes': [0.0, 0.05, 0.1, 0.15000000000000002, 0.2, 0.25, 0.3, 0.35, 0.39999999999999997, 0.44999999999999996, 0.49999999999999994, 0.5499999999999999, 0.6, 0.65, 0.7000000000000001, 0.7500000000000001, 0.8000000000000002, 0.8500000000000002, 0.9000000000000002, 0.9500000000000003, 1.0000000000000002], 'sim_method_jac_reuse': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'sim_method_newton_iter': 3, 'sim_method_newton_tol': 0.0, 'sim_method_num_stages': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], 'sim_method_num_steps': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 'tf': 1, 'time_steps': [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05], 'with_adaptive_levenberg_marquardt': False, 'with_solution_sens_wrt_params': False, 'with_value_sens_wrt_params': False}\n" ] } ], @@ -521,7 +509,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "total CPU time previous call : 0.002611\n", + "total CPU time previous call : 0.002203\n", "\n", "iter\tres_stat\tres_eq\t\tres_ineq\tres_comp\tqp_stat\tqp_iter\talpha\n", "0\t3.141593e+01\t7.208271e-17\t1.500000e+01\t0.000000e+00\t0\t0\t0.000000e+00\t\n", @@ -567,7 +555,7 @@ ], "source": [ "# see https://docs.acados.org/python_interface/index.html#acados_template.acados_ocp_solver.AcadosOcpSolver.get_stats\n", - "print(\"total CPU time previous call :\",ocp_solver.get_stats('time_tot'))\n", + "print(\"total CPU time previous call :\",ocp_solver.get_stats(\"time_tot\"))\n", "ocp_solver.print_statistics()" ] }, @@ -596,8 +584,8 @@ ], "source": [ "u_traj_acados = np.ndarray((K, nu))\n", - "for i in range(K):\n", - " u_traj_acados[i,:] = ocp_solver.get(i, \"u\")\n", + "for k in range(K):\n", + " u_traj_acados[k,:] = ocp_solver.get(k, \"u\")\n", "\n", "timestamp = np.array(range(K))*dt\n", "plt.plot(timestamp, u_traj_casadi,linewidth=3,label=\"casadi (chapter 5)\")\n", @@ -633,7 +621,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.10.12" } }, "nbformat": 4,