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

Allow MAV_CMD_DO_WINCH to be accepted via COMMAND_INT #24902

Merged
merged 2 commits into from
Sep 11, 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
19 changes: 13 additions & 6 deletions ArduCopter/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ MAV_RESULT GCS_MAVLINK_Copter::handle_command_int_packet(const mavlink_command_i
return handle_MAV_CMD_SOLO_BTN_FLY_CLICK(packet);
#endif

#if AP_WINCH_ENABLED
case MAV_CMD_DO_WINCH:
return handle_MAV_CMD_DO_WINCH(packet);
#endif

default:
return GCS_MAVLINK::handle_command_int_packet(packet, msg);
}
Expand Down Expand Up @@ -924,8 +929,14 @@ MAV_RESULT GCS_MAVLINK_Copter::handle_command_long_packet(const mavlink_command_
packet.param4,
(uint8_t)packet.param5);

default:
return GCS_MAVLINK::handle_command_long_packet(packet, msg);
}
}

#if AP_WINCH_ENABLED
case MAV_CMD_DO_WINCH:
MAV_RESULT GCS_MAVLINK_Copter::handle_MAV_CMD_DO_WINCH(const mavlink_command_int_t &packet)
{
// param1 : winch number (ignored)
// param2 : action (0=relax, 1=relative length control, 2=rate control). See WINCH_ACTIONS enum.
if (!copter.g2.winch.enabled()) {
Expand All @@ -946,12 +957,8 @@ MAV_RESULT GCS_MAVLINK_Copter::handle_command_long_packet(const mavlink_command_
break;
}
return MAV_RESULT_FAILED;
#endif

default:
return GCS_MAVLINK::handle_command_long_packet(packet, msg);
}
}
#endif // AP_WINCH_ENABLED

#if AC_MAVLINK_SOLO_BUTTON_COMMAND_HANDLING_ENABLED
MAV_RESULT GCS_MAVLINK_Copter::handle_MAV_CMD_SOLO_BTN_FLY_CLICK(const mavlink_command_int_t &packet)
Expand Down
5 changes: 5 additions & 0 deletions ArduCopter/GCS_Mavlink.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <GCS_MAVLink/GCS.h>
#include <AP_Winch/AP_Winch_config.h>

#ifndef AC_MAVLINK_SOLO_BUTTON_COMMAND_HANDLING_ENABLED
#define AC_MAVLINK_SOLO_BUTTON_COMMAND_HANDLING_ENABLED 1
Expand Down Expand Up @@ -103,4 +104,8 @@ class GCS_MAVLINK_Copter : public GCS_MAVLINK
MAV_RESULT handle_MAV_CMD_SOLO_BTN_PAUSE_CLICK(const mavlink_command_int_t &packet);
#endif

#if AP_WINCH_ENABLED
MAV_RESULT handle_MAV_CMD_DO_WINCH(const mavlink_command_int_t &packet);
#endif

};
69 changes: 69 additions & 0 deletions Tools/autotest/arducopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4735,6 +4735,74 @@ def Weathervane(self):
self.wait_heading(100, accuracy=8, timeout=100)
self.do_RTL()

def _DO_WINCH(self, command):
self.context_push()
self.load_default_params_file("copter-winch.parm")
self.reboot_sitl()
self.wait_ready_to_arm()

self.start_subtest("starts relaxed")
self.wait_servo_channel_value(9, 0)

self.start_subtest("rate control")
command(
mavutil.mavlink.MAV_CMD_DO_WINCH,
p1=1, # instance number
p2=mavutil.mavlink.WINCH_RATE_CONTROL, # command
p3=0, # length to release
p4=1, # rate in m/s
)
self.wait_servo_channel_value(9, 1900)

self.start_subtest("relax")
command(
mavutil.mavlink.MAV_CMD_DO_WINCH,
p1=1, # instance number
p2=mavutil.mavlink.WINCH_RELAXED, # command
p3=0, # length to release
p4=1, # rate in m/s
)
self.wait_servo_channel_value(9, 0)

self.start_subtest("hold but zero output")
command(
mavutil.mavlink.MAV_CMD_DO_WINCH,
p1=1, # instance number
p2=mavutil.mavlink.WINCH_RATE_CONTROL, # command
p3=0, # length to release
p4=0, # rate in m/s
)
self.wait_servo_channel_value(9, 1500)

self.start_subtest("relax")
command(
mavutil.mavlink.MAV_CMD_DO_WINCH,
p1=1, # instance number
p2=mavutil.mavlink.WINCH_RELAXED, # command
p3=0, # length to release
p4=1, # rate in m/s
)
self.wait_servo_channel_value(9, 0)

self.start_subtest("position")
command(
mavutil.mavlink.MAV_CMD_DO_WINCH,
p1=1, # instance number
p2=mavutil.mavlink.WINCH_RELATIVE_LENGTH_CONTROL, # command
p3=2, # length to release
p4=1, # rate in m/s
)
self.wait_servo_channel_value(9, 1900)
self.wait_servo_channel_value(9, 1500, timeout=60)

self.context_pop()
self.reboot_sitl()

def DO_WINCH(self):
'''test mavlink DO_WINCH command'''
self._DO_WINCH(self.run_cmd_int)
self._DO_WINCH(self.run_cmd)

def GuidedSubModeChange(self):
""""Ensure we can move around in guided after a takeoff command."""

Expand Down Expand Up @@ -10180,6 +10248,7 @@ def tests2b(self): # this block currently around 9.5mins here
self.WPNAV_SPEED,
self.WPNAV_SPEED_UP,
self.WPNAV_SPEED_DN,
self.DO_WINCH,
self.SensorErrorFlags,
self.GPSForYaw,
self.DefaultIntervalsFromFiles,
Expand Down