control_allocator: add Custom + MC with tilts effectiveness

The param group is changed to Geometry, as this reflects the naming in the
QGC UI.
This commit is contained in:
Beat Küng
2021-12-10 13:15:11 +01:00
committed by Daniel Agar
parent 0818bb4be0
commit 8c782b7cd9
11 changed files with 377 additions and 27 deletions
@@ -0,0 +1,59 @@
/****************************************************************************
*
* Copyright (c) 2021 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 "ActuatorEffectivenessCustom.hpp"
using namespace matrix;
ActuatorEffectivenessCustom::ActuatorEffectivenessCustom(ModuleParams *parent)
: ModuleParams(parent), _motors(this), _torque(this)
{
}
bool
ActuatorEffectivenessCustom::getEffectivenessMatrix(Configuration &configuration, bool force)
{
if (!force) {
return false;
}
// motors
_motors.enableYawControl(false);
_motors.getEffectivenessMatrix(configuration, true);
// Torque
_torque.getEffectivenessMatrix(configuration, true);
return true;
}
@@ -0,0 +1,53 @@
/****************************************************************************
*
* Copyright (c) 2021 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
#include "ActuatorEffectiveness.hpp"
#include "ActuatorEffectivenessRotors.hpp"
#include "ActuatorEffectivenessControlSurfaces.hpp"
class ActuatorEffectivenessCustom : public ModuleParams, public ActuatorEffectiveness
{
public:
ActuatorEffectivenessCustom(ModuleParams *parent);
virtual ~ActuatorEffectivenessCustom() = default;
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
const char *name() const override { return "Custom"; }
protected:
ActuatorEffectivenessRotors _motors;
ActuatorEffectivenessControlSurfaces _torque;
};
@@ -0,0 +1,83 @@
/****************************************************************************
*
* Copyright (c) 2021 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 "ActuatorEffectivenessMCTilt.hpp"
using namespace matrix;
ActuatorEffectivenessMCTilt::ActuatorEffectivenessMCTilt(ModuleParams *parent)
: ModuleParams(parent),
_mc_rotors(this, ActuatorEffectivenessRotors::AxisConfiguration::FixedUpwards, true),
_tilts(this)
{
}
bool
ActuatorEffectivenessMCTilt::getEffectivenessMatrix(Configuration &configuration, bool force)
{
if (!force) {
return false;
}
// MC motors
_mc_rotors.enableYawControl(!_tilts.hasYawControl());
_mc_rotors.getEffectivenessMatrix(configuration, true);
// Tilts
int first_tilt_idx = configuration.num_actuators_matrix[0];
_tilts.updateTorqueSign(_mc_rotors.geometry());
_tilts.getEffectivenessMatrix(configuration, true);
// Set offset such that tilts point upwards when control input == 0 (trim is 0 if min_angle == -max_angle).
// Note that we don't set configuration.trim here, because in the case of trim == +-1, yaw is always saturated
// and reduced to 0 with the sequential desaturation method. Instead we add it after.
_tilt_offsets.setZero();
for (int i = 0; i < _tilts.count(); ++i) {
float delta_angle = _tilts.config(i).max_angle - _tilts.config(i).min_angle;
if (delta_angle > FLT_EPSILON) {
float trim = -1.f - 2.f * _tilts.config(i).min_angle / delta_angle;
_tilt_offsets(first_tilt_idx + i) = trim;
}
}
return true;
}
void ActuatorEffectivenessMCTilt::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
int matrix_index, ActuatorVector &actuator_sp)
{
actuator_sp += _tilt_offsets;
// TODO: dynamic matrix update
}
@@ -0,0 +1,62 @@
/****************************************************************************
*
* Copyright (c) 2021 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
#include "ActuatorEffectiveness.hpp"
#include "ActuatorEffectivenessRotors.hpp"
#include "ActuatorEffectivenessTilts.hpp"
class ActuatorEffectivenessMCTilt : public ModuleParams, public ActuatorEffectiveness
{
public:
ActuatorEffectivenessMCTilt(ModuleParams *parent);
virtual ~ActuatorEffectivenessMCTilt() = default;
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
void getDesiredAllocationMethod(AllocationMethod allocation_method_out[MAX_NUM_MATRICES]) const override
{
allocation_method_out[0] = AllocationMethod::SEQUENTIAL_DESATURATION;
}
void updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp, int matrix_index,
ActuatorVector &actuator_sp) override;
const char *name() const override { return "MC Tilt"; }
protected:
ActuatorVector _tilt_offsets;
ActuatorEffectivenessRotors _mc_rotors;
ActuatorEffectivenessTilts _tilts;
};
@@ -72,7 +72,7 @@ ActuatorEffectivenessTiltrotorVTOL::getEffectivenessMatrix(Configuration &config
// Tilts
configuration.selected_matrix = 0;
_first_tilt_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
_tilts.updateYawSign(_mc_rotors.geometry());
_tilts.updateTorqueSign(_mc_rotors.geometry(), true /* disable pitch to avoid configuration errors */);
_tilts.getEffectivenessMatrix(configuration, true);
_updated = false;
@@ -80,7 +80,7 @@ void ActuatorEffectivenessTilts::updateParams()
_params[i].min_angle = math::radians(_params[i].min_angle);
_params[i].max_angle = math::radians(_params[i].max_angle);
_yaw_torque[i] = 0.f;
_torque[i].setZero();
}
}
@@ -91,19 +91,14 @@ bool ActuatorEffectivenessTilts::getEffectivenessMatrix(Configuration &configura
}
for (int i = 0; i < _count; i++) {
Vector3f torque{};
if (_params[i].control == Control::Yaw) {
torque(2) = _yaw_torque[i];
}
configuration.addActuator(ActuatorType::SERVOS, torque, Vector3f{});
configuration.addActuator(ActuatorType::SERVOS, _torque[i], Vector3f{});
}
return true;
}
void ActuatorEffectivenessTilts::updateYawSign(const ActuatorEffectivenessRotors::Geometry &geometry)
void ActuatorEffectivenessTilts::updateTorqueSign(const ActuatorEffectivenessRotors::Geometry &geometry,
bool disable_pitch)
{
for (int i = 0; i < geometry.num_rotors; ++i) {
int tilt_index = geometry.rotors[i].tilt_index;
@@ -112,28 +107,34 @@ void ActuatorEffectivenessTilts::updateYawSign(const ActuatorEffectivenessRotors
continue;
}
if (_params[tilt_index].control != Control::Yaw) {
continue;
if (_params[tilt_index].control == Control::Yaw || _params[tilt_index].control == Control::YawAndPitch) {
// Find the yaw torque sign by checking the motor position and tilt direction.
// Rotate position by -tilt_direction around z, then check the sign of y pos
float tilt_direction = math::radians((float)_params[tilt_index].tilt_direction);
Vector3f rotated_pos = Dcmf{Eulerf{0.f, 0.f, -tilt_direction}} * geometry.rotors[i].position;
if (rotated_pos(1) < -0.01f) { // add minimal margin
_torque[tilt_index](2) = 1.f;
} else if (rotated_pos(1) > 0.01f) {
_torque[tilt_index](2) = -1.f;
}
}
// Find the yaw torque sign by checking the motor position and tilt direction.
// Rotate position by -tilt_direction around z, then check the sign of y pos
float tilt_direction = math::radians((float)_params[tilt_index].tilt_direction);
Vector3f rotated_pos = Dcmf{Eulerf{0.f, 0.f, -tilt_direction}} * geometry.rotors[i].position;
if (rotated_pos(1) < -0.01f) { // add minimal margin
_yaw_torque[tilt_index] = 1.f;
} else if (rotated_pos(1) > 0.01f) {
_yaw_torque[tilt_index] = -1.f;
if (!disable_pitch && (_params[tilt_index].control == Control::Pitch
|| _params[tilt_index].control == Control::YawAndPitch)) {
bool tilting_forwards = (int)_params[tilt_index].tilt_direction < 90 || (int)_params[tilt_index].tilt_direction > 270;
_torque[tilt_index](1) = tilting_forwards ? -1.f : 1.f;
}
}
}
bool ActuatorEffectivenessTilts::hasYawControl() const
{
for (int i = 0; i < _count; i++) {
if (_params[i].control == Control::Yaw) {
if (_params[i].control == Control::Yaw || _params[i].control == Control::YawAndPitch) {
return true;
}
}
@@ -48,6 +48,8 @@ public:
// This matches with the parameter
None = 0,
Yaw = 1,
Pitch = 2,
YawAndPitch = 3,
};
enum class TiltDirection : int32_t {
// This matches with the parameter
@@ -73,7 +75,7 @@ public:
const Params &config(int idx) const { return _params[idx]; }
void updateYawSign(const ActuatorEffectivenessRotors::Geometry &geometry);
void updateTorqueSign(const ActuatorEffectivenessRotors::Geometry &geometry, bool disable_pitch = false);
bool hasYawControl() const;
@@ -93,5 +95,5 @@ private:
Params _params[MAX_COUNT] {};
int _count{0};
float _yaw_torque[MAX_COUNT] {};
matrix::Vector3f _torque[MAX_COUNT] {};
};
@@ -36,8 +36,12 @@ px4_add_library(ActuatorEffectiveness
ActuatorEffectiveness.hpp
ActuatorEffectivenessControlSurfaces.cpp
ActuatorEffectivenessControlSurfaces.hpp
ActuatorEffectivenessCustom.cpp
ActuatorEffectivenessCustom.hpp
ActuatorEffectivenessFixedWing.cpp
ActuatorEffectivenessFixedWing.hpp
ActuatorEffectivenessMCTilt.cpp
ActuatorEffectivenessMCTilt.hpp
ActuatorEffectivenessTilts.cpp
ActuatorEffectivenessTilts.hpp
ActuatorEffectivenessRotors.cpp
@@ -235,6 +235,14 @@ ControlAllocator::update_effectiveness_source()
tmp = new ActuatorEffectivenessRotors(this);
break;
case EffectivenessSource::MULTIROTOR_WITH_TILT:
tmp = new ActuatorEffectivenessMCTilt(this);
break;
case EffectivenessSource::CUSTOM:
tmp = new ActuatorEffectivenessCustom(this);
break;
default:
PX4_ERR("Unknown airframe");
break;
@@ -49,6 +49,8 @@
#include <ActuatorEffectivenessRoverAckermann.hpp>
#include <ActuatorEffectivenessRoverDifferential.hpp>
#include <ActuatorEffectivenessFixedWing.hpp>
#include <ActuatorEffectivenessMCTilt.hpp>
#include <ActuatorEffectivenessCustom.hpp>
#include <ControlAllocation.hpp>
#include <ControlAllocationPseudoInverse.hpp>
@@ -144,6 +146,8 @@ private:
ROVER_ACKERMANN = 5,
ROVER_DIFFERENTIAL = 6,
MOTORS_6DOF = 7,
MULTIROTOR_WITH_TILT = 8,
CUSTOM = 9,
};
EffectivenessSource _effectiveness_source_id{EffectivenessSource::NONE};
+76 -2
View File
@@ -5,7 +5,7 @@ __max_num_tilts: &max_num_tilts 4
module_name: Control Allocation
parameters:
- group: Control Allocation
- group: Geometry
definitions:
CA_AIRFRAME:
description:
@@ -13,6 +13,8 @@ parameters:
long: |
Defines which mixer implementation to use.
Some are generic, while others are specifically fit to a certain vehicle with a fixed set of actuators.
'Custom' should only be used if noting else can be used.
type: enum
values:
0: Multirotor
@@ -23,6 +25,8 @@ parameters:
5: Rover (Ackermann)
6: Rover (Differential)
7: Motors (6DOF)
8: Multirotor with Tilt
9: Custom
default: 0
CA_METHOD:
@@ -312,10 +316,12 @@ parameters:
description:
short: Tilt ${i} is used for control
long: Define if this servo is used for additional control.
type: enum
type: enum # This could be a bitset, but the enum shows up nicer in the UI
values:
0: 'None'
1: 'Yaw'
2: 'Pitch'
3: 'Yaw and Pitch'
num_instances: *max_num_tilts
instance_start: 0
default: 1
@@ -358,6 +364,8 @@ parameters:
values:
0: 'Towards Front'
90: 'Towards Right'
min: 0
max: 359
num_instances: *max_num_tilts
instance_start: 0
default: 0
@@ -643,3 +651,69 @@ mixer:
- name: 'CA_ROTOR${i}_KM'
label: "Moment\nCoefficient"
8: # Multirotor with Tilt
actuators:
- actuator_type: 'motor'
count: 'CA_ROTOR_COUNT'
per_item_parameters:
standard:
position: [ 'CA_ROTOR${i}_PX', 'CA_ROTOR${i}_PY', 'CA_ROTOR${i}_PZ' ]
extra:
- name: 'CA_ROTOR${i}_KM'
label: 'Direction CCW'
function: 'spin-dir'
show_as: 'true-if-positive'
- name: 'CA_ROTOR${i}_TILT'
label: 'Tilted by'
- actuator_type: 'servo'
group_label: 'Tilt Servos'
count: 'CA_SV_TL_COUNT'
item_label_prefix: 'Tilt ${i}'
per_item_parameters:
extra:
- name: 'CA_SV_TL${i}_MINA'
label: "Angle at Min\nTilt"
- name: 'CA_SV_TL${i}_MAXA'
label: "Angle at Max\nTilt"
- name: 'CA_SV_TL${i}_TD'
label: 'Tilt Direction'
- name: 'CA_SV_TL${i}_CT'
label: 'Use for Control'
9: # Custom
actuators:
- actuator_type: 'motor'
group_label: 'Thrust/Motors'
count: 'CA_ROTOR_COUNT'
per_item_parameters:
standard:
position: [ 'CA_ROTOR${i}_PX', 'CA_ROTOR${i}_PY', 'CA_ROTOR${i}_PZ' ]
extra:
- name: 'CA_ROTOR${i}_AX'
label: 'Axis X'
function: 'axisx'
- name: 'CA_ROTOR${i}_AY'
label: 'Axis Y'
function: 'axisy'
- name: 'CA_ROTOR${i}_AZ'
label: 'Axis Z'
function: 'axisz'
- name: 'CA_ROTOR${i}_CT'
label: "Thrust\nCoefficient"
- name: 'CA_ROTOR${i}_KM'
label: "Moment\nCoefficient"
- actuator_type: 'servo'
group_label: 'Torque'
count: 'CA_SV_CS_COUNT'
item_label_prefix: 'Torque ${i}'
per_item_parameters:
extra:
- name: 'CA_SV_CS${i}_TRQ_R'
label: 'Roll Scale'
- name: 'CA_SV_CS${i}_TRQ_P'
label: 'Pitch Scale'
- name: 'CA_SV_CS${i}_TRQ_Y'
label: 'Yaw Scale'
- name: 'CA_SV_CS${i}_TRIM'
label: 'Trim'