OCS2 入门教程(一)

2023-12-17 16:40:04

系列文章目录


前言 -?概述

????????OCS2 是专为切换系统优化控制(Optimal?Control for?Switched?Systems,OCS2)定制的 C++ 工具箱。该工具箱提供以下算法的高效实现:

  • SLQ:连续时间域约束 DDP
  • iLQR:离散时域约束 DDP
  • SQP:基于 HPIPM 的多重打靶算法
  • IPM: 基于非线性内点法的多重搜索算法
  • SLP:基于 PIPG 的顺序线性规划算法

????????部分翻译:

英文中文
Multiple-?shooting algorithm多重打靶法
DDP微分动态规划
HPIPM一个 QP 求解器
Path integral stochatic optimal control路径积分随机最优控制

????????OCS2 通过增强拉格朗日法(Augmented Lagrangian)或松弛障碍法(relaxed barrier methods)处理一般路径约束。为了便于将 OCS2 应用于机器人任务,它为用户提供了额外的工具,以便根据 URDF 模型设置系统动力学(如运动学(kinematic)或动力学(dynamic)模型)和成本/约束(cost/constraints)(如避免自碰撞(self-collision avoidance)和末端执行器跟踪(end-effector tracking))。

????????该库还提供了一个自动微分(automatic differentiation)工具,用于计算系统动力学、约束和成本的导数(derivatives)。为了便于在机器人平台上部署,OCS2 提供了 ROS 接口工具。该工具箱的实现高效且数值稳定,加上其友好的用户界面,为在机载计算能力有限(limited onboard computation)的众多机器人应用中使用该工具箱铺平了道路。

0.1 如何使用 OCS2 工具箱?

????????OCS2 可以轻松安装在 Ubuntu 上。源代码也是公开的。要开始使用控制工具箱,请参阅 "开始安装 "和 "入门 "页面。

0.2 许可证

????????OCS2 工具箱根据 BSD 3 条款许可发布。请注意源代码目录中的许可证和注意事项文件。

0.3 荣誉

????????以下人员参与了 OCS2 的开发:

项目经理: Farbod Farshidian。

主要开发人员 Farbod Farshidian、Ruben Grandia、Michael Spieler、Jan Carius、Jean-Pierre Sleiman。

其他开发人员 Alexander Reske、Sotaro Katayama、Mayank Mittal、Jia-Ruei Chiu、Johannes Pankert、Perry Franklin、Tom Lankhorst、David Hoeller、Asutosh Satapathy、Markus Giftthaler、Edo Jelavic。

????????致谢: OCS2 工具箱的开发由苏黎世联邦理工学院的 ADRL 团队发起,该项目在苏黎世联邦理工学院的 RSL 继续发展。RSL 团队现在积极支持 OCS2 的开发。

0.4 引用 OCS2

????????要在学术研究中引用工具箱,请使用以下方式:

@misc{OCS2、
? ?title = {{OCS2}: ?开关系统优化控制开源库}、
? ?note = {[在线]。Available: \url{https://github.com/leggedrobotics/ocs2}}、
? ?author = {Farbod Farshidian and others}}.
}

0.5 视频教程

  • OCS2 工具箱教程,Farbod Farshidian,MPC 研讨会,RSS 2021(链接)。
  • 腿部运动和操纵的实时优化控制,Marco Hutter,MPC 研讨会,RSS 2021(链接)。

0.6 相关出版物

????????本工具箱已在以下出版物中使用:

  1. Farbod Farshidian, Michael Neunert, Alexander?W Winkler, Gonzalo Rey, and Jonas Buchli. An efficient optimal planning and control framework for quadrupedal locomotion. In?2017 IEEE International Conference on Robotics and Automation (ICRA), 93–100. IEEE, 2017.

  2. Farbod Farshidian, Maryam Kamgarpour, Diego Pardo, and Jonas Buchli. Sequential linear quadratic optimal control for nonlinear switched systems.?IFAC, 50(1):1463–1469, 2017.

  3. Farbod Farshidian, Edo Jelavic, Asutosh Satapathy, Markus Giftthaler, and Jonas Buchli. Real-time motion planning of legged robots: a model predictive control approach. In?2017 IEEE-RAS 17th International Conference on Humanoid Robotics (Humanoids), 577–584. IEEE, 2017.

  4. Markus Giftthaler, Farbod Farshidian, Timothy Sandy, Lukas Stadelmann, and Jonas Buchli. Efficient kinematic planning for mobile manipulators with non-holonomic constraints using optimal control. In?2017 IEEE International Conference on Robotics and Automation (ICRA), 3411–3417. IEEE, 2017.

  5. Farbod Farshidian, David Hoeller, and Marco Hutter. Deep value model predictive control. In?Conference on Robot Learning (CoRL), 990–1004. PMLR, 2020.

  6. Ruben Grandia, Farbod Farshidian, Alexey Dosovitskiy, René Ranftl, and Marco Hutter. Frequency-aware model predictive control.?IEEE Robotics and Automation Letters, 4(2):1517–1524, 2019.

  7. Maria?Vittoria Minniti, Farbod Farshidian, Ruben Grandia, and Marco Hutter. Whole-body mpc for a dynamically stable mobile manipulator.?IEEE Robotics and Automation Letters, 4(4):3687–3694, 2019.

  8. Jan Carius, Farbod Farshidian, and Marco Hutter. Mpc-net: a first principles guided policy search.?IEEE Robotics and Automation Letters, 5(2):2897–2904, 2020.

  9. Ruben Grandia, Farbod Farshidian, René Ranftl, and Marco Hutter. Feedback mpc for torque-controlled legged robots. In?2019 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), 4730–4737. IEEE, 2019.

  10. Abel Gawel, Hermann Blum, Johannes Pankert, Koen Kr?mer, Luca Bartolomei, Selen Ercan, Farbod Farshidian, Margarita Chli, Fabio Gramazio, Roland Siegwart, and others. A fully-integrated sensing and control system for high-accuracy mobile robotic building construction. In?2019 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), 2300–2307. IEEE, 2019.

  11. Jean-Pierre Sleiman, Farbod Farshidian, Maria?Vittoria Minniti, and Marco Hutter. A unified mpc framework for whole-body dynamic locomotion and manipulation.?IEEE Robotics and Automation Letters, 6(3):4688–4695, 2021.

  12. Ruben Grandia, Andrew?J Taylor, Aaron?D Ames, and Marco Hutter. Multi-layered safety for legged robots via control barrier functions and model predictive control.?arXiv preprint arXiv:2011.00032, 2020.

  13. Magnus Gaertner, Marko Bjelonic, Farbod Farshidian, and Marco Hutter. Collision-free mpc for legged robots in static and dynamic scenes. In?2021 IEEE International Conference on Robotics and Automation (ICRA). IEEE, 2021.

  14. Jean-Pierre Sleiman, Farbod Farshidian, and Marco Hutter. Constraint handling in continuous-time ddp-based model predictive control. In?2021 IEEE International Conference on Robotics and Automation (ICRA). IEEE, 2021.

  15. Alexander Reske, Jan Carius, Yuntao Ma, Farbod Farshidian, and Marco Hutter. Imitation learning from mpc for quadrupedal multi-gait control. In?2021 IEEE International Conference on Robotics and Automation (ICRA). IEEE, 2021.

  16. Maria?Vittoria Minniti, Ruben Grandia, Kevin F?h, Farbod Farshidian, and Marco Hutter. Model predictive robot-environment interaction control for mobile manipulation tasks. In?2021 IEEE International Conference on Robotics and Automation (ICRA). IEEE, 2021.

  17. Mayank Mittal, David Hoeller, Farbod Farshidian, Marco Hutter, and Animesh Garg. Articulated object interaction in unknown scenes with whole-body mobile manipulation.?arXiv preprint arXiv:2103.10534, 2021.


一、安装

1.1 前提条件

????????OCS2 库以 C++11 编写,在 Ubuntu 20.04 下测试,库版本与软件包源码中提供的版本一致。

1.1.1?源代码

????????源代码托管在 GitHub:leggedrobotics/ocs2。

# Clone OCS2
git clone git@github.com:leggedrobotics/ocs2.git

?1.1.2?依赖

  • C++ compiler with C++11 support

  • Eigen (v3.3)

  • Boost C++ (v1.71)

  • GLPK?

    sudo?apt?install?libglpk-dev
  • catkin?

    sudo?apt-get?install?catkin
  • pybind11_catkin, ROS package, installable via?

    sudo?apt?install?ros-noetic-pybind11-catkin
  • catkin-pkg package for python3. Install with?

    sudo?apt?install?python3-catkin-tools
  • Doxygen for documentation. Install with?

    sudo?apt?install?doxygen?doxygen-latex

1.1.3?可选依赖项

  • 将 Pinocchio 和 HPP-FCL 克隆到工作区,以获得刚性多体动力学库和自碰撞支持?
# Clone pinocchio
git clone --recurse-submodules https://github.com/leggedrobotics/pinocchio.git
# Clone hpp-fcl
git clone --recurse-submodules https://github.com/leggedrobotics/hpp-fcl.git
# install dependencies
sudo apt install liburdfdom-dev liboctomap-dev libassimp-dev
  • 对于 OCS2 单元测试和机器人示例中使用的各种机器人资产
# Clone ocs2_robotic_assets
git clone https://github.com/leggedrobotics/ocs2_robotic_assets.git
  • ?rqt_multiplot 软件包可用于可视化求解器的性能指标和其他优化输出结果
sudo apt-get install ros-noetic-rqt-multiplot
  • RaiSim 模拟器可用作滚动的提供者。相应的 ocs2_raisim 软件包有额外要求:

????????RaiSim 软件包需要通过克隆到工作区从源代码中安装:

git clone --depth 1 https://github.com/raisimTech/raisimLib.git -b v1.1.01

????????请按照 RaiSim 网页上的说明进行安装。或者,为了让 catkin 容易找到安装程序并在将来方便卸载,可以考虑使用 CheckInstall 将 RaiSim 安装为 debian 软件包。为此,请替换原来的命令:

cmake .. -DCMAKE_INSTALL_PREFIX=$LOCAL_INSTALL <other options>
make install -j4

?????????与:

cmake .. <other options>     (Without INSTALL_PREFIX)
make -j4 && sudo checkinstall

????????这将把 RaiSim 安装到 /usr/local/lib 的默认位置,catkin 也会自动检测到该位置。当 checkinstall 提出要求时,请将软件包名称更改为合适的名称(如 "raisim"),以便日后进行软件包管理时查找,例如卸载(dpkg -r <package_name>)。

????????要实现可视化,请使用 RaiSim Unity,在 raisimLib/raisimUnity 目录中提供了预置的可执行文件。例如,它可用于调试目的,查看 OCS2 和 RaiSim 之间的转换是否正确。

  • 网格地图 catkin 软件包,可使用 sudo apt install ros-noetic-grid-map-msgs 安装。
  • ONNX Runtime 是一种推理和训练加速器。在这里,它用于在 C++ 代码中部署学习到的 MPC-Net 策略。要在本地安装它,请执行以下操作:
cd /tmp
wget https://github.com/microsoft/onnxruntime/releases/download/v1.7.0/onnxruntime-linux-x64-1.7.0.tgz
tar xf onnxruntime-linux-x64-1.7.0.tgz
mkdir -p ~/.local/bin ~/.local/include/onnxruntime ~/.local/lib ~/.local/share/cmake/onnxruntime
rsync -a /tmp/onnxruntime-linux-x64-1.7.0/include/ ~/.local/include/onnxruntime
rsync -a /tmp/onnxruntime-linux-x64-1.7.0/lib/ ~/.local/lib
rsync -a ~/git/ocs2/ocs2_mpcnet/ocs2_mpcnet_core/misc/onnxruntime/cmake/ ~/.local/share/cmake/onnxruntime

????????我们提供了自定义的 cmake 配置和版本文件,以便在不修改 LIBRARY_PATH 和 LD_LIBRARY_PATH 的情况下启用 find_package(onnxruntime)。请注意,上述最后一条命令假定您已将 OCS2 克隆到用户主目录下的 git 文件夹中。?

?

  • 训练 MPC-Net 策略时建议使用虚拟环境:
sudo apt-get install python3-venv

????????创建一个环境,并赋予其访问系统站点软件包的权限:

mkdir venvs && cd venvs
python3 -m venv mpcnet

????????激活环境并安装需求:

source ~/venvs/mpcnet/bin/activate
python3 -m pip install -r ~/git/ocs2/ocs2_mpcnet/ocs2_mpcnet_core/requirements.txt

????????较新的显卡可能需要 CUDA 功能,而标准 PyTorch 安装目前还不支持该功能。在这种情况下,检查 PyTorch Start Locally 是否有兼容的版本,例如,运行

pip3 install torch==1.10.2+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

?

1.2 安装

1.2.1 创建程序库

????????创建一个新的 catkin 工作区:

# Create the directories
# Do not forget to change <...> parts
mkdir -p <directory_to_ws>/<catkin_ws_name>/src
cd <directory_to_ws>/<catkin_ws_name>/

# Initialize the catkin workspace
catkin init
catkin config --extend /opt/ros/noetic
catkin config -DCMAKE_BUILD_TYPE=RelWithDebInfo

????????克隆 OCS2 库:

# Navigate to the directory of src
# Do not forget to change <...> parts
cd <directory_to_ws>/<catkin_ws_name>/src
git clone git@github.com:leggedrobotics/ocs2.git

????????构建并运行单元测试

# Build it
catkin build ocs2

# Source it
source <directory_to_ws>/<catkin_ws_name>/devel/setup.bash

# run tests
catkin run_tests ocs2

1.2.2 构建本文档

????????假设已安装 python catkin 工具,请运行以下命令:

# Navigate to the directory of ocs2_doc
# Do not forget to change <...> parts
cd <directory_to_ws>/<catkin_ws_name>/src/ocs2/ocs2_doc

# make build directory
mkdir -p build
# Navigate to the build folder
cd build

# build docs
cmake ..
make

????????这将生成文档并将其放在 build/output/sphinx 文件夹中。在浏览器中打开 index.html。?

文章来源:https://blog.csdn.net/weixin_46300916/article/details/135044675
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。