Skip to content

Commit

Permalink
ArduPlane: handle MAV_CMD_NAV_TAKEOFF via command_long and command_in
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Oct 24, 2023
1 parent ca3b5a8 commit a97adcf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
59 changes: 46 additions & 13 deletions ArduPlane/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,9 @@ MAV_RESULT GCS_MAVLINK_Plane::handle_command_int_packet(const mavlink_command_in

case MAV_CMD_DO_VTOL_TRANSITION:
return handle_command_DO_VTOL_TRANSITION(packet);

case MAV_CMD_NAV_TAKEOFF:
return handle_command_MAV_CMD_NAV_TAKEOFF(packet);
#endif

case MAV_CMD_DO_GO_AROUND:
Expand Down Expand Up @@ -1045,26 +1048,56 @@ MAV_RESULT GCS_MAVLINK_Plane::handle_command_DO_CHANGE_SPEED(const mavlink_comma
return MAV_RESULT_FAILED;
}

MAV_RESULT GCS_MAVLINK_Plane::handle_command_long_packet(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
#if HAL_QUADPLANE_ENABLED
void GCS_MAVLINK_Plane::convert_MAV_CMD_NAV_TAKEOFF_to_COMMAND_INT(const mavlink_command_long_t &in, mavlink_command_int_t &out)
{
switch(packet.command) {
// convert to MAV_FRAME_LOCAL_OFFSET_NED, "NED local tangent frame
// with origin that travels with the vehicle"
out = {};
out.target_system = in.target_system;
out.target_component = in.target_component;
out.frame = MAV_FRAME_LOCAL_OFFSET_NED;
out.command = in.command;
// out.current = 0;
// out.autocontinue = 0;
// out.param1 = in.param1; // we only use the "z" parameter in this command:
// out.param2 = in.param2;
// out.param3 = in.param3;
// out.param4 = in.param4;
// out.x = 0; // we don't handle positioning when doing takeoffs
// out.y = 0;
out.z = -in.param7; // up -> down
}

#if HAL_QUADPLANE_ENABLED
case MAV_CMD_NAV_TAKEOFF: {
// user takeoff only works with quadplane code for now
// param7 : altitude [metres]
float takeoff_alt = packet.param7;
if (plane.quadplane.available() && plane.quadplane.do_user_takeoff(takeoff_alt)) {
return MAV_RESULT_ACCEPTED;
}
return MAV_RESULT_FAILED;
void GCS_MAVLINK_Plane::convert_COMMAND_LONG_to_COMMAND_INT(const mavlink_command_long_t &in, mavlink_command_int_t &out, MAV_FRAME frame)
{
switch (in.command) {
case MAV_CMD_NAV_TAKEOFF:
convert_MAV_CMD_NAV_TAKEOFF_to_COMMAND_INT(in, out);
return;
}
#endif // HAL_QUADPLANE_ENABLED
return GCS_MAVLINK::convert_COMMAND_LONG_to_COMMAND_INT(in, out, frame);
}

MAV_RESULT GCS_MAVLINK_Plane::handle_command_MAV_CMD_NAV_TAKEOFF(const mavlink_command_int_t &packet)
{
float takeoff_alt = packet.z;
switch (packet.frame) {
case MAV_FRAME_LOCAL_OFFSET_NED: // "NED local tangent frame with origin that travels with the vehicle"
takeoff_alt = -takeoff_alt; // down -> up
break;
default:
return GCS_MAVLINK::handle_command_long_packet(packet, msg);
return MAV_RESULT_DENIED; // "is supported but has invalid parameters"
}
if (!plane.quadplane.available()) {
return MAV_RESULT_FAILED;
}
if (!plane.quadplane.do_user_takeoff(takeoff_alt)) {
return MAV_RESULT_FAILED;
}
return MAV_RESULT_ACCEPTED;
}
#endif

MAV_RESULT GCS_MAVLINK_Plane::handle_MAV_CMD_DO_AUTOTUNE_ENABLE(const mavlink_command_int_t &packet)
{
Expand Down
8 changes: 7 additions & 1 deletion ArduPlane/GCS_Mavlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <GCS_MAVLink/GCS.h>
#include <AP_Logger/AP_Logger.h>
#include <AP_Airspeed/AP_Airspeed_config.h>
#include "quadplane.h"

class GCS_MAVLINK_Plane : public GCS_MAVLINK
{
Expand All @@ -25,7 +26,6 @@ class GCS_MAVLINK_Plane : public GCS_MAVLINK

MAV_RESULT handle_command_preflight_calibration(const mavlink_command_int_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_int_packet(const mavlink_command_int_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_long_packet(const mavlink_command_long_t &packet, const mavlink_message_t &msg) override;
MAV_RESULT handle_command_do_set_mission_current(const mavlink_command_long_t &packet) override;

void send_position_target_global_int() override;
Expand Down Expand Up @@ -60,6 +60,12 @@ class GCS_MAVLINK_Plane : public GCS_MAVLINK
MAV_RESULT handle_MAV_CMD_DO_PARACHUTE(const mavlink_command_int_t &packet);
MAV_RESULT handle_command_DO_VTOL_TRANSITION(const mavlink_command_int_t &packet);

#if HAL_QUADPLANE_ENABLED
void convert_MAV_CMD_NAV_TAKEOFF_to_COMMAND_INT(const mavlink_command_long_t &in, mavlink_command_int_t &out);
void convert_COMMAND_LONG_to_COMMAND_INT(const mavlink_command_long_t &in, mavlink_command_int_t &out, MAV_FRAME frame = MAV_FRAME_GLOBAL_RELATIVE_ALT) override;
MAV_RESULT handle_command_MAV_CMD_NAV_TAKEOFF(const mavlink_command_int_t &packet);
#endif

bool try_send_message(enum ap_message id) override;
void packetReceived(const mavlink_status_t &status, const mavlink_message_t &msg) override;

Expand Down

0 comments on commit a97adcf

Please sign in to comment.