ROS tf-數據類型


博客參考:https://www.ncnynl.com/archives/201702/1305.html

ROS與C++入門教程-tf-數據類型

說明:

  • 介紹roscpp的Data Types(數據類型)及使用

數據類型

  • 數據類型定義在tf/transform_datatypes.h

基本數據類型

  • 基本數據類型有:(Quaternion, Vector, Point, Pose, Transform)
  • ROS Fuerte后,TF已經定義了自己的數據類型。關於如何遷移pre-Fuerte代碼到更新的ROS版本,查閱geometry/bullet_migration
  • 基本類型:

Type

tf

Quaternion

tf::Quaternion

Vector

tf::Vector3

Point

tf::Point

Pose

tf::Pose

Transform

tf::Transform

tf::Stamped 模板

  • tf::Stamped 對上述數據類型做模板化(除了tf::Transform),並附帶元素frame_id_和stamp_ 。
  • 定義代碼:
template <typename T>
class Stamped : public T{
 public:
  ros::Time stamp_;
  std::string frame_id_;

  Stamped() :frame_id_ ("NO_ID_STAMPED_DEFAULT_CONSTRUCTION"){}; //Default constructor used only for preallocation

  Stamped(const T& input, const ros::Time& timestamp, const std::string & frame_id);
  
  void setData(const T& input);
};

tf::StampedTransform

  • tf::StampedTransform 是tf::Transforms的特例,它要求frame_id 、stamp 、child_frame_id.
  • 定義代碼:
/** \brief The Stamped Transform datatype used by tf */
class StampedTransform : public tf::Transform
{
public:
  ros::Time stamp_; ///< The timestamp associated with this transform                                                                                                                                                                                                                                                        
  std::string frame_id_; ///< The frame_id of the coordinate frame  in which this transform is defined                                                                                                                                                                                                                       
  std::string child_frame_id_; ///< The frame_id of the coordinate frame this transform defines                                                                                                                                                                                                                              
  StampedTransform(const tf::Transform& input, const ros::Time& timestamp, const std::string & frame_id, const std::string & child_frame_id):
    tf::Transform (input), stamp_ ( timestamp ), frame_id_ (frame_id), child_frame_id_(child_frame_id){ };

  /** \brief Default constructor only to be used for preallocation */
  StampedTransform() { };

  /** \brief Set the inherited Traonsform data */
  void setData(const tf::Transform& input){*static_cast<tf::Transform*>(this) = input;};

};

輔助函數

  • 函數:tf::Quaternion createIdentityQuaternion()
  • 作用:返回四元數句柄
  • 函數:tf::Quaternion createQuaternionFromRPY(double roll,double pitch,double yaw)
  • 作用:返回從固定軸的Roll, Pitch and Yaw(滾動,俯仰和偏轉)構造的tf::Quaternion四元數
  • 函數:geometry_msgs::Quaternion createQuaternionMsgFromRollPitchYaw(double roll,double pitch,double yaw)
  • 作用:返回從固定軸的Roll, Pitch and Yaw(滾動,俯仰和偏轉)構造的geometry_msgs::Quaternion四元數

數據類型轉換

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM