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

GCS_MAVLink: handle MAV_CMD_DO_SET_SAFETY_SWITCH_STATE #26243

Merged
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
6 changes: 6 additions & 0 deletions Tools/autotest/arducopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10281,6 +10281,12 @@ def SafetySwitch(self):
self.change_mode('LAND')
self.wait_disarmed()

# test turning safty on/off using explicit MAVLink command:
self.run_cmd_int(mavutil.mavlink.MAV_CMD_DO_SET_SAFETY_SWITCH_STATE, mavutil.mavlink.SAFETY_SWITCH_STATE_SAFE)
self.assert_prearm_failure("safety switch")
self.run_cmd_int(mavutil.mavlink.MAV_CMD_DO_SET_SAFETY_SWITCH_STATE, mavutil.mavlink.SAFETY_SWITCH_STATE_DANGEROUS)
self.wait_ready_to_arm()

def GuidedYawRate(self):
'''ensuer guided yaw rate is not affected by rate of sewt-attitude messages'''
self.takeoff(30, mode='GUIDED')
Expand Down
2 changes: 2 additions & 0 deletions libraries/GCS_MAVLink/GCS.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ class GCS_MAVLINK
void deadlock_sem(void);
#endif

MAV_RESULT handle_do_set_safety_switch_state(const mavlink_command_int_t &packet, const mavlink_message_t &msg);

// reset a message interval via mavlink:
MAV_RESULT handle_command_set_message_interval(const mavlink_command_int_t &packet);
MAV_RESULT handle_command_get_message_interval(const mavlink_command_int_t &packet);
Expand Down
22 changes: 22 additions & 0 deletions libraries/GCS_MAVLink/GCS_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5131,6 +5131,25 @@ MAV_RESULT GCS_MAVLINK::handle_command_storage_format(const mavlink_command_int_
}
#endif

MAV_RESULT GCS_MAVLINK::handle_do_set_safety_switch_state(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
switch ((SAFETY_SWITCH_STATE)packet.param1) {
case SAFETY_SWITCH_STATE_DANGEROUS:
// turn safety off (pwm outputs flow to the motors)
hal.rcout->force_safety_off();
return MAV_RESULT_ACCEPTED;
case SAFETY_SWITCH_STATE_SAFE:
// turn safety on (no pwm outputs to the motors)
if (hal.rcout->force_safety_on()) {
return MAV_RESULT_ACCEPTED;
}
return MAV_RESULT_FAILED;
default:
return MAV_RESULT_DENIED;
}
}


MAV_RESULT GCS_MAVLINK::handle_command_int_packet(const mavlink_command_int_t &packet, const mavlink_message_t &msg)
{
switch (packet.command) {
Expand Down Expand Up @@ -5288,6 +5307,9 @@ MAV_RESULT GCS_MAVLINK::handle_command_int_packet(const mavlink_command_int_t &p
case MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN:
return handle_preflight_reboot(packet, msg);

case MAV_CMD_DO_SET_SAFETY_SWITCH_STATE:
return handle_do_set_safety_switch_state(packet, msg);

#if AP_MAVLINK_SERVO_RELAY_ENABLED
case MAV_CMD_DO_SET_SERVO:
case MAV_CMD_DO_REPEAT_SERVO:
Expand Down
2 changes: 1 addition & 1 deletion modules/mavlink
Loading