ROS tf知識整理

發佈:

include <tf/transform_broadcaster.h>

定義發佈者   static tf::TransformBroadcaster br;
定義轉換 tf::Transform transform;
設置平移轉換  transform.setOrigin( tf::Vector3(msg->x, msg->y, 0.0);
定義四元數  tf::Quaternion q;
設置四元數    q.setRPY(0, 0, msg->theta);
設置旋轉轉換   transform.setRotation(q);
發佈tf轉換 br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), “world”, turtle_name));

監聽:

include <tf/transform_listener.h>

設置監聽  tf::TransformListener listener;
定義轉換 tf::StampedTransform transform;
監聽轉換 listener.lookupTransform(“/turtle2”, “/turtle1”, ros::Time(0), transform);

Here, the real work is done, we query the listener for a specific transformation. Let’s take a look at the four arguments:
1.We want the transform from frame /turtle1 to frame /turtle2.
2.The time at which we want to transform. Providing ros::Time(0) will just get us the latest available transform.
3.The object in which we store the resulting transform.

try{
ros::Time now = ros::Time::now();
listener.waitForTransform(“/turtle2”, “/turtle1”,
now, ros::Duration(3.0));
listener.lookupTransform(“/turtle2”, “/turtle1”,
now, transform);
}
The waitForTransform() takes four arguments:
1. Wait for the transform from this frame…
2. … to this frame,
3. at this time, and
4. timeout: don’t wait for longer than this maximum duration

try{
ros::Time now = ros::Time::now();
ros::Time past = now - ros::Duration(5.0);
listener.waitForTransform(“/turtle2”, now,
“/turtle1”, past,
“/world”, ros::Duration(1.0));
listener.lookupTransform(“/turtle2”, now,
“/turtle1”, past,
“/world”, transform);
}
The advanced API for lookupTransform() takes six arguments:
1. Give the transform from this frame,
2. at this time …
3. … to this frame,
4. at this time.
5. Specify the frame that does not change over time, in this case the “/world” frame, and
6. the variable to store the result in.

添加一個frame:

include <ros/ros.h>

include <tf/transform_broadcaster.h>

int main(int argc, char** argv){
ros::init(argc, argv, “my_tf_broadcaster”);
ros::NodeHandle node;

tf::TransformBroadcaster br;
tf::Transform transform;

ros::Rate rate(10.0);
while (node.ok()){
transform.setOrigin( tf::Vector3(0.0, 2.0, 0.0) );
transform.setRotation( tf::Quaternion(0, 0, 0, 1) );
br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), “turtle1”, “carrot1”));
rate.sleep();
}
return 0;
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章