浅谈APM系列

您所在的位置:网站首页 copter和helicopter区别 浅谈APM系列

浅谈APM系列

2024-06-30 21:43:16| 来源: 网络整理| 查看: 265

APM与PX4底层之间的关系

PX4创建任务之后,调用APM中的void Copter::setup()和void Copter::loop()函数

位置:X:\ardupilot\libraries\AP_HAL_PX4\HAL_PX4_Class.cpp

在HAL_PX4_Class.cpp文件中,有如下代码

static AP_HAL::HAL::Callbacks* g_callbacks; void HAL_PX4::run(int argc, char * const argv[], Callbacks* callbacks) g_callbacks = callbacks;

在main_loop中调用了

g_callbacks->setup(); g_callbacks->loop();

我们应该还记得APM中的

AP_HAL_MAIN_CALLBACKS(&copter);

#pragma once #include "HAL.h" #if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN #define AP_MAIN __EXPORT ArduPilot_main #endif #ifndef AP_MAIN #define AP_MAIN main #endif #define AP_HAL_MAIN() \ AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \ extern "C" { \ int AP_MAIN(int argc, char* const argv[]); \ int AP_MAIN(int argc, char* const argv[]) { \ hal.run(argc, argv, &callbacks); \ return 0; \ } \ } #define AP_HAL_MAIN_CALLBACKS(CALLBACKS) extern "C" { \ int AP_MAIN(int argc, char* const argv[]); \ int AP_MAIN(int argc, char* const argv[]) { \ hal.run(argc, argv, CALLBACKS); \ return 0; \ } \ }

其中的copter,是一个Copter的对象

Copter copter;

看到这里你应该明白了,APM中的set函数和loop函数是怎么被调用的了

APM中的void Copter::setup()函数,由PX4调用

位置:X:\ardupilot\ArduCopter\ArduCopter.cpp

void Copter::setup() { // Load the default values of variables listed in var_info[]s AP_Param::setup_sketch_defaults(); // setup storage layout for copter StorageManager::set_layout_copter(); init_ardupilot(); // initialise the main loop scheduler scheduler.init(&scheduler_tasks[0], ARRAY_SIZE(scheduler_tasks)); // setup initial performance counters perf_info.reset(scheduler.get_loop_rate_hz()); fast_loopTimer = AP_HAL::micros(); }

APM中的void Copter::loop()函数,同样是由PX4调用

位置:X:\ardupilot\ArduCopter\ArduCopter.cpp

void Copter::loop() { // wait for an INS sample ins.wait_for_sample();//等待最新的传感器数据 uint32_t timer = micros(); // check loop time perf_info.check_loop_time(timer - fast_loopTimer); // used by PI Loops G_Dt = (float)(timer - fast_loopTimer) / 1000000.0f;//计算Dt,用于PID计算 fast_loopTimer = timer; // for mainloop failure monitoring mainLoop_count++; // Execute the fast loop // --------------------- fast_loop(); // tell the scheduler one tick has passed scheduler.tick(); // run all the tasks that are due to run. Note that we only // have to call this once per loop, as the tasks are scheduled // in multiples of the main loop tick. So if they don't run on // the first call to the scheduler they won't run on a later // call until scheduler.tick() is called again const uint32_t loop_us = scheduler.get_loop_period_us(); const uint32_t time_available = (timer + loop_us) - micros(); scheduler.run(time_available > loop_us ? 0u : time_available); }

 

明日复明日,明日何其多

后面将继续更新,APM的其他部分代码。希望能对你的学习和工作有所帮助。

请耐心等待。。。。。



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭