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;
};

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值