Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mission item logging #28246

Merged
merged 8 commits into from
Oct 1, 2024
7 changes: 0 additions & 7 deletions ArduCopter/mode_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,6 @@ bool ModeAuto::set_speed_down(float speed_down_cms)
// start_command - this function will be called when the ap_mission lib wishes to start a new command
bool ModeAuto::start_command(const AP_Mission::Mission_Command& cmd)
{
#if HAL_LOGGING_ENABLED
// To-Do: logging when new commands start/end
if (copter.should_log(MASK_LOG_CMD)) {
copter.logger.Write_Mission_Cmd(mission, cmd);
}
#endif

switch(cmd.id) {

///
Expand Down
3 changes: 3 additions & 0 deletions ArduCopter/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ void Copter::init_ardupilot()
#if MODE_AUTO_ENABLED
// initialise mission library
mode_auto.mission.init();
#if HAL_LOGGING_ENABLED
mode_auto.mission.set_log_start_mission_item_bit(MASK_LOG_CMD);
#endif
#endif

#if MODE_SMARTRTL_ENABLED
Expand Down
7 changes: 0 additions & 7 deletions ArduPlane/commands_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ bool Plane::start_command(const AP_Mission::Mission_Command& cmd)
plane.target_altitude.terrain_following_pending = false;
#endif

#if HAL_LOGGING_ENABLED
// log when new commands start
if (should_log(MASK_LOG_CMD)) {
logger.Write_Mission_Cmd(mission, cmd);
}
#endif

// special handling for nav vs non-nav commands
if (AP_Mission::is_nav_cmd(cmd)) {
// set takeoff_complete to true so we don't add extra elevator
Expand Down
3 changes: 3 additions & 0 deletions ArduPlane/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ void Plane::init_ardupilot()

// initialise mission library
mission.init();
#if HAL_LOGGING_ENABLED
mission.set_log_start_mission_item_bit(MASK_LOG_CMD);
#endif

// initialise AP_Logger library
#if HAL_LOGGING_ENABLED
Expand Down
7 changes: 0 additions & 7 deletions ArduSub/commands_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ static enum AutoSurfaceState auto_surface_state = AUTO_SURFACE_STATE_GO_TO_LOCAT
// start_command - this function will be called when the ap_mission lib wishes to start a new command
bool Sub::start_command(const AP_Mission::Mission_Command& cmd)
{
#if HAL_LOGGING_ENABLED
// To-Do: logging when new commands start/end
if (should_log(MASK_LOG_CMD)) {
logger.Write_Mission_Cmd(mission, cmd);
}
#endif

const Location &target_loc = cmd.content.location;
auto alt_frame = target_loc.get_alt_frame();

Expand Down
3 changes: 3 additions & 0 deletions ArduSub/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ void Sub::init_ardupilot()

// initialise mission library
mission.init();
#if HAL_LOGGING_ENABLED
mission.set_log_start_mission_item_bit(MASK_LOG_CMD);
#endif

// initialise AP_Logger library
#if HAL_LOGGING_ENABLED
Expand Down
7 changes: 0 additions & 7 deletions Rover/mode_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,6 @@ void ModeAuto::send_guided_position_target()
/********************************************************************************/
bool ModeAuto::start_command(const AP_Mission::Mission_Command& cmd)
{
#if HAL_LOGGING_ENABLED
// log when new commands start
if (rover.should_log(MASK_LOG_CMD)) {
rover.logger.Write_Mission_Cmd(mission, cmd);
}
#endif

switch (cmd.id) {
case MAV_CMD_NAV_WAYPOINT: // Navigate to Waypoint
return do_nav_wp(cmd, false);
Expand Down
3 changes: 3 additions & 0 deletions Rover/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ void Rover::init_ardupilot()
#if AP_MISSION_ENABLED
// initialise mission library
mode_auto.mission.init();
#if HAL_LOGGING_ENABLED
mode_auto.mission.set_log_start_mission_item_bit(MASK_LOG_CMD);
#endif
#endif

// initialise AP_Logger library
Expand Down
5 changes: 3 additions & 2 deletions libraries/AP_Logger/AP_Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,10 @@ void AP_Logger::Write_Parameter(const char *name, float value)
}

void AP_Logger::Write_Mission_Cmd(const AP_Mission &mission,
const AP_Mission::Mission_Command &cmd)
const AP_Mission::Mission_Command &cmd,
LogMessages id)
{
FOR_EACH_BACKEND(Write_Mission_Cmd(mission, cmd));
FOR_EACH_BACKEND(Write_Mission_Cmd(mission, cmd, id));
}

#if HAL_RALLY_ENABLED
Expand Down
9 changes: 8 additions & 1 deletion libraries/AP_Logger/AP_Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,15 @@ class AP_Logger
uint8_t source_component,
MAV_RESULT result,
bool was_command_long=false);
void Write_MISE(const AP_Mission &mission, const AP_Mission::Mission_Command &cmd) {
Write_Mission_Cmd(mission, cmd, LOG_MISE_MSG);
}
void Write_CMD(const AP_Mission &mission, const AP_Mission::Mission_Command &cmd) {
Write_Mission_Cmd(mission, cmd, LOG_CMD_MSG);
}
void Write_Mission_Cmd(const AP_Mission &mission,
const AP_Mission::Mission_Command &cmd);
const AP_Mission::Mission_Command &cmd,
LogMessages id);
void Write_RallyPoint(uint8_t total,
uint8_t sequence,
const class RallyLocation &rally_point);
Expand Down
3 changes: 2 additions & 1 deletion libraries/AP_Logger/AP_Logger_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class AP_Logger_Backend
bool Write_Message(const char *message);
bool Write_MessageF(const char *fmt, ...);
bool Write_Mission_Cmd(const AP_Mission &mission,
const AP_Mission::Mission_Command &cmd);
const AP_Mission::Mission_Command &cmd,
LogMessages id);
bool Write_Mode(uint8_t mode, const ModeReason reason);
bool Write_Parameter(const char *name, float value, float default_val);
bool Write_Parameter(const AP_Param *ap,
Expand Down
7 changes: 4 additions & 3 deletions libraries/AP_Logger/LogFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,13 @@ void AP_Logger::Write_Command(const mavlink_command_int_t &packet,
}

bool AP_Logger_Backend::Write_Mission_Cmd(const AP_Mission &mission,
const AP_Mission::Mission_Command &cmd)
const AP_Mission::Mission_Command &cmd,
LogMessages msgid)
{
mavlink_mission_item_int_t mav_cmd = {};
AP_Mission::mission_cmd_to_mavlink_int(cmd,mav_cmd);
const struct log_Cmd pkt{
LOG_PACKET_HEADER_INIT(LOG_CMD_MSG),
const struct log_CMD pkt{
LOG_PACKET_HEADER_INIT(msgid),
time_us : AP_HAL::micros64(),
command_total : mission.num_commands(),
sequence : mav_cmd.seq,
Expand Down
37 changes: 3 additions & 34 deletions libraries/AP_Logger/LogStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const struct MultiplierStructure log_Multipliers[] = {
#include <AP_Landing/LogStructure.h>
#include <AC_AttitudeControl/LogStructure.h>
#include <AP_HAL/LogStructure.h>
#include <AP_Mission/LogStructure.h>

// structure used to define logging format
// It is packed on ChibiOS to save flash space; however, this causes problems
Expand Down Expand Up @@ -350,22 +351,6 @@ struct PACKED log_MCU {
float MCU_voltage_max;
};

struct PACKED log_Cmd {
LOG_PACKET_HEADER;
uint64_t time_us;
uint16_t command_total;
uint16_t sequence;
uint16_t command;
float param1;
float param2;
float param3;
float param4;
int32_t latitude;
int32_t longitude;
float altitude;
uint8_t frame;
};

struct PACKED log_MAVLink_Command {
LOG_PACKET_HEADER;
uint64_t time_us;
Expand Down Expand Up @@ -712,21 +697,6 @@ struct PACKED log_VER {
// @Field: TR: innovation test ratio
// @Field: Pri: True if sensor is the primary sensor

// @LoggerMessage: CMD
// @Description: Executed mission command information
// @Field: TimeUS: Time since system startup
// @Field: CTot: Total number of mission commands
// @Field: CNum: This command's offset in mission
// @Field: CId: Command type
// @Field: Prm1: Parameter 1
// @Field: Prm2: Parameter 2
// @Field: Prm3: Parameter 3
// @Field: Prm4: Parameter 4
// @Field: Lat: Command latitude
// @Field: Lng: Command longitude
// @Field: Alt: Command altitude
// @Field: Frame: Frame used for position

// @LoggerMessage: CSRV
// @Description: Servo feedback data
// @Field: TimeUS: Time since system startup
Expand Down Expand Up @@ -1218,8 +1188,7 @@ LOG_STRUCTURE_FROM_PRECLAND \
"POWR","QffHHB","TimeUS,Vcc,VServo,Flags,AccFlags,Safety", "svv---", "F00---", true }, \
{ LOG_MCU_MSG, sizeof(log_MCU), \
"MCU","Qffff","TimeUS,MTemp,MVolt,MVmin,MVmax", "sOvvv", "F0000", true }, \
{ LOG_CMD_MSG, sizeof(log_Cmd), \
"CMD", "QHHHffffLLfB","TimeUS,CTot,CNum,CId,Prm1,Prm2,Prm3,Prm4,Lat,Lng,Alt,Frame", "s-------DUm-", "F-------GG0-" }, \
LOG_STRUCTURE_FROM_MISSION \
{ LOG_MAVLINK_COMMAND_MSG, sizeof(log_MAVLink_Command), \
"MAVC", "QBBBBBHffffiifBB","TimeUS,TS,TC,SS,SC,Fr,Cmd,P1,P2,P3,P4,X,Y,Z,Res,WL", "s---------------", "F---------------" }, \
{ LOG_RADIO_MSG, sizeof(log_Radio), \
Expand Down Expand Up @@ -1326,7 +1295,6 @@ enum LogMessages : uint8_t {
LOG_MCU_MSG,
LOG_IDS_FROM_AHRS,
LOG_SIMSTATE_MSG,
LOG_CMD_MSG,
LOG_MAVLINK_COMMAND_MSG,
LOG_RADIO_MSG,
LOG_ATRP_MSG,
Expand All @@ -1337,6 +1305,7 @@ enum LogMessages : uint8_t {
LOG_IDS_FROM_ESC_TELEM,
LOG_IDS_FROM_BATTMONITOR,
LOG_IDS_FROM_HAL_CHIBIOS,
LOG_IDS_FROM_MISSION,

LOG_IDS_FROM_GPS,

Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Logger/LoggerMessageWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void LoggerMessageWriter_WriteEntireMission::process() {
// upon failure to write the mission we will re-read from
// storage; this could be improved.
if (_mission->read_cmd_from_storage(_mission_number_to_send,cmd)) {
if (!_logger_backend->Write_Mission_Cmd(*_mission, cmd)) {
if (!_logger_backend->Write_Mission_Cmd(*_mission, cmd, LOG_CMD_MSG)) {
return; // call me again
}
}
Expand Down
10 changes: 10 additions & 0 deletions libraries/AP_Mission/AP_Mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <GCS_MAVLink/GCS.h>
#include <RC_Channel/RC_Channel_config.h>
#include <AC_Fence/AC_Fence.h>
#include <AP_Logger/AP_Logger.h>

const AP_Param::GroupInfo AP_Mission::var_info[] = {

Expand Down Expand Up @@ -400,6 +401,15 @@ bool AP_Mission::verify_command(const Mission_Command& cmd)

bool AP_Mission::start_command(const Mission_Command& cmd)
{
#if HAL_LOGGING_ENABLED
if (log_start_mission_item_bit != (uint32_t)-1) {
auto &logger = AP::logger();
if (logger.should_log(log_start_mission_item_bit)) {
logger.Write_MISE(*this, cmd);
}
}
#endif

// check for landing related commands and set flags
if (is_landing_type_cmd(cmd.id) || cmd.id == MAV_CMD_DO_LAND_START) {
_flags.in_landing_sequence = true;
Expand Down
9 changes: 9 additions & 0 deletions libraries/AP_Mission/AP_Mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,10 @@ class AP_Mission
}
#endif

#if HAL_LOGGING_ENABLED
void set_log_start_mission_item_bit(uint32_t bit) { log_start_mission_item_bit = bit; }
#endif

private:
static AP_Mission *_singleton;

Expand Down Expand Up @@ -949,6 +953,11 @@ class AP_Mission
format to take advantage of new packing
*/
void format_conversion(uint8_t tag_byte, const Mission_Command &cmd, PackedContent &packed_content) const;

#if HAL_LOGGING_ENABLED
// if not -1, this bit in LOG_BITMASK specifies whether to log a message each time we start a command:
uint32_t log_start_mission_item_bit = -1;
#endif
};

namespace AP
Expand Down
59 changes: 59 additions & 0 deletions libraries/AP_Mission/LogStructure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

#include <AP_Logger/LogStructure.h>

#define LOG_IDS_FROM_MISSION \
LOG_MISE_MSG, \
LOG_CMD_MSG

// @LoggerMessage: CMD
// @Description: Uploaded mission command information
// @Field: TimeUS: Time since system startup
// @Field: CTot: Total number of mission commands
// @Field: CNum: This command's offset in mission
// @Field: CId: Command type
// @Field: Prm1: Parameter 1
// @Field: Prm2: Parameter 2
// @Field: Prm3: Parameter 3
// @Field: Prm4: Parameter 4
// @Field: Lat: Command latitude
// @Field: Lng: Command longitude
// @Field: Alt: Command altitude
// @Field: Frame: Frame used for position
struct PACKED log_CMD {
LOG_PACKET_HEADER;
uint64_t time_us;
uint16_t command_total;
uint16_t sequence;
uint16_t command;
float param1;
float param2;
float param3;
float param4;
int32_t latitude;
int32_t longitude;
float altitude;
uint8_t frame;
};

// @LoggerMessage: MISE
// @Description: Executed mission command information; emitted when we start to run an item
// @Field: TimeUS: Time since system startup
// @Field: CTot: Total number of mission commands
// @Field: CNum: This command's offset in mission
// @Field: CId: Command type
// @Field: Prm1: Parameter 1
// @Field: Prm2: Parameter 2
// @Field: Prm3: Parameter 3
// @Field: Prm4: Parameter 4
// @Field: Lat: Command latitude
// @Field: Lng: Command longitude
// @Field: Alt: Command altitude
// @Field: Frame: Frame used for position

// note we currently reuse the same structure for CMD and MISE.
#define LOG_STRUCTURE_FROM_MISSION \
{ LOG_CMD_MSG, sizeof(log_CMD), \
"CMD", "QHHHffffLLfB","TimeUS,CTot,CNum,CId,Prm1,Prm2,Prm3,Prm4,Lat,Lng,Alt,Frame", "s-------DUm-", "F-------GG0-" }, \
{ LOG_MISE_MSG, sizeof(log_CMD), \
"MISE", "QHHHffffLLfB","TimeUS,CTot,CNum,CId,Prm1,Prm2,Prm3,Prm4,Lat,Lng,Alt,Frame", "s-------DUm-", "F-------GG0-" },
Loading