fw pos control: revert name until we delineate this module a bit more (#21442)

This commit is contained in:
Thomas Stastny
2023-04-13 17:00:04 +02:00
committed by GitHub
parent a2ce73d39d
commit 82fd2987c9
68 changed files with 76 additions and 77 deletions
@@ -0,0 +1,36 @@
############################################################################
#
# Copyright (c) 2015 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_library(launchdetection
LaunchDetector.cpp
)
@@ -0,0 +1,121 @@
/****************************************************************************
*
* Copyright (c) 2013-2022 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 launchDetection.cpp
* Auto launch detection for catapult/hand-launch vehicles
*
* @author Thomas Gubler <thomasgubler@gmail.com>
*/
#include "LaunchDetector.h"
#include <px4_platform_common/log.h>
#include <px4_platform_common/events.h>
namespace launchdetection
{
void LaunchDetector::update(const float dt, const float accel_x)
{
switch (state_) {
case launch_detection_status_s::STATE_WAITING_FOR_LAUNCH:
info_delay_counter_s_ += dt;
/* Inform user that launchdetection is running every kInfoDelay seconds */
if (info_delay_counter_s_ >= kInfoDelay) {
events::send(events::ID("launch_detection_running_info"), events::Log::Info, "Launch detection running");
info_delay_counter_s_ = 0.f; // reset counter
}
/* Detect a acceleration that is longer and stronger as the minimum given by the params */
if (accel_x > param_fw_laun_ac_thld_.get()) {
acceleration_detected_counter_ += dt;
if (acceleration_detected_counter_ > param_fw_laun_ac_t_.get()) {
if (param_fw_laun_mot_del_.get() > 0.f) {
state_ = launch_detection_status_s::STATE_LAUNCH_DETECTED_DISABLED_MOTOR;
events::send<float>(events::ID("launch_detection_wait_for_throttle"), {events::Log::Info, events::LogInternal::Info},
"Launch detected: enablecontrol, waiting {1:.1}s until full throttle", (double)param_fw_laun_mot_del_.get());
} else {
/* No motor delay set: go directly to enablemotors state */
state_ = launch_detection_status_s::STATE_FLYING;
events::send(events::ID("launch_detection_no_motor_delay"), {events::Log::Info, events::LogInternal::Info},
"Launch detected: enable motors (no motor delay)");
}
}
} else {
acceleration_detected_counter_ = 0.f;
}
break;
case launch_detection_status_s::STATE_LAUNCH_DETECTED_DISABLED_MOTOR:
/* Vehicle is currently controlling attitude but at idle throttle. Waiting until delay is
* over to allow full throttle */
motor_delay_counter_ += dt;
if (motor_delay_counter_ > param_fw_laun_mot_del_.get()) {
events::send(events::ID("launch_detection_enable_motors"), {events::Log::Info, events::LogInternal::Info},
"Launch detected: enable motors");
state_ = launch_detection_status_s::STATE_FLYING;
}
info_delay_counter_s_ = kInfoDelay; // reset counter
break;
default: // state flying
info_delay_counter_s_ = kInfoDelay; // reset counter
break;
}
}
uint LaunchDetector::getLaunchDetected() const
{
return state_;
}
void LaunchDetector::reset()
{
info_delay_counter_s_ = 0.f;
acceleration_detected_counter_ = 0.f;
motor_delay_counter_ = 0.f;
state_ = launch_detection_status_s::STATE_WAITING_FOR_LAUNCH;
}
} // namespace launchdetection
@@ -0,0 +1,117 @@
/****************************************************************************
*
* Copyright (c) 2013-2022 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 LaunchDetector.h
* Auto launch detection for catapult/hand-launch vehicles
*
* @author Thomas Gubler <thomasgubler@gmail.com>
*/
#ifndef LAUNCHDETECTOR_H
#define LAUNCHDETECTOR_H
#include <px4_platform_common/module_params.h>
#include <uORB/topics/launch_detection_status.h>
namespace launchdetection
{
// Info delay threshold (to publish info every kInfoDelay seconds)
static constexpr float kInfoDelay = 4.f;
class __EXPORT LaunchDetector : public ModuleParams
{
public:
LaunchDetector(ModuleParams *parent) : ModuleParams(parent) {}
~LaunchDetector() = default;
LaunchDetector(const LaunchDetector &) = delete;
LaunchDetector operator=(const LaunchDetector &) = delete;
/**
* @brief Reset launch detection state machine.
*/
void reset();
/**
* @brief Updates the state machine based on the current vehicle condition.
*
* @param dt Time step [us]
* @param accel_x Measured acceleration in body x [m/s/s]
*/
void update(const float dt, const float accel_x);
/**
* @brief Get the Launch Detected state
*
* @return uint (aligned with launch_detection_status_s::launch_detection_state)
*/
uint getLaunchDetected() const;
/**
* @brief Forces state of launch detection state machine to STATE_FLYING.
*/
void forceSetFlyState() { state_ = launch_detection_status_s::STATE_FLYING; }
private:
/**
* Motor delay counter [s]
*/
float motor_delay_counter_{0.f};
/**
* Info delay counter (to publish info every kInfoDelay seconds) [s]
*/
float info_delay_counter_s_{kInfoDelay};
/**
* Counter for how long the measured acceleration is above the defined threshold [s]
*/
float acceleration_detected_counter_{0.f};
/**
* Current state of the launch detection state machine [launch_detection_status_s::launch_detection_state]
*/
uint state_{launch_detection_status_s::STATE_WAITING_FOR_LAUNCH};
DEFINE_PARAMETERS(
(ParamFloat<px4::params::FW_LAUN_AC_THLD>) param_fw_laun_ac_thld_,
(ParamFloat<px4::params::FW_LAUN_AC_T>) param_fw_laun_ac_t_,
(ParamFloat<px4::params::FW_LAUN_MOT_DEL>) param_fw_laun_mot_del_
)
};
} // namespace launchdetection
#endif // LAUNCHDETECTOR_H
@@ -0,0 +1,81 @@
/****************************************************************************
*
* Copyright (c) 2013, 2014 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 launchdetection_params.c
*
* Parameters for launchdetection
*
* @author Thomas Gubler <thomasgubler@gmail.com>
*/
/**
* Trigger acceleration threshold
*
* Launch is detected when acceleration in body forward direction is above FW_LAUN_AC_THLD for FW_LAUN_AC_T seconds.
*
* @unit m/s^2
* @min 0
* @decimal 1
* @increment 0.5
* @group FW Launch detection
*/
PARAM_DEFINE_FLOAT(FW_LAUN_AC_THLD, 30.0f);
/**
* Trigger time
*
* Launch is detected when acceleration in body forward direction is above FW_LAUN_AC_THLD for FW_LAUN_AC_T seconds.
*
* @unit s
* @min 0.0
* @max 5.0
* @decimal 2
* @increment 0.05
* @group FW Launch detection
*/
PARAM_DEFINE_FLOAT(FW_LAUN_AC_T, 0.05f);
/**
* Motor delay
*
* Start the motor(s) this amount of seconds after launch is detected.
*
* @unit s
* @min 0.0
* @max 10.0
* @decimal 1
* @increment 0.5
* @group FW Launch detection
*/
PARAM_DEFINE_FLOAT(FW_LAUN_MOT_DEL, 0.0f);