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-24 20:06:13 -05: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