Compare commits

...

2 Commits

Author SHA1 Message Date
RomanBapst 45c8b64810 hacks to make unified effectiveness matrix work
Signed-off-by: RomanBapst <bapstroman@gmail.com>
2022-07-26 15:45:22 +03:00
Daniel Agar 8726698afd WIP: VTOL standard unfied control effectiveness 2022-07-14 10:16:22 -04:00
11 changed files with 257 additions and 16 deletions
@@ -12,8 +12,8 @@
param set-default FD_ACT_EN 0
param set-default FD_ACT_MOT_TOUT 500
# param set-default SYS_CTRL_ALLOC 1
param set-default CA_AIRFRAME 2
param set-default SYS_CTRL_ALLOC 1
param set-default CA_AIRFRAME 11
param set-default CA_ROTOR_COUNT 5
param set-default CA_ROTOR0_PX 0.1515
@@ -84,5 +84,5 @@ param set-default VT_FW_MOT_OFFID 1234
param set-default VT_B_TRANS_DUR 8
param set-default VT_TYPE 2
set MIXER_FILE etc/mixers-sitl/standard_vtol_sitl.main.mix
set MIXER custom
#set MIXER_FILE etc/mixers-sitl/standard_vtol_sitl.main.mix
set MIXER skip
@@ -63,6 +63,7 @@ enum class EffectivenessUpdateReason {
NO_EXTERNAL_UPDATE = 0,
CONFIGURATION_UPDATE = 1,
MOTOR_ACTIVATION_UPDATE = 2,
AIRSPEED_CHANGED = 3
};
@@ -133,6 +134,16 @@ public:
_flight_phase = flight_phase;
}
/**
* Set the equivalent airspeed
*
* @param Equivalent airspeed
*/
virtual void setEquivalentAirspeed(const float airspeed)
{
_airspeed_equivalent = airspeed;
}
/**
* Get the number of effectiveness matrices. Must be <= MAX_NUM_MATRICES.
* This is expected to stay constant.
@@ -198,4 +209,5 @@ public:
protected:
FlightPhase _flight_phase{FlightPhase::HOVER_FLIGHT}; ///< Current flight phase
float _airspeed_equivalent{NAN};
};
@@ -34,6 +34,7 @@
#include <px4_platform_common/log.h>
#include "ActuatorEffectivenessControlSurfaces.hpp"
#include <lib/mathlib/mathlib.h>
using namespace matrix;
@@ -127,7 +128,12 @@ void ActuatorEffectivenessControlSurfaces::updateParams()
bool ActuatorEffectivenessControlSurfaces::addActuators(Configuration &configuration)
{
for (int i = 0; i < _count; i++) {
int actuator_idx = configuration.addActuator(ActuatorType::SERVOS, _params[i].torque, Vector3f{});
const float airspeed_trim = 15.0f;
_airspeed_equivalent = math::max(_airspeed_equivalent, 3.0f);
float airspeed_scaling = _airspeed_equivalent / airspeed_trim;
airspeed_scaling = math::constrain(airspeed_scaling, 0.001f, 1000.0f);
Vector3f actual_torque = _params[i].torque * airspeed_scaling * airspeed_scaling;
int actuator_idx = configuration.addActuator(ActuatorType::SERVOS, actual_torque, Vector3f{});
if (actuator_idx >= 0) {
configuration.trim[configuration.selected_matrix](actuator_idx) = _params[i].trim;
@@ -89,7 +89,7 @@ void ActuatorEffectivenessStandardVTOL::setFlightPhase(const FlightPhase &flight
// update stopped motors
switch (flight_phase) {
case FlightPhase::FORWARD_FLIGHT:
_stopped_motors = _mc_motors_mask;
//_stopped_motors = _mc_motors_mask;
break;
case FlightPhase::HOVER_FLIGHT:
@@ -0,0 +1,107 @@
/****************************************************************************
*
* Copyright (c) 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.
*
****************************************************************************/
#include "ActuatorEffectivenessStandardVTOLUnified.hpp"
#include <ControlAllocation/ControlAllocation.hpp>
using namespace matrix;
ActuatorEffectivenessStandardVTOLUnified::ActuatorEffectivenessStandardVTOLUnified(ModuleParams *parent) :
ModuleParams(parent),
_rotors(this),
_control_surfaces(this)
{
}
bool ActuatorEffectivenessStandardVTOLUnified::getEffectivenessMatrix(Configuration &configuration,
EffectivenessUpdateReason external_update)
{
if (external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
return false;
}
if (external_update == EffectivenessUpdateReason::AIRSPEED_CHANGED) {
//printf("Updating due to airspeed %.2f\n", (double)_airspeed_equivalent);
_control_surfaces.setEquivalentAirspeed(_airspeed_equivalent);
}
// Motors
configuration.selected_matrix = 0;
_rotors.enablePropellerTorqueNonUpwards(false);
const bool mc_rotors_added_successfully = _rotors.addActuators(configuration);
_mc_motors_mask = _rotors.getUpwardsMotors();
// Control Surfaces
configuration.selected_matrix = 0;
_first_control_surface_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
const bool surfaces_added_successfully = _control_surfaces.addActuators(configuration);
return (mc_rotors_added_successfully && surfaces_added_successfully);
}
void ActuatorEffectivenessStandardVTOLUnified::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
int matrix_index, ActuatorVector &actuator_sp)
{
// apply flaps
if (matrix_index == 1) {
actuator_controls_s actuator_controls_1;
if (_actuator_controls_1_sub.copy(&actuator_controls_1)) {
float control_flaps = actuator_controls_1.control[actuator_controls_s::INDEX_FLAPS];
float airbrakes_control = actuator_controls_1.control[actuator_controls_s::INDEX_AIRBRAKES];
_control_surfaces.applyFlapsAndAirbrakes(control_flaps, airbrakes_control, _first_control_surface_idx, actuator_sp);
}
}
}
void ActuatorEffectivenessStandardVTOLUnified::setFlightPhase(const FlightPhase &flight_phase)
{
if (_flight_phase == flight_phase) {
return;
}
ActuatorEffectiveness::setFlightPhase(flight_phase);
// update stopped motors
switch (flight_phase) {
case FlightPhase::FORWARD_FLIGHT:
//_stopped_motors = _mc_motors_mask;
break;
case FlightPhase::HOVER_FLIGHT:
case FlightPhase::TRANSITION_FF_TO_HF:
case FlightPhase::TRANSITION_HF_TO_FF:
_stopped_motors = 0;
break;
}
}
@@ -0,0 +1,92 @@
/****************************************************************************
*
* Copyright (c) 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 ActuatorEffectivenessStandardVTOLUnified.hpp
*
* Actuator effectiveness for standard VTOL (unified control effectiveness)
*
*/
#pragma once
#include "ActuatorEffectiveness.hpp"
#include "ActuatorEffectivenessRotors.hpp"
#include "ActuatorEffectivenessControlSurfaces.hpp"
#include <uORB/topics/actuator_controls.h>
class ActuatorEffectivenessStandardVTOLUnified : public ModuleParams, public ActuatorEffectiveness
{
public:
ActuatorEffectivenessStandardVTOLUnified(ModuleParams *parent);
virtual ~ActuatorEffectivenessStandardVTOLUnified() = default;
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
const char *name() const override { return "Standard VTOL Unified"; }
int numMatrices() const override { return 1; }
void getDesiredAllocationMethod(AllocationMethod allocation_method_out[MAX_NUM_MATRICES]) const override
{
//static_assert(MAX_NUM_MATRICES >= 2, "expecting at least 2 matrices");
allocation_method_out[0] = AllocationMethod::PSEUDO_INVERSE;
//allocation_method_out[1] = AllocationMethod::PSEUDO_INVERSE;
}
void getNormalizeRPY(bool normalize[MAX_NUM_MATRICES]) const override
{
normalize[0] = true;
//normalize[1] = false;
}
void updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp, int matrix_index,
ActuatorVector &actuator_sp) override;
void setFlightPhase(const FlightPhase &flight_phase) override;
uint32_t getStoppedMotors() const override { return _stopped_motors; }
private:
ActuatorEffectivenessRotors _rotors;
ActuatorEffectivenessControlSurfaces _control_surfaces;
uint32_t _mc_motors_mask{}; ///< mc motors (stopped during forward flight)
uint32_t _stopped_motors{}; ///< currently stopped motors
int _first_control_surface_idx{0}; ///< applies to matrix 1
uORB::Subscription _actuator_controls_1_sub{ORB_ID(actuator_controls_0)};
};
@@ -52,6 +52,8 @@ px4_add_library(ActuatorEffectiveness
ActuatorEffectivenessRotors.hpp
ActuatorEffectivenessStandardVTOL.cpp
ActuatorEffectivenessStandardVTOL.hpp
ActuatorEffectivenessStandardVTOLUnified.cpp
ActuatorEffectivenessStandardVTOLUnified.hpp
ActuatorEffectivenessTiltrotorVTOL.cpp
ActuatorEffectivenessTiltrotorVTOL.hpp
ActuatorEffectivenessTailsitterVTOL.cpp
@@ -260,6 +260,10 @@ ControlAllocator::update_effectiveness_source()
tmp = new ActuatorEffectivenessHelicopter(this);
break;
case EffectivenessSource::STANDARD_VTOL_UNIFIED:
tmp = new ActuatorEffectivenessStandardVTOLUnified(this);
break;
default:
PX4_ERR("Unknown airframe");
break;
@@ -361,6 +365,13 @@ ControlAllocator::Run()
vehicle_torque_setpoint_s vehicle_torque_setpoint;
vehicle_thrust_setpoint_s vehicle_thrust_setpoint;
if (_airspeed_sub.updated()) {
airspeed_validated_s airspeed{};
_airspeed_sub.copy(&airspeed);
_actuator_effectiveness->setEquivalentAirspeed(airspeed.calibrated_airspeed_m_s);
update_effectiveness_matrix_if_needed(EffectivenessUpdateReason::AIRSPEED_CHANGED);
}
// Run allocator on torque changes
if (_vehicle_torque_setpoint_sub.update(&vehicle_torque_setpoint)) {
_torque_sp = matrix::Vector3f(vehicle_torque_setpoint.xyz);
@@ -44,6 +44,7 @@
#include <ActuatorEffectiveness.hpp>
#include <ActuatorEffectivenessMultirotor.hpp>
#include <ActuatorEffectivenessStandardVTOL.hpp>
#include <ActuatorEffectivenessStandardVTOLUnified.hpp>
#include <ActuatorEffectivenessTiltrotorVTOL.hpp>
#include <ActuatorEffectivenessTailsitterVTOL.hpp>
#include <ActuatorEffectivenessRoverAckermann.hpp>
@@ -75,6 +76,7 @@
#include <uORB/topics/vehicle_thrust_setpoint.h>
#include <uORB/topics/vehicle_status.h>
#include <uORB/topics/failure_detector_status.h>
#include <uORB/topics/airspeed_validated.h>
class ControlAllocator : public ModuleBase<ControlAllocator>, public ModuleParams, public px4::ScheduledWorkItem
{
@@ -153,6 +155,7 @@ private:
MULTIROTOR_WITH_TILT = 8,
CUSTOM = 9,
HELICOPTER = 10,
STANDARD_VTOL_UNIFIED = 11,
};
enum class FailureMode {
@@ -184,6 +187,7 @@ private:
uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)};
uORB::Subscription _failure_detector_status_sub{ORB_ID(failure_detector_status)};
uORB::Subscription _airspeed_sub{ORB_ID(airspeed_validated)};
matrix::Vector3f _torque_sp;
matrix::Vector3f _thrust_sp;
@@ -28,6 +28,7 @@ parameters:
8: Multirotor with Tilt
9: Custom
10: Helicopter
11: Standard VTOL Unified (testing)
default: 0
CA_METHOD:
+16 -10
View File
@@ -400,11 +400,17 @@ void Standard::fill_actuator_outputs()
_torque_setpoint_0->xyz[1] = mc_out[actuator_controls_s::INDEX_PITCH];
_torque_setpoint_0->xyz[2] = mc_out[actuator_controls_s::INDEX_YAW];
_torque_setpoint_1->timestamp = hrt_absolute_time();
_torque_setpoint_1->timestamp_sample = _actuators_fw_in->timestamp_sample;
_torque_setpoint_1->xyz[0] = fw_out[actuator_controls_s::INDEX_ROLL];
_torque_setpoint_1->xyz[1] = fw_out[actuator_controls_s::INDEX_PITCH];
_torque_setpoint_1->xyz[2] = fw_out[actuator_controls_s::INDEX_YAW];
if (_vtol_schedule.flight_mode == vtol_mode::FW_MODE) {
_torque_setpoint_0->xyz[0] = fw_out[actuator_controls_s::INDEX_ROLL];
_torque_setpoint_0->xyz[1] = fw_out[actuator_controls_s::INDEX_PITCH];
_torque_setpoint_0->xyz[2] = fw_out[actuator_controls_s::INDEX_YAW];
}
// _torque_setpoint_1->timestamp = hrt_absolute_time();
// _torque_setpoint_1->timestamp_sample = _actuators_fw_in->timestamp_sample;
// _torque_setpoint_1->xyz[0] = fw_out[actuator_controls_s::INDEX_ROLL];
// _torque_setpoint_1->xyz[1] = fw_out[actuator_controls_s::INDEX_PITCH];
// _torque_setpoint_1->xyz[2] = fw_out[actuator_controls_s::INDEX_YAW];
_thrust_setpoint_0->timestamp = hrt_absolute_time();
_thrust_setpoint_0->timestamp_sample = _actuators_mc_in->timestamp_sample;
@@ -412,11 +418,11 @@ void Standard::fill_actuator_outputs()
_thrust_setpoint_0->xyz[1] = 0.f;
_thrust_setpoint_0->xyz[2] = -mc_out[actuator_controls_s::INDEX_THROTTLE];
_thrust_setpoint_1->timestamp = hrt_absolute_time();
_thrust_setpoint_1->timestamp_sample = _actuators_fw_in->timestamp_sample;
_thrust_setpoint_1->xyz[0] = 0.f;
_thrust_setpoint_1->xyz[1] = 0.f;
_thrust_setpoint_1->xyz[2] = 0.f;
// _thrust_setpoint_1->timestamp = hrt_absolute_time();
// _thrust_setpoint_1->timestamp_sample = _actuators_fw_in->timestamp_sample;
// _thrust_setpoint_1->xyz[0] = 0.f;
// _thrust_setpoint_1->xyz[1] = 0.f;
// _thrust_setpoint_1->xyz[2] = 0.f;
_actuators_out_0->timestamp_sample = _actuators_mc_in->timestamp_sample;
_actuators_out_1->timestamp_sample = _actuators_fw_in->timestamp_sample;