mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-09 06:50:36 +08:00
Add boiler plate
FW guidance control boiler plate Remove modules Remove modules Add FWGuidanceControl Add KConfig Build guidance controller Make boiler plate compile Remove code Cleanup Remove trajectory setpoint F
This commit is contained in:
@@ -21,6 +21,7 @@ CONFIG_MODULES_FLIGHT_MODE_MANAGER=y
|
||||
CONFIG_MODULES_FW_ATT_CONTROL=y
|
||||
CONFIG_MODULES_FW_AUTOTUNE_ATTITUDE_CONTROL=y
|
||||
CONFIG_MODULES_FW_MODE_MANAGER=y
|
||||
CONFIG_MODULES_FW_GUIDANCE_CONTROL=y
|
||||
CONFIG_MODULES_FW_LATERAL_LONGITUDINAL_CONTROL=y
|
||||
CONFIG_FIGURE_OF_EIGHT=y
|
||||
CONFIG_MODULES_FW_RATE_CONTROL=y
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2015-2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_module(
|
||||
MODULE modules__fw_guidance_control
|
||||
MAIN fw_guidance_control
|
||||
SRCS
|
||||
FixedWingGuidanceControl.cpp
|
||||
FixedWingGuidanceControl.hpp
|
||||
ControllerConfigurationHandler.cpp
|
||||
ControllerConfigurationHandler.hpp
|
||||
DEPENDS
|
||||
npfg
|
||||
SlewRate
|
||||
tecs
|
||||
motion_planning
|
||||
performance_model
|
||||
Sticks
|
||||
)
|
||||
@@ -0,0 +1,139 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @file CombinedControllerConfigurationHandler.cpp
|
||||
*/
|
||||
|
||||
#include "ControllerConfigurationHandler.hpp"
|
||||
#include <drivers/drv_hrt.h>
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
|
||||
void CombinedControllerConfigurationHandler::update(const hrt_abstime now)
|
||||
{
|
||||
_longitudinal_updated = floatValueChanged(_longitudinal_configuration_current_cycle.pitch_min,
|
||||
_longitudinal_publisher.get().pitch_min);
|
||||
_longitudinal_updated |= floatValueChanged(_longitudinal_configuration_current_cycle.pitch_max,
|
||||
_longitudinal_publisher.get().pitch_max);
|
||||
_longitudinal_updated |= floatValueChanged(_longitudinal_configuration_current_cycle.throttle_min,
|
||||
_longitudinal_publisher.get().throttle_min);
|
||||
_longitudinal_updated |= floatValueChanged(_longitudinal_configuration_current_cycle.throttle_max,
|
||||
_longitudinal_publisher.get().throttle_max);
|
||||
_longitudinal_updated |= floatValueChanged(_longitudinal_configuration_current_cycle.speed_weight,
|
||||
_longitudinal_publisher.get().speed_weight);
|
||||
_longitudinal_updated |= floatValueChanged(_longitudinal_configuration_current_cycle.climb_rate_target,
|
||||
_longitudinal_publisher.get().climb_rate_target);
|
||||
_longitudinal_updated |= floatValueChanged(_longitudinal_configuration_current_cycle.sink_rate_target,
|
||||
_longitudinal_publisher.get().sink_rate_target);
|
||||
_longitudinal_updated |= booleanValueChanged(_longitudinal_configuration_current_cycle.enforce_low_height_condition,
|
||||
_longitudinal_publisher.get().enforce_low_height_condition);
|
||||
_longitudinal_updated |= booleanValueChanged(_longitudinal_configuration_current_cycle.disable_underspeed_protection,
|
||||
_longitudinal_publisher.get().disable_underspeed_protection);
|
||||
|
||||
_lateral_updated |= floatValueChanged(_lateral_configuration_current_cycle.lateral_accel_max,
|
||||
_lateral_publisher.get().lateral_accel_max);
|
||||
|
||||
if (_longitudinal_updated || now - _time_last_longitudinal_publish > 1_s) {
|
||||
_longitudinal_configuration_current_cycle.timestamp = now;
|
||||
_longitudinal_publisher.update(_longitudinal_configuration_current_cycle);
|
||||
_time_last_longitudinal_publish = _longitudinal_configuration_current_cycle.timestamp;
|
||||
}
|
||||
|
||||
if (_lateral_updated || now - _time_last_lateral_publish > 1_s) {
|
||||
_lateral_configuration_current_cycle.timestamp = now;
|
||||
_lateral_publisher.update(_lateral_configuration_current_cycle);
|
||||
_time_last_lateral_publish = _lateral_configuration_current_cycle.timestamp;
|
||||
}
|
||||
|
||||
_longitudinal_updated = _lateral_updated = false;
|
||||
_longitudinal_configuration_current_cycle = empty_longitudinal_control_configuration;
|
||||
_lateral_configuration_current_cycle = empty_lateral_control_configuration;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setThrottleMax(float throttle_max)
|
||||
{
|
||||
_longitudinal_configuration_current_cycle.throttle_max = throttle_max;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setThrottleMin(float throttle_min)
|
||||
{
|
||||
_longitudinal_configuration_current_cycle.throttle_min = throttle_min;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setSpeedWeight(float speed_weight)
|
||||
{
|
||||
_longitudinal_configuration_current_cycle.speed_weight = speed_weight;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setPitchMin(const float pitch_min)
|
||||
{
|
||||
_longitudinal_configuration_current_cycle.pitch_min = pitch_min;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setPitchMax(const float pitch_max)
|
||||
{
|
||||
_longitudinal_configuration_current_cycle.pitch_max = pitch_max;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setClimbRateTarget(float climbrate_target)
|
||||
{
|
||||
_longitudinal_configuration_current_cycle.climb_rate_target = climbrate_target;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setDisableUnderspeedProtection(bool disable)
|
||||
{
|
||||
_longitudinal_configuration_current_cycle.disable_underspeed_protection = disable;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setSinkRateTarget(const float sinkrate_target)
|
||||
{
|
||||
_longitudinal_configuration_current_cycle.sink_rate_target = sinkrate_target;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setLateralAccelMax(float lateral_accel_max)
|
||||
{
|
||||
_lateral_configuration_current_cycle.lateral_accel_max = lateral_accel_max;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::setEnforceLowHeightCondition(bool low_height_condition)
|
||||
{
|
||||
_longitudinal_configuration_current_cycle.enforce_low_height_condition = low_height_condition;
|
||||
}
|
||||
|
||||
void CombinedControllerConfigurationHandler::resetLastPublishTime()
|
||||
{
|
||||
_time_last_longitudinal_publish = _time_last_lateral_publish = 0;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @file CombinedControllerConfigurationHandler.hpp
|
||||
*/
|
||||
#ifndef PX4_CONTROLLERCONFIGURATIONHANDLER_HPP
|
||||
#define PX4_CONTROLLERCONFIGURATIONHANDLER_HPP
|
||||
|
||||
#include <uORB/topics/longitudinal_control_configuration.h>
|
||||
#include <uORB/topics/lateral_control_configuration.h>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <lib/mathlib/mathlib.h>
|
||||
|
||||
static constexpr longitudinal_control_configuration_s empty_longitudinal_control_configuration = {.timestamp = 0, .pitch_min = NAN, .pitch_max = NAN, .throttle_min = NAN, .throttle_max = NAN, .climb_rate_target = NAN, .sink_rate_target = NAN, .speed_weight = NAN, .enforce_low_height_condition = false, .disable_underspeed_protection = false };
|
||||
static constexpr lateral_control_configuration_s empty_lateral_control_configuration = {.timestamp = 0, .lateral_accel_max = NAN};
|
||||
|
||||
|
||||
class CombinedControllerConfigurationHandler
|
||||
{
|
||||
public:
|
||||
CombinedControllerConfigurationHandler() = default;
|
||||
~CombinedControllerConfigurationHandler() = default;
|
||||
|
||||
void update(const hrt_abstime now);
|
||||
|
||||
void setEnforceLowHeightCondition(bool low_height_condition);
|
||||
|
||||
void setThrottleMax(float throttle_max);
|
||||
|
||||
void setThrottleMin(float throttle_min);
|
||||
|
||||
void setSpeedWeight(float speed_weight);
|
||||
|
||||
void setPitchMin(const float pitch_min);
|
||||
|
||||
void setPitchMax(const float pitch_max);
|
||||
|
||||
void setClimbRateTarget(float climbrate_target);
|
||||
|
||||
void setDisableUnderspeedProtection(bool disable);
|
||||
|
||||
void setSinkRateTarget(const float sinkrate_target);
|
||||
|
||||
void setLateralAccelMax(float lateral_accel_max);
|
||||
|
||||
void resetLastPublishTime();
|
||||
|
||||
private:
|
||||
bool booleanValueChanged(bool new_value, bool current_value)
|
||||
{
|
||||
return current_value != new_value;
|
||||
}
|
||||
|
||||
bool floatValueChanged(float new_value, float current_value)
|
||||
{
|
||||
bool diff;
|
||||
|
||||
if (PX4_ISFINITE(new_value)) {
|
||||
diff = PX4_ISFINITE(current_value) ? (fabsf(new_value - current_value) > FLT_EPSILON) : true;
|
||||
|
||||
} else {
|
||||
diff = PX4_ISFINITE(current_value);
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
bool _lateral_updated{false};
|
||||
bool _longitudinal_updated{false};
|
||||
|
||||
hrt_abstime _time_last_longitudinal_publish{0};
|
||||
hrt_abstime _time_last_lateral_publish{0};
|
||||
|
||||
uORB::PublicationData<lateral_control_configuration_s> _lateral_publisher{ORB_ID(lateral_control_configuration)};
|
||||
uORB::PublicationData<longitudinal_control_configuration_s> _longitudinal_publisher{ORB_ID(longitudinal_control_configuration)};
|
||||
|
||||
lateral_control_configuration_s _lateral_configuration_current_cycle{empty_lateral_control_configuration};
|
||||
longitudinal_control_configuration_s _longitudinal_configuration_current_cycle {empty_longitudinal_control_configuration};
|
||||
};
|
||||
|
||||
#endif //PX4_CONTROLLERCONFIGURATIONHANDLER_HPP
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,689 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2013-2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @file FixedWingGuidanceControl.hpp
|
||||
* Implementation of various fixed-wing control modes.
|
||||
*/
|
||||
|
||||
#ifndef FIXEDWINGGUIDANCECONTROL_HPP_
|
||||
#define FIXEDWINGGUIDANCECONTROL_HPP_
|
||||
|
||||
#include "ControllerConfigurationHandler.hpp"
|
||||
|
||||
#include <float.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/geo/geo.h>
|
||||
#include <lib/atmosphere/atmosphere.h>
|
||||
#include <lib/npfg/DirectionalGuidance.hpp>
|
||||
#include <lib/mathlib/mathlib.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <lib/sticks/Sticks.hpp>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <px4_platform_common/module.h>
|
||||
#include <px4_platform_common/module_params.h>
|
||||
#include <px4_platform_common/posix.h>
|
||||
#include <px4_platform_common/px4_work_queue/WorkItem.hpp>
|
||||
#include <uORB/uORB.h>
|
||||
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/SubscriptionCallback.hpp>
|
||||
#include <uORB/topics/airspeed_validated.h>
|
||||
#include <uORB/topics/fixed_wing_lateral_setpoint.h>
|
||||
#include <uORB/topics/fixed_wing_lateral_guidance_status.h>
|
||||
#include <uORB/topics/fixed_wing_longitudinal_setpoint.h>
|
||||
#include <uORB/topics/fixed_wing_runway_control.h>
|
||||
#include <uORB/topics/landing_gear.h>
|
||||
#include <uORB/topics/launch_detection_status.h>
|
||||
#include <uORB/topics/normalized_unsigned_setpoint.h>
|
||||
#include <uORB/topics/parameter_update.h>
|
||||
#include <uORB/topics/position_controller_landing_status.h>
|
||||
#include <uORB/topics/position_controller_status.h>
|
||||
#include <uORB/topics/position_setpoint_triplet.h>
|
||||
#include <uORB/topics/trajectory_setpoint.h>
|
||||
#include <uORB/topics/vehicle_angular_velocity.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/vehicle_command.h>
|
||||
#include <uORB/topics/vehicle_control_mode.h>
|
||||
#include <uORB/topics/vehicle_global_position.h>
|
||||
#include <uORB/topics/vehicle_land_detected.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/vehicle_local_position_setpoint.h>
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
#include <uORB/topics/wind.h>
|
||||
#include <uORB/topics/orbit_status.h>
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
using matrix::Vector2d;
|
||||
using matrix::Vector2f;
|
||||
|
||||
// [m] initial distance of waypoint in front of plane in heading hold mode
|
||||
static constexpr float HDG_HOLD_DIST_NEXT = 3000.0f;
|
||||
|
||||
// [rad/s] max yawrate at which plane locks yaw for heading hold mode
|
||||
static constexpr float HDG_HOLD_YAWRATE_THRESH = 0.15f;
|
||||
|
||||
// [.] max manual roll/yaw normalized input from user which does not change the locked heading
|
||||
static constexpr float HDG_HOLD_MAN_INPUT_THRESH = 0.01f;
|
||||
|
||||
// [us] time after which we abort landing if terrain estimate is not valid. this timer start whenever the terrain altitude
|
||||
// was previously valid, and has changed to invalid.
|
||||
static constexpr hrt_abstime TERRAIN_ALT_TIMEOUT = 1_s;
|
||||
|
||||
// [us] within this timeout, if a distance sensor measurement not yet made, the land waypoint altitude is used for terrain
|
||||
// altitude. this timer starts at the beginning of the landing glide slope.
|
||||
static constexpr hrt_abstime TERRAIN_ALT_FIRST_MEASUREMENT_TIMEOUT = 10_s;
|
||||
|
||||
// [.] max throttle from user which will not lead to motors spinning up in altitude controlled modes
|
||||
static constexpr float THROTTLE_THRESH = -.9f;
|
||||
|
||||
// [us] time after which the wind estimate is disabled if no longer updating
|
||||
static constexpr hrt_abstime WIND_EST_TIMEOUT = 10_s;
|
||||
|
||||
// [s] minimum time step between auto control updates
|
||||
static constexpr float MIN_AUTO_TIMESTEP = 0.01f;
|
||||
|
||||
// [s] maximum time step between auto control updates
|
||||
static constexpr float MAX_AUTO_TIMESTEP = 0.05f;
|
||||
|
||||
// [rad] minimum pitch while airspeed has not yet reached a controllable value in manual position controlled takeoff modes
|
||||
static constexpr float MIN_PITCH_DURING_MANUAL_TAKEOFF = 0.0f;
|
||||
|
||||
// [m] arbitrary buffer altitude added to clearance altitude setpoint during takeoff to ensure aircraft passes the clearance
|
||||
// altitude while waiting for navigator to flag it exceeded
|
||||
static constexpr float kClearanceAltitudeBuffer = 10.0f;
|
||||
|
||||
// [m/s] maximum rate at which the touchdown position can be nudged
|
||||
static constexpr float MAX_TOUCHDOWN_POSITION_NUDGE_RATE = 4.0f;
|
||||
|
||||
// [.] normalized deadzone threshold for manual nudging input
|
||||
static constexpr float MANUAL_TOUCHDOWN_NUDGE_INPUT_DEADZONE = 0.15f;
|
||||
|
||||
// [s] time interval after touchdown for ramping in runway clamping constraints (touchdown is assumed at FW_LND_TD_TIME after start of flare)
|
||||
static constexpr float POST_TOUCHDOWN_CLAMP_TIME = 0.5f;
|
||||
|
||||
// [] Stick deadzon
|
||||
static constexpr float kStickDeadBand = 0.06f;
|
||||
|
||||
class FixedWingGuidanceControl final : public ModuleBase<FixedWingGuidanceControl>, public ModuleParams,
|
||||
public px4::WorkItem
|
||||
{
|
||||
public:
|
||||
FixedWingGuidanceControl();
|
||||
~FixedWingGuidanceControl() override;
|
||||
|
||||
/** @see ModuleBase */
|
||||
static int task_spawn(int argc, char *argv[]);
|
||||
|
||||
/** @see ModuleBase */
|
||||
static int custom_command(int argc, char *argv[]);
|
||||
|
||||
/** @see ModuleBase */
|
||||
static int print_usage(const char *reason = nullptr);
|
||||
|
||||
bool init();
|
||||
|
||||
private:
|
||||
void Run() override;
|
||||
|
||||
uORB::SubscriptionCallbackWorkItem _local_pos_sub{this, ORB_ID(vehicle_local_position)};
|
||||
|
||||
uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
|
||||
|
||||
uORB::Subscription _airspeed_validated_sub{ORB_ID(airspeed_validated)};
|
||||
uORB::Subscription _wind_sub{ORB_ID(wind)};
|
||||
uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)};
|
||||
uORB::Subscription _global_pos_sub{ORB_ID(vehicle_global_position)};
|
||||
uORB::Subscription _pos_sp_triplet_sub{ORB_ID(position_setpoint_triplet)};
|
||||
uORB::Subscription _trajectory_setpoint_sub{ORB_ID(trajectory_setpoint)};
|
||||
uORB::Subscription _vehicle_angular_velocity_sub{ORB_ID(vehicle_angular_velocity)};
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _vehicle_command_sub{ORB_ID(vehicle_command)};
|
||||
uORB::Subscription _vehicle_land_detected_sub{ORB_ID(vehicle_land_detected)};
|
||||
uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)};
|
||||
|
||||
uORB::Publication<vehicle_local_position_setpoint_s> _local_pos_sp_pub{ORB_ID(vehicle_local_position_setpoint)};
|
||||
uORB::Publication<position_controller_landing_status_s> _pos_ctrl_landing_status_pub{ORB_ID(position_controller_landing_status)};
|
||||
uORB::Publication<launch_detection_status_s> _launch_detection_status_pub{ORB_ID(launch_detection_status)};
|
||||
uORB::PublicationMulti<orbit_status_s> _orbit_status_pub{ORB_ID(orbit_status)};
|
||||
uORB::Publication<landing_gear_s> _landing_gear_pub {ORB_ID(landing_gear)};
|
||||
uORB::Publication<normalized_unsigned_setpoint_s> _flaps_setpoint_pub{ORB_ID(flaps_setpoint)};
|
||||
uORB::Publication<normalized_unsigned_setpoint_s> _spoilers_setpoint_pub{ORB_ID(spoilers_setpoint)};
|
||||
uORB::PublicationData<fixed_wing_lateral_setpoint_s> _lateral_ctrl_sp_pub{ORB_ID(fixed_wing_lateral_setpoint)};
|
||||
uORB::PublicationData<fixed_wing_longitudinal_setpoint_s> _longitudinal_ctrl_sp_pub{ORB_ID(fixed_wing_longitudinal_setpoint)};
|
||||
uORB::Publication<fixed_wing_lateral_guidance_status_s> _fixed_wing_lateral_guidance_status_pub{ORB_ID(fixed_wing_lateral_guidance_status)};
|
||||
uORB::Publication<fixed_wing_runway_control_s> _fixed_wing_runway_control_pub{ORB_ID(fixed_wing_runway_control)};
|
||||
|
||||
position_setpoint_triplet_s _pos_sp_triplet{};
|
||||
vehicle_control_mode_s _control_mode{};
|
||||
vehicle_local_position_s _local_pos{};
|
||||
vehicle_status_s _vehicle_status{};
|
||||
|
||||
CombinedControllerConfigurationHandler _ctrl_configuration_handler;
|
||||
|
||||
Vector2f _lpos_where_backtrans_started;
|
||||
|
||||
bool _position_setpoint_previous_valid{false};
|
||||
bool _position_setpoint_current_valid{false};
|
||||
bool _position_setpoint_next_valid{false};
|
||||
|
||||
perf_counter_t _loop_perf; // loop performance counter
|
||||
|
||||
// [us] Last absolute time position control has been called
|
||||
hrt_abstime _last_time_position_control_called{0};
|
||||
|
||||
uint8_t _position_sp_type{0};
|
||||
|
||||
enum FW_POSCTRL_MODE {
|
||||
FW_POSCTRL_MODE_AUTO,
|
||||
FW_POSCTRL_MODE_AUTO_ALTITUDE,
|
||||
FW_POSCTRL_MODE_AUTO_CLIMBRATE,
|
||||
FW_POSCTRL_MODE_AUTO_TAKEOFF,
|
||||
FW_POSCTRL_MODE_AUTO_TAKEOFF_NO_NAV,
|
||||
FW_POSCTRL_MODE_AUTO_LANDING_STRAIGHT,
|
||||
FW_POSCTRL_MODE_AUTO_LANDING_CIRCULAR,
|
||||
FW_POSCTRL_MODE_AUTO_PATH,
|
||||
FW_POSCTRL_MODE_MANUAL_POSITION,
|
||||
FW_POSCTRL_MODE_MANUAL_ALTITUDE,
|
||||
FW_POSCTRL_MODE_TRANSITION_TO_HOVER_LINE_FOLLOW,
|
||||
FW_POSCTRL_MODE_TRANSITION_TO_HOVER_HEADING_HOLD,
|
||||
FW_POSCTRL_MODE_OTHER
|
||||
} _control_mode_current{FW_POSCTRL_MODE_OTHER}; // used to check if the mode has changed
|
||||
|
||||
enum StickConfig {
|
||||
STICK_CONFIG_SWAP_STICKS_BIT = (1 << 0),
|
||||
STICK_CONFIG_ENABLE_AIRSPEED_SP_MANUAL_BIT = (1 << 1)
|
||||
};
|
||||
|
||||
|
||||
Sticks _sticks{this};
|
||||
|
||||
// VEHICLE STATES
|
||||
|
||||
double _current_latitude{0};
|
||||
double _current_longitude{0};
|
||||
float _current_altitude{0.f};
|
||||
|
||||
float _yaw{0.0f};
|
||||
float _yawrate{0.0f};
|
||||
|
||||
float _body_acceleration_x{0.f};
|
||||
float _body_velocity_x{0.f};
|
||||
|
||||
MapProjection _global_local_proj_ref{};
|
||||
|
||||
float _reference_altitude{NAN}; // [m AMSL] altitude of the local projection reference point
|
||||
|
||||
bool _landed{true};
|
||||
|
||||
// MANUAL MODES
|
||||
|
||||
// indicates whether we have completed a manual takeoff in a position control mode
|
||||
bool _completed_manual_takeoff{false};
|
||||
|
||||
// [rad] yaw setpoint for manual position mode heading hold
|
||||
float _hdg_hold_yaw{0.0f};
|
||||
|
||||
bool _hdg_hold_enabled{false}; // heading hold enabled
|
||||
bool _yaw_lock_engaged{false}; // yaw is locked for heading hold
|
||||
|
||||
Vector2f _hdg_hold_position{}; // position where heading hold started
|
||||
|
||||
// [.] normalized setpoint for manual altitude control [-1,1]; -1,0,1 maps to min,zero,max height rate commands
|
||||
float _manual_control_setpoint_for_height_rate{0.0f};
|
||||
|
||||
// [.] normalized setpoint for manual airspeed control [-1,1]; -1,0,1 maps to min,cruise,max airspeed commands
|
||||
float _manual_control_setpoint_for_airspeed{0.0f};
|
||||
|
||||
// [m/s] airspeed setpoint for manual modes commanded via MAV_CMD_DO_CHANGE_SPEED
|
||||
float _commanded_manual_airspeed_setpoint{NAN};
|
||||
|
||||
// AUTO TAKEOFF
|
||||
|
||||
// [m] ground altitude AMSL where the plane was launched
|
||||
float _takeoff_ground_alt{0.0f};
|
||||
|
||||
// true if a launch, specifically using the launch detector, has been detected
|
||||
bool _launch_detected{false};
|
||||
|
||||
// [deg] global position of the vehicle at the time launch is detected (using launch detector) or takeoff is started (runway)
|
||||
Vector2d _takeoff_init_position{0, 0};
|
||||
|
||||
// [rad] current vehicle yaw at the time the launch is detected
|
||||
float _launch_current_yaw{0.f};
|
||||
|
||||
bool _skipping_takeoff_detection{false};
|
||||
|
||||
// AUTO LANDING
|
||||
|
||||
// corresponds to param FW_LND_NUDGE
|
||||
enum LandingNudgingOption {
|
||||
kNudgingDisabled = 0,
|
||||
kNudgeApproachAngle,
|
||||
kNudgeApproachPath
|
||||
};
|
||||
|
||||
// [us] Start time of the landing approach. If a fixed-wing landing pattern is used, this timer starts *after any
|
||||
// orbit to altitude only when the aircraft has entered the final *straight approach.
|
||||
hrt_abstime _time_started_landing{0};
|
||||
|
||||
// [m] lateral touchdown position offset manually commanded during landing
|
||||
float _lateral_touchdown_position_offset{0.0f};
|
||||
|
||||
// [m] relative vector from land point to approach entrance (NE)
|
||||
Vector2f _landing_approach_entrance_offset_vector{};
|
||||
|
||||
// [m] relative height above land point
|
||||
float _landing_approach_entrance_rel_alt{0.0f};
|
||||
|
||||
uint8_t _landing_abort_status{position_controller_landing_status_s::NOT_ABORTED};
|
||||
|
||||
// organize flare states XXX: need to split into a separate class at some point!
|
||||
struct FlareStates {
|
||||
bool flaring{false};
|
||||
hrt_abstime start_time{0}; // [us]
|
||||
float initial_height_rate_setpoint{0.0f}; // [m/s]
|
||||
} _flare_states;
|
||||
|
||||
// [m] last terrain estimate which was valid
|
||||
float _last_valid_terrain_alt_estimate{0.0f};
|
||||
|
||||
// [us] time at which we had last valid terrain alt
|
||||
hrt_abstime _last_time_terrain_alt_was_valid{0};
|
||||
|
||||
enum TerrainEstimateUseOnLanding {
|
||||
kDisableTerrainEstimation = 0,
|
||||
kTriggerFlareWithTerrainEstimate,
|
||||
kFollowTerrainRelativeLandingGlideSlope
|
||||
};
|
||||
|
||||
// AIRSPEED
|
||||
|
||||
float _airspeed_eas{0.f};
|
||||
bool _airspeed_valid{false};
|
||||
|
||||
// [us] last time airspeed was received. used to detect timeouts.
|
||||
hrt_abstime _time_airspeed_last_valid{0};
|
||||
|
||||
// WIND
|
||||
|
||||
// [m/s] wind velocity vector
|
||||
Vector2f _wind_vel{0.0f, 0.0f};
|
||||
|
||||
bool _wind_valid{false};
|
||||
|
||||
hrt_abstime _time_wind_last_received{0}; // [us]
|
||||
|
||||
// VTOL / TRANSITION
|
||||
matrix::Vector2d _transition_waypoint{(double)NAN, (double)NAN};
|
||||
float _backtrans_heading{NAN}; // used to lock the initial heading for backtransition with no position control
|
||||
|
||||
// ESTIMATOR RESET COUNTERS
|
||||
uint8_t _xy_reset_counter{0};
|
||||
uint64_t _time_last_xy_reset{0};
|
||||
|
||||
// LATERAL-DIRECTIONAL GUIDANCE
|
||||
|
||||
// CLosest point on path to track
|
||||
matrix::Vector2f _closest_point_on_path;
|
||||
|
||||
// nonlinear path following guidance - lateral-directional position control
|
||||
DirectionalGuidance _directional_guidance;
|
||||
|
||||
// LANDING GEAR
|
||||
int8_t _new_landing_gear_position{landing_gear_s::GEAR_KEEP};
|
||||
|
||||
// FLAPS/SPOILERS
|
||||
float _flaps_setpoint{0.f};
|
||||
float _spoilers_setpoint{0.f};
|
||||
|
||||
hrt_abstime _time_in_fixed_bank_loiter{0}; // [us]
|
||||
float _min_current_sp_distance_xy{FLT_MAX};
|
||||
|
||||
// Update our local parameter cache.
|
||||
void parameters_update();
|
||||
|
||||
// Update subscriptions
|
||||
void airspeed_poll();
|
||||
|
||||
void manual_control_setpoint_poll();
|
||||
void vehicle_attitude_poll();
|
||||
void vehicle_command_poll();
|
||||
void vehicle_control_mode_poll();
|
||||
|
||||
void wind_poll(const hrt_abstime now);
|
||||
|
||||
void landing_status_publish();
|
||||
|
||||
void publishLocalPositionSetpoint(const position_setpoint_s ¤t_waypoint);
|
||||
|
||||
/**
|
||||
* @brief Sets the landing abort status and publishes landing status.
|
||||
*
|
||||
* @param new_abort_status Either 0 (not aborted) or the singular bit >0 which triggered the abort
|
||||
*/
|
||||
void updateLandingAbortStatus(const uint8_t new_abort_status = position_controller_landing_status_s::NOT_ABORTED);
|
||||
|
||||
/**
|
||||
* @brief Checks if the automatic abort bitmask (from FW_LND_ABORT) contains the given abort criterion.
|
||||
*
|
||||
* @param automatic_abort_criteria_bitmask Bitmask containing all active abort criteria
|
||||
* @param landing_abort_criterion The specifc criterion we are checking for
|
||||
* @return true if the bitmask contains the criterion
|
||||
*/
|
||||
bool checkLandingAbortBitMask(const uint8_t automatic_abort_criteria_bitmask, uint8_t landing_abort_criterion);
|
||||
|
||||
/**
|
||||
* @brief Maps the manual control setpoint (pilot sticks) to height rate commands
|
||||
*
|
||||
* @return Manual height rate setpoint [m/s]
|
||||
*/
|
||||
float getManualHeightRateSetpoint();
|
||||
|
||||
/**
|
||||
* @brief Updates a state indicating whether a manual takeoff has been completed.
|
||||
*
|
||||
* Criteria include passing an airspeed threshold and not being in a landed state. VTOL airframes always pass.
|
||||
*/
|
||||
void updateManualTakeoffStatus();
|
||||
|
||||
/**
|
||||
* @brief Updates timing information for landed and in-air states.
|
||||
*
|
||||
* @param now Current system time [us]
|
||||
*/
|
||||
void update_in_air_states(const hrt_abstime now);
|
||||
|
||||
/**
|
||||
* @brief Moves the current position setpoint to a value far ahead of the current vehicle yaw when in a VTOL
|
||||
* transition.
|
||||
*
|
||||
* @param[in,out] current_sp Current position setpoint
|
||||
*/
|
||||
void move_position_setpoint_for_vtol_transition(position_setpoint_s ¤t_sp);
|
||||
|
||||
/**
|
||||
* @brief Changes the position setpoint type to achieve the desired behavior in some instances.
|
||||
*
|
||||
* @param pos_sp_curr Current position setpoint
|
||||
* @return Adjusted position setpoint type
|
||||
*/
|
||||
uint8_t handle_setpoint_type(const position_setpoint_s &pos_sp_curr,
|
||||
const position_setpoint_s &pos_sp_next);
|
||||
|
||||
/* automatic control methods */
|
||||
|
||||
float get_manual_airspeed_setpoint();
|
||||
|
||||
void reset_takeoff_state();
|
||||
void reset_landing_state();
|
||||
|
||||
/**
|
||||
* @brief Decides which control mode to execute.
|
||||
*
|
||||
* May also change the position setpoint type depending on the desired behavior.
|
||||
*
|
||||
* @param now Current system time [us]
|
||||
*/
|
||||
// void set_control_mode_current(const hrt_abstime &now);
|
||||
|
||||
void publishOrbitStatus(const position_setpoint_s pos_sp);
|
||||
|
||||
float getMaxRollAngleNearGround(const float altitude, const float terrain_altitude) const;
|
||||
|
||||
/**
|
||||
* @brief Calculates the touchdown position for landing with optional manual lateral adjustments.
|
||||
*
|
||||
* Manual inputs (from the remote) are used to command a rate at which the position moves and the integrated
|
||||
* position is bounded. This is useful for manually adjusting the landing point in real time when map or GNSS
|
||||
* errors cause an offset from the desired landing vector.
|
||||
*
|
||||
* @param control_interval Time since the last position control update [s]
|
||||
* @param local_land_position Originally commanded local land position (NE) [m]
|
||||
* @return (Nudged) Local touchdown position (NE) [m]
|
||||
*/
|
||||
Vector2f calculateTouchdownPosition(const float control_interval, const Vector2f &local_land_position);
|
||||
|
||||
/**
|
||||
* @brief Calculates the vector from landing approach entrance to touchdown point
|
||||
*
|
||||
* NOTE: calculateTouchdownPosition() MUST be called before this method
|
||||
*
|
||||
* @return Landing approach vector [m]
|
||||
*/
|
||||
Vector2f calculateLandingApproachVector() const;
|
||||
|
||||
/**
|
||||
* @brief Returns a terrain altitude estimate with consideration of altimeter measurements.
|
||||
*
|
||||
* @param now Current system time [us]
|
||||
* @param land_point_altitude Altitude (AMSL) of the land point [m]
|
||||
* @param abort_on_terrain_measurement_timeout Abort if distance to ground estimation doesn't get valid when we expect it to
|
||||
* @param abort_on_terrain_timeout Abort if distance to ground estimation is invalid after being valid before
|
||||
* @return Terrain altitude (AMSL) [m]
|
||||
*/
|
||||
float getLandingTerrainAltitudeEstimate(const hrt_abstime &now, const float land_point_altitude,
|
||||
const bool abort_on_terrain_measurement_timeout, const bool abort_on_terrain_timeout);
|
||||
|
||||
/**
|
||||
* @brief Initializes landing states
|
||||
*
|
||||
* @param now Current system time [us]
|
||||
* @param pos_sp_prev Previous position setpoint
|
||||
* @param land_point_alt Landing point altitude setpoint AMSL [m]
|
||||
* @param local_position Local aircraft position (NE) [m]
|
||||
* @param local_land_point Local land point (NE) [m]
|
||||
*/
|
||||
void initializeAutoLanding(const hrt_abstime &now, const position_setpoint_s &pos_sp_prev,
|
||||
const float land_point_alt, const Vector2f &local_position, const Vector2f &local_land_point);
|
||||
|
||||
/*
|
||||
* Waypoint handling logic following closely to the ECL_L1_Pos_Controller
|
||||
* method of the same name. Takes two waypoints, steering the vehicle to track
|
||||
* the line segment between them.
|
||||
*
|
||||
* @param[in] start_waypoint Segment starting position in local coordinates. (N,E) [m]
|
||||
* @param[in] end_waypoint Segment end position in local coordinates. (N,E) [m]
|
||||
* @param[in] vehicle_pos Vehicle position in local coordinates. (N,E) [m]
|
||||
* @param[in] ground_vel Vehicle ground velocity vector [m/s]
|
||||
* @param[in] wind_vel Wind velocity vector [m/s]
|
||||
*/
|
||||
DirectionalGuidanceOutput navigateWaypoints(const matrix::Vector2f &start_waypoint,
|
||||
const matrix::Vector2f &end_waypoint,
|
||||
const matrix::Vector2f &vehicle_pos, const matrix::Vector2f &ground_vel,
|
||||
const matrix::Vector2f &wind_vel);
|
||||
|
||||
/*
|
||||
* Takes one waypoint and steers the vehicle towards this.
|
||||
*
|
||||
* NOTE: this *will lead to "flowering" behavior if no higher level state machine or
|
||||
* switching condition changes the waypoint.
|
||||
*
|
||||
* @param[in] waypoint_pos Waypoint position in local coordinates. (N,E) [m]
|
||||
* @param[in] vehicle_pos Vehicle position in local coordinates. (N,E) [m]
|
||||
* @param[in] ground_vel Vehicle ground velocity vector [m/s]
|
||||
* @param[in] wind_vel Wind velocity vector [m/s]
|
||||
*/
|
||||
DirectionalGuidanceOutput navigateWaypoint(const matrix::Vector2f &waypoint_pos, const matrix::Vector2f &vehicle_pos,
|
||||
const matrix::Vector2f &ground_vel, const matrix::Vector2f &wind_vel);
|
||||
|
||||
/*
|
||||
* Line (infinite) following logic. Two points on the line are used to define the
|
||||
* line in 2D space (first to second point determines the direction). Determines the
|
||||
* relevant parameters for evaluating the NPFG guidance law, then updates control setpoints.
|
||||
*
|
||||
* @param[in] point_on_line_1 Arbitrary first position on line in local coordinates. (N,E) [m]
|
||||
* @param[in] point_on_line_2 Arbitrary second position on line in local coordinates. (N,E) [m]
|
||||
* @param[in] vehicle_pos Vehicle position in local coordinates. (N,E) [m]
|
||||
* @param[in] ground_vel Vehicle ground velocity vector [m/s]
|
||||
* @param[in] wind_vel Wind velocity vector [m/s]
|
||||
*/
|
||||
DirectionalGuidanceOutput navigateLine(const Vector2f &point_on_line_1, const Vector2f &point_on_line_2,
|
||||
const Vector2f &vehicle_pos,
|
||||
const Vector2f &ground_vel, const Vector2f &wind_vel);
|
||||
|
||||
/*
|
||||
* Line (infinite) following logic. One point on the line and a line bearing are used to define
|
||||
* the line in 2D space. Determines the relevant parameters for evaluating the NPFG guidance law,
|
||||
* then updates control setpoints.
|
||||
*
|
||||
* @param[in] point_on_line Arbitrary position on line in local coordinates. (N,E) [m]
|
||||
* @param[in] line_bearing Line bearing [rad] (from north)
|
||||
* @param[in] vehicle_pos Vehicle position in local coordinates. (N,E) [m]
|
||||
* @param[in] ground_vel Vehicle ground velocity vector [m/s]
|
||||
* @param[in] wind_vel Wind velocity vector [m/s]
|
||||
*/
|
||||
DirectionalGuidanceOutput navigateLine(const Vector2f &point_on_line, const float line_bearing,
|
||||
const Vector2f &vehicle_pos,
|
||||
const Vector2f &ground_vel, const Vector2f &wind_vel);
|
||||
|
||||
/*
|
||||
* Loitering (unlimited) logic. Takes loiter center, radius, and direction and
|
||||
* determines the relevant parameters for evaluating the NPFG guidance law,
|
||||
* then updates control setpoints.
|
||||
*
|
||||
* @param[in] loiter_center The position of the center of the loiter circle [m]
|
||||
* @param[in] vehicle_pos Vehicle position in local coordinates. (N,E) [m]
|
||||
* @param[in] radius Loiter radius [m]
|
||||
* @param[in] loiter_direction_counter_clockwise Specifies loiter direction
|
||||
* @param[in] ground_vel Vehicle ground velocity vector [m/s]
|
||||
* @param[in] wind_vel Wind velocity vector [m/s]
|
||||
*/
|
||||
DirectionalGuidanceOutput navigateLoiter(const matrix::Vector2f &loiter_center, const matrix::Vector2f &vehicle_pos,
|
||||
float radius, bool loiter_direction_counter_clockwise, const matrix::Vector2f &ground_vel,
|
||||
const matrix::Vector2f &wind_vel);
|
||||
|
||||
/*
|
||||
* Path following logic. Takes poisiton, path tangent, curvature and
|
||||
* then updates control setpoints to follow a path setpoint.
|
||||
*
|
||||
* TODO: deprecate this function with a proper API to NPFG.
|
||||
*
|
||||
* @param[in] vehicle_pos vehicle_pos Vehicle position in local coordinates. (N,E) [m]
|
||||
* @param[in] position_setpoint closest point on a path in local coordinates. (N,E) [m]
|
||||
* @param[in] tangent_setpoint unit tangent vector of the path [m]
|
||||
* @param[in] ground_vel Vehicle ground velocity vector [m/s]
|
||||
* @param[in] wind_vel Wind velocity vector [m/s]
|
||||
* @param[in] curvature of the path setpoint [1/m]
|
||||
*/
|
||||
DirectionalGuidanceOutput navigatePathTangent(const matrix::Vector2f &vehicle_pos,
|
||||
const matrix::Vector2f &position_setpoint,
|
||||
const matrix::Vector2f &tangent_setpoint,
|
||||
const matrix::Vector2f &ground_vel, const matrix::Vector2f &wind_vel, const float &curvature);
|
||||
|
||||
/*
|
||||
* Navigate on a fixed bearing.
|
||||
*
|
||||
* This only holds a certain (ground relative) direction and does not perform
|
||||
* cross track correction. Helpful for semi-autonomous modes.
|
||||
*
|
||||
* @param[in] vehicle_pos vehicle_pos Vehicle position in local coordinates. (N,E) [m]
|
||||
* @param[in] bearing Bearing angle [rad]
|
||||
* @param[in] ground_vel Vehicle ground velocity vector [m/s]
|
||||
* @param[in] wind_vel Wind velocity vector [m/s]
|
||||
*/
|
||||
DirectionalGuidanceOutput navigateBearing(const matrix::Vector2f &vehicle_pos, float bearing,
|
||||
const matrix::Vector2f &ground_vel,
|
||||
const matrix::Vector2f &wind_vel);
|
||||
|
||||
void control_idle();
|
||||
void publish_lateral_guidance_status(const hrt_abstime now);
|
||||
|
||||
float rollAngleToLateralAccel(float roll_body) const;
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::FW_R_LIM>) _param_fw_r_lim,
|
||||
|
||||
(ParamFloat<px4::params::NPFG_PERIOD>) _param_npfg_period,
|
||||
(ParamFloat<px4::params::NPFG_DAMPING>) _param_npfg_damping,
|
||||
(ParamBool<px4::params::NPFG_LB_PERIOD>) _param_npfg_en_period_lb,
|
||||
(ParamBool<px4::params::NPFG_UB_PERIOD>) _param_npfg_en_period_ub,
|
||||
(ParamFloat<px4::params::NPFG_ROLL_TC>) _param_npfg_roll_time_const,
|
||||
(ParamFloat<px4::params::NPFG_SW_DST_MLT>) _param_npfg_switch_distance_multiplier,
|
||||
(ParamFloat<px4::params::NPFG_PERIOD_SF>) _param_npfg_period_safety_factor,
|
||||
|
||||
(ParamFloat<px4::params::FW_LND_AIRSPD>) _param_fw_lnd_airspd,
|
||||
(ParamFloat<px4::params::FW_LND_ANG>) _param_fw_lnd_ang,
|
||||
(ParamFloat<px4::params::FW_LND_FL_PMAX>) _param_fw_lnd_fl_pmax,
|
||||
(ParamFloat<px4::params::FW_LND_FL_PMIN>) _param_fw_lnd_fl_pmin,
|
||||
(ParamFloat<px4::params::FW_LND_FLALT>) _param_fw_lnd_flalt,
|
||||
(ParamBool<px4::params::FW_LND_EARLYCFG>) _param_fw_lnd_earlycfg,
|
||||
(ParamInt<px4::params::FW_LND_USETER>) _param_fw_lnd_useter,
|
||||
|
||||
(ParamFloat<px4::params::FW_P_LIM_MAX>) _param_fw_p_lim_max,
|
||||
(ParamFloat<px4::params::FW_P_LIM_MIN>) _param_fw_p_lim_min,
|
||||
(ParamFloat<px4::params::FW_T_CLMB_R_SP>) _param_climbrate_target,
|
||||
(ParamFloat<px4::params::FW_T_SINK_R_SP>) _param_sinkrate_target,
|
||||
(ParamFloat<px4::params::FW_THR_IDLE>) _param_fw_thr_idle,
|
||||
(ParamFloat<px4::params::FW_THR_MAX>) _param_fw_thr_max,
|
||||
(ParamFloat<px4::params::FW_THR_MIN>) _param_fw_thr_min,
|
||||
(ParamFloat<px4::params::FW_FLAPS_LND_SCL>) _param_fw_flaps_lnd_scl,
|
||||
(ParamFloat<px4::params::FW_FLAPS_TO_SCL>) _param_fw_flaps_to_scl,
|
||||
(ParamFloat<px4::params::FW_SPOILERS_LND>) _param_fw_spoilers_lnd,
|
||||
(ParamInt<px4::params::FW_POS_STK_CONF>) _param_fw_pos_stk_conf,
|
||||
(ParamInt<px4::params::FW_GPSF_LT>) _param_nav_gpsf_lt,
|
||||
(ParamFloat<px4::params::FW_GPSF_R>) _param_nav_gpsf_r,
|
||||
(ParamFloat<px4::params::FW_T_SPDWEIGHT>) _param_t_spdweight,
|
||||
|
||||
// external parameters
|
||||
(ParamBool<px4::params::FW_USE_AIRSPD>) _param_fw_use_airspd,
|
||||
(ParamFloat<px4::params::NAV_LOITER_RAD>) _param_nav_loiter_rad,
|
||||
(ParamFloat<px4::params::FW_TKO_PITCH_MIN>) _takeoff_pitch_min,
|
||||
(ParamFloat<px4::params::NAV_FW_ALT_RAD>) _param_nav_fw_alt_rad,
|
||||
(ParamFloat<px4::params::FW_WING_SPAN>) _param_fw_wing_span,
|
||||
(ParamFloat<px4::params::FW_WING_HEIGHT>) _param_fw_wing_height,
|
||||
(ParamBool<px4::params::RWTO_NUDGE>) _param_rwto_nudge,
|
||||
(ParamFloat<px4::params::FW_LND_FL_TIME>) _param_fw_lnd_fl_time,
|
||||
(ParamFloat<px4::params::FW_LND_FL_SINK>) _param_fw_lnd_fl_sink,
|
||||
(ParamFloat<px4::params::FW_LND_TD_TIME>) _param_fw_lnd_td_time,
|
||||
(ParamFloat<px4::params::FW_LND_TD_OFF>) _param_fw_lnd_td_off,
|
||||
(ParamInt<px4::params::FW_LND_NUDGE>) _param_fw_lnd_nudge,
|
||||
(ParamInt<px4::params::FW_LND_ABORT>) _param_fw_lnd_abort,
|
||||
(ParamFloat<px4::params::FW_TKO_AIRSPD>) _param_fw_tko_airspd,
|
||||
(ParamFloat<px4::params::RWTO_PSP>) _param_rwto_psp,
|
||||
(ParamBool<px4::params::FW_LAUN_DETCN_ON>) _param_fw_laun_detcn_on,
|
||||
(ParamFloat<px4::params::FW_AIRSPD_MAX>) _param_fw_airspd_max,
|
||||
(ParamFloat<px4::params::FW_AIRSPD_MIN>) _param_fw_airspd_min,
|
||||
(ParamFloat<px4::params::FW_AIRSPD_TRIM>) _param_fw_airspd_trim,
|
||||
(ParamFloat<px4::params::FW_T_CLMB_MAX>) _param_fw_t_clmb_max
|
||||
)
|
||||
};
|
||||
|
||||
#endif // FIXEDWINGGUIDANCECONTROL_HPP_
|
||||
@@ -0,0 +1,12 @@
|
||||
menuconfig MODULES_FW_GUIDANCE_CONTROL
|
||||
bool "fw_guidance_control"
|
||||
default n
|
||||
---help---
|
||||
Enable support for fw_guidance_control
|
||||
|
||||
menuconfig USER_FW_MODE_MANAGER
|
||||
bool "fw_guidance_control running as userspace module"
|
||||
default n
|
||||
depends on BOARD_PROTECTED && MODULES_FW_MODE_MANAGER
|
||||
---help---
|
||||
Put fw_guidance_control in userspace memory
|
||||
@@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2013-2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -1033,47 +1033,6 @@ void FixedWingModeManager::publishFigureEightStatus(const position_setpoint_s po
|
||||
}
|
||||
#endif // CONFIG_FIGURE_OF_EIGHT
|
||||
|
||||
void
|
||||
FixedWingModeManager::control_auto_path(const float control_interval, const Vector2d &curr_pos,
|
||||
const Vector2f &ground_speed, const position_setpoint_s &pos_sp_curr)
|
||||
{
|
||||
const float target_airspeed = pos_sp_curr.cruising_speed > FLT_EPSILON ? pos_sp_curr.cruising_speed : NAN;
|
||||
|
||||
Vector2f curr_pos_local{_local_pos.x, _local_pos.y};
|
||||
Vector2f curr_wp_local = _global_local_proj_ref.project(pos_sp_curr.lat, pos_sp_curr.lon);
|
||||
|
||||
// Navigate directly on position setpoint and path tangent
|
||||
const matrix::Vector2f velocity_2d(pos_sp_curr.vx, pos_sp_curr.vy);
|
||||
const float curvature = PX4_ISFINITE(_pos_sp_triplet.current.loiter_radius) ? 1 /
|
||||
_pos_sp_triplet.current.loiter_radius :
|
||||
0.0f;
|
||||
const DirectionalGuidanceOutput sp = navigatePathTangent(curr_pos_local, curr_wp_local, velocity_2d.normalized(),
|
||||
ground_speed, _wind_vel, curvature);
|
||||
|
||||
fixed_wing_lateral_setpoint_s fw_lateral_ctrl_sp{empty_lateral_control_setpoint};
|
||||
fw_lateral_ctrl_sp.timestamp = hrt_absolute_time();
|
||||
fw_lateral_ctrl_sp.course = sp.course_setpoint;
|
||||
fw_lateral_ctrl_sp.lateral_acceleration = sp.lateral_acceleration_feedforward;
|
||||
_lateral_ctrl_sp_pub.publish(fw_lateral_ctrl_sp);
|
||||
|
||||
const fixed_wing_longitudinal_setpoint_s fw_longitudinal_control_sp = {
|
||||
.timestamp = hrt_absolute_time(),
|
||||
.altitude = pos_sp_curr.alt,
|
||||
.height_rate = NAN,
|
||||
.equivalent_airspeed = target_airspeed,
|
||||
.pitch_direct = NAN,
|
||||
.throttle_direct = NAN
|
||||
};
|
||||
|
||||
_longitudinal_ctrl_sp_pub.publish(fw_longitudinal_control_sp);
|
||||
|
||||
if (pos_sp_curr.gliding_enabled) {
|
||||
_ctrl_configuration_handler.setThrottleMin(0.0f);
|
||||
_ctrl_configuration_handler.setThrottleMax(0.0f);
|
||||
_ctrl_configuration_handler.setSpeedWeight(2.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FixedWingModeManager::control_auto_takeoff(const hrt_abstime &now, const float control_interval,
|
||||
const Vector2d &global_position, const Vector2f &ground_speed, const position_setpoint_s &pos_sp_curr)
|
||||
@@ -2052,80 +2011,22 @@ FixedWingModeManager::Run()
|
||||
_local_pos.ref_timestamp);
|
||||
}
|
||||
|
||||
if (_control_mode.flag_control_offboard_enabled) {
|
||||
trajectory_setpoint_s trajectory_setpoint;
|
||||
if (_pos_sp_triplet_sub.update(&_pos_sp_triplet)) {
|
||||
|
||||
if (_trajectory_setpoint_sub.update(&trajectory_setpoint)) {
|
||||
bool valid_setpoint = false;
|
||||
_pos_sp_triplet = {}; // clear any existing
|
||||
_pos_sp_triplet.timestamp = trajectory_setpoint.timestamp;
|
||||
_pos_sp_triplet.current.timestamp = trajectory_setpoint.timestamp;
|
||||
_pos_sp_triplet.current.cruising_speed = NAN; // ignored
|
||||
_pos_sp_triplet.current.cruising_throttle = NAN; // ignored
|
||||
_pos_sp_triplet.current.vx = NAN;
|
||||
_pos_sp_triplet.current.vy = NAN;
|
||||
_pos_sp_triplet.current.vz = NAN;
|
||||
_pos_sp_triplet.current.lat = static_cast<double>(NAN);
|
||||
_pos_sp_triplet.current.lon = static_cast<double>(NAN);
|
||||
_pos_sp_triplet.current.alt = NAN;
|
||||
_position_setpoint_previous_valid = PX4_ISFINITE(_pos_sp_triplet.previous.lat)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.previous.lon)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.previous.alt);
|
||||
|
||||
if (Vector3f(trajectory_setpoint.position).isAllFinite()) {
|
||||
if (_global_local_proj_ref.isInitialized()) {
|
||||
double lat;
|
||||
double lon;
|
||||
_global_local_proj_ref.reproject(trajectory_setpoint.position[0], trajectory_setpoint.position[1], lat, lon);
|
||||
valid_setpoint = true;
|
||||
_pos_sp_triplet.current.type = position_setpoint_s::SETPOINT_TYPE_POSITION;
|
||||
_pos_sp_triplet.current.lat = lat;
|
||||
_pos_sp_triplet.current.lon = lon;
|
||||
_pos_sp_triplet.current.alt = _reference_altitude - trajectory_setpoint.position[2];
|
||||
}
|
||||
_position_setpoint_current_valid = PX4_ISFINITE(_pos_sp_triplet.current.lat)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.current.lon)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.current.alt);
|
||||
|
||||
}
|
||||
_position_setpoint_next_valid = PX4_ISFINITE(_pos_sp_triplet.next.lat)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.next.lon)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.next.alt);
|
||||
|
||||
if (Vector3f(trajectory_setpoint.velocity).isAllFinite()) {
|
||||
valid_setpoint = true;
|
||||
_pos_sp_triplet.current.type = position_setpoint_s::SETPOINT_TYPE_POSITION;
|
||||
_pos_sp_triplet.current.vx = trajectory_setpoint.velocity[0];
|
||||
_pos_sp_triplet.current.vy = trajectory_setpoint.velocity[1];
|
||||
_pos_sp_triplet.current.vz = trajectory_setpoint.velocity[2];
|
||||
|
||||
if (Vector3f(trajectory_setpoint.acceleration).isAllFinite()) {
|
||||
Vector2f velocity_sp_2d(trajectory_setpoint.velocity[0], trajectory_setpoint.velocity[1]);
|
||||
Vector2f normalized_velocity_sp_2d = velocity_sp_2d.normalized();
|
||||
Vector2f acceleration_sp_2d(trajectory_setpoint.acceleration[0], trajectory_setpoint.acceleration[1]);
|
||||
Vector2f acceleration_normal = acceleration_sp_2d - acceleration_sp_2d.dot(normalized_velocity_sp_2d) *
|
||||
normalized_velocity_sp_2d;
|
||||
float direction = -normalized_velocity_sp_2d.cross(acceleration_normal.normalized());
|
||||
_pos_sp_triplet.current.loiter_radius = direction * velocity_sp_2d.norm() * velocity_sp_2d.norm() /
|
||||
acceleration_normal.norm();
|
||||
|
||||
} else {
|
||||
_pos_sp_triplet.current.loiter_radius = NAN;
|
||||
}
|
||||
}
|
||||
|
||||
_position_setpoint_current_valid = valid_setpoint;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (_pos_sp_triplet_sub.update(&_pos_sp_triplet)) {
|
||||
|
||||
_position_setpoint_previous_valid = PX4_ISFINITE(_pos_sp_triplet.previous.lat)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.previous.lon)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.previous.alt);
|
||||
|
||||
_position_setpoint_current_valid = PX4_ISFINITE(_pos_sp_triplet.current.lat)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.current.lon)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.current.alt);
|
||||
|
||||
_position_setpoint_next_valid = PX4_ISFINITE(_pos_sp_triplet.next.lat)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.next.lon)
|
||||
&& PX4_ISFINITE(_pos_sp_triplet.next.alt);
|
||||
|
||||
// reset the altitude foh (first order hold) logic
|
||||
_min_current_sp_distance_xy = FLT_MAX;
|
||||
}
|
||||
// reset the altitude foh (first order hold) logic
|
||||
_min_current_sp_distance_xy = FLT_MAX;
|
||||
}
|
||||
|
||||
airspeed_poll();
|
||||
@@ -2211,7 +2112,6 @@ FixedWingModeManager::Run()
|
||||
}
|
||||
|
||||
case FW_POSCTRL_MODE_AUTO_PATH: {
|
||||
control_auto_path(control_interval, curr_pos, ground_speed, _pos_sp_triplet.current);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,6 @@
|
||||
#include <uORB/topics/position_controller_landing_status.h>
|
||||
#include <uORB/topics/position_controller_status.h>
|
||||
#include <uORB/topics/position_setpoint_triplet.h>
|
||||
#include <uORB/topics/trajectory_setpoint.h>
|
||||
#include <uORB/topics/vehicle_angular_velocity.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_attitude_setpoint.h>
|
||||
@@ -181,7 +180,6 @@ private:
|
||||
uORB::Subscription _control_mode_sub{ORB_ID(vehicle_control_mode)};
|
||||
uORB::Subscription _global_pos_sub{ORB_ID(vehicle_global_position)};
|
||||
uORB::Subscription _pos_sp_triplet_sub{ORB_ID(position_setpoint_triplet)};
|
||||
uORB::Subscription _trajectory_setpoint_sub{ORB_ID(trajectory_setpoint)};
|
||||
uORB::Subscription _vehicle_angular_velocity_sub{ORB_ID(vehicle_angular_velocity)};
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _vehicle_command_sub{ORB_ID(vehicle_command)};
|
||||
|
||||
Reference in New Issue
Block a user