像这种庞大系统的代码, 我一般喜欢先大致了解一下代码结构,然后按照执行流程阅读分析。我阅读的是高通8074平台的px4代码。
代码地址:ATLFlight/Firmware
参考文档:px4 devguide
由于没有足够的时间再去细细研究, 所以只有这么一个粗略的笔记.
============================================================================================================
##关键路径及文件
1 | W:\uav\Firmware\src\modules\mavlink // 信息数据处理 |
##按执行调用(log)顺序阅读
###APPS Processor
执行指令: ./mainapp mainapp.config - (main.cpp + W:\uav\Firmware\posix-configs\eagle\flight\mainapp-flight.config)
1 | W:\uav\Firmware\src\platforms\posix\main.cpp |
执行时打印的log如下:
1 | px4muorbKraitWrapper.cpp (C:\Qualcomm\Hexagon_SDK\2.0\flight_controller\krait\inc\px4muorb_KraitRpcWrapper.hpp) |
mainapp.config的内容如下:
1 | uorb start |
ADSP
adsp端打印的log如下:
1 | symbol.c (链接ELF( Executable and Linkable Format) 和 object) |
adsp端main.cp源码如下:
1 | #W:\uav\Firmware\src\platforms\qurt\px4_layer\main.cpp |
adsp端配置文件如下:
1 | # W:\uav\Firmware\posix-configs\eagle\flight\px4-flight.config |
uorb & muorb
uorb&muorb是负责数据传输的模块。
1 | # 关键路径 |
uorb start
1 | W:\uav\Firmware\src\modules\uORB\uORBMain.cpp |
W:\uav\Firmware\src\modules\uORB\uORBDevices_posix.hpp
1 | class uORB::DeviceNode : public device::VDev |
muorb start
1 | uORBDevices_posix.cpp |
Krait muorb
1 | int muorb_main(int argc, char *argv[]) (W:\uav\Firmware\src\modules\muorb\krait\muorb_main.cpp) |
####muorb通信
1 | ========================================================================================================================== |
W:\uav\Firmware\src\modules\muorb\krait\uORBKraitFastRpcChannel.hpp
1 | namespace uORB |
####uorb通信
1 | ========================================================================== |
add subscriber
1 | void uORB::DeviceNode::add_internal_subscriber() (W:\uav\Firmware\src\modules\uORB\uORBDevices_posix.cpp # 调用adsp 和 Krait中muorb中实现的 接口 ?) |
W:\uav\Firmware\src\modules\muorb\adsp\uORBFastRpcChannel.hpp
1 | namespace uORB |
W:\uav\Firmware\src\modules\uORB\uORBCommunicator.hpp
1 | /** |
W:\uav\Firmware\src\modules\uORB\uORBDevices_posix.cpp ( apps processor 数据交互 ?)
1 | void uORB::DeviceNode::add_internal_subscriber() |
W:\uav\Firmware\src\modules\uORB\uORBManager_posix.cpp (px4_ioctl)
1 | int16_t uORB::Manager::process_add_subscription(const char *messageName, int32_t msgRateInHz) |
W:\uav\Firmware\src\drivers\drv_orb_dev.h
W:\uav\Firmware\src\drivers\device\vdev.cpp
编译后执行程序 打印路径变成
1 | W:\uav\apq8074-le-1-0_ap_standard_oem\apps_proc\oe-core\build\tmp-eglibc\work\cortexa8hf-vfp-neon-linux-gnueabi\adsprpc\1.0-r0\adsprpc-1.0\src |
数据传输流程
adsp –> libmpu9x50.so->mpu9x50_main.cpp->orb
1 | W:\uav\Firmware\src\drivers\mpu9x50\mpu9x50_main.cpp |
commander
飞行安全管理, 订阅相关主题, 用来检查飞行安全,并做相应处理,。。。。。
1 | W:\uav\Firmware\src\modules\commander\commander.cpp |
W:\uav\Firmware\src\platforms\ros\nodes\commander\commander.cpp (与上一commander.cpp 对应 ?)
W:\uav\Firmware\src\drivers\px4io\px4io.cpp
Mavlink
int mavlink_main(int argc, char *argv[]) # W:\uav\Firmware\src\modules\mavlink\mavlink_main.cpp
1 | "start" |
Mavlink Reiceiver
MavlinkReceiver::receive_start(Mavlink *parent) # W:\uav\Firmware\src\modules\mavlink\mavlink_receiver.cpp
1 | *MavlinkReceiver::start_helper(void *context) |
W:\uav\Firmware\src\modules\mavlink\mavlink_messages.cpp # 各种数据流 stream 类定义。。。
uart_esc start -D /dev/tty-2
int uart_esc_main(int argc, char *argv[]) # W:\uav\Firmware\src\drivers\px4_legacy_driver_wrapper\uart_esc\uart_esc_main.cpp
1 | uart_esc::start()->task_main(int argc, char *argv[]) |
attitude_estimator_q start (主要接收sensor和vehicle_global_position主题,处理, 发布飞行姿态主题)
W:\uav\Firmware\src\modules\attitude_estimator_q\attitude_estimator_q_main.cpp
1 | int attitude_estimator_q_main(int argc, char *argv[]) |
position_estimator_inav start (订阅飞控等相关主题,接收到主题后,进行一些算法处理。 发布vehicle_local_position、vehicle_global_position主题)
W:\uav\Firmware\src\modules\position_estimator_inav\position_estimator_inav_main.c
1 | int position_estimator_inav_thread_main(int argc, char *argv[]) |
mc_att_control start
W:\uav\Firmware\src\modules\mc_att_control\mc_att_control_main.cpp
1 | int mc_att_control_main(int argc, char *argv[]) |
mc_pos_control start
W:\uav\Firmware\src\modules\mc_pos_control\mc_pos_control_main.cpp
1 | int mc_pos_control_main(int argc, char *argv[]) |