mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 01:23:33 +08:00
Initialize all outgoing vehicle_command_ack_s and vehicle_command_s
This will initialize those structs with zero in all fields not set and all fields set will only be change once to the final value not wasting CPU time zeroing it. This will guarantee that no non-unitialized structs will have a trash value on from_external causing it to be sent to the MAVLink channel without need it.
This commit is contained in:
committed by
Lorenz Meier
parent
7c268f4fa1
commit
925efe990d
@@ -476,11 +476,14 @@ MissionBlock::issue_command(const struct mission_item_s *item)
|
||||
}
|
||||
|
||||
} else {
|
||||
struct vehicle_command_s cmd = {};
|
||||
mission_item_to_vehicle_command(item, &cmd);
|
||||
const hrt_abstime now = hrt_absolute_time();
|
||||
|
||||
struct vehicle_command_s cmd = {
|
||||
.timestamp = now
|
||||
};
|
||||
|
||||
mission_item_to_vehicle_command(item, &cmd);
|
||||
_action_start = now;
|
||||
cmd.timestamp = now;
|
||||
|
||||
_navigator->publish_vehicle_cmd(cmd);
|
||||
}
|
||||
@@ -715,10 +718,17 @@ MissionBlock::set_land_item(struct mission_item_s *item, bool at_current_locatio
|
||||
!_navigator->get_vstatus()->is_rotary_wing &&
|
||||
_param_force_vtol.get() == 1) {
|
||||
|
||||
struct vehicle_command_s cmd = {};
|
||||
cmd.command = NAV_CMD_DO_VTOL_TRANSITION;
|
||||
cmd.param1 = vtol_vehicle_status_s::VEHICLE_VTOL_STATE_MC;
|
||||
cmd.timestamp = hrt_absolute_time();
|
||||
struct vehicle_command_s cmd = {
|
||||
.timestamp = hrt_absolute_time(),
|
||||
.param5 = 0.0f,
|
||||
.param6 = 0.0f,
|
||||
.param1 = vtol_vehicle_status_s::VEHICLE_VTOL_STATE_MC,
|
||||
.param2 = 0.0f,
|
||||
.param3 = 0.0f,
|
||||
.param4 = 0.0f,
|
||||
.param7 = 0.0f,
|
||||
.command = NAV_CMD_DO_VTOL_TRANSITION
|
||||
};
|
||||
|
||||
_navigator->publish_vehicle_cmd(cmd);
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ Navigator::task_main()
|
||||
orb_check(_vehicle_command_sub, &updated);
|
||||
|
||||
if (updated) {
|
||||
vehicle_command_s cmd = {};
|
||||
vehicle_command_s cmd;
|
||||
orb_copy(ORB_ID(vehicle_command), _vehicle_command_sub, &cmd);
|
||||
|
||||
if (cmd.command == vehicle_command_s::VEHICLE_CMD_DO_REPOSITION) {
|
||||
@@ -479,15 +479,24 @@ Navigator::task_main()
|
||||
int land_start = _mission.find_offboard_land_start();
|
||||
|
||||
if (land_start != -1) {
|
||||
vehicle_command_s cmd_mission_start = {};
|
||||
cmd_mission_start.timestamp = hrt_absolute_time();
|
||||
cmd_mission_start.target_system = get_vstatus()->system_id;
|
||||
cmd_mission_start.target_component = get_vstatus()->component_id;
|
||||
cmd_mission_start.command = vehicle_command_s::VEHICLE_CMD_MISSION_START;
|
||||
cmd_mission_start.param1 = land_start;
|
||||
cmd_mission_start.param2 = 0;
|
||||
struct vehicle_command_s vcmd = {};
|
||||
vcmd.timestamp = hrt_absolute_time(),
|
||||
vcmd.param1 = (float)land_start,
|
||||
vcmd.param2 = 0.0f,
|
||||
vcmd.param3 = 0.0f,
|
||||
vcmd.param4 = 0.0f,
|
||||
vcmd.param5 = 0.0,
|
||||
vcmd.param6 = 0.0,
|
||||
vcmd.param7 = 0.0f,
|
||||
vcmd.command = vehicle_command_s::VEHICLE_CMD_MISSION_START;
|
||||
vcmd.target_system = (uint8_t)get_vstatus()->system_id;
|
||||
vcmd.target_component = (uint8_t)get_vstatus()->component_id;
|
||||
vcmd.source_system = (uint8_t)get_vstatus()->system_id;
|
||||
vcmd.source_component = (uint8_t)get_vstatus()->component_id;
|
||||
vcmd.confirmation = false;
|
||||
vcmd.from_external = false;
|
||||
|
||||
publish_vehicle_cmd(cmd_mission_start);
|
||||
publish_vehicle_cmd(vcmd);
|
||||
|
||||
} else {
|
||||
PX4_WARN("planned landing not available");
|
||||
|
||||
Reference in New Issue
Block a user