mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-30 00:50:34 +08:00
Merged master into linux
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <systemlib/err.h>
|
||||
#include <systemlib/param/param.h>
|
||||
@@ -62,6 +63,7 @@
|
||||
#include <drivers/drv_airspeed.h>
|
||||
|
||||
#include <uORB/topics/airspeed.h>
|
||||
#include <uORB/topics/vehicle_gps_position.h>
|
||||
|
||||
#include <mavlink/mavlink_log.h>
|
||||
|
||||
@@ -270,8 +272,38 @@ out:
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool gnssCheck(int mavlink_fd)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
int gpsSub = orb_subscribe(ORB_ID(vehicle_gps_position));
|
||||
|
||||
//Wait up to 2000ms to allow the driver to detect a GNSS receiver module
|
||||
struct pollfd fds[1];
|
||||
fds[0].fd = gpsSub;
|
||||
fds[0].events = POLLIN;
|
||||
if(poll(fds, 1, 2000) <= 0) {
|
||||
success = false;
|
||||
}
|
||||
else {
|
||||
struct vehicle_gps_position_s gps;
|
||||
if ( (OK != orb_copy(ORB_ID(vehicle_gps_position), gpsSub, &gps)) ||
|
||||
(hrt_elapsed_time(&gps.timestamp_position) > 1000000)) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Report failure to detect module
|
||||
if(!success) {
|
||||
mavlink_and_console_log_critical(mavlink_fd, "PREFLIGHT FAIL: GPS RECEIVER MISSING");
|
||||
}
|
||||
|
||||
close(gpsSub);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool preflightCheck(int mavlink_fd, bool checkMag, bool checkAcc, bool checkGyro,
|
||||
bool checkBaro, bool checkAirspeed, bool checkRC, bool checkDynamic)
|
||||
bool checkBaro, bool checkAirspeed, bool checkRC, bool checkGNSS, bool checkDynamic)
|
||||
{
|
||||
bool failed = false;
|
||||
|
||||
@@ -337,6 +369,13 @@ bool preflightCheck(int mavlink_fd, bool checkMag, bool checkAcc, bool checkGyro
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- Global Navigation Satellite System receiver ---- */
|
||||
if(checkGNSS) {
|
||||
if(!gnssCheck(mavlink_fd)) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Report status */
|
||||
return !failed;
|
||||
}
|
||||
|
||||
@@ -59,11 +59,15 @@ namespace Commander
|
||||
* true if the gyroscopes should be checked
|
||||
* @param checkBaro
|
||||
* true if the barometer should be checked
|
||||
* @param checkAirspeed
|
||||
* true if the airspeed sensor should be checked
|
||||
* @param checkRC
|
||||
* true if the Remote Controller should be checked
|
||||
* @param checkGNSS
|
||||
* true if the GNSS receiver should be checked
|
||||
**/
|
||||
bool preflightCheck(int mavlink_fd, bool checkMag, bool checkAcc,
|
||||
bool checkGyro, bool checkBaro, bool checkAirspeed, bool checkRC, bool checkDynamic = false);
|
||||
bool checkGyro, bool checkBaro, bool checkAirspeed, bool checkRC, bool checkGNSS, bool checkDynamic = false);
|
||||
|
||||
const unsigned max_mandatory_gyro_count = 1;
|
||||
const unsigned max_optional_gyro_count = 3;
|
||||
|
||||
@@ -135,6 +135,7 @@
|
||||
#include <fcntl.h>
|
||||
//#include <sys/prctl.h>
|
||||
#include <math.h>
|
||||
#include <poll.h>
|
||||
#include <float.h>
|
||||
#include <mathlib/mathlib.h>
|
||||
#include <string.h>
|
||||
@@ -145,6 +146,7 @@
|
||||
#include <systemlib/param/param.h>
|
||||
#include <systemlib/err.h>
|
||||
#include <mavlink/mavlink_log.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
|
||||
/* oddly, ERROR is not defined for c++ */
|
||||
#ifdef ERROR
|
||||
@@ -554,3 +556,74 @@ calibrate_return calculate_calibration_values(unsigned sensor, float (&accel_ref
|
||||
|
||||
return calibrate_return_ok;
|
||||
}
|
||||
|
||||
int do_level_calibration(int mavlink_fd) {
|
||||
const unsigned cal_time = 5;
|
||||
const unsigned cal_hz = 250;
|
||||
const unsigned settle_time = 30;
|
||||
int att_sub = orb_subscribe(ORB_ID(vehicle_attitude));
|
||||
struct vehicle_attitude_s att;
|
||||
memset(&att, 0, sizeof(att));
|
||||
|
||||
mavlink_and_console_log_info(mavlink_fd, CAL_QGC_STARTED_MSG, "level");
|
||||
|
||||
param_t roll_offset_handler = param_find("SENS_BOARD_X_OFF");
|
||||
param_t pitch_offset_handler = param_find("SENS_BOARD_Y_OFF");
|
||||
|
||||
float zero = 0.0f;
|
||||
param_set(roll_offset_handler, &zero);
|
||||
param_set(pitch_offset_handler, &zero);
|
||||
|
||||
struct pollfd fds[1];
|
||||
|
||||
fds[0].fd = att_sub;
|
||||
fds[0].events = POLLIN;
|
||||
|
||||
float roll_mean = 0.0f;
|
||||
float pitch_mean = 0.0f;
|
||||
unsigned counter = 0;
|
||||
|
||||
// sleep for some time
|
||||
hrt_abstime start = hrt_absolute_time();
|
||||
while(hrt_elapsed_time(&start) < settle_time * 1000000) {
|
||||
mavlink_and_console_log_info(mavlink_fd, CAL_QGC_PROGRESS_MSG, (int)(90*hrt_elapsed_time(&start)/1e6f/(float)settle_time));
|
||||
sleep(settle_time / 10);
|
||||
}
|
||||
|
||||
start = hrt_absolute_time();
|
||||
// average attitude for 5 seconds
|
||||
while(hrt_elapsed_time(&start) < cal_time * 1000000) {
|
||||
poll(&fds[0], (sizeof(fds) / sizeof(fds[0])), 100);
|
||||
orb_copy(ORB_ID(vehicle_attitude), att_sub, &att);
|
||||
roll_mean += att.roll;
|
||||
pitch_mean += att.pitch;
|
||||
counter++;
|
||||
}
|
||||
|
||||
mavlink_and_console_log_info(mavlink_fd, CAL_QGC_PROGRESS_MSG, 100);
|
||||
|
||||
if (counter > (cal_time * cal_hz / 2 )) {
|
||||
roll_mean /= counter;
|
||||
pitch_mean /= counter;
|
||||
} else {
|
||||
mavlink_and_console_log_info(mavlink_fd, "not enough measurements taken");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fabsf(roll_mean) > 0.8f ) {
|
||||
mavlink_and_console_log_critical(mavlink_fd, "excess roll angle");
|
||||
return 1;
|
||||
} else if (fabsf(pitch_mean) > 0.8f ) {
|
||||
mavlink_and_console_log_critical(mavlink_fd, "excess pitch angle");
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
roll_mean *= (float)M_RAD_TO_DEG;
|
||||
pitch_mean *= (float)M_RAD_TO_DEG;
|
||||
param_set(roll_offset_handler, &roll_mean);
|
||||
param_set(pitch_offset_handler, &pitch_mean);
|
||||
}
|
||||
mavlink_and_console_log_info(mavlink_fd, CAL_QGC_DONE_MSG, "level");
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -45,5 +45,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
int do_accel_calibration(int mavlink_fd);
|
||||
int do_level_calibration(int mavlink_fd);
|
||||
|
||||
#endif /* ACCELEROMETER_CALIBRATION_H_ */
|
||||
|
||||
@@ -130,6 +130,8 @@ static const int ERROR = -1;
|
||||
|
||||
extern struct system_load_s system_load;
|
||||
|
||||
static constexpr uint8_t COMMANDER_MAX_GPS_NOISE = 60; /**< Maximum percentage signal to noise ratio allowed for GPS reception */
|
||||
|
||||
/* Decouple update interval and hysteris counters, all depends on intervals */
|
||||
#define COMMANDER_MONITORING_INTERVAL 50000
|
||||
#define COMMANDER_MONITORING_LOOPSPERMSEC (1/(COMMANDER_MONITORING_INTERVAL/1000.0f))
|
||||
@@ -322,6 +324,8 @@ int commander_main(int argc, char *argv[])
|
||||
calib_ret = do_accel_calibration(mavlink_fd);
|
||||
} else if (!strcmp(argv[2], "gyro")) {
|
||||
calib_ret = do_gyro_calibration(mavlink_fd);
|
||||
} else if (!strcmp(argv[2], "level")) {
|
||||
calib_ret = do_level_calibration(mavlink_fd);
|
||||
} else {
|
||||
warnx("argument %s unsupported.", argv[2]);
|
||||
}
|
||||
@@ -923,6 +927,7 @@ int commander_thread_main(int argc, char *argv[])
|
||||
status.circuit_breaker_engaged_airspd_check = false;
|
||||
status.circuit_breaker_engaged_enginefailure_check = false;
|
||||
status.circuit_breaker_engaged_gpsfailure_check = false;
|
||||
get_circuit_breaker_params();
|
||||
|
||||
/* publish initial state */
|
||||
status_pub = orb_advertise(ORB_ID(vehicle_status), &status);
|
||||
@@ -1124,8 +1129,6 @@ int commander_thread_main(int argc, char *argv[])
|
||||
param_get(_param_sys_type, &(status.system_type)); // get system type
|
||||
status.is_rotary_wing = is_rotary_wing(&status) || is_vtol(&status);
|
||||
|
||||
get_circuit_breaker_params();
|
||||
|
||||
bool checkAirspeed = false;
|
||||
/* Perform airspeed check only if circuit breaker is not
|
||||
* engaged and it's not a rotary wing */
|
||||
@@ -1134,7 +1137,7 @@ int commander_thread_main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Run preflight check
|
||||
status.condition_system_sensors_initialized = Commander::preflightCheck(mavlink_fd, true, true, true, true, checkAirspeed, true);
|
||||
status.condition_system_sensors_initialized = Commander::preflightCheck(mavlink_fd, true, true, true, true, checkAirspeed, true, !status.circuit_breaker_engaged_gpsfailure_check);
|
||||
if (!status.condition_system_sensors_initialized) {
|
||||
set_tune_override(TONE_GPS_WARNING_TUNE); //sensor fail tune
|
||||
}
|
||||
@@ -1307,7 +1310,7 @@ int commander_thread_main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* provide RC and sensor status feedback to the user */
|
||||
(void)Commander::preflightCheck(mavlink_fd, true, true, true, true, chAirspeed, true);
|
||||
(void)Commander::preflightCheck(mavlink_fd, true, true, true, true, chAirspeed, true, !status.circuit_breaker_engaged_gpsfailure_check);
|
||||
}
|
||||
|
||||
telemetry_last_heartbeat[i] = telemetry.heartbeat_time;
|
||||
@@ -1644,19 +1647,31 @@ int commander_thread_main(int argc, char *argv[])
|
||||
(float)gps_position.alt * 1.0e-3f, hrt_absolute_time());
|
||||
}
|
||||
|
||||
/* check if GPS fix is ok */
|
||||
if (status.circuit_breaker_engaged_gpsfailure_check ||
|
||||
(gps_position.fix_type >= 3 &&
|
||||
hrt_elapsed_time(&gps_position.timestamp_position) < FAILSAFE_DEFAULT_TIMEOUT)) {
|
||||
/* handle the case where gps was regained */
|
||||
if (status.gps_failure) {
|
||||
status.gps_failure = false;
|
||||
status_changed = true;
|
||||
mavlink_log_critical(mavlink_fd, "gps regained");
|
||||
/* check if GPS is ok */
|
||||
if (!status.circuit_breaker_engaged_gpsfailure_check) {
|
||||
bool gpsIsNoisy = gps_position.noise_per_ms > 0 && gps_position.noise_per_ms < COMMANDER_MAX_GPS_NOISE;
|
||||
|
||||
//Check if GPS receiver is too noisy while we are disarmed
|
||||
if (!armed.armed && gpsIsNoisy) {
|
||||
if (!status.gps_failure) {
|
||||
mavlink_log_critical(mavlink_fd, "GPS signal noisy");
|
||||
set_tune_override(TONE_GPS_WARNING_TUNE);
|
||||
|
||||
//GPS suffers from signal jamming or excessive noise, disable GPS-aided flight
|
||||
status.gps_failure = true;
|
||||
status_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!status.gps_failure) {
|
||||
if (gps_position.fix_type >= 3 && hrt_elapsed_time(&gps_position.timestamp_position) < FAILSAFE_DEFAULT_TIMEOUT) {
|
||||
/* handle the case where gps was regained */
|
||||
if (status.gps_failure && !gpsIsNoisy) {
|
||||
status.gps_failure = false;
|
||||
status_changed = true;
|
||||
mavlink_log_critical(mavlink_fd, "gps regained");
|
||||
}
|
||||
|
||||
} else if (!status.gps_failure) {
|
||||
status.gps_failure = true;
|
||||
status_changed = true;
|
||||
mavlink_log_critical(mavlink_fd, "gps fix lost");
|
||||
@@ -2716,7 +2731,10 @@ void *commander_low_prio_loop(void *arg)
|
||||
/* accelerometer calibration */
|
||||
answer_command(cmd, VEHICLE_CMD_RESULT_ACCEPTED);
|
||||
calib_ret = do_accel_calibration(mavlink_fd);
|
||||
|
||||
} else if ((int)(cmd.param5) == 2) {
|
||||
// board offset calibration
|
||||
answer_command(cmd, VEHICLE_CMD_RESULT_ACCEPTED);
|
||||
calib_ret = do_level_calibration(mavlink_fd);
|
||||
} else if ((int)(cmd.param6) == 1) {
|
||||
/* airspeed calibration */
|
||||
answer_command(cmd, VEHICLE_CMD_RESULT_ACCEPTED);
|
||||
@@ -2760,7 +2778,7 @@ void *commander_low_prio_loop(void *arg)
|
||||
checkAirspeed = true;
|
||||
}
|
||||
|
||||
status.condition_system_sensors_initialized = Commander::preflightCheck(mavlink_fd, true, true, true, true, checkAirspeed, true);
|
||||
status.condition_system_sensors_initialized = Commander::preflightCheck(mavlink_fd, true, true, true, true, checkAirspeed, true, !status.circuit_breaker_engaged_gpsfailure_check);
|
||||
|
||||
arming_state_transition(&status, &safety, vehicle_status_s::ARMING_STATE_STANDBY, &armed, true /* fRunPreArmChecks */, mavlink_fd);
|
||||
|
||||
|
||||
@@ -739,5 +739,5 @@ int prearm_check(const struct vehicle_status_s *status, const int mavlink_fd)
|
||||
checkAirspeed = true;
|
||||
}
|
||||
|
||||
return !Commander::preflightCheck(mavlink_fd, true, true, true, true, checkAirspeed, true, true);
|
||||
return !Commander::preflightCheck(mavlink_fd, true, true, true, true, checkAirspeed, true, !status->circuit_breaker_engaged_gpsfailure_check, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user