Copter: support logging while disarmed

This commit is contained in:
Andrew Tridgell 2014-10-17 11:37:49 +11:00 committed by Randy Mackay
parent 874efe95a1
commit c3d839456b
10 changed files with 66 additions and 30 deletions

View File

@ -206,6 +206,9 @@ static AP_Notify notify;
// used to detect MAVLink acks from GCS to stop compassmot // used to detect MAVLink acks from GCS to stop compassmot
static uint8_t command_ack_counter; static uint8_t command_ack_counter;
// has a log download started?
static bool in_log_download;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// prototypes // prototypes
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -951,7 +954,7 @@ static void barometer_accumulate(void)
static void perf_update(void) static void perf_update(void)
{ {
if (g.log_bitmask & MASK_LOG_PM) if (should_log(MASK_LOG_PM))
Log_Write_Performance(); Log_Write_Performance();
if (scheduler.debug()) { if (scheduler.debug()) {
cliSerial->printf_P(PSTR("PERF: %u/%u %lu\n"), cliSerial->printf_P(PSTR("PERF: %u/%u %lu\n"),
@ -1089,7 +1092,7 @@ static void update_batt_compass(void)
compass.set_throttle((float)g.rc_3.servo_out/1000.0f); compass.set_throttle((float)g.rc_3.servo_out/1000.0f);
compass.read(); compass.read();
// log compass information // log compass information
if (g.log_bitmask & MASK_LOG_COMPASS) { if (should_log(MASK_LOG_COMPASS)) {
Log_Write_Compass(); Log_Write_Compass();
} }
} }
@ -1102,16 +1105,16 @@ static void update_batt_compass(void)
// should be run at 10hz // should be run at 10hz
static void ten_hz_logging_loop() static void ten_hz_logging_loop()
{ {
if (g.log_bitmask & MASK_LOG_ATTITUDE_MED) { if (should_log(MASK_LOG_ATTITUDE_MED)) {
Log_Write_Attitude(); Log_Write_Attitude();
} }
if (g.log_bitmask & MASK_LOG_RCIN) { if (should_log(MASK_LOG_RCIN)) {
DataFlash.Log_Write_RCIN(); DataFlash.Log_Write_RCIN();
} }
if (g.log_bitmask & MASK_LOG_RCOUT) { if (should_log(MASK_LOG_RCOUT)) {
DataFlash.Log_Write_RCOUT(); DataFlash.Log_Write_RCOUT();
} }
if ((g.log_bitmask & MASK_LOG_NTUN) && (mode_requires_GPS(control_mode) || landing_with_GPS())) { if (should_log(MASK_LOG_NTUN) && (mode_requires_GPS(control_mode) || landing_with_GPS())) {
Log_Write_Nav_Tuning(); Log_Write_Nav_Tuning();
} }
} }
@ -1126,11 +1129,11 @@ static void fifty_hz_logging_loop()
#endif #endif
#if HIL_MODE == HIL_MODE_DISABLED #if HIL_MODE == HIL_MODE_DISABLED
if (g.log_bitmask & MASK_LOG_ATTITUDE_FAST) { if (should_log(MASK_LOG_ATTITUDE_FAST)) {
Log_Write_Attitude(); Log_Write_Attitude();
} }
if (g.log_bitmask & MASK_LOG_IMU) { if (should_log(MASK_LOG_IMU)) {
DataFlash.Log_Write_IMU(ins); DataFlash.Log_Write_IMU(ins);
} }
#endif #endif
@ -1160,7 +1163,7 @@ static void three_hz_loop()
// one_hz_loop - runs at 1Hz // one_hz_loop - runs at 1Hz
static void one_hz_loop() static void one_hz_loop()
{ {
if (g.log_bitmask != 0) { if (should_log(MASK_LOG_ANY)) {
Log_Write_Data(DATA_AP_STATE, ap.value); Log_Write_Data(DATA_AP_STATE, ap.value);
} }
@ -1219,7 +1222,7 @@ static void update_GPS(void)
last_gps_reading[i] = gps.last_message_time_ms(i); last_gps_reading[i] = gps.last_message_time_ms(i);
// log GPS message // log GPS message
if (g.log_bitmask & MASK_LOG_GPS) { if (should_log(MASK_LOG_GPS)) {
DataFlash.Log_Write_GPS(gps, i, current_loc.alt); DataFlash.Log_Write_GPS(gps, i, current_loc.alt);
} }
@ -1305,7 +1308,7 @@ init_simple_bearing()
super_simple_sin_yaw = simple_sin_yaw; super_simple_sin_yaw = simple_sin_yaw;
// log the simple bearing to dataflash // log the simple bearing to dataflash
if (g.log_bitmask != 0) { if (should_log(MASK_LOG_ANY)) {
Log_Write_Data(DATA_INIT_SIMPLE_BEARING, ahrs.yaw_sensor); Log_Write_Data(DATA_INIT_SIMPLE_BEARING, ahrs.yaw_sensor);
} }
} }
@ -1376,7 +1379,7 @@ static void update_altitude()
sonar_alt = read_sonar(); sonar_alt = read_sonar();
// write altitude info to dataflash logs // write altitude info to dataflash logs
if (g.log_bitmask & MASK_LOG_CTUN) { if (should_log(MASK_LOG_CTUN)) {
Log_Write_Control_Tuning(); Log_Write_Control_Tuning();
} }
} }

View File

@ -1376,11 +1376,21 @@ void GCS_MAVLINK::handleMessage(mavlink_message_t* msg)
case MAVLINK_MSG_ID_RADIO: case MAVLINK_MSG_ID_RADIO:
case MAVLINK_MSG_ID_RADIO_STATUS: // MAV ID: 109 case MAVLINK_MSG_ID_RADIO_STATUS: // MAV ID: 109
{ {
handle_radio_status(msg, DataFlash, (g.log_bitmask & MASK_LOG_PM) != 0); handle_radio_status(msg, DataFlash, should_log(MASK_LOG_PM));
break; break;
} }
case MAVLINK_MSG_ID_LOG_REQUEST_LIST ... MAVLINK_MSG_ID_LOG_REQUEST_END: // MAV ID: 117 ... 122 case MAVLINK_MSG_ID_LOG_REQUEST_DATA:
case MAVLINK_MSG_ID_LOG_ERASE:
in_log_download = true;
// fallthru
case MAVLINK_MSG_ID_LOG_REQUEST_LIST:
if (!in_mavlink_delay && !motors.armed()) {
handle_log_message(msg, DataFlash);
}
break;
case MAVLINK_MSG_ID_LOG_REQUEST_END:
in_log_download = false;
if (!in_mavlink_delay && !motors.armed()) { if (!in_mavlink_delay && !motors.armed()) {
handle_log_message(msg, DataFlash); handle_log_message(msg, DataFlash);
} }

View File

@ -535,7 +535,7 @@ struct PACKED log_Event {
// Wrote an event packet // Wrote an event packet
static void Log_Write_Event(uint8_t id) static void Log_Write_Event(uint8_t id)
{ {
if (g.log_bitmask != 0) { if (should_log(MASK_LOG_ANY)) {
struct log_Event pkt = { struct log_Event pkt = {
LOG_PACKET_HEADER_INIT(LOG_EVENT_MSG), LOG_PACKET_HEADER_INIT(LOG_EVENT_MSG),
id : id id : id
@ -553,7 +553,7 @@ struct PACKED log_Data_Int16t {
// Write an int16_t data packet // Write an int16_t data packet
static void Log_Write_Data(uint8_t id, int16_t value) static void Log_Write_Data(uint8_t id, int16_t value)
{ {
if (g.log_bitmask != 0) { if (should_log(MASK_LOG_ANY)) {
struct log_Data_Int16t pkt = { struct log_Data_Int16t pkt = {
LOG_PACKET_HEADER_INIT(LOG_DATA_INT16_MSG), LOG_PACKET_HEADER_INIT(LOG_DATA_INT16_MSG),
id : id, id : id,
@ -572,7 +572,7 @@ struct PACKED log_Data_UInt16t {
// Write an uint16_t data packet // Write an uint16_t data packet
static void Log_Write_Data(uint8_t id, uint16_t value) static void Log_Write_Data(uint8_t id, uint16_t value)
{ {
if (g.log_bitmask != 0) { if (should_log(MASK_LOG_ANY)) {
struct log_Data_UInt16t pkt = { struct log_Data_UInt16t pkt = {
LOG_PACKET_HEADER_INIT(LOG_DATA_UINT16_MSG), LOG_PACKET_HEADER_INIT(LOG_DATA_UINT16_MSG),
id : id, id : id,
@ -591,7 +591,7 @@ struct PACKED log_Data_Int32t {
// Write an int32_t data packet // Write an int32_t data packet
static void Log_Write_Data(uint8_t id, int32_t value) static void Log_Write_Data(uint8_t id, int32_t value)
{ {
if (g.log_bitmask != 0) { if (should_log(MASK_LOG_ANY)) {
struct log_Data_Int32t pkt = { struct log_Data_Int32t pkt = {
LOG_PACKET_HEADER_INIT(LOG_DATA_INT32_MSG), LOG_PACKET_HEADER_INIT(LOG_DATA_INT32_MSG),
id : id, id : id,
@ -610,7 +610,7 @@ struct PACKED log_Data_UInt32t {
// Write a uint32_t data packet // Write a uint32_t data packet
static void Log_Write_Data(uint8_t id, uint32_t value) static void Log_Write_Data(uint8_t id, uint32_t value)
{ {
if (g.log_bitmask != 0) { if (should_log(MASK_LOG_ANY)) {
struct log_Data_UInt32t pkt = { struct log_Data_UInt32t pkt = {
LOG_PACKET_HEADER_INIT(LOG_DATA_UINT32_MSG), LOG_PACKET_HEADER_INIT(LOG_DATA_UINT32_MSG),
id : id, id : id,
@ -629,7 +629,7 @@ struct PACKED log_Data_Float {
// Write a float data packet // Write a float data packet
static void Log_Write_Data(uint8_t id, float value) static void Log_Write_Data(uint8_t id, float value)
{ {
if (g.log_bitmask != 0) { if (should_log(MASK_LOG_ANY)) {
struct log_Data_Float pkt = { struct log_Data_Float pkt = {
LOG_PACKET_HEADER_INIT(LOG_DATA_FLOAT_MSG), LOG_PACKET_HEADER_INIT(LOG_DATA_FLOAT_MSG),
id : id, id : id,

View File

@ -81,7 +81,7 @@ public:
// Misc // Misc
// //
k_param_log_bitmask = 20, k_param_log_bitmask_old = 20, // Deprecated
k_param_log_last_filenumber, // *** Deprecated - remove k_param_log_last_filenumber, // *** Deprecated - remove
// with next eeprom number // with next eeprom number
// change // change
@ -123,6 +123,7 @@ public:
k_param_throttle_deadzone, k_param_throttle_deadzone,
k_param_optflow, k_param_optflow,
k_param_dcmcheck_thresh, // 59 k_param_dcmcheck_thresh, // 59
k_param_log_bitmask,
// 65: AP_Limits Library // 65: AP_Limits Library
k_param_limits = 65, // deprecated - remove k_param_limits = 65, // deprecated - remove
@ -381,7 +382,7 @@ public:
// Misc // Misc
// //
AP_Int16 log_bitmask; AP_Int32 log_bitmask;
AP_Int8 esc_calibrate; AP_Int8 esc_calibrate;
AP_Int8 radio_tuning; AP_Int8 radio_tuning;
AP_Int16 radio_tuning_high; AP_Int16 radio_tuning_high;

View File

@ -348,8 +348,8 @@ const AP_Param::Info var_info[] PROGMEM = {
// @Param: LOG_BITMASK // @Param: LOG_BITMASK
// @DisplayName: Log bitmask // @DisplayName: Log bitmask
// @Description: 2 byte bitmap of log types to enable // @Description: 4 byte bitmap of log types to enable
// @Values: 830:Default,894:Default+RCIN,958:Default+IMU,1854:Default+Motors,-6146:NearlyAll,-22530:All,0:Disabled // @Values: 830:Default,894:Default+RCIN,958:Default+IMU,1854:Default+Motors,59390:NearlyAll,131071:All+DisarmedLogging,0:Disabled
// @User: Standard // @User: Standard
GSCALAR(log_bitmask, "LOG_BITMASK", DEFAULT_LOG_BITMASK), GSCALAR(log_bitmask, "LOG_BITMASK", DEFAULT_LOG_BITMASK),
@ -1144,6 +1144,7 @@ const AP_Param::ConversionInfo conversion_table[] PROGMEM = {
{ Parameters::k_param_volt_div_ratio, 0, AP_PARAM_FLOAT, "BATT_VOLT_MULT" }, { Parameters::k_param_volt_div_ratio, 0, AP_PARAM_FLOAT, "BATT_VOLT_MULT" },
{ Parameters::k_param_curr_amp_per_volt, 0, AP_PARAM_FLOAT, "BATT_AMP_PERVOLT" }, { Parameters::k_param_curr_amp_per_volt, 0, AP_PARAM_FLOAT, "BATT_AMP_PERVOLT" },
{ Parameters::k_param_pack_capacity, 0, AP_PARAM_INT32, "BATT_CAPACITY" }, { Parameters::k_param_pack_capacity, 0, AP_PARAM_INT32, "BATT_CAPACITY" },
{ Parameters::k_param_log_bitmask_old, 0, AP_PARAM_INT16, "LOG_BITMASK" },
}; };
static void load_parameters(void) static void load_parameters(void)

View File

@ -14,7 +14,7 @@ static void init_home()
inertial_nav.setup_home_position(); inertial_nav.setup_home_position();
// log new home position which mission library will pull from ahrs // log new home position which mission library will pull from ahrs
if (g.log_bitmask & MASK_LOG_CMD) { if (should_log(MASK_LOG_CMD)) {
AP_Mission::Mission_Command temp_cmd; AP_Mission::Mission_Command temp_cmd;
if (mission.read_cmd_from_storage(0, temp_cmd)) { if (mission.read_cmd_from_storage(0, temp_cmd)) {
Log_Write_Cmd(temp_cmd); Log_Write_Cmd(temp_cmd);

View File

@ -37,7 +37,7 @@ static void auto_spline_start(const Vector3f& destination, bool stopped_at_start
static bool start_command(const AP_Mission::Mission_Command& cmd) static bool start_command(const AP_Mission::Mission_Command& cmd)
{ {
// To-Do: logging when new commands start/end // To-Do: logging when new commands start/end
if (g.log_bitmask & MASK_LOG_CMD) { if (should_log(MASK_LOG_CMD)) {
Log_Write_Cmd(cmd); Log_Write_Cmd(cmd);
} }
@ -925,7 +925,7 @@ static void do_take_picture()
{ {
#if CAMERA == ENABLED #if CAMERA == ENABLED
camera.trigger_pic(); camera.trigger_pic();
if (g.log_bitmask & MASK_LOG_CAMERA) { if (should_log(MASK_LOG_CAMERA)) {
DataFlash.Log_Write_Camera(ahrs, gps, current_loc); DataFlash.Log_Write_Camera(ahrs, gps, current_loc);
} }
#endif #endif

View File

@ -255,6 +255,8 @@ enum FlipState {
#define MASK_LOG_COMPASS (1<<13) #define MASK_LOG_COMPASS (1<<13)
#define MASK_LOG_INAV (1<<14) // deprecated #define MASK_LOG_INAV (1<<14) // deprecated
#define MASK_LOG_CAMERA (1<<15) #define MASK_LOG_CAMERA (1<<15)
#define MASK_LOG_WHEN_DISARMED (1UL<<16)
#define MASK_LOG_ANY 0xFFFF
// DATA - event logging // DATA - event logging
#define DATA_MAVLINK_FLOAT 1 #define DATA_MAVLINK_FLOAT 1

View File

@ -22,7 +22,7 @@ static void init_barometer(bool full_calibration)
static int32_t read_barometer(void) static int32_t read_barometer(void)
{ {
barometer.read(); barometer.read();
if (g.log_bitmask & MASK_LOG_IMU) { if (should_log(MASK_LOG_IMU)) {
Log_Write_Baro(); Log_Write_Baro();
} }
int32_t balt = barometer.get_altitude() * 100.0f; int32_t balt = barometer.get_altitude() * 100.0f;
@ -124,7 +124,7 @@ static void update_optflow(void)
// write to log if new data has arrived // write to log if new data has arrived
if (optflow.last_update() != last_of_update) { if (optflow.last_update() != last_of_update) {
last_of_update = optflow.last_update(); last_of_update = optflow.last_update();
if (g.log_bitmask & MASK_LOG_OPTFLOW) { if (should_log(MASK_LOG_OPTFLOW)) {
Log_Write_Optflow(); Log_Write_Optflow();
} }
} }
@ -149,7 +149,7 @@ static void read_battery(void)
} }
// log battery info to the dataflash // log battery info to the dataflash
if (g.log_bitmask & MASK_LOG_CURRENT) { if (should_log(MASK_LOG_CURRENT)) {
Log_Write_Current(); Log_Write_Current();
} }
} }

View File

@ -403,3 +403,22 @@ static void telemetry_send(void)
(AP_Frsky_Telem::FrSkyProtocol)g.serial2_protocol.get()); (AP_Frsky_Telem::FrSkyProtocol)g.serial2_protocol.get());
#endif #endif
} }
/*
should we log a message type now?
*/
static bool should_log(uint32_t mask)
{
if (!(mask & g.log_bitmask) || in_mavlink_delay) {
return false;
}
bool ret = motors.armed() || (g.log_bitmask & MASK_LOG_WHEN_DISARMED) != 0;
if (ret && !DataFlash.logging_started() && !in_log_download) {
// we have to set in_mavlink_delay to prevent logging while
// writing headers
in_mavlink_delay = true;
start_logging();
in_mavlink_delay = false;
}
return ret;
}