【kdl】源码解析-动力学求解器

博客介绍了多个用于机器人动力学计算的类,如 chainidsolver_recursive_newton_euler 等。这些类基于不同算法,可根据关节状态和外力信息计算关节扭矩或加速度,考虑了代码健壮性,应用于机器人控制、模拟和分析等场景。

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

52b2cc6011e8ee6d988c1289dfb52115.png

求解器思维导图

chainidsolver_recursive_newton_euler

ChainIdSolver_RNE:这个类是用于解决逆动力学问题的,它基于书籍 "Rigid Body Dynamics Algorithms" (Roy Featherstone, 2008)中的算法。

ChainIdSolver_RNE 类的定义如下:

  • 它继承自 ChainIdSolver 类,是 KDL 中专用于逆动力学求解的一部分。

  • 构造函数 ChainIdSolver_RNE 创建求解器实例,接受一个动力学链(Chain 类型)和一个表示重力的向量(Vector grav)作为参数。内部会创建这个动力学链的副本以及分配必要的内存用于计算。

  • 析构函数 ~ChainIdSolver_RNE 是空的,说明类中无需特殊处理的资源释放。

  • CartToJnt 方法用于计算由 Cartesian 力量到关节扭矩的转换,需要提供当前关节位置 (q)、当前关节速度 (q_dot)、当前关节加速度 (q_dotdot)、外部作用在各个链段上的力量(f_ext 不包括重力),输出结果为关节扭矩 (torques)。

  • updateInternalDataStructures 方法虚拟实现,用于更新内部数据结构,这在基类 SolverI 中定义,并要求每个具体的求解器类进行实现。

ChainIdSolver_RNE 类的成员变量用于存储计算逆动力学过程中需要的中间值,包括:

  • const Chain& chain:运动链对象,求解器针对这个链进行计算。

  • unsigned int nj:运动链中关节的数量。

  • unsigned int ns:运动链中链段的数量。

  • std::vector<Frame> X:存储运动链中每个链段相对于基座的坐标变换。

  • std::vector<Twist> S:存储运动链中每个关节的motion subspace向量。

  • std::vector<Twist> v:存储运动链中每个链段的速度。

  • std::vector<Twist> a:存储运动链中每个链段的加速度。

  • std::vector<Wrench> f:存储运动链中对每个链段产生作用的力和力矩。

  • Twist ag:存储由重力产生的加速度。

这个类的实现使得用户可以通过提供某一时刻的关节状态和外力信息,来计算出各个关节所需的扭矩,这对于机器人的控制和仿真至关重要。

#ifndef KDL_CHAIN_IKSOLVER_RECURSIVE_NEWTON_EULER_HPP
#define KDL_CHAIN_IKSOLVER_RECURSIVE_NEWTON_EULER_HPP


#include "chainidsolver.hpp"


namespace KDL{
    /**
     * \brief 递归牛顿-欧拉逆动力学求解器
     *
     * 算法的实现是基于 Roy Featherstone 2008 年的书 "Rigid Body
     * Dynamics Algorithms" (ISBN:978-0-387-74314-1) 第96页的伪代码。
     * 
     * 它计算关节的扭矩,给定关节的运动(q,qdot,qdotdot)、作用在段上的外部力
     * (在段的参考框架中表示)以及段的动力学参数。
     */
    class ChainIdSolver_RNE : public ChainIdSolver{
    public:
        /**
         * 该求解器的构造函数,将分配所有必要的内存
         * \param chain 要计算逆动力学的动力链,将制作一个内部副本。
         * \param grav 在计算中使用的重力向量。
         */
        ChainIdSolver_RNE(const Chain& chain,Vector grav);
        ~ChainIdSolver_RNE(){}; // 析构函数
        
        /**
         * 从笛卡尔力计算到关节扭矩的函数。
         * 输入参数:
         * \param q 当前关节位置
         * \param q_dot 当前关节速度
         * \param q_dotdot 当前关节加速度
         * \param f_ext 段上的外部力(不含重力)
         * 输出参数:
         * \param torques 结果关节的扭矩
         */
        int CartToJnt(const JntArray &q, const JntArray &q_dot, const JntArray &q_dotdot, const Wrenches& f_ext,JntArray &torques);


        /// @copydoc KDL::SolverI::updateInternalDataStructures
        // 更新内部数据结构
        virtual void updateInternalDataStructures();


    private:
        const Chain& chain; // 动力链
        unsigned int nj;    // 关节数量
        unsigned int ns;    // 段数量
        std::vector<Frame> X; // 保存从基坐标系到当前段末端局部坐标系的变换
        std::vector<Twist> S; // 保存当前段的速度
        std::vector<Twist> v; // 保存当前段的速度
        std::vector<Twist> a; // 保存当前段的加速度
        std::vector<Wrench> f; // 保存段受到的力
        Twist ag; // 保存重力加速度
    };
}


#endif

该段代码定义了一个根据机械臂的运动学模型来计算关节力矩的类ChainIdSolver_RNE。主要功能包括:

  • 根据给定的关节位置(q),速度(q_dot),加速度(q_dotdot)和外部扭矩(f_ext),通过牛顿-欧拉递归算法计算相应的关节扭矩(torques)。

  • 通过KDL库提供的数据结构和函数来获取关节和段的数量、位姿、转动惯量等信息,并进行物理量的转换和计算。

  • 编写时考虑了代码的健壮性,具体表现在检查了数组尺寸的正确性,并提供了错误代码以处理可能的异常情况。

  • 设计了从机械臂基部到末端以及从末端反向到基部的两次遍历,以计算节点力和力矩。

这段代码是机器人动力学计算的基础,被应用在机器人控制、模拟和分析等场景中。

这段代码定义了一个名为 ChainIdSolver_RNE 的递归牛顿-欧拉逆动力学求解器类。该类使用递归牛顿-欧拉算法计算KDL::Chain(机器人运动学链)中的逆动力学,给定关节的位置、速度和加速度以及外部力矩,计算出机器人关节所需的力矩。

chainidsolver_vereshchagin

ChainHdSolver_Vereshchagin 的类,该类实现了科学家Vereshchagin于1989年提出的解算运动学和动力学方程的解算器。该求解器可以处理机器人姿态、速度、加速度以及外力、内力和约束力的关系,

Rigid Body Dynamics Algorithms presents the subject of computational rigid-body dynamics through the medium of spatial 6D vector notation. It explains how to model a rigid-body system and how to analyze it, and it presents the most comprehensive collection of the best rigid-body dynamics algorithms to be found in a single source. The use of spatial vector notation greatly reduces the volume of algebra which allows systems to be described using fewer equations and fewer quantities. It also allows problems to be solved in fewer steps, and solutions to be expressed more succinctly. In addition algorithms are explained simply and clearly, and are expressed in a compact form. The use of spatial vector notation facilitates the implementation of dynamics algorithms on a computer: shorter, simpler code that is easier to write, understand and debug, with no loss of efficiency. Unique features include: • A comprehensive collection of the best rigid-body dynamics algorithms • Use of spatial (6D) vectors to greatly reduce the volume of algebra, to simplify the treatment of the subject, and to simplify the computer code that implements the algorithms • Algorithms expressed both mathematically and in pseudocode for easy translation into computer programs • Source code for many algorithms available on the internet Rigid Body Dynamics Algorithms is aimed at readers who already have some elementary knowledge of rigid-body dynamics, and are interested in calculating the dynamics of a rigid-body system. This book serves as an algorithms recipe book as well as a guide to the analysis and deeper understanding of rigid-body systems.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值