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

从零开始学习PX4源码2(PX4姿态误差计算)

目录

文章目录

  • 目录
  • 摘要
  • 1.源码
    • 1.1源码路径
    • 1.2源码程序
    • 1.3源码功能
  • 2.源码分析

摘要

本节主要记录PX4姿态误差计算过程,欢迎批评指正。

1.源码

1.1源码路径

PX4-Autopilot/src/modules/mc_att_control/AttitudeControl/AttitudeControl.cpp

1.2源码程序

matrix::Vector3f AttitudeControl::update(const Quatf &q) const
{Quatf qd = _attitude_setpoint_q;// calculate reduced desired attitude neglecting vehicle's yaw to prioritize roll and pitchconst Vector3f e_z = q.dcm_z();const Vector3f e_z_d = qd.dcm_z();Quatf qd_red(e_z, e_z_d);if (fabsf(qd_red(1)) > (1.f - 1e-5f) || fabsf(qd_red(2)) > (1.f - 1e-5f)){// In the infinitesimal corner case where the vehicle and thrust have the completely opposite direction,// full attitude control anyways generates no yaw input and directly takes the combination of// roll and pitch leading to the correct desired yaw. Ignoring this case would still be totally safe and stable.qd_red = qd;} else{// transform rotation from current to desired thrust vector into a world frame reduced desired attitudeqd_red *= q;}// mix full and reduced desired attitudeQuatf q_mix = qd_red.inversed() * qd;q_mix.canonicalize();// catch numerical problems with the domain of acosf and asinfq_mix(0) = math::constrain(q_mix(0), -1.f, 1.f);q_mix(3) = math::constrain(q_mix(3), -1.f, 1.f);qd = qd_red * Quatf(cosf(_yaw_w * acosf(q_mix(0))), 0, 0, sinf(_yaw_w * asinf(q_mix(3))));// quaternion attitude control law, qe is rotation from q to qdconst Quatf qe = q.inversed() * qd;// using sin(alpha/2) scaled rotation axis as attitude error (see quaternion definition by axis angle)// also taking care of the antipodal unit quaternion ambiguityconst Vector3f eq = 2.f * qe.canonical().imag();// calculate angular rates setpointVector3f rate_setpoint = eq.emult(_proportional_gain);// Feed forward the yaw setpoint rate.// yawspeed_setpoint is the feed forward commanded rotation around the world z-axis,// but we need to apply it in the body frame (because _rates_sp is expressed in the body frame).// Therefore we infer the world z-axis (expressed in the body frame) by taking the last column of R.transposed (== q.inversed)// and multiply it by the yaw setpoint rate (yawspeed_setpoint).// This yields a vector representing the commanded rotatation around the world z-axis expressed in the body frame// such that it can be added to the rates setpoint.if (std::isfinite(_yawspeed_setpoint)){rate_setpoint += q.inversed().dcm_z() * _yawspeed_setpoint;}// limit ratesfor (int i = 0; i < 3; i++){rate_setpoint(i) = math::constrain(rate_setpoint(i), -_rate_limit(i), _rate_limit(i));}return rate_setpoint;
}

1.3源码功能

实现姿态误差计算,得到目标角速度。

2.源码分析

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

对应的PDF下载地址:
下载地址

http://www.lryc.cn/news/311630.html

相关文章:

  • git安装与使用4.3
  • Python:关于数据服务中的Web API的设计
  • VMwareWorkstation17.0虚拟机安装搭建PcDos2000虚拟机(完整图文详细步骤教程)
  • 第七个程序:两个字符串连接后计算长度
  • 【大数据】-- dataworks 创建odps 的 hudi 外表
  • ChatGPT与GEE+ENVI+python高光谱,多光谱等成像遥感数据处理技术
  • 学习linux从0到初级工程师-3
  • java实现文件上传到本地
  • 基于springboot+vue的多媒体素材库的开发与应用系统
  • 《GitHub新手入门指南:从零开始掌握基本用法》
  • K8S存储卷与PV,PVC
  • (科目三)简答题汇总
  • 8、Redis-Jedis、Lettuce和一个Demo
  • (Linux学习六)用户特殊权限类型,suid,chattr,umask
  • Mysql 数据类型的转换之 cast()
  • python重命名指定文件夹下的所有文件
  • 通过多线程并发方式实现服务器
  • 【C语言】指针超级无敌金刚霹雳进阶(但不难,还是基础)
  • 上位机图像处理和嵌入式模块部署(qmacvisual入门)
  • 数据库事务问题整理-MySQL
  • 工具函数模板题(蓝桥杯 C++ 代码 注解)
  • Ansible playbook 简介 使用场景
  • TS总结10、ts的 class 类型(配置项strictPropertyInitialization、非空断言)
  • leetcode 热题 100_找到字符串中所有字母异位词
  • 百度百科数据爬取 python 词条数据获取
  • 为不同文章形式选择不同的WordPress文章模板
  • MySQL存储引擎及索引机制
  • Leetcode算法题
  • 数据结构之七大排序
  • 【MySQL】数据库中常用的函数