从零上手机器人动力学库pinocchio(一)pinocchio简介

本文介绍了Pinocchio库,一个快速且灵活的机器人动力学算法实现,包括安装教程、与Pybullet的集成以及其提供的主要算法如正向运动学、逆动力学等。此外,还讨论了官方指南和与Pybullet的接口应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、安装

二、Pinocchio中实现的主要算法

三、官方指南

四、pinocchio与pybullet联调



GitHub - stack-of-tasks/pinocchio: A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivativesA fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives - GitHub - stack-of-tasks/pinocchio: A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivativesicon-default.png?t=N7T8https://github.com/stack-of-tasks/pinocchio

一、安装

github明确给出了安装步骤和指令,非常简单,根据需求二选一即可。

系统:ubutntu 20.04

安装指令:

conda安装:

conda install pinocchio -c conda-forge

pip 安装:

pip install pin  # 只适用于Linux

部署在ROS上,通过以下指令可以安装具有 HPP-FCL 支持和 Python 绑定的 Pinocchio:

sudo apt install ros-$ROS_DISTRO-pinocchio

详细步骤请参考上方github链接。

官方配套可视化工具:

pinocchio支持许多开源可视化工具,根据需求安装适合自己的即可,我装的是gepetto viewer。

可视化工具
Gepetto Viewer
conda安装指令:conda install gepetto-viewer gepetto-viewer-corba -c conda-forge

与pinocchio一起使用时需要先在终端打开gepetto:

gepetto-gui

基于FCL方法实现了运动树的碰撞和距离算法。

Panda3dpip安装:pip install panda3d_viewer
Meshcat
pip安装:pip install meshcat

跟Panda3d一样,通过嵌入式浏览器实现交互

RViz

可以与其他ROS包交互

二、Pinocchio中实现的主要算法

Pinocchio提供基于revisited Roy Featherstone's algorithms的多关节系统刚体算法,提供主要刚体算法的解析导数(例如:Recurisive Newton-Euler Algorithm或Articulated-Body Algorithm),详见官方论文。

The Pinocchio C++ library : A fast and flexible implementation of rigid body dynamics algorithms and their analytical derivatives | IEEE Conference Publication | IEEE Xploreicon-default.png?t=N7T8https://ieeexplore.ieee.org/abstract/document/8700380?casa_token=iavz9sD7eccAAAAA:Bo6MXDNsxCOKO6NxCX5SEn_8qpGNsYXhoO3GfYqGlfGOFkNE8j22aBf4J0PfLcQ1e0dBV9xX实现的主要算法:

  • 正向运动学(forward kinematics):给定机器人构型,计算每个关节的空间位置并将其存储为坐标变换。如果给定速度或加速度,将计算每个关节的空间速度(以局部坐标系表示)。
  • 运动学雅可比矩阵(kinematic jacobian):在机械臂运动学中用来计算机械臂末端执行器的速度与各个关节运动速度之间的关系。
  • 逆动力学(inverse dynamics):采用Recursive Newton-Euler Algorithm (RNEA) 计算逆动力学。即给定所需的机器人构型、速度、加速度,计算并存储执行该运动所需的扭矩。
  • 关节空间惯性矩阵(Joint space inertia matrix):采用Compostie rigid body algortihm (CRBA)算法,计算关节空间惯性矩阵。
  • 前向动力学(forward dynamics):采用Articulated Body Algorithm(ABA)计算无约束的前向动力学。即给定机器人构型、速度、扭矩和外力的情况下,可以计算出由此产生的关节加速度。
  • 其他算法:其他算法包括约束正运动学,脉冲动力学,逆关节空间惯性矩阵,向心动力学。

三、官方指南

pinocchio: Overviewicon-default.png?t=N7T8https://gepettoweb.laas.fr/doc/stack-of-tasks/pinocchio/master/doxygen-html/index.html#OverviewConclu

四、pinocchio与pybullet联调

参考项目:github repo:

 GitHub - KanishkNavale/Robot-Physics-Engine: This repository implements an optimization strategy for singularity free trajectory generation for the serial robots.This repository implements an optimization strategy for singularity free trajectory generation for the serial robots. - GitHub - KanishkNavale/Robot-Physics-Engine: This repository implements an optimization strategy for singularity free trajectory generation for the serial robots.icon-default.png?t=N7T8https://github.com/KanishkNavale/Robot-Physics-EngineGitHub - nyu-legged-group/pinocchio_bulletContribute to nyu-legged-group/pinocchio_bullet development by creating an account on GitHub.icon-default.png?t=N7T8https://github.com/nyu-legged-group/pinocchio_bullet

https://github.com/machines-in-motion/mim_robotsicon-default.png?t=N7T8https://github.com/machines-in-motion/mim_robots———————————————— 分割线 2023.12.18——————————————————

pinocchio运动学计算及参数更新机制:

1. 导入URDF模型,创建数据模型。注意,model为刚体的模型结构,data存储了刚体系统的数据结构,当调用forwardKinematics()函数计算正向运动学时,函数根据当前关节位置、速度和加速度,更新data中存储的关节位置、空间速度和空间加速度。

import pinocchio
from sys import argv
from os.path import dirname, join, abspath
 
# This path refers to Pinocchio source code but you can define your own directory here.
pinocchio_model_dir = join(dirname(dirname(str(abspath(__file__)))), "models")
 
# You should change here to set up your own URDF file or just pass it as an argument of this example.
urdf_filename = pinocchio_model_dir + '/example-robot-data/robots/ur_description/urdf/ur5_robot.urdf' if len(argv)<2 else argv[1]
 
# Load the urdf model
model = pinocchio.buildModelFromUrdf(urdf_filename)
print('model name: ' + model.name)
 
# Create data required by the algorithms
data = model.createData()
 
# Sample a random configuration
q = pinocchio.randomConfiguration(model)
print('q: %s' % q.T)
 
# Perform the forward kinematics over the kinematic tree
pinocchio.forwardKinematics(model,data,q)
 
# Print out the placement of each joint of the kinematic tree
for name, oMi in zip(model.names, data.oMi):
    print(("{:<24} : {: .2f} {: .2f} {: .2f}"
          .format( name, *oMi.translation.T.flat)))

——————————————————分割线 2023.12.23————————————————

2. Pinocchio与Pybullet联调:pinocchio_bullet_wrapper.py

这个python文件是纽约大学团队开发的,为需要pybullet物理引擎仿真和pinocchio库计算设计的,使用这个接口一是为了用pinocchio,另一个原因是bullet可以集成到OpenAI Gym框架中,方便开发和比较强化学习算法。

(仿真在 PyBullet中进行,动力学库 Pinocchio 用于更新机器人的动态项,如惯性矩阵和雅可比矩阵)

包中关键函数是根据bullet中状态更新pinocchio参数:

    def get_state_update_pinocchio(self):
        """Get state from pybullet and update pinocchio robot internals.
        This gets the state from the pybullet simulator and forwards
        the kinematics, jacobians, centroidal moments on the pinocchio robot
        (see forward_pinocchio for details on computed quantities). """
        q, dq, ef = self.get_state()
        self.update_pinocchio(q, dq)
        return q, dq, ef

cons_cost_func:增广奖励函数,在有约束的MPPI中使用

cost_func:奖励函数,在env中调用,用于step函数中获取 当前状态的reward,并且存储在mem中,用于NAF网络训练。

### Python 实现逆运动学 示例 代码 教程 #### 使用 Pink 实现逆动力学 对于基于 Pinocchio 的 Pink ,该提供了强大的工具来处理机器人系统的逆动力学问题。通过安装并导入 `pink` 及其依赖项,可以方便地构建和求解复杂的机械臂逆运动学问题。 首先,确保已安装必要的软件包: ```bash pip install pinocchio pink ``` 接着,在 Python 中定义个简单的六自由度机械臂模型,并利用内置函数解决给定末端执行器姿态下的关节角反向映射问题[^1]。 ```python import numpy as np from pinocchio import SE3, Quaternion from pink.models.robot_model import RobotModelPinocchio from pink.tasks import FrameTask, PostureTask from pink.solvers import solve_ik def setup_robot(): """设置机器人类""" robot = RobotModelPinocchio() robot.set_joint_config(np.zeros(robot.nv)) return robot def compute_inverse_kinematics(target_pose): """ 给定目标位姿矩阵 target_pose (SE3), 返回满足条件的组可能的关节配置. 参数: target_pose -- 目标空间坐标系中的变换矩阵 输出: solution -- 获得的新关节角度数组 """ # 初始化机器人实例 robot = setup_robot() # 定义末端效应器的任务 ee_task = FrameTask('ee_link', weight=10.) posture_task = PostureTask(weight=1e-3) # 设置期望的位置与方向 ee_task.target = target_pose # 执行迭代优化过程寻找合适的解 q_current = robot.q0.copy() # 初始猜测值设为偏移量 result = solve_ik([ee_task], q_current=q_current) if not result.success: raise RuntimeError("未能找到有效的逆运动学解决方案") return result.x[:robot.model.nq] if __name__ == "__main__": # 创建目标位置(相对于基座) goal_position = np.array([-0.5, 0., 0.8]) orientation_quat = Quaternion.FromTwoVectors( np.array([0, 0, 1]), # 当前Z轴指向 np.array([0, -1, 0]) # 新Y轴朝向 ) desired_transform = SE3(orientation_quat.matrix(), goal_position) try: joints_solution = compute_inverse_kinematics(desired_transform) print(f"成功找到了组可行的关节角度:\n{joints_solution}") except Exception as e: print(e) ``` 上述脚本展示了如何创建个基本框架来进行逆运动学分析。这里的关键在于正确指定各个部件之间的相对关系以及合理选择初始估计值以提高收敛速度和稳定性[^2]。 #### 关于四轮转向车辆的动力学建模 除了传统的多连杆结构外,针对特定应用场景如移动平台上的全向轮设计也有相应的研究工作。例如,在 ROS2 环境下开发的个开源项目实现了对具有四个独立驱动车轮的小型无人地面载具进行精确控制的功能[^3]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值