Attitude Adjustment Fast Quaternion Attitude

admin 2024年6月24日08:09:27评论15 views字数 2327阅读7分45秒阅读模式


环境搭建

首先我们拿到github提供的文件,看到有challenge,generator,solver三个文件夹。我们需要的主要是challenge和generator。为了更加方便的部署环境而不需要大量的docker环境,因此,我选用直接执行脚本实现题目环境。

打开官网的generator-base文件夹,查看Makefile文件内容。

Attitude Adjustment  Fast Quaternion Attitude

直接执行 docker build . -t generator-base:debug

然后执行 docker run,根据需要选择参数。

Attitude Adjustment  Fast Quaternion Attitude

然后clone下官网hack-a-sat的文件夹,进入attitude文件夹。

Attitude Adjustment  Fast Quaternion Attitude

首先需要生成题目所需文件,所以进入generator文件夹,执行python3 generator.py。

Attitude Adjustment  Fast Quaternion Attitude

如果需要更改生成文件位置可以打开generator.py的文件,修改filename的值。

Attitude Adjustment  Fast Quaternion Attitude

然后进入challenge文件夹,执行python3 challenge.py文件即可开启题目。

如果需要挂载在端口可以使用socat tcp-listen:port,fork exec:./程序名,reuseaddr。

至此,题目环境搭建完成。


基础知识

Attitude Adjustment  Fast Quaternion Attitude

题目意图比较两个向量从而确定当前姿态。这无疑涉及一些专业知识。所以根据attitude和vector两个关键词在搜索引擎中搜索,随后得到以下两个比较合适的论文标题,而两者区别在于一个是attitude,一个是quaternion。

Attitude Adjustment  Fast Quaternion Attitude

Attitude Adjustment  Fast Quaternion Attitude

首先了解一下什么是quaternion,以及常见的attitude描述形式从而判断我们选择哪一个文章进行实现

quaternion and Direction cosine matrix

quaternion叫做四元数,本身形式时三个虚部加上一个实部构成的复数。如下图所示。

Attitude Adjustment  Fast Quaternion Attitude

但是对于我们来说,我们需要知道quaternion在spacecraft中的意义。

在Introduction to Satellite Attitude Control文章中,我找到了相关的内容。

第一个关键定义是,姿态是用来确定航天器的方位,而航天器有自己的三维方向,同时需要将这个航天器坐标系与一些惯性参考系进行比较,以便测量变化。

因此,一个航天器的姿态是指其相对于特定参考系的三维方向。

然后是探究该三维方向的表现形式是什么?

在wiki中表示,该三维方向可以用多种方法来描述;然而,最常见的是旋转矩阵、四元数和欧拉角。

旋转矩阵如下图所示:

Attitude Adjustment  Fast Quaternion Attitude

四元数如下图所示

Attitude Adjustment  Fast Quaternion Attitude

欧拉角如下图所示:

Attitude Adjustment  Fast Quaternion Attitude

接下来看看题目需要的描述方法是什么。

执行python3 challenge.py后,任意输入发现提示输入格式为四个数值,因此,判断需要的结果是四元数。

Attitude Adjustment  Fast Quaternion Attitude

Attitude Determination

确定我们需要的结果是四元数后,我们进一步阅读Fast Quaternion Attitude Estimation from Two Vector Measurements的论文内容。

该方法实现的前提条件是有两个在航天器坐标系下的星星位置方向的单位向量以及两个在参考坐标系下的测量向量,这个参考坐标系通常是惯性系。而我们需要得到的姿态是将矢量从参考坐标系旋转到航天器本体坐标系的矩阵。

确定航天器姿态的最简便方法是TRIAD,目前已有的解题方案中ADDVulcan使用了这一方案,其计算方式为

A = b1*r1.T + b3*r3.T + np.cross(b1, b3) * np.cross(r1, r3).T

其中b1是参考坐标系下的测量向量,r1航天器坐标系下的星星位置方向的向量,b3和r3则是根据b1,b2,r1,r2计算得到的数值。计算方法为

Attitude Adjustment  Fast Quaternion Attitude

而这一方法得到的结果是旋转矩阵还需要转化成四元数。

我们今天使用的方法则是直接得到四元数。

首先,我们引入WAHBA's Problem

Attitude Adjustment  Fast Quaternion Attitude

其中w_k是参考坐标系下的三维向量,v_k是航天器坐标系下的三维向量,R是我们需要求解的3*3的旋转矩阵。a_k是该观测星星的权重。

当向量为单位向量时,原式可变成1/2(a*(1-wRv)),最小化损失函数则需要使得awRv最大。

在上式中,并没有四元数的存在,所以我们意图将四元数引入到上式中,从而得到关于四元数的损失函数。

四元数和旋转矩阵存在2:1的关系,即:

Attitude Adjustment  Fast Quaternion Attitude

Attitude Adjustment  Fast Quaternion Attitude

根据四元组和旋转矩阵的转化关系得到:

Attitude Adjustment  Fast Quaternion Attitude

因此,R可以表示成Attitude Adjustment  Fast Quaternion Attitude

其中qX为与q相关的叉积矩阵:

Attitude Adjustment  Fast Quaternion Attitude

I为3*3的单位矩阵。

因此,awRv可以表示成q.TKq

设awv为B,则其中K为:

Attitude Adjustment  Fast Quaternion Attitude

tr代表矩阵的迹,即对角线元素之和。

要想计算J(R),我们还需要获得q值,接下来计算q。回到最开始的定义,航天器的姿态是航天器坐标系和惯性系坐标系相对关系。所以首先了解两个坐标系如何建立关系。

关于r1向b1投影的一般方程为:

Attitude Adjustment  Fast Quaternion Attitude

其中q_min为r1向b1投影的最小角四元组:

Attitude Adjustment  Fast Quaternion Attitude

所以:

Attitude Adjustment  Fast Quaternion Attitude

Attitude Adjustment  Fast Quaternion Attitude=Attitude Adjustment  Fast Quaternion Attitude+Attitude Adjustment  Fast Quaternion Attitude时,

Attitude Adjustment  Fast Quaternion Attitude

因此,对于WAHBA's Problem的J(R)可以表示为:

Attitude Adjustment  Fast Quaternion Attitude

其中,

Attitude Adjustment  Fast Quaternion Attitude

为了最小化损失,Attitude Adjustment  Fast Quaternion Attitude的值需要最大化,为Attitude Adjustment  Fast Quaternion Attitude

Attitude Adjustment  Fast Quaternion Attitude

Attitude Adjustment  Fast Quaternion Attitude

这个时候我们再回过头求q,

Attitude Adjustment  Fast Quaternion Attitude

解决题目

对于解决这道题目来说,并不一定需要完全理解方案中的原理,只需要使用结论编写代码完成即可。

首先是题目交互基本的代码。

Attitude Adjustment  Fast Quaternion Attitude

打开generator生成的txt文件,获得航天器坐标系下的星星参数,记作r。

读取程序显示的内容作为b,只需要取前两个即可。

Attitude Adjustment  Fast Quaternion Attitude

随后基于subopt的结论,如下图所示,计算μ,v,ρ三个值,并编写最终的算式。

Attitude Adjustment  Fast Quaternion Attitude

Attitude Adjustment  Fast Quaternion Attitude

Attitude Adjustment  Fast Quaternion Attitude

Attitude Adjustment  Fast Quaternion Attitude

最终实现:

Attitude Adjustment  Fast Quaternion Attitude

Attitude Adjustment  Fast Quaternion Attitude

看雪ID:DR@03

https://bbs.kanxue.com/user-home-925284.htm

*本文为看雪论坛优秀文章,由 DR@03 原创,转载请注明来自看雪社区

Attitude Adjustment  Fast Quaternion Attitude

原文始发于微信公众号(看雪学苑):Attitude Adjustment -- Fast Quaternion Attitude

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年6月24日08:09:27
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Attitude Adjustment Fast Quaternion Attitudehttps://cn-sec.com/archives/2872666.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息