Skip to content

Instantly share code, notes, and snippets.

View mayataka's full-sized avatar

Sotaro Katayama mayataka

View GitHub Profile
@mayataka
mayataka / casadi_milp.py
Last active August 5, 2022 13:58
A very simple MILP via CasADi
from casadi import *
import numpy as np
# optimization variables
x1 = SX.sym('x1')
x2 = SX.sym('x2')
w = [x1, x2]
w0 = [0, 0]
lbw = [-np.inf, -np.inf]
@mayataka
mayataka / set-my-ubuntu.sh
Last active April 25, 2023 07:25
Set Ubuntu 22.04
gsettings set org.gnome.desktop.input-sources xkb-options "['ctrl:nocaps']"
sudo apt update -y
sudo apt upgrade -y
sudo apt autoremove -y
sudo apt install build-essential cmake git libeigen3-dev vim tmux doxygen graphviz ffmpeg libglpk-dev -y
sudo apt install python3-sphinx -y
# install docker
sudo apt install lsb-release -y
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
@mayataka
mayataka / introduction_to_numerical_optimal_control.ipynb
Last active September 2, 2024 08:02
数値最適制御入門の入門
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mayataka
mayataka / optuna_mpc.py
Last active January 23, 2022 05:57
Parameter tuning of MPC via Optuna
from casadi import *
import math
import numpy as np
import optuna
class CartPole:
def __init__(self):
self.mc = 2.0 # cart の質量[kg]
self.mp = 0.2 # pole の質量[kg]
@mayataka
mayataka / casadi_introduction.md
Last active July 19, 2024 07:59
How to Use CasADi

CasADi とは?

数値最適化用の自動微分&各種ソルバーへのインターフェースツールです. MPCなどでの活用が便利です.

なぜ CasADiを使うのか?

  • 定式化が非常に直感的で使いやすい.
  • かなり変わった定式化にも対応可能(一般的な数値最適化ソルバーであるため)
  • バックエンドソルバーが豊富
  • AutoGenU,ACADO Toolkitといったシンボリック計算MPCツールと比べてトータルの実装時間が圧倒的に高速
@mayataka
mayataka / casadi_mpc.py
Last active November 26, 2022 08:52
MPC via CasADi
from casadi import *
import math
import numpy as np
# cartpole のダイナミクスを記述
# cartpoleの運動方程式は(https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-832-underactuated-robotics-spring-2009/readings/MIT6_832s09_read_ch03.pdf)を参照した
class CartPole:
def __init__(self):
self.mc = 2.0 # cart の質量[kg]
@mayataka
mayataka / casadi_ocp.py
Created October 7, 2021 23:41
Direct Optimal Control via CasADi
from casadi import *
import math
# 問題設定
T = 5.0 # ホライゾン長さ
N = 100 # ホライゾン離散化グリッド数
dt = T / N # 離散化ステップ
nx = 4 # 状態空間の次元
nu = 1 # 制御入力の次元
@mayataka
mayataka / client_settings.sh
Last active April 26, 2021 05:38
mayataka-client-settings
gsettings set org.gnome.desktop.input-sources xkb-options "['ctrl:nocaps']"
echo export PATH=/opt/openrobots/bin:$PATH >> ~/.bashrc
echo export PKG_CONFIG_PATH=/opt/openrobots/lib/pkgconfig:$PKG_CONFIG_PATH >> ~/.bashrc
echo export LD_LIBRARY_PATH=/opt/openrobots/lib:$LD_LIBRARY_PATH >> ~/.bashrc
echo export PYTHONPATH=/opt/openrobots/lib/python3.8/site-packages:$PYTHONPATH >> ~/.bashrc
echo export CMAKE_PREFIX_PATH=/opt/openrobots:$CMAKE_PREFIX_PATH >> ~/.bashrc
source ~/.bashrc
@mayataka
mayataka / install_pinocchio_viewer.sh
Last active January 19, 2021 00:49
install pinocchio viewer
sudo apt update
sudo apt install robotpkg-py38-qt5-gepetto-viewer-corba -y
git clone https://github.com/stack-of-tasks/pinocchio-gepetto-viewer.git --recursive
cd pinocchio-gepetto-viewer
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
sudo make install
@mayataka
mayataka / install_pinocchio.sh
Last active July 24, 2024 08:19
Install pinocchio for Ubuntu 20.04
sudo apt install -qqy lsb-release gnupg2 curl
echo "deb [arch=amd64] http://robotpkg.openrobots.org/packages/debian/pub $(lsb_release -cs) robotpkg" | sudo tee /etc/apt/sources.list.d/robotpkg.list
curl http://robotpkg.openrobots.org/packages/debian/robotpkg.key | sudo apt-key add -
sudo apt update -y
sudo apt install -qqy robotpkg-py38-pinocchio
echo export PATH=/opt/openrobots/bin:$PATH >> ~/.bashrc
echo export PKG_CONFIG_PATH=/opt/openrobots/lib/pkgconfig:$PKG_CONFIG_PATH >> ~/.bashrc
echo export LD_LIBRARY_PATH=/opt/openrobots/lib:$LD_LIBRARY_PATH >> ~/.bashrc
echo export PYTHONPATH=/opt/openrobots/lib/python3.8/site-packages:$PYTHONPATH >> ~/.bashrc
echo export CMAKE_PREFIX_PATH=/opt/openrobots:$CMAKE_PREFIX_PATH >> ~/.bashrc