mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-12 19:50:35 +08:00
130 lines
4.8 KiB
C++
130 lines
4.8 KiB
C++
/****************************************************************************
|
|
*
|
|
* 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.
|
|
*
|
|
****************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
// PX4 includes
|
|
#include <px4_platform_common/module_params.h>
|
|
#include <px4_platform_common/events.h>
|
|
|
|
// Libraries
|
|
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
|
#include <lib/pid/PID.hpp>
|
|
#include <lib/slew_rate/SlewRate.hpp>
|
|
#include <math.h>
|
|
|
|
// uORB includes
|
|
#include <uORB/Publication.hpp>
|
|
#include <uORB/Subscription.hpp>
|
|
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
|
#include <uORB/topics/vehicle_angular_velocity.h>
|
|
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
|
#include <uORB/topics/surface_vehicle_rate_status.h>
|
|
#include <uORB/topics/actuator_motors.h>
|
|
|
|
/**
|
|
* @brief Class for ackermann rate control.
|
|
*/
|
|
class AckermannRateControl : public ModuleParams
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor for AckermannRateControl.
|
|
* @param parent The parent ModuleParams object.
|
|
*/
|
|
AckermannRateControl(ModuleParams *parent);
|
|
~AckermannRateControl() = default;
|
|
|
|
/**
|
|
* @brief Generate and publish SurfaceVehicleSteeringSetpoint from SurfaceVehicleRateSetpoint.
|
|
*/
|
|
void updateRateControl();
|
|
|
|
/**
|
|
* @brief Check if the necessary parameters are set.
|
|
* @return True if all checks pass.
|
|
*/
|
|
bool runSanityChecks();
|
|
|
|
/**
|
|
* @brief Reset rate controller.
|
|
*/
|
|
void reset() {_pid_yaw_rate.resetIntegral(); _yaw_rate_setpoint = NAN;};
|
|
|
|
protected:
|
|
/**
|
|
* @brief Update the parameters of the module.
|
|
*/
|
|
void updateParams() override;
|
|
|
|
private:
|
|
/**
|
|
* @brief Update uORB subscriptions used in rate controller.
|
|
*/
|
|
void updateSubscriptions();
|
|
|
|
// uORB subscriptions
|
|
uORB::Subscription _surface_vehicle_rate_setpoint_sub{ORB_ID(surface_vehicle_rate_setpoint)};
|
|
uORB::Subscription _vehicle_angular_velocity_sub{ORB_ID(vehicle_angular_velocity)};
|
|
uORB::Subscription _actuator_motors_sub{ORB_ID(actuator_motors)};
|
|
|
|
// uORB publications
|
|
uORB::Publication<surface_vehicle_steering_setpoint_s> _surface_vehicle_steering_setpoint_pub{ORB_ID(surface_vehicle_steering_setpoint)};
|
|
uORB::Publication<surface_vehicle_rate_status_s> _surface_vehicle_rate_status_pub{ORB_ID(surface_vehicle_rate_status)};
|
|
|
|
// Variables
|
|
float _estimated_speed{0.f}; /*Vehicle speed estimated by interpolating [actuatorMotorSetpoint, _estimated_speed]
|
|
between [0, 0] and [1, _param_sv_max_thr_speed].*/
|
|
float _max_yaw_rate{0.f};
|
|
float _vehicle_yaw_rate{0.f};
|
|
float _yaw_rate_setpoint{NAN};
|
|
hrt_abstime _timestamp{0};
|
|
|
|
// Controllers
|
|
PID _pid_yaw_rate;
|
|
SlewRate<float> _adjusted_yaw_rate_setpoint{0.f};
|
|
|
|
DEFINE_PARAMETERS(
|
|
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
|
(ParamFloat<px4::params::RA_WHEEL_BASE>) _param_ra_wheel_base,
|
|
(ParamFloat<px4::params::RA_MAX_STR_ANG>) _param_ra_max_str_ang,
|
|
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
|
(ParamFloat<px4::params::SV_YAW_RATE_TH>) _param_sv_yaw_rate_th,
|
|
(ParamFloat<px4::params::SV_YAW_RATE_P>) _param_sv_yaw_rate_p,
|
|
(ParamFloat<px4::params::SV_YAW_RATE_I>) _param_sv_yaw_rate_i,
|
|
(ParamFloat<px4::params::SV_YAW_ACCEL_LIM>) _param_sv_yaw_accel_limit,
|
|
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th,
|
|
(ParamFloat<px4::params::SV_YAW_RATE_CORR>) _param_sv_yaw_rate_corr
|
|
)
|
|
};
|