Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
BryonOI authored Jul 18, 2024
2 parents 52c7107 + 5a54d9a commit 93cf3fb
Show file tree
Hide file tree
Showing 111 changed files with 28,499 additions and 24,854 deletions.
3 changes: 2 additions & 1 deletion ArduCopter/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,13 @@ class ModeAuto : public Mode {

private:

enum class Options : int32_t {
enum class Option : int32_t {
AllowArming = (1 << 0U),
AllowTakeOffWithoutRaisingThrottle = (1 << 1U),
IgnorePilotYaw = (1 << 2U),
AllowWeatherVaning = (1 << 7U),
};
bool option_is_enabled(Option option) const;

// Enter auto rtl pseudo mode
bool enter_auto_rtl(ModeReason reason);
Expand Down
18 changes: 13 additions & 5 deletions ArduCopter/mode_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,23 @@ void ModeAuto::set_submode(SubMode new_submode)
}
}

bool ModeAuto::option_is_enabled(Option option) const
{
return ((copter.g2.auto_options & (uint32_t)option) != 0);
}

bool ModeAuto::allows_arming(AP_Arming::Method method) const
{
return ((copter.g2.auto_options & (uint32_t)Options::AllowArming) != 0) && !auto_RTL;
};
if (auto_RTL) {
return false;
}
return option_is_enabled(Option::AllowArming);
}

#if WEATHERVANE_ENABLED == ENABLED
bool ModeAuto::allows_weathervaning() const
{
return (copter.g2.auto_options & (uint32_t)Options::AllowWeatherVaning) != 0;
return option_is_enabled(Option::AllowWeatherVaning);
}
#endif

Expand Down Expand Up @@ -638,7 +646,7 @@ void PayloadPlace::start_descent()
// returns true if pilot's yaw input should be used to adjust vehicle's heading
bool ModeAuto::use_pilot_yaw(void) const
{
const bool allow_yaw_option = (copter.g2.auto_options.get() & uint32_t(Options::IgnorePilotYaw)) == 0;
const bool allow_yaw_option = !option_is_enabled(Option::IgnorePilotYaw);
const bool rtl_allow_yaw = (_mode == SubMode::RTL) && copter.mode_rtl.use_pilot_yaw();
const bool landing = _mode == SubMode::LAND;
return allow_yaw_option || rtl_allow_yaw || landing;
Expand Down Expand Up @@ -1039,7 +1047,7 @@ void ModeAuto::takeoff_run()
{
// if the user doesn't want to raise the throttle we can set it automatically
// note that this can defeat the disarm check on takeoff
if ((copter.g2.auto_options & (int32_t)Options::AllowTakeOffWithoutRaisingThrottle) != 0) {
if (option_is_enabled(Option::AllowTakeOffWithoutRaisingThrottle)) {
copter.set_auto_armed(true);
}
auto_takeoff.run();
Expand Down
6 changes: 6 additions & 0 deletions ArduPlane/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,12 @@ MAV_RESULT GCS_MAVLINK_Plane::handle_command_int_packet(const mavlink_command_in
plane.set_mode(plane.mode_rtl, ModeReason::GCS_COMMAND);
return MAV_RESULT_ACCEPTED;

#if AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED
case MAV_CMD_SET_HAGL:
plane.handle_external_hagl(packet);
return MAV_RESULT_ACCEPTED;
#endif

default:
return GCS_MAVLINK::handle_command_int_packet(packet, msg);
}
Expand Down
14 changes: 14 additions & 0 deletions ArduPlane/Plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ class Plane : public AP_Vehicle {
AP_FixedWing::Rangefinder_State rangefinder_state;
#endif

#if AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED
struct {
// allow for external height above ground estimate
float hagl;
uint32_t last_update_ms;
uint32_t timeout_ms;
} external_hagl;
bool get_external_HAGL(float &height_agl);
void handle_external_hagl(const mavlink_command_int_t &packet);
#endif // AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED

float get_landing_height(bool &using_rangefinder);


#if AP_RPM_ENABLED
AP_RPM rpm_sensor;
#endif
Expand Down
72 changes: 72 additions & 0 deletions ArduPlane/altitude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ int32_t Plane::get_RTL_altitude_cm() const
*/
float Plane::relative_ground_altitude(bool use_rangefinder_if_available, bool use_terrain_if_available)
{
#if AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED
float height_AGL;
// use external HAGL if available
if (get_external_HAGL(height_AGL)) {
return height_AGL;
}
#endif // AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED

#if AP_RANGEFINDER_ENABLED
if (use_rangefinder_if_available && rangefinder_state.in_range) {
return rangefinder_state.height_estimate;
Expand Down Expand Up @@ -810,3 +818,67 @@ bool Plane::terrain_enabled_in_mode(Mode::Number num) const
return false;
}
#endif

#if AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED
/*
handle a MAV_CMD_SET_HAGL request. The accuracy is ignored
*/
void Plane::handle_external_hagl(const mavlink_command_int_t &packet)
{
auto &hagl = plane.external_hagl;
hagl.hagl = packet.param1;
hagl.last_update_ms = AP_HAL::millis();
hagl.timeout_ms = uint32_t(packet.param3 * 1000);
}

/*
get HAGL from external source if current
*/
bool Plane::get_external_HAGL(float &height_agl)
{
auto &hagl = plane.external_hagl;
if (hagl.last_update_ms != 0) {
const uint32_t now_ms = AP_HAL::millis();
if (now_ms - hagl.last_update_ms <= hagl.timeout_ms) {
height_agl = hagl.hagl;
return true;
}
hagl.last_update_ms = 0;
}
return false;
}
#endif // AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED

/*
get height for landing. Set using_rangefinder to true if a rangefinder
or external HAGL source is active
*/
float Plane::get_landing_height(bool &rangefinder_active)
{
float height;

#if AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED
// if external HAGL is active use that
if (get_external_HAGL(height)) {
// ensure no terrain correction is applied - that is the job
// of the external system if it is wanted
auto_state.terrain_correction = 0;

// an external HAGL is considered to be a type of rangefinder
rangefinder_active = true;
return height;
}
#endif

// get basic height above target
height = height_above_target();
rangefinder_active = false;

#if AP_RANGEFINDER_ENABLED
// possibly correct with rangefinder
height -= rangefinder_correction();
rangefinder_active = g.rangefinder_landing && rangefinder_state.in_range;
#endif

return height;
}
15 changes: 4 additions & 11 deletions ArduPlane/commands_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,16 @@ bool Plane::verify_command(const AP_Mission::Mission_Command& cmd) // Ret

} else {
// use rangefinder to correct if possible
#if AP_RANGEFINDER_ENABLED
float height = height_above_target() - rangefinder_correction();
#else
float height = height_above_target();
#endif
bool rangefinder_active = false;
float height = plane.get_landing_height(rangefinder_active);

// for flare calculations we don't want to use the terrain
// correction as otherwise we will flare early on rising
// ground
height -= auto_state.terrain_correction;
return landing.verify_land(prev_WP_loc, next_WP_loc, current_loc,
height, auto_state.sink_rate, auto_state.wp_proportion, auto_state.last_flying_ms, arming.is_armed(), is_flying(),
#if AP_RANGEFINDER_ENABLED
g.rangefinder_landing && rangefinder_state.in_range
#else
false
#endif
);
rangefinder_active);
}

case MAV_CMD_NAV_LOITER_UNLIM:
Expand Down
14 changes: 11 additions & 3 deletions Tools/AP_Bootloader/support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,19 @@ void port_setbaud(uint32_t baudrate)
check if flash has any ECC errors and if it does then erase all of
flash
*/
#define ECC_CHECK_CHUNK_SIZE (32*sizeof(uint32_t))
void check_ecc_errors(void)
{
__disable_fault_irq();
// stm32_flash_corrupt(0x8043200);
auto *dma = dmaStreamAlloc(STM32_DMA_STREAM_ID(1, 1), 0, nullptr, nullptr);
uint32_t buf[32];

uint32_t *buf = (uint32_t*)malloc_dma(ECC_CHECK_CHUNK_SIZE);

if (buf == nullptr) {
// DMA'ble memory not available
return;
}
uint32_t ofs = 0;
while (ofs < BOARD_FLASH_SIZE*1024) {
if (FLASH->SR1 != 0) {
Expand All @@ -556,9 +564,9 @@ void check_ecc_errors(void)
dmaStartMemCopy(dma,
STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_BYTE |
STM32_DMA_CR_MSIZE_BYTE,
ofs+(uint8_t*)FLASH_BASE, buf, sizeof(buf));
ofs+(uint8_t*)FLASH_BASE, buf, ECC_CHECK_CHUNK_SIZE);
dmaWaitCompletion(dma);
ofs += sizeof(buf);
ofs += ECC_CHECK_CHUNK_SIZE;
}
dmaStreamFree(dma);

Expand Down
2 changes: 1 addition & 1 deletion Tools/autotest/arducopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11517,7 +11517,7 @@ def Clamp(self):
here = self.mav.location()
loc = self.offset_location_ne(here, 10, 0)
self.takeoff(5, mode='GUIDED')
self.do_reposition(loc, frame=mavutil.mavlink.MAV_FRAME_GLOBAL)
self.send_do_reposition(loc, frame=mavutil.mavlink.MAV_FRAME_GLOBAL)
self.wait_location(loc, timeout=120)
self.land_and_disarm()

Expand Down
49 changes: 18 additions & 31 deletions Tools/autotest/arduplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,18 +1608,14 @@ def FenceStatic(self):
# Test arming outside inclusion zone
self.progress("Test arming while vehicle outside of inclusion zone")
self.set_parameter("FENCE_TYPE", 4) # Enables polygon fence types
locs = [
mavutil.location(1.000, 1.000, 0, 0),
mavutil.location(1.000, 1.001, 0, 0),
mavutil.location(1.001, 1.001, 0, 0),
mavutil.location(1.001, 1.000, 0, 0)
]
self.upload_fences_from_locations(
mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION,
[
locs
self.upload_fences_from_locations([(
mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, [
mavutil.location(1.000, 1.000, 0, 0),
mavutil.location(1.000, 1.001, 0, 0),
mavutil.location(1.001, 1.001, 0, 0),
mavutil.location(1.001, 1.000, 0, 0)
]
)
)])
self.delay_sim_time(10) # let fence check run so it loads-from-eeprom
self.do_fence_enable()
self.assert_fence_enabled()
Expand All @@ -1637,12 +1633,9 @@ def FenceStatic(self):
mavutil.location(home_loc.lat + 0.001, home_loc.lng + 0.001, 0, 0),
mavutil.location(home_loc.lat + 0.001, home_loc.lng - 0.001, 0, 0),
]
self.upload_fences_from_locations(
mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION,
[
locs
]
)
self.upload_fences_from_locations([
(mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION, locs),
])
self.delay_sim_time(10) # let fence check run so it loads-from-eeprom
self.do_fence_enable()
self.assert_fence_enabled()
Expand Down Expand Up @@ -1895,7 +1888,7 @@ def terrain_wait_path(loc1, loc2, steps):
self.install_message_hook_context(terrain_following_above_80m)

self.change_mode("GUIDED")
self.do_reposition(guided_loc, frame=mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT)
self.send_do_reposition(guided_loc, frame=mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT)
self.progress("Flying to guided location")
self.wait_location(
guided_loc,
Expand All @@ -1918,7 +1911,7 @@ def terrain_wait_path(loc1, loc2, steps):

# Fly back to guided location
self.change_mode("GUIDED")
self.do_reposition(guided_loc, frame=mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT)
self.send_do_reposition(guided_loc, frame=mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT)
self.progress("Flying to back to guided location")

# Disable terrain following and re-load rally point with relative to terrain altitude
Expand Down Expand Up @@ -3720,12 +3713,9 @@ def FenceBreachedChangeMode(self):
mavutil.location(home_loc.lat + 0.001, home_loc.lng + 0.001, 0, 0),
mavutil.location(home_loc.lat + 0.001, home_loc.lng - 0.001, 0, 0),
]
self.upload_fences_from_locations(
mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION,
[
locs
]
)
self.upload_fences_from_locations([
(mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, locs),
])
self.delay_sim_time(1)
self.wait_ready_to_arm()
self.takeoff(alt=50)
Expand Down Expand Up @@ -3783,12 +3773,9 @@ def FenceNoFenceReturnPoint(self):
mavutil.location(home_loc.lat + 0.001, home_loc.lng + 0.003, 0, 0),
mavutil.location(home_loc.lat + 0.001, home_loc.lng - 0.001, 0, 0),
]
self.upload_fences_from_locations(
mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION,
[
locs
]
)
self.upload_fences_from_locations([
(mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, locs),
])
self.delay_sim_time(1)
self.wait_ready_to_arm()
self.takeoff(alt=50)
Expand Down
4 changes: 2 additions & 2 deletions Tools/autotest/quadplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,13 +862,13 @@ def QAssist(self):
guided_loc = self.home_relative_loc_ne(0, 0)
guided_loc.alt = 60
self.change_mode("GUIDED")
self.do_reposition(guided_loc)
self.send_do_reposition(guided_loc)
self.wait_altitude(58, 62, relative=True)
self.set_parameter("Q_ASSIST_ALT", 50)

# Try and descent to 40m
guided_loc.alt = 40
self.do_reposition(guided_loc)
self.send_do_reposition(guided_loc)

# Expect alt assist to kick in, eg "Alt assist 48.9m"
self.wait_statustext(r"Alt assist \d*.\d*m", regex=True, timeout=100)
Expand Down
Loading

0 comments on commit 93cf3fb

Please sign in to comment.