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

Sub: accept NAV_LOITER_UNLIM and NAV_LAND as command_int too #25060

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions ArduSub/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,21 +459,40 @@ bool GCS_MAVLINK_Sub::set_home(const Location& loc, bool _lock) {
return sub.set_home(loc, _lock);
}


MAV_RESULT GCS_MAVLINK_Sub::handle_command_long_packet(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
MAV_RESULT GCS_MAVLINK_Sub::handle_command_int_packet(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
switch (packet.command) {
switch(packet.command) {

case MAV_CMD_NAV_LOITER_UNLIM:
return handle_MAV_CMD_NAV_LOITER_UNLIM(packet);

case MAV_CMD_NAV_LAND:
return handle_MAV_CMD_NAV_LAND(packet);

}

return GCS_MAVLINK::handle_command_int_packet(packet, msg);
}

MAV_RESULT GCS_MAVLINK_Sub::handle_MAV_CMD_NAV_LOITER_UNLIM(const mavlink_command_int_t &packet)
{
if (!sub.set_mode(Mode::Number::POSHOLD, ModeReason::GCS_COMMAND)) {
return MAV_RESULT_FAILED;
}
return MAV_RESULT_ACCEPTED;
}

case MAV_CMD_NAV_LAND:
MAV_RESULT GCS_MAVLINK_Sub::handle_MAV_CMD_NAV_LAND(const mavlink_command_int_t &packet)
{
if (!sub.set_mode(Mode::Number::SURFACE, ModeReason::GCS_COMMAND)) {
return MAV_RESULT_FAILED;
}
return MAV_RESULT_ACCEPTED;
}

MAV_RESULT GCS_MAVLINK_Sub::handle_command_long_packet(const mavlink_command_long_t &packet, const mavlink_message_t &msg)
{
switch (packet.command) {

case MAV_CMD_CONDITION_YAW:
// param1 : target angle [0-360]
Expand Down
5 changes: 5 additions & 0 deletions ArduSub/GCS_Mavlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class GCS_MAVLINK_Sub : 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_long_packet(const mavlink_command_long_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;

// override sending of scaled_pressure3 to send on-board temperature:
void send_scaled_pressure3() override;

Expand Down Expand Up @@ -51,6 +53,9 @@ class GCS_MAVLINK_Sub : public GCS_MAVLINK {

int16_t vfr_hud_throttle() const override;

MAV_RESULT handle_MAV_CMD_NAV_LOITER_UNLIM(const mavlink_command_int_t &packet);
MAV_RESULT handle_MAV_CMD_NAV_LAND(const mavlink_command_int_t &packet);

#if HAL_HIGH_LATENCY2_ENABLED
int16_t high_latency_target_altitude() const override;
uint8_t high_latency_tgt_heading() const override;
Expand Down
16 changes: 16 additions & 0 deletions Tools/autotest/ardusub.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ def disabled_tests(self):
})
return ret

def MAV_CMD_NAV_LOITER_UNLIM(self):
'''test handling of MAV_CMD_NAV_LOITER_UNLIM received via mavlink'''
for cmd in self.run_cmd, self.run_cmd_int:
self.change_mode('CIRCLE')
cmd(mavutil.mavlink.MAV_CMD_NAV_LOITER_UNLIM)
self.assert_mode('POSHOLD')

def MAV_CMD_NAV_LAND(self):
'''test handling of MAV_CMD_NAV_LAND received via mavlink'''
for cmd in self.run_cmd, self.run_cmd_int:
self.change_mode('CIRCLE')
cmd(mavutil.mavlink.MAV_CMD_NAV_LAND)
self.assert_mode('SURFACE')

def tests(self):
'''return list of all tests'''
ret = super(AutoTestSub, self).tests()
Expand All @@ -440,6 +454,8 @@ def tests(self):
self.MotorThrustHoverParameterIgnore,
self.SET_POSITION_TARGET_GLOBAL_INT,
self.TestLogDownloadMAVProxy,
self.MAV_CMD_NAV_LOITER_UNLIM,
self.MAV_CMD_NAV_LAND,
])

return ret