四元数插值 ros tf tf2

http://docs.ros.org/jade/api/tf2/html/classtf2_1_1Quaternion.html

Quaternion tf2::Quaternion::slerp(const Quaternion & q,
  const tf2Scalar & t 
 ) const [inline]

Return the quaternion which is the result of Spherical Linear Interpolation between this and the other quaternion.

Parameters:

qThe other quaternion to interpolate with
tThe ratio between this and q to interpolate. If t = 0 the result is this, if t=1 the result is q. Slerp interpolates assuming constant velocity.

Definition at line 314 of file Quaternion.h.

 

example:

#include <ros/ros.h>
#include <tf2_ros/transform_listener.h>
#include <geometry_msgs/TransformStamped.h>
#include <geometry_msgs/Twist.h>
#include <tf2/LinearMath/Quaternion.h>
#include <geometry_msgs/Pose.h>
#include <tf2/utils.h>
#include <turtlesim/Spawn.h>
#include <tf2_ros/transform_broadcaster.h>
#include <geometry_msgs/TransformStamped.h>
#define epsilo 0.000001
using namespace std;
using namespace tf2;
#define r2d 57.29577951308232
#define d2r 0.017453292519943295
void seeq(Quaternion q)
{
printf("[%f, %f, %f,%f]\n", q.getX(),q.getY(), q.getZ(), q.getW());
}
void test() {
	Quaternion q,qb,qc;

	float r, p, y;
	float du = 270;
	q.setRPY(0, 0, du*d2r);//
	printf("绕Z旋转270度 ");
	seeq(q);
	y = tf2::getYaw(q);
	printf("%f \n", y);
	du = -90;
	qb.setRPY(0, 0, du*d2r);
	printf("绕Z旋转-90度 ");
	seeq(q);
	y = tf2::getYaw(q);
	printf("%f \n", y);
	printf("end-----四元数每个元素都取反后和自身等价-----\n---四元数插值示例-----\n");

	q.setRPY(0,0,100*d2r);//100 du
	printf("q 100 du  ");
	seeq(q);

	qb.setRPY(0,0,-120*d2r);//-100 du
	printf("qb -120 du");
	seeq(qb);
	qc=q.slerp(qb,0);// qc = q
	printf("插值系数为0,得到qc = q ");
	seeq(qc);

	qc=q.slerp(qb,0.3);// qc = q
	y = tf2::getYaw(qc);
	
	printf("插值系数为0.3,得到qc ");
	seeq(qc);
	printf("插值系数为0.3,得到qc的yaw :%f du\n", y*r2d);

	qc=q.slerp(qb,0.8);// qc = q
	y = tf2::getYaw(qc);
	
	printf("插值系数为0.8,得到qc ");
	seeq(qc);
	printf("插值系数为0.8,得到qc的yaw :%f du\n", y*r2d);
	qc=q.slerp(qb,1);// qc = q
	printf("插值系数为1,得到qc=qb ");
	seeq(qc);
}

int main(int argc, char** argv) {
	ros::init(argc, argv, "markerListener");

	ros::NodeHandle node("~");
	test();
	return 0;

}

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值