mc_pos_control.cpp 之 generate_attitude_setpoint(dt)

2023-05-16


void
MulticopterPositionControl::generate_attitude_setpoint(float dt)
{
    /* reset yaw setpoint to current position if needed */
    if (_reset_yaw_sp) {
        _reset_yaw_sp = false;
        _att_sp.yaw_body = _yaw;
    }

    /* do not move yaw while sitting on the ground */
    else if (!_vehicle_land_detected.landed &&
         !(!_control_mode.flag_control_altitude_enabled && _manual.z < 0.1f)) {

        /* we want to know the real constraint, and global overrides manual */
        const float yaw_rate_max = (_params.man_yaw_max < _params.global_yaw_max) ? _params.man_yaw_max :
                       _params.global_yaw_max;
        const float yaw_offset_max = yaw_rate_max / _params.mc_att_yaw_p;

        _att_sp.yaw_sp_move_rate = _manual.r * yaw_rate_max;
        float yaw_target = _wrap_pi(_att_sp.yaw_body + _att_sp.yaw_sp_move_rate * dt);
        float yaw_offs = _wrap_pi(yaw_target - _yaw);

        // If the yaw offset became too big for the system to track stop
        // shifting it, only allow if it would make the offset smaller again.
        if (fabsf(yaw_offs) < yaw_offset_max ||
            (_att_sp.yaw_sp_move_rate > 0 && yaw_offs < 0) ||
            (_att_sp.yaw_sp_move_rate < 0 && yaw_offs > 0)) {
            _att_sp.yaw_body = yaw_target;
        }
    }

    /* control throttle directly if no climb rate controller is active */
    if (!_control_mode.flag_control_climb_rate_enabled) {
        float thr_val = throttle_curve(_manual.z, _params.thr_hover);
        _att_sp.thrust = math::min(thr_val, _manual_thr_max.get());

        /* enforce minimum throttle if not landed */
        if (!_vehicle_land_detected.landed) {
            _att_sp.thrust = math::max(_att_sp.thrust, _manual_thr_min.get());
        }
    }

    /* control roll and pitch directly if no aiding velocity controller is active */
    if (!_control_mode.flag_control_velocity_enabled) {
        _att_sp.roll_body = _manual.y * _params.man_roll_max;
        _att_sp.pitch_body = -_manual.x * _params.man_pitch_max;

        /* only if optimal recovery is not used, modify roll/pitch */
        if (_params.opt_recover <= 0) {
            // construct attitude setpoint rotation matrix. modify the setpoints for roll
            // and pitch such that they reflect the user's intention even if a yaw error
            // (yaw_sp - yaw) is present. In the presence of a yaw error constructing a rotation matrix
            // from the pure euler angle setpoints will lead to unexpected attitude behaviour from
            // the user's view as the euler angle sequence uses the  yaw setpoint and not the current
            // heading of the vehicle.

            // calculate our current yaw error
            float yaw_error = _wrap_pi(_att_sp.yaw_body - _yaw);

            // compute the vector obtained by rotating a z unit vector by the rotation
            // given by the roll and pitch commands of the user
            math::Vector<3> zB = {0, 0, 1};
            math::Matrix<3, 3> R_sp_roll_pitch;
            R_sp_roll_pitch.from_euler(_att_sp.roll_body, _att_sp.pitch_body, 0);
            math::Vector<3> z_roll_pitch_sp = R_sp_roll_pitch * zB;


            // transform the vector into a new frame which is rotated around the z axis
            // by the current yaw error. this vector defines the desired tilt when we look
            // into the direction of the desired heading
            math::Matrix<3, 3> R_yaw_correction;
            R_yaw_correction.from_euler(0.0f, 0.0f, -yaw_error);
            z_roll_pitch_sp = R_yaw_correction * z_roll_pitch_sp;

            // use the formula z_roll_pitch_sp = R_tilt * [0;0;1]
            // R_tilt is computed from_euler; only true if cos(roll) not equal zero
            // -> valid if roll is not +-pi/2;
            _att_sp.roll_body = -asinf(z_roll_pitch_sp(1));
            _att_sp.pitch_body = atan2f(z_roll_pitch_sp(0), z_roll_pitch_sp(2));
        }

        /* copy quaternion setpoint to attitude setpoint topic */
        matrix::Quatf q_sp = matrix::Eulerf(_att_sp.roll_body, _att_sp.pitch_body, _att_sp.yaw_body);
        memcpy(&_att_sp.q_d[0], q_sp.data(), sizeof(_att_sp.q_d));
        _att_sp.q_d_valid = true;
    }

    if (_manual.gear_switch == manual_control_setpoint_s::SWITCH_POS_ON &&
        !_vehicle_land_detected.landed) {
        _att_sp.landing_gear = 1.0f;

    } else if (_manual.gear_switch == manual_control_setpoint_s::SWITCH_POS_OFF) {
        _att_sp.landing_gear = -1.0f;
    }

    _att_sp.timestamp = hrt_absolute_time();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

mc_pos_control.cpp 之 generate_attitude_setpoint(dt) 的相关文章

  • STM32CubeMX上手初体验

    STM32CubeMX 提起嵌入式开发常用的IDE xff0c 你都用过哪些 xff1f 相信大家都用过keil xff0c 它上手简单 xff0c 许可证也可以通过众所周知的途径拿到 IAR有些小伙伴也用过 xff0c 它功能强大 xff

随机推荐

  • 学习ucosii要用到的几本书和软件

    原帖地址 xff1a http bbs ednchina com BLOG ARTICLE 2020186 HTM 打算学习一个嵌入式操作系统 xff0c 研究了一下决定还是先研究一下ucosii xff0c 一方面权当学习C语言 xff0
  • Linux防火墙——Firewalld基础命令

    Firewalld概述 Firewalld简介 xff08 1 xff09 支持网络区域所定义的网络连接以及接口安全的动态防火墙管理工具 xff08 2 xff09 支持IPv4 IPv6防火墙设置以及以太网桥接 xff08 3 xff09
  • 本地服务调用 K8S 环境中的 SpringCloud 微服务实战

    常规手段 xff1a 通过 service 访问对应的 pod 通常情况下 xff0c 从外部访问 kubernetes 内部 pod 服务的方法是创建 service xff0c 再通过访问 service 的方式来访问对应的 Pod x
  • Azure Redhat挂载盘操作导致重启后无法ssh登录

    问题 在Azure环境中创建了一台 Redhat VM xff0c 挂载了一块128GB新盘 xff0c 晚上stop后 xff0c 第二天start后无法ssh登录 发现问题过程 进入虚拟机信息页面 2 进入左侧 Support 43 T
  • KCF目标跟踪

    ROS调包侠 KCF目标跟踪 项目说明 参考项目 xff1a GitHub TianyeAlex tracker kcf ros 基于ros下应用深度相机的kcf追踪算法实现 修改内容 xff1a 1 解决原作者使用OpenCV版本比较老
  • 如何查看go依赖包的license (glice)

    Reference https github com ribice glice Installation Download and install glice by executing go install github com ribic
  • MINIO PutObject (erasureServerPools)源码分析

    实验环境 xff1a MINIO 源码版本 xff1a RELEASE 2021 04 22 minio server 后跟四块盘 一个erasureServerPool 1个erasureSet xff0c 4个Drives 2个Data
  • VNC 的应用及灰屏鼠标变X问题

    Ubuntu中vnc服务器端的安装很简单 xff0c 运行如下命令 xff1a sudo apt get install vnc4server 第一次启动vncserver后 xff0c 在用户家目录中会生成 vnc 目录 xff0c 注意
  • Intel VT-x enabled 却无法打开64位虚拟机

    情景 xff1a 机型 xff1a 联想 T430 前些天运行64位虚拟机没有问题 xff0c 今天打开却跳出无法执行64位操作 xff0c 很是诧异 便根据提示进行检查 BIOS中Virtual Technology 虚拟技术已打开 xf
  • Valgrind:failed to start tool 'memcheck' for platform 'x86-linux': No such file or directory

    引文 xff1a Valgrind安装与使用Ubuntu下添加环境变量方法 问题 通过 configure prefix 61 where you want to install将Valgrind安装到自己希望的目录安装Valgrind 3
  • hp z840 上安装ESXi

    ESXi安装 镜像下载 VMware viclient all 5 1 0 2306356 exe VMware ESXi 5 1 0 Update3 2323236 HP 510 9 4 24 Nov2015 iso VMware ESX
  • ESXi 6.0 中虚拟机拷贝(克隆)

    情况一 xff1a 拥有一台配置好的虚拟机 xff0c 想通过clone方式复制多台虚拟机来进行模糊测试 xff0c 但是vSphere Client 6 0没有提供克隆虚拟机功能 xff08 可能收费版拥有吧 xff09 解决方法 xff
  • Vmware 虚拟机瘦身

    问题 vmware 占用硬盘空间只增大不减少 即使删除虚拟机系统里面的文件 xff0c 占用宿主机的硬盘空间也不释放 导致虚拟机越来越大 xff01 方法一 xff1a 运用虚拟机自带的磁盘整理工具来进行磁盘清理 xff01 1 虚拟机 g
  • 从peach源码生成工程文件

    编译过程中几个软件 msvc Microsoft Visual C 43 43 often abbreviated as MSVC or VC 43 43 is an integrated development environment I
  • QT读取GPS信息,信息组包,防止异常错乱

    以下如果有错误 xff0c 请留言指正 GNRMC为双模定位 xff1a GPRMC 43 BD 读取 GNRMC经纬度信息 xff1b 含GPRMC xff1b 处理类似 GNRMC 064401 65 A 3110 4706987 N
  • 自定义数据结构(C++)

    1 动态数组 include lt iostream gt template lt typename T gt class MyVector T m p int m capacity int m size public 构造函数 expli
  • ubuntu20 下 qtcreator ros配置过程

    1 去下载qtcreator ros bionic latest offline installer run文件进行安装 xff1b 参考这里 xff1a How to Install Users ROS Qt Creator Plug i
  • 【竞赛记录】kpi异常检测

    搞了个华为的KPI异常检测竞赛 xff0c 当然搞的时候就没觉得自己会拿奖 xff08 我指安慰奖 xff09 xff0c 但没想到有这么悬殊 一方面是没搞过时间序列的东西 xff0c 好多东西要重新开始学 xff1b 另一方面是 xff0
  • vscode调试container中的程序

    在写cmu14 445的project时 xff0c 我希望在本地vscode编辑代码 xff0c 然后在docker中编译和测试代码 但是如果测试出了问题 xff0c 直接在本地调试就变得麻烦了 所以希望利用vscode进行远程调试 参考
  • mc_pos_control.cpp 之 generate_attitude_setpoint(dt)

    span class hljs keyword void span MulticopterPositionControl generate attitude setpoint span class hljs keyword float sp