1 基操
本文件搜索
全局搜索
后退
前进
ctrl+p,搜索文件名
右键,书签功能
(ctrl+单击) / F12,转到定义
大纲视图
vscode的Open Folder插件搜索文件夹名
2 利用测试代码帮助理解
测试代码是为了测试本模块代码是否正确,会给定一些输入,并判断其输出与预期输出是否一致。
例如:
src/modules/mc_att_control/AttitudeControl/AttitudeControlTest.cpp
就测试了多旋翼姿态控制算法是否正确。
测试代码书写简单明了,能够帮助理解主干代码。
例如多旋翼的混控过程非常冗长
(见src/lib/mixer/MultirotorMixer/MultirotorMixer.cpp)
但看src/lib/mixer/MultirotorMixer/test_mixer_multirotor.cpp就非常简单明了,能让人快速提取主干内容。
MultirotorMixer mixer(mixer_callback, 0, rotors, rotor_count);
mixer.set_airmode((Mixer::Airmode)airmode);
int test_counter = 0;
int num_failed = 0;
while (!feof(file_in)) {
unsigned count = 0;
while (count < 4 && fscanf(file_in, "%f", &actuator_controls[count]) == 1) {
++count;
}
if (count < 4) {
break;
}
if (mixer.mix(actuator_outputs, output_max) != rotor_count) {
return -1;
}
for (unsigned i = 0; i < rotor_count; i++) {
actuator_outputs[i] = (actuator_outputs[i] + 1.f) * .5f;
}
不失为阅读代码的一个技巧。
3 使用source insight查看调用关系
3.1 Source Insight破解汉化版
链接: link
本人安装测试成功
导入项目后显示为空白,此时点击 文件 -> 打开
就会出现项目文件框,导引到自己的项目文件路径即可。
3.2 Source Insight完美破解
Source Insight 4.0 完美破解 - 简书
https://www.jianshu.com/p/a4735cf9f334
这个方法也很好,没有测试。
3.3 Source Insight查看引用、调用关系图
(46条消息) source insight查看函数调用关系(总结全网资料)_小熊coder的博客-CSDN博客_查看函数调用关系
link
例如对void FlightTaskAutoLineSmoothVel::_prepareSetpoints()函数查看3级调用,可自动生成如下图片:
极大提高了看代码的效率,很棒!
4 使用mavlink_log输出消息
会记录在日志中,也会显示在地面站提示消息中。
// 使用MavLink_log的方法
#include <systemlib/mavlink_log.h>
// 定义orb_advert_t
orb_advert_t _mavlink_log_pub{nullptr};
mavlink_log_info(&_mavlink_log_pub, "[IO] mixer upload fail");
mavlink_log_warning(&_mavlink_log_pub, "Arming denied! Already armed");
mavlink_log_critical(&_mavlink_log_pub, "IO RC config upload fail");
4 待补充
4 待补充
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)