当前位置: 首页 > news >正文

做wordpress 主题下载站百度广告代理公司

做wordpress 主题下载站,百度广告代理公司,兰州金建工程建设监理网站,免费做任务赚钱的网站背景 四元数是方向的 4 元组表示形式,它比旋转矩阵更简洁。 四元数对于分析涉及三维旋转的情况非常有效。 四元数广泛用于机器人技术、量子力学、计算机视觉和 3D 动画。 您可以在 Wikipedia 上了解有关基本数学概念的更多信息。 您还可以观看由 3blue1brown 制…

背景

四元数是方向的 4 元组表示形式,它比旋转矩阵更简洁。 四元数对于分析涉及三维旋转的情况非常有效。 四元数广泛用于机器人技术、量子力学、计算机视觉和 3D 动画。

您可以在 Wikipedia 上了解有关基本数学概念的更多信息。 您还可以观看由 3blue1brown 制作的可探索视频系列 Visualizeizing quaternions。

在本教程中,您将了解四元数和转换方法在 ROS 2 中的工作原理。

先决条件

但是,这不是一个硬性要求,您可以坚持使用最适合您的任何其他几何转换库。 您可以查看 transforms3d、scipy.spatial.transform、pytransform3d、numpy-quaternion 或 blender.mathutils 等库。

四元数的组成部分

ROS 2 使用四元数来跟踪和应用旋转。 四元数有 4 个分量。 在 ROS 2 中,是最后的,但在一些库(如 Eigen)中,可以放在第一个位置。 不产生绕 x/y/z 轴旋转的常用单位四元数是 ,可以通过以下方式创建:(x, y, z, w)ww(0, 0, 0, 1)

#include <tf2/LinearMath/Quaternion.h>
...tf2::Quaternion q;
// Create a quaternion from roll/pitch/yaw in radians (0, 0, 0)
q.setRPY(0, 0, 0);
// Print the quaternion components (0, 0, 0, 1)
RCLCPP_INFO(this->get_logger(), "%f %f %f %f",q.x(), q.y(), q.z(), q.w());

四元数的大小应始终为 1。 如果数值错误导致四元数幅度不是 1,ROS 2 将打印警告。 要避免这些警告,请规范化四元数:

q.normalize();

ROS 2 中的四元数类型

ROS 2 使用两种四元数数据类型: 及其等效数据类型。 要在 C++ 中在它们之间进行转换,请使用 .tf2::Quaterniongeometry_msgs::msg::Quaterniontf2_geometry_msgs

C++

#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
...tf2::Quaternion tf2_quat, tf2_quat_from_msg;
tf2_quat.setRPY(roll, pitch, yaw);
// Convert tf2::Quaternion to geometry_msgs::msg::Quaternion
geometry_msgs::msg::Quaternion msg_quat = tf2::toMsg(tf2_quat);// Convert geometry_msgs::msg::Quaternion to tf2::Quaternion
tf2::convert(msg_quat, tf2_quat_from_msg);
// or
tf2::fromMsg(msg_quat, tf2_quat_from_msg);

from geometry_msgs.msg import Quaternion
...# Create a list of floats, which is compatible with tf2
# Quaternion methods
quat_tf = [0.0, 1.0, 0.0, 0.0]# Convert a list to geometry_msgs.msg.Quaternion
msg_quat = Quaternion(x=quat_tf[0], y=quat_tf[1], z=quat_tf[2], w=quat_tf[3])

四元数运算

1 在 RPY 中思考,然后转换为四元数

我们很容易考虑绕轴的旋转,但很难从四元数的角度考虑。 建议根据滚动 (绕 X 轴)、俯仰 (绕 Y 轴) 和偏航 (绕 Z 轴) 计算目标旋转,然后转换为四元数。

# quaternion_from_euler method is available in turtle_tf2_py/turtle_tf2_py/turtle_tf2_broadcaster.py
q = quaternion_from_euler(1.5707, 0, -1.5707)
print(f'The quaternion representation is x: {q[0]} y: {q[1]} z: {q[2]} w: {q[3]}.')

2 应用四元数旋转

要将一个四元数的旋转应用于姿势,只需将姿势的前一个四元数乘以表示所需旋转的四元数即可。 这个乘法的顺序很重要。

C++

#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
...tf2::Quaternion q_orig, q_rot, q_new;q_orig.setRPY(0.0, 0.0, 0.0);
// Rotate the previous pose by 180* about X
q_rot.setRPY(3.14159, 0.0, 0.0);
q_new = q_rot * q_orig;
q_new.normalize();或
q_orig = quaternion_from_euler(0, 0, 0)
# Rotate the previous pose by 180* about X
q_rot = quaternion_from_euler(3.14159, 0, 0)
q_new = quaternion_multiply(q_rot, q_orig)

3 反转四元数

反转四元数的一种简单方法是对 w 分量求反:

q[3] = -q[3]

4 相对旋转

假设你有两个来自同一帧的四元数,并且 。 您希望查找按以下方式转换为 的相对旋转 :q_1q_2q_rq_1q_2

q_2 = q_r * q_1

您可以像求解矩阵方程一样进行求解。 反转并右乘两侧。同样,乘法的顺序也很重要:q_rq_1

q_r = q_2 * q_1_inverse

下面是一个在 python 中获取从上一个机器人姿势到当前机器人姿势的相对旋转的示例:

def quaternion_multiply(q0, q1):"""
    Multiplies two quaternions.    Input
    :param q0: A 4 element array containing the first quaternion (q01, q11, q21, q31)
    :param q1: A 4 element array containing the second quaternion (q02, q12, q22, q32)    Output
    :return: A 4 element array containing the final quaternion (q03,q13,q23,q33)    """# Extract the values from q0w0 = q0[0]x0 = q0[1]y0 = q0[2]z0 = q0[3]# Extract the values from q1w1 = q1[0]x1 = q1[1]y1 = q1[2]z1 = q1[3]# Computer the product of the two quaternions, term by termq0q1_w = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1q0q1_x = w0 * x1 + x0 * w1 + y0 * z1 - z0 * y1q0q1_y = w0 * y1 - x0 * z1 + y0 * w1 + z0 * x1q0q1_z = w0 * z1 + x0 * y1 - y0 * x1 + z0 * w1# Create a 4 element array containing the final quaternionfinal_quaternion = np.array([q0q1_w, q0q1_x, q0q1_y, q0q1_z])# Return a 4 element array containing the final quaternion (q02,q12,q22,q32)return final_quaternionq1_inv[0] = prev_pose.pose.orientation.x
q1_inv[1] = prev_pose.pose.orientation.y
q1_inv[2] = prev_pose.pose.orientation.z
q1_inv[3] = -prev_pose.pose.orientation.w # Negate for inverseq2[0] = current_pose.pose.orientation.x
q2[1] = current_pose.pose.orientation.y
q2[2] = current_pose.pose.orientation.z
q2[3] = current_pose.pose.orientation.wqr = quaternion_multiply(q2, q1_inv)

总结

在本教程中,您了解了四元数的基本概念及其相关的数学运算,例如反转和旋转。 您还了解了它在 ROS 2 中的使用示例以及两个单独的 Quaternion 类之间的转换方法。

http://www.ds6.com.cn/news/111917.html

相关文章:

  • 网站开发 商标第几类网络营销公司怎么注册
  • 银行需要网站开发人员吗一份完整app运营推广方案
  • 产品报价网站建设费用手游推广平台代理
  • 政府网站的作用佛山网站定制
  • 淮南招聘网站建设app运营方案
  • 做网站用html5全网营销的公司
  • wordpress拉黑用户登录什么叫seo
  • 龙岩网站改版较好的公司seo建站工具
  • 做p2p网站的公司重庆 seo
  • 建设一个视频网站需要什么条件长沙网站关键词推广
  • 怎么做视频还有网站吗常州谷歌优化
  • 展会网站怎么做营销型网站建设设计
  • 怎么样在网上建设网站挣钱热门职业培训班
  • 佛山外贸网站设计站长工具seo综合查询访问
  • 一个商城网站开发要多少时间发帖推广平台
  • 网站服务器租用资质哪些网站推广不收费
  • 宁夏制作网站公司网络推广平台有哪些
  • 湘潭市哪里做网站bt磁力在线种子搜索神器
  • 做网站注册公司百度小说风云榜排名完结
  • 建设网站的难点如何关闭2345网址导航
  • 深圳工商注册公司流程seo站
  • 免费建站的网站如何建网站详细步骤
  • 望牛墩镇仿做网站semir是什么牌子
  • 长沙做网站有哪些网络营销的方法有哪些?
  • 乌克兰设计网站建设营业推广经典案例
  • 傻瓜式做网站软件百度优化服务
  • wordpress做的网站吗免费长尾词挖掘工具
  • java做的网站 jsp市场营销十大经典案例
  • 广州响应网站建设今日国内新闻头条
  • 泉州公司网站模板建站无锡seo关键词排名