zoukankan      html  css  js  c++  java
  • ROS tf基础使用知识

    博客参考:https://www.ncnynl.com/archives/201702/1306.html

    ROS与C++入门教程-tf-坐标变换

    说明:

    • 介绍在c++实现TF的坐标变换

    概念:

    • Coodinate Frames (坐标框架,坐标系)
    • Transforms (变换)
    • TF

    参考:

    Frames and Points

    • Frame是坐标系统,在ROS里都是以3D形式存在,右手原则,X向前,Y向左,Z向上.
    • Points在坐标系以tf::Point形式表达,等同与bullet类型的btVector3。
    • 在坐标系W里,坐标的点p,可以用:Wp

    其余参考原文:http://wiki.ros.org/tf/Overview/Transformations

    ROS与C++入门教程-tf-广播变换

    说明:

    • 介绍如何在roscpp的节点广播变换关系。

    广播变换:

    • 在节点里广播变换,推荐使用tf::TransformBroadcaster.

    构造器

    • 无参数构造器:
    tf::TransformBroadcaster();

    发送变换

    • 发送变换通过调用sendTransform()函数实现,传递StampedTransform或geometry_msgs::TransformStamped为参数
    • 示例代码:
    void sendTransform(const StampedTransform & transform);
    void sendTransform(const geometry_msgs::TransformStamped & transform);
    

    ROS与C++入门教程-tf-使用已发布的变换

    说明:

    • 介绍roscpp节点获取和使用TF的变换。

    TransformListener

    • 通过调用 tf::TransformListener类来处理变换,它继承自tf::Transformer。

    核心方法

    (1)构造函数

    • 示例代码:
    TransformListener(const ros::NodeHandle &nh, ros::Duration max_cache_time=ros::Duration(DEFAULT_CACHE_TIME), bool spin_thread=true)
    TransformListener(ros::Duration max_cache_time=ros::Duration(DEFAULT_CACHE_TIME), bool spin_thread=true)
    

    (2)辅助方法

    • 示例代码:
    std::string tf::TransformListener::resolve (const std::string &frame_id)

    (3)canTransform()函数

    • 返回bool ,判断能否实现变换。不会抛出异常,如果出错,会返回error_msg的内容。
    • 基本API:
    bool tf::TransformListener::canTransform (const std::string &target_frame, const std::string &source_frame, const ros::Time &time, std::string *error_msg=NULL) const 
    • 检查在时间time,source_frame能否变换到target_frame。
    • 高级API:
    bool tf::TransformListener::canTransform (const std::string &target_frame, const ros::Time &target_time, const std::string &source_frame, const ros::Time &source_time, const std::string &fixed_frame, std::string *error_msg=NULL) const 
    • 检查在时间source_time,source_frame能否变换到fixed_frame,那么再实现在target_time变换到target_frame。

    (4)waitForTransform()函数

    • 返回bool值,评估变换是否有效。
    • 基本API:
    bool tf::TransformListener::waitForTransform (const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration &timeout, 
    const ros::Duration &polling_sleep_duration=ros::Duration(0.01), std::string *error_msg=NULL) const
    • 检查在时间time, source_frame能否变换到target_frame
    • 它将休眠并重试每个polling_duration,直到超时的持续时间已经过去。 它不会抛出异常。 在一个错误的情况下,如果你传递一个非NULL字符串指针,它会填充字符串error_msg。 (注意:这需要大量的资源来生成错误消息。)
    • 高级API
    bool tf::TransformListener::waitForTransform (const std::string &target_frame, const ros::Time &target_time, const std::string &source_frame, const ros::Time &source_time, 
    const std::string &fixed_frame, const ros::Duration &timeout, const ros::Duration &polling_sleep_duration=ros::Duration(0.01), std::string *error_msg=NULL) const
    • 测试在source_time时间,source_frame能否变换到fixed_frame,那么在target_time,变换到target_frame。

    (5)lookupTransform

    • lookupTransform()是一个更底层的方法用于返回两个坐标系的变换。

    • 这个方法是 tf库的核心方法。大部分transform的方法都是终端用户使用,而这个方法设计在transform()方法内使用的。

    • 返回的变换的方向将从target_frame到source_frame。 如果应用于数据,将把source_frame中的数据转换为target_frame。查阅geometry/CoordinateFrameConventions#Transform_Direction

    • 这个方法会抛出TF的异常

    • 基本API:

    void tf::TransformListener::lookupTransform (const std::string &target_frame, const std::string &source_frame, const ros::Time &time, StampedTransform &transform) const 
    • 在时间time上使用从source_frame到target_frame的变换填充transform
    • 高级API:
    void tf::TransformListener::lookupTransform (const std::string &target_frame, const ros::Time &target_time, const std::string &source_frame, const ros::Time &source_time,
    const std::string &fixed_frame, StampedTransform &transform) const
    • 在source_time使用从source_frame到fixed_frame的变换填充transform,在target_time从fixed_frame到target_frame的链接变换。

    transformDATA 方法

    • tf::TransformListener类的主要目的是在坐标系间进行变换数据。
    • 支持的数据类型:

    C++ Method Name

    Python Method Name

    Full Datatype

    transformQuaternion()

    none

    tf::Stamped<tf::Quaternion>

    transformVector()

    none

    tf::Stamped<tf::Vector3>

    transformPoint()

    none

    tf::Stamped<tf::Point>

    transformPose()

    none

    tf::Stamped<tf::Pose>

    transformQuaternion()

    transformQuaternion()

    geometry_msgs/QuaternionStamped

    transformVector()

    transformVector3()

    geometry_msgs/Vector3Stamped

    transformPoint()

    transformPoint()

    geometry_msgs/PointStamped

    transformPose()

    transformPose()

    geometry_msgs/PoseStamped

    transformPointCloud()

    transformPointCloud()

    sensor_msgs/PointCloud

    • 基本API:
    void tf::TransformListener::transformDATATYPE (const std::string &target_frame, const geometry_msgs::DATATYPEStamped &stamped_in, geometry_msgs::DATATYPEStamped &stamped_out) const 
    • 将数据stamped_in转换为target_frame,使用标记的数据类型中的frame_id和stamp作为源。
    • 高级API:
    void tf::TransformListener::transformDATATYPE (const std::string &target_frame, const ros::Time &target_time, const geometry_msgs::DATATYPEStamped &pin, 
    const std::string &fixed_frame, geometry_msgs::DATATYPEStamped &pout) const
    • 将数据stamped_in转换为fixed_frame。 使用标记数据类型中的frame_id和stamp作为源。 然后在target_time从fixed_frame变换到target_frame。

     

    ROS与C++入门教程-tf-异常

    说明:

    • 介绍roscpp的tf的异常类型及作用

    TF异常

    • 所有在TF里异常继承自tf::TransformException,它继承自std::runtime_error。

    异常类型:

    • 异常类:tf::ConnectivityException
    • 作用:如果由于两个坐标系ID不在同一个连接的树中而无法完成请求,则抛出。
    • 异常类:tf::ExtrapolationException
    • 作用:如果请求的坐标系id之间存在连接,但一个或多个变换已过期,则抛出。
    • 异常类:tf::InvalidArgument
    • 作用:如果参数无效则抛出。 最常见的情况是非规范化的四元数。
    • 异常类:tf::LookupException
    • 作用:如果引用了未发布的坐标系ID,则抛出。
  • 相关阅读:
    出差常熟,郁闷中 沧海
    ABAP中程序之间传递参数的办法 沧海
    LSMW中出现No logical path specified. 沧海
    请认真对待生活 沧海
    escape sequence 沧海
    休假一周 沧海
    Print Program and Form Modify 沧海
    下周回南京 沧海
    LO020真麻烦 沧海
    函数讲解函数列表(ZT) 沧海
  • 原文地址:https://www.cnblogs.com/flyinggod/p/10810166.html
Copyright © 2011-2022 走看看