当前位置:   article > 正文

四元数插值 ros tf tf2_tf2::getyaw

tf2::getyaw

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:

  1. #include <ros/ros.h>
  2. #include <tf2_ros/transform_listener.h>
  3. #include <geometry_msgs/TransformStamped.h>
  4. #include <geometry_msgs/Twist.h>
  5. #include <tf2/LinearMath/Quaternion.h>
  6. #include <geometry_msgs/Pose.h>
  7. #include <tf2/utils.h>
  8. #include <turtlesim/Spawn.h>
  9. #include <tf2_ros/transform_broadcaster.h>
  10. #include <geometry_msgs/TransformStamped.h>
  11. #define epsilo 0.000001
  12. using namespace std;
  13. using namespace tf2;
  14. #define r2d 57.29577951308232
  15. #define d2r 0.017453292519943295
  16. void seeq(Quaternion q)
  17. {
  18. printf("[%f, %f, %f,%f]\n", q.getX(),q.getY(), q.getZ(), q.getW());
  19. }
  20. void test() {
  21. Quaternion q,qb,qc;
  22. float r, p, y;
  23. float du = 270;
  24. q.setRPY(0, 0, du*d2r);//
  25. printf("绕Z旋转270度 ");
  26. seeq(q);
  27. y = tf2::getYaw(q);
  28. printf("%f \n", y);
  29. du = -90;
  30. qb.setRPY(0, 0, du*d2r);
  31. printf("绕Z旋转-90度 ");
  32. seeq(q);
  33. y = tf2::getYaw(q);
  34. printf("%f \n", y);
  35. printf("end-----四元数每个元素都取反后和自身等价-----\n---四元数插值示例-----\n");
  36. q.setRPY(0,0,100*d2r);//100 du
  37. printf("q 100 du ");
  38. seeq(q);
  39. qb.setRPY(0,0,-120*d2r);//-100 du
  40. printf("qb -120 du");
  41. seeq(qb);
  42. qc=q.slerp(qb,0);// qc = q
  43. printf("插值系数为0,得到qc = q ");
  44. seeq(qc);
  45. qc=q.slerp(qb,0.3);// qc = q
  46. y = tf2::getYaw(qc);
  47. printf("插值系数为0.3,得到qc ");
  48. seeq(qc);
  49. printf("插值系数为0.3,得到qc的yaw :%f du\n", y*r2d);
  50. qc=q.slerp(qb,0.8);// qc = q
  51. y = tf2::getYaw(qc);
  52. printf("插值系数为0.8,得到qc ");
  53. seeq(qc);
  54. printf("插值系数为0.8,得到qc的yaw :%f du\n", y*r2d);
  55. qc=q.slerp(qb,1);// qc = q
  56. printf("插值系数为1,得到qc=qb ");
  57. seeq(qc);
  58. }
  59. int main(int argc, char** argv) {
  60. ros::init(argc, argv, "markerListener");
  61. ros::NodeHandle node("~");
  62. test();
  63. return 0;
  64. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/206515
推荐阅读
相关标签
  

闽ICP备14008679号