感谢兰州—Zing的指教。。
1. 飞行日志
下载flightplot,官网是http://www.pixhawk.com/dev/flightplot
px4飞行日志位置在log文件夹中数字越大表示越新,新加的日志不会覆盖旧的日志。
日志简单操作:
第一步:Open Log orFile→OpenLog….打开你要看的日志
第二步:点 Field List,选择你想看的数据类型,点Add.添加你要看的数据类型
第三步:添加进“simple”里面
第四步:flightplot为用户开发了函数功能,在画图区点Add,可以将处理完的数据画出来。
最后的效果:
绿颜色:传感器测的高度 红颜色:期望高度 蓝颜色:垂直方向速度 黑颜色:垂直速度的积分
2. mavlink添加想发送的信息
mavlink_log_info(&mavlink_log_pub, "1212121212121");
mavlink_log_critical(&mavlink_log_pub, "czyv587...")
int ii=0; if(ii<1000) { mavlink_and_console_log_info(&mavlink_log_pub, "czy: #%ii", ii); ii++; } else ii=0;
3. nsh
第一步:打开TeraTerm第二步:点setup选Serial port setup,并设置串口和波特率(默认COM5,57600)
第三步:输入命令:先回车,再输入“?”或者“help”,编译好的应用会被打印出来
第四步:重点看你需要看的部分(输入的命令)
总结:nsh输入的命令调试bug,首先需要将你要调试的部分用cmke编译生成.px4,输入“?”会显示所以编译好的应用,输入的命令实际上是在程序中写好的,对应于每个应用的相应位置。添加一个应用,有助于帮助理解nsh
int commander_main(int argc, char *argv[]) { if (argc < 2) { usage("missing command"); return 1; } if (!strcmp(argv[1], "start")) { if (thread_running) { warnx("already running"); /* this is not an error */ return 0; } thread_should_exit = false; daemon_task = px4_task_spawn_cmd("commander", SCHED_DEFAULT, SCHED_PRIORITY_DEFAULT + 40, 3600, commander_thread_main, (char * const *)&argv[0]); unsigned constexpr max_wait_us = 1000000; unsigned constexpr max_wait_steps = 2000; unsigned i; for (i = 0; i < max_wait_steps; i++) { usleep(max_wait_us / max_wait_steps); if (thread_running) { break; } } return !(i < max_wait_steps); } if (!strcmp(argv[1], "stop")) { if (!thread_running) { warnx("commander already stopped"); return 0; } thread_should_exit = true; while (thread_running) { usleep(200000); warnx("."); } warnx("terminated."); return 0; } /* commands needing the app to run below */ if (!thread_running) { warnx("\tcommander not started"); return 1; } if (!strcmp(argv[1], "status")) { print_status(); return 0; } if (!strcmp(argv[1], "calibrate")) { if (argc > 2) { int calib_ret = OK; if (!strcmp(argv[2], "mag")) { calib_ret = do_mag_calibration(&mavlink_log_pub); } else if (!strcmp(argv[2], "accel")) { calib_ret = do_accel_calibration(&mavlink_log_pub); } else if (!strcmp(argv[2], "gyro")) { calib_ret = do_gyro_calibration(&mavlink_log_pub); } else if (!strcmp(argv[2], "level")) { calib_ret = do_level_calibration(&mavlink_log_pub); } else if (!strcmp(argv[2], "esc")) { calib_ret = do_esc_calibration(&mavlink_log_pub, &armed); } else if (!strcmp(argv[2], "airspeed")) { calib_ret = do_airspeed_calibration(&mavlink_log_pub); } else { warnx("argument %s unsupported.", argv[2]); } if (calib_ret) { warnx("calibration failed, exiting."); return 1; } else { return 0; } } else { warnx("missing argument"); } } if (!strcmp(argv[1], "check")) { int checkres = 0; checkres = preflight_check(&status, &mavlink_log_pub, false, true, &status_flags, &battery); warnx("Preflight check: %s", (checkres == 0) ? "OK" : "FAILED"); checkres = preflight_check(&status, &mavlink_log_pub, true, true, &status_flags, &battery); warnx("Prearm check: %s", (checkres == 0) ? "OK" : "FAILED"); return 0; } if (!strcmp(argv[1], "arm")) { if (TRANSITION_CHANGED != arm_disarm(true, &mavlink_log_pub, "command line")) { warnx("arming failed"); } return 0; } if (!strcmp(argv[1], "disarm")) { if (TRANSITION_DENIED == arm_disarm(false, &mavlink_log_pub, "command line")) { warnx("rejected disarm"); } return 0; } if (!strcmp(argv[1], "takeoff")) { /* see if we got a home position */ if (status_flags.condition_home_position_valid) { if (TRANSITION_DENIED != arm_disarm(true, &mavlink_log_pub, "command line")) { vehicle_command_s cmd = {}; cmd.target_system = status.system_id; cmd.target_component = status.component_id; cmd.command = vehicle_command_s::VEHICLE_CMD_NAV_TAKEOFF; cmd.param1 = NAN; /* minimum pitch */ /* param 2-3 unused */ cmd.param2 = NAN; cmd.param3 = NAN; cmd.param4 = NAN; cmd.param5 = NAN; cmd.param6 = NAN; cmd.param7 = NAN; orb_advert_t h = orb_advertise(ORB_ID(vehicle_command), &cmd); (void)orb_unadvertise(h); } else { warnx("arming failed"); } } else { warnx("rejecting takeoff, no position lock yet. Please retry.."); } return 0; } if (!strcmp(argv[1], "land")) { vehicle_command_s cmd = {}; cmd.target_system = status.system_id; cmd.target_component = status.component_id; cmd.command = vehicle_command_s::VEHICLE_CMD_NAV_LAND; /* param 2-3 unused */ cmd.param2 = NAN; cmd.param3 = NAN; cmd.param4 = NAN; cmd.param5 = NAN; cmd.param6 = NAN; cmd.param7 = NAN; orb_advert_t h = orb_advertise(ORB_ID(vehicle_command), &cmd); (void)orb_unadvertise(h); return 0; } if (!strcmp(argv[1], "transition")) { vehicle_command_s cmd = {}; cmd.target_system = status.system_id; cmd.target_component = status.component_id; cmd.command = vehicle_command_s::VEHICLE_CMD_DO_VTOL_TRANSITION; /* transition to the other mode */ cmd.param1 = (status.is_rotary_wing) ? vtol_vehicle_status_s::VEHICLE_VTOL_STATE_FW : vtol_vehicle_status_s::VEHICLE_VTOL_STATE_MC; /* param 2-3 unused */ cmd.param2 = NAN; cmd.param3 = NAN; cmd.param4 = NAN; cmd.param5 = NAN; cmd.param6 = NAN; cmd.param7 = NAN; orb_advert_t h = orb_advertise(ORB_ID(vehicle_command), &cmd); (void)orb_unadvertise(h); return 0; } if (!strcmp(argv[1], "mode")) { if (argc > 2) { uint8_t new_main_state = commander_state_s::MAIN_STATE_MAX; if (!strcmp(argv[2], "manual")) { new_main_state = commander_state_s::MAIN_STATE_MANUAL; } else if (!strcmp(argv[2], "altctl")) { new_main_state = commander_state_s::MAIN_STATE_ALTCTL; } else if (!strcmp(argv[2], "posctl")) { new_main_state = commander_state_s::MAIN_STATE_POSCTL; } else if (!strcmp(argv[2], "auto:mission")) { new_main_state = commander_state_s::MAIN_STATE_AUTO_MISSION; } else if (!strcmp(argv[2], "auto:loiter")) { new_main_state = commander_state_s::MAIN_STATE_AUTO_LOITER; } else if (!strcmp(argv[2], "auto:rtl")) { new_main_state = commander_state_s::MAIN_STATE_AUTO_RTL; } else if (!strcmp(argv[2], "acro")) { new_main_state = commander_state_s::MAIN_STATE_ACRO; } else if (!strcmp(argv[2], "offboard")) { new_main_state = commander_state_s::MAIN_STATE_OFFBOARD; } else if (!strcmp(argv[2], "stabilized")) { new_main_state = commander_state_s::MAIN_STATE_STAB; } else if (!strcmp(argv[2], "rattitude")) { new_main_state = commander_state_s::MAIN_STATE_RATTITUDE; } else if (!strcmp(argv[2], "auto:takeoff")) { new_main_state = commander_state_s::MAIN_STATE_AUTO_TAKEOFF; } else if (!strcmp(argv[2], "auto:land")) { new_main_state = commander_state_s::MAIN_STATE_AUTO_LAND; } else { warnx("argument %s unsupported.", argv[2]); } if (TRANSITION_DENIED == main_state_transition(&status, new_main_state, main_state_prev, &status_flags, &internal_state)) { warnx("mode change failed"); } return 0; } else { warnx("missing argument"); } } if (!strcmp(argv[1], "lockdown")) { if (argc < 3) { usage("not enough arguments, missing [on, off]"); return 1; } vehicle_command_s cmd = {}; cmd.target_system = status.system_id; cmd.target_component = status.component_id; cmd.command = vehicle_command_s::VEHICLE_CMD_DO_FLIGHTTERMINATION; /* if the comparison matches for off (== 0) set 0.0f, 2.0f (on) else */ cmd.param1 = strcmp(argv[2], "off") ? 2.0f : 0.0f; /* lockdown */ // XXX inspect use of publication handle (void)orb_advertise(ORB_ID(vehicle_command), &cmd); return 0; } usage("unrecognized command"); return 1; }
4. QGC调试的用法
(1) 参数修改的地方
这些参数对应着程序parameter_update
(2) 查看飞控实时的各种数据(都是通过mavlink传输过来的)
点击你要看的数据前面的方框