mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 18:27:05 +08:00
CA: refactor logic for matrix updating
-pass flag EffectivenessUpdateReason into effectiveness, indicating if there was an external update or not. Reasons for external updates are: -config changes (parameter) -motor failure detected or certain redundant motors are switched off to save energy Signed-off-by: Silvan Fuhrer <silvan@auterion.com>
This commit is contained in:
@@ -57,6 +57,12 @@ enum class ActuatorType {
|
|||||||
COUNT
|
COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class EffectivenessUpdateReason {
|
||||||
|
NO_EXTERNAL_UPDATE = 0,
|
||||||
|
CONFIGURATION_UPDATE = 1,
|
||||||
|
MOTOR_ACTIVATION_UPDATE = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class ActuatorEffectiveness
|
class ActuatorEffectiveness
|
||||||
{
|
{
|
||||||
@@ -147,7 +153,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return true if updated and matrix is set
|
* @return true if updated and matrix is set
|
||||||
*/
|
*/
|
||||||
virtual bool getEffectivenessMatrix(Configuration &configuration, bool force) = 0;
|
virtual bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) { return false;}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current flight phase
|
* Get the current flight phase
|
||||||
|
|||||||
+1
-5
@@ -124,12 +124,8 @@ void ActuatorEffectivenessControlSurfaces::updateParams()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActuatorEffectivenessControlSurfaces::getEffectivenessMatrix(Configuration &configuration, bool force)
|
bool ActuatorEffectivenessControlSurfaces::addActuators(Configuration &configuration)
|
||||||
{
|
{
|
||||||
if (!force) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < _count; i++) {
|
for (int i = 0; i < _count; i++) {
|
||||||
int actuator_idx = configuration.addActuator(ActuatorType::SERVOS, _params[i].torque, Vector3f{});
|
int actuator_idx = configuration.addActuator(ActuatorType::SERVOS, _params[i].torque, Vector3f{});
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ public:
|
|||||||
ActuatorEffectivenessControlSurfaces(ModuleParams *parent);
|
ActuatorEffectivenessControlSurfaces(ModuleParams *parent);
|
||||||
virtual ~ActuatorEffectivenessControlSurfaces() = default;
|
virtual ~ActuatorEffectivenessControlSurfaces() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool addActuators(Configuration &configuration);
|
||||||
|
|
||||||
const char *name() const override { return "Control Surfaces"; }
|
const char *name() const override { return "Control Surfaces"; }
|
||||||
|
|
||||||
|
|||||||
@@ -41,19 +41,20 @@ ActuatorEffectivenessCustom::ActuatorEffectivenessCustom(ModuleParams *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ActuatorEffectivenessCustom::getEffectivenessMatrix(Configuration &configuration, bool force)
|
ActuatorEffectivenessCustom::getEffectivenessMatrix(Configuration &configuration,
|
||||||
|
EffectivenessUpdateReason external_update)
|
||||||
{
|
{
|
||||||
if (!force) {
|
if (external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// motors
|
// motors
|
||||||
_motors.enableYawControl(false);
|
_motors.enableYawControl(false);
|
||||||
_motors.getEffectivenessMatrix(configuration, true);
|
const bool motors_added_successfully = _motors.addActuators(configuration);
|
||||||
|
|
||||||
// Torque
|
// Torque
|
||||||
_torque.getEffectivenessMatrix(configuration, true);
|
const bool torque_added_successfully = _torque.addActuators(configuration);
|
||||||
|
|
||||||
return true;
|
return (motors_added_successfully && torque_added_successfully);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
ActuatorEffectivenessCustom(ModuleParams *parent);
|
ActuatorEffectivenessCustom(ModuleParams *parent);
|
||||||
virtual ~ActuatorEffectivenessCustom() = default;
|
virtual ~ActuatorEffectivenessCustom() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
|
||||||
|
|
||||||
const char *name() const override { return "Custom"; }
|
const char *name() const override { return "Custom"; }
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -43,21 +43,22 @@ ActuatorEffectivenessFixedWing::ActuatorEffectivenessFixedWing(ModuleParams *par
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ActuatorEffectivenessFixedWing::getEffectivenessMatrix(Configuration &configuration, bool force)
|
ActuatorEffectivenessFixedWing::getEffectivenessMatrix(Configuration &configuration,
|
||||||
|
EffectivenessUpdateReason external_update)
|
||||||
{
|
{
|
||||||
if (!force) {
|
if (external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Motors
|
// Motors
|
||||||
_rotors.enableYawControl(false);
|
_rotors.enableYawControl(false);
|
||||||
_rotors.getEffectivenessMatrix(configuration, true);
|
const bool rotors_added_successfully = _rotors.addActuators(configuration);
|
||||||
|
|
||||||
// Control Surfaces
|
// Control Surfaces
|
||||||
_first_control_surface_idx = configuration.num_actuators_matrix[0];
|
_first_control_surface_idx = configuration.num_actuators_matrix[0];
|
||||||
_control_surfaces.getEffectivenessMatrix(configuration, true);
|
const bool surfaces_added_successfully = _control_surfaces.addActuators(configuration);
|
||||||
|
|
||||||
return true;
|
return (rotors_added_successfully && surfaces_added_successfully);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActuatorEffectivenessFixedWing::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
|
void ActuatorEffectivenessFixedWing::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@ public:
|
|||||||
ActuatorEffectivenessFixedWing(ModuleParams *parent);
|
ActuatorEffectivenessFixedWing(ModuleParams *parent);
|
||||||
virtual ~ActuatorEffectivenessFixedWing() = default;
|
virtual ~ActuatorEffectivenessFixedWing() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
|
||||||
|
|
||||||
const char *name() const override { return "Fixed Wing"; }
|
const char *name() const override { return "Fixed Wing"; }
|
||||||
|
|
||||||
|
|||||||
@@ -43,20 +43,21 @@ ActuatorEffectivenessMCTilt::ActuatorEffectivenessMCTilt(ModuleParams *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ActuatorEffectivenessMCTilt::getEffectivenessMatrix(Configuration &configuration, bool force)
|
ActuatorEffectivenessMCTilt::getEffectivenessMatrix(Configuration &configuration,
|
||||||
|
EffectivenessUpdateReason external_update)
|
||||||
{
|
{
|
||||||
if (!force) {
|
if (external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MC motors
|
// MC motors
|
||||||
_mc_rotors.enableYawControl(!_tilts.hasYawControl());
|
_mc_rotors.enableYawControl(!_tilts.hasYawControl());
|
||||||
_mc_rotors.getEffectivenessMatrix(configuration, true);
|
const bool rotors_added_successfully = _mc_rotors.addActuators(configuration);
|
||||||
|
|
||||||
// Tilts
|
// Tilts
|
||||||
int first_tilt_idx = configuration.num_actuators_matrix[0];
|
int first_tilt_idx = configuration.num_actuators_matrix[0];
|
||||||
_tilts.updateTorqueSign(_mc_rotors.geometry());
|
_tilts.updateTorqueSign(_mc_rotors.geometry());
|
||||||
_tilts.getEffectivenessMatrix(configuration, true);
|
const bool tilts_added_successfully = _tilts.addActuators(configuration);
|
||||||
|
|
||||||
// Set offset such that tilts point upwards when control input == 0 (trim is 0 if min_angle == -max_angle).
|
// 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
|
// Note that we don't set configuration.trim here, because in the case of trim == +-1, yaw is always saturated
|
||||||
@@ -72,7 +73,7 @@ ActuatorEffectivenessMCTilt::getEffectivenessMatrix(Configuration &configuration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return (rotors_added_successfully && tilts_added_successfully);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActuatorEffectivenessMCTilt::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
|
void ActuatorEffectivenessMCTilt::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
ActuatorEffectivenessMCTilt(ModuleParams *parent);
|
ActuatorEffectivenessMCTilt(ModuleParams *parent);
|
||||||
virtual ~ActuatorEffectivenessMCTilt() = default;
|
virtual ~ActuatorEffectivenessMCTilt() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
|
||||||
|
|
||||||
void getDesiredAllocationMethod(AllocationMethod allocation_method_out[MAX_NUM_MATRICES]) const override
|
void getDesiredAllocationMethod(AllocationMethod allocation_method_out[MAX_NUM_MATRICES]) const override
|
||||||
{
|
{
|
||||||
|
|||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-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 "ActuatorEffectivenessMultirotor.hpp"
|
||||||
|
|
||||||
|
using namespace matrix;
|
||||||
|
|
||||||
|
ActuatorEffectivenessMultirotor::ActuatorEffectivenessMultirotor(ModuleParams *parent)
|
||||||
|
: ModuleParams(parent),
|
||||||
|
_mc_rotors(this)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ActuatorEffectivenessMultirotor::getEffectivenessMatrix(Configuration &configuration,
|
||||||
|
EffectivenessUpdateReason external_update)
|
||||||
|
{
|
||||||
|
if (external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Motors
|
||||||
|
const bool rotors_added_successfully = _mc_rotors.addActuators(configuration);
|
||||||
|
|
||||||
|
return rotors_added_successfully;
|
||||||
|
}
|
||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ActuatorEffectiveness.hpp"
|
||||||
|
#include "ActuatorEffectivenessRotors.hpp"
|
||||||
|
|
||||||
|
class ActuatorEffectivenessMultirotor : public ModuleParams, public ActuatorEffectiveness
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ActuatorEffectivenessMultirotor(ModuleParams *parent);
|
||||||
|
virtual ~ActuatorEffectivenessMultirotor() = default;
|
||||||
|
|
||||||
|
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
|
||||||
|
|
||||||
|
void getDesiredAllocationMethod(AllocationMethod allocation_method_out[MAX_NUM_MATRICES]) const override
|
||||||
|
{
|
||||||
|
allocation_method_out[0] = AllocationMethod::SEQUENTIAL_DESATURATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
void getNormalizeRPY(bool normalize[MAX_NUM_MATRICES]) const override
|
||||||
|
{
|
||||||
|
normalize[0] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *name() const override { return "Multirotor"; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ActuatorEffectivenessRotors _mc_rotors;
|
||||||
|
};
|
||||||
+9
-15
@@ -136,24 +136,18 @@ void ActuatorEffectivenessRotors::updateParams()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ActuatorEffectivenessRotors::getEffectivenessMatrix(Configuration &configuration, bool force)
|
ActuatorEffectivenessRotors::addActuators(Configuration &configuration)
|
||||||
{
|
{
|
||||||
if (_updated || force) {
|
if (configuration.num_actuators[(int)ActuatorType::SERVOS] > 0) {
|
||||||
_updated = false;
|
PX4_ERR("Wrong actuator ordering: servos need to be after motors");
|
||||||
|
return false;
|
||||||
if (configuration.num_actuators[(int)ActuatorType::SERVOS] > 0) {
|
|
||||||
PX4_ERR("Wrong actuator ordering: servos need to be after motors");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int num_actuators = computeEffectivenessMatrix(_geometry,
|
|
||||||
configuration.effectiveness_matrices[configuration.selected_matrix],
|
|
||||||
configuration.num_actuators_matrix[configuration.selected_matrix]);
|
|
||||||
configuration.actuatorsAdded(ActuatorType::MOTORS, num_actuators);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
int num_actuators = computeEffectivenessMatrix(_geometry,
|
||||||
|
configuration.effectiveness_matrices[configuration.selected_matrix],
|
||||||
|
configuration.num_actuators_matrix[configuration.selected_matrix]);
|
||||||
|
configuration.actuatorsAdded(ActuatorType::MOTORS, num_actuators);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public:
|
|||||||
static int computeEffectivenessMatrix(const Geometry &geometry,
|
static int computeEffectivenessMatrix(const Geometry &geometry,
|
||||||
EffectivenessMatrix &effectiveness, int actuator_start_index = 0);
|
EffectivenessMatrix &effectiveness, int actuator_start_index = 0);
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool addActuators(Configuration &configuration);
|
||||||
|
|
||||||
const char *name() const override { return "Multirotor"; }
|
const char *name() const override { return "Multirotor"; }
|
||||||
|
|
||||||
@@ -117,8 +117,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateParams() override;
|
void updateParams() override;
|
||||||
|
|
||||||
bool _updated{true};
|
|
||||||
const AxisConfiguration _axis_config;
|
const AxisConfiguration _axis_config;
|
||||||
const bool _tilt_support; ///< if true, tilt servo assignment params are loaded
|
const bool _tilt_support; ///< if true, tilt servo assignment params are loaded
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -37,9 +37,10 @@
|
|||||||
using namespace matrix;
|
using namespace matrix;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ActuatorEffectivenessRoverAckermann::getEffectivenessMatrix(Configuration &configuration, bool force)
|
ActuatorEffectivenessRoverAckermann::getEffectivenessMatrix(Configuration &configuration,
|
||||||
|
EffectivenessUpdateReason external_update)
|
||||||
{
|
{
|
||||||
if (!force) {
|
if (external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ public:
|
|||||||
ActuatorEffectivenessRoverAckermann() = default;
|
ActuatorEffectivenessRoverAckermann() = default;
|
||||||
virtual ~ActuatorEffectivenessRoverAckermann() = default;
|
virtual ~ActuatorEffectivenessRoverAckermann() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
|
||||||
|
|
||||||
const char *name() const override { return "Rover (Ackermann)"; }
|
const char *name() const override { return "Rover (Ackermann)"; }
|
||||||
private:
|
private:
|
||||||
|
|||||||
+3
-2
@@ -37,9 +37,10 @@
|
|||||||
using namespace matrix;
|
using namespace matrix;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ActuatorEffectivenessRoverDifferential::getEffectivenessMatrix(Configuration &configuration, bool force)
|
ActuatorEffectivenessRoverDifferential::getEffectivenessMatrix(Configuration &configuration,
|
||||||
|
EffectivenessUpdateReason external_update)
|
||||||
{
|
{
|
||||||
if (!force) {
|
if (external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ public:
|
|||||||
ActuatorEffectivenessRoverDifferential() = default;
|
ActuatorEffectivenessRoverDifferential() = default;
|
||||||
virtual ~ActuatorEffectivenessRoverDifferential() = default;
|
virtual ~ActuatorEffectivenessRoverDifferential() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
|
||||||
|
|
||||||
const char *name() const override { return "Rover (Differential)"; }
|
const char *name() const override { return "Rover (Differential)"; }
|
||||||
private:
|
private:
|
||||||
|
|||||||
+6
-5
@@ -42,15 +42,16 @@ ActuatorEffectivenessStandardVTOL::ActuatorEffectivenessStandardVTOL(ModuleParam
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ActuatorEffectivenessStandardVTOL::getEffectivenessMatrix(Configuration &configuration, bool force)
|
ActuatorEffectivenessStandardVTOL::getEffectivenessMatrix(Configuration &configuration,
|
||||||
|
EffectivenessUpdateReason external_update)
|
||||||
{
|
{
|
||||||
if (!force) {
|
if (external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MC motors
|
// MC motors
|
||||||
configuration.selected_matrix = 0;
|
configuration.selected_matrix = 0;
|
||||||
_mc_rotors.getEffectivenessMatrix(configuration, true);
|
const bool mc_rotors_added_successfully = _mc_rotors.addActuators(configuration);
|
||||||
_mc_motors_mask = (1u << _mc_rotors.geometry().num_rotors) - 1;
|
_mc_motors_mask = (1u << _mc_rotors.geometry().num_rotors) - 1;
|
||||||
|
|
||||||
// Pusher/Puller
|
// Pusher/Puller
|
||||||
@@ -63,9 +64,9 @@ ActuatorEffectivenessStandardVTOL::getEffectivenessMatrix(Configuration &configu
|
|||||||
// Control Surfaces
|
// Control Surfaces
|
||||||
configuration.selected_matrix = 1;
|
configuration.selected_matrix = 1;
|
||||||
_first_control_surface_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
|
_first_control_surface_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
|
||||||
_control_surfaces.getEffectivenessMatrix(configuration, true);
|
const bool surfaces_added_successfully = _control_surfaces.addActuators(configuration);
|
||||||
|
|
||||||
return true;
|
return (mc_rotors_added_successfully && surfaces_added_successfully);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActuatorEffectivenessStandardVTOL::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
|
void ActuatorEffectivenessStandardVTOL::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ public:
|
|||||||
ActuatorEffectivenessStandardVTOL(ModuleParams *parent);
|
ActuatorEffectivenessStandardVTOL(ModuleParams *parent);
|
||||||
virtual ~ActuatorEffectivenessStandardVTOL() = default;
|
virtual ~ActuatorEffectivenessStandardVTOL() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
|
||||||
|
|
||||||
const char *name() const override { return "Standard VTOL"; }
|
const char *name() const override { return "Standard VTOL"; }
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -47,24 +47,24 @@ ActuatorEffectivenessTailsitterVTOL::ActuatorEffectivenessTailsitterVTOL(ModuleP
|
|||||||
setFlightPhase(FlightPhase::HOVER_FLIGHT);
|
setFlightPhase(FlightPhase::HOVER_FLIGHT);
|
||||||
}
|
}
|
||||||
bool
|
bool
|
||||||
ActuatorEffectivenessTailsitterVTOL::getEffectivenessMatrix(Configuration &configuration, bool force)
|
ActuatorEffectivenessTailsitterVTOL::getEffectivenessMatrix(Configuration &configuration,
|
||||||
|
EffectivenessUpdateReason external_update)
|
||||||
{
|
{
|
||||||
if (!force) {
|
if (external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MC motors
|
// MC motors
|
||||||
configuration.selected_matrix = 0;
|
configuration.selected_matrix = 0;
|
||||||
_mc_rotors.enableYawControl(_mc_rotors.geometry().num_rotors > 3); // enable MC yaw control if more than 3 rotors
|
_mc_rotors.enableYawControl(_mc_rotors.geometry().num_rotors > 3); // enable MC yaw control if more than 3 rotors
|
||||||
|
const bool mc_rotors_added_successfully = _mc_rotors.addActuators(configuration);
|
||||||
_mc_rotors.getEffectivenessMatrix(configuration, true);
|
|
||||||
|
|
||||||
// Control Surfaces
|
// Control Surfaces
|
||||||
configuration.selected_matrix = 1;
|
configuration.selected_matrix = 1;
|
||||||
_first_control_surface_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
|
_first_control_surface_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
|
||||||
_control_surfaces.getEffectivenessMatrix(configuration, true);
|
const bool surfaces_added_successfully = _control_surfaces.addActuators(configuration);
|
||||||
|
|
||||||
return true;
|
return (mc_rotors_added_successfully && surfaces_added_successfully);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActuatorEffectivenessTailsitterVTOL::setFlightPhase(const FlightPhase &flight_phase)
|
void ActuatorEffectivenessTailsitterVTOL::setFlightPhase(const FlightPhase &flight_phase)
|
||||||
|
|||||||
+1
-2
@@ -52,7 +52,7 @@ public:
|
|||||||
ActuatorEffectivenessTailsitterVTOL(ModuleParams *parent);
|
ActuatorEffectivenessTailsitterVTOL(ModuleParams *parent);
|
||||||
virtual ~ActuatorEffectivenessTailsitterVTOL() = default;
|
virtual ~ActuatorEffectivenessTailsitterVTOL() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
|
||||||
|
|
||||||
int numMatrices() const override { return 2; }
|
int numMatrices() const override { return 2; }
|
||||||
|
|
||||||
@@ -75,7 +75,6 @@ public:
|
|||||||
|
|
||||||
uint32_t getStoppedMotors() const override { return _stopped_motors; }
|
uint32_t getStoppedMotors() const override { return _stopped_motors; }
|
||||||
protected:
|
protected:
|
||||||
bool _updated{true};
|
|
||||||
ActuatorEffectivenessRotors _mc_rotors;
|
ActuatorEffectivenessRotors _mc_rotors;
|
||||||
ActuatorEffectivenessControlSurfaces _control_surfaces;
|
ActuatorEffectivenessControlSurfaces _control_surfaces;
|
||||||
|
|
||||||
|
|||||||
+14
-12
@@ -51,9 +51,10 @@ ActuatorEffectivenessTiltrotorVTOL::ActuatorEffectivenessTiltrotorVTOL(ModulePar
|
|||||||
setFlightPhase(FlightPhase::HOVER_FLIGHT);
|
setFlightPhase(FlightPhase::HOVER_FLIGHT);
|
||||||
}
|
}
|
||||||
bool
|
bool
|
||||||
ActuatorEffectivenessTiltrotorVTOL::getEffectivenessMatrix(Configuration &configuration, bool force)
|
ActuatorEffectivenessTiltrotorVTOL::getEffectivenessMatrix(Configuration &configuration,
|
||||||
|
EffectivenessUpdateReason external_update)
|
||||||
{
|
{
|
||||||
if (!_updated && !force) {
|
if (!_combined_tilt_updated && external_update == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,30 +63,31 @@ ActuatorEffectivenessTiltrotorVTOL::getEffectivenessMatrix(Configuration &config
|
|||||||
_mc_rotors.enableYawControl(!_tilts.hasYawControl());
|
_mc_rotors.enableYawControl(!_tilts.hasYawControl());
|
||||||
|
|
||||||
// Update matrix with tilts in vertical position when update is triggered by a manual
|
// Update matrix with tilts in vertical position when update is triggered by a manual
|
||||||
// configuration (parameter) change (=force update). This is to make sure the normalization
|
// configuration (parameter) change. This is to make sure the normalization
|
||||||
// scales are tilt-invariant. Note: force update only possible when disarm.
|
// scales are tilt-invariant. Note: configuration updates are only possible when disarmed.
|
||||||
const float tilt_control_applied = force ? -1.f : _last_tilt_control;
|
const float tilt_control_applied = (external_update == EffectivenessUpdateReason::CONFIGURATION_UPDATE) ? -1.f :
|
||||||
|
_last_tilt_control;
|
||||||
_nontilted_motors = _mc_rotors.updateAxisFromTilts(_tilts, tilt_control_applied)
|
_nontilted_motors = _mc_rotors.updateAxisFromTilts(_tilts, tilt_control_applied)
|
||||||
<< configuration.num_actuators[(int)ActuatorType::MOTORS];
|
<< configuration.num_actuators[(int)ActuatorType::MOTORS];
|
||||||
|
|
||||||
_mc_rotors.getEffectivenessMatrix(configuration, true);
|
const bool mc_rotors_added_successfully = _mc_rotors.addActuators(configuration);
|
||||||
|
|
||||||
// Control Surfaces
|
// Control Surfaces
|
||||||
configuration.selected_matrix = 1;
|
configuration.selected_matrix = 1;
|
||||||
_first_control_surface_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
|
_first_control_surface_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
|
||||||
_control_surfaces.getEffectivenessMatrix(configuration, true);
|
const bool surfaces_added_successfully = _control_surfaces.addActuators(configuration);
|
||||||
|
|
||||||
// Tilts
|
// Tilts
|
||||||
configuration.selected_matrix = 0;
|
configuration.selected_matrix = 0;
|
||||||
_first_tilt_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
|
_first_tilt_idx = configuration.num_actuators_matrix[configuration.selected_matrix];
|
||||||
_tilts.updateTorqueSign(_mc_rotors.geometry(), true /* disable pitch to avoid configuration errors */);
|
_tilts.updateTorqueSign(_mc_rotors.geometry(), true /* disable pitch to avoid configuration errors */);
|
||||||
_tilts.getEffectivenessMatrix(configuration, true);
|
const bool tilts_added_successfully = _tilts.addActuators(configuration);
|
||||||
|
|
||||||
// If it was a forced update (thus coming from a config change), then make sure to update matrix in
|
// If it was an update coming from a config change, then make sure to update matrix in
|
||||||
// the next iteration again with the correct tilt (but without updating the normalization scale).
|
// the next iteration again with the correct tilt (but without updating the normalization scale).
|
||||||
_updated = force;
|
_combined_tilt_updated = (external_update == EffectivenessUpdateReason::CONFIGURATION_UPDATE);
|
||||||
|
|
||||||
return true;
|
return (mc_rotors_added_successfully && surfaces_added_successfully && tilts_added_successfully);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActuatorEffectivenessTiltrotorVTOL::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
|
void ActuatorEffectivenessTiltrotorVTOL::updateSetpoint(const matrix::Vector<float, NUM_AXES> &control_sp,
|
||||||
@@ -114,7 +116,7 @@ void ActuatorEffectivenessTiltrotorVTOL::updateSetpoint(const matrix::Vector<flo
|
|||||||
_last_tilt_control = control_tilt;
|
_last_tilt_control = control_tilt;
|
||||||
|
|
||||||
} else if (fabsf(control_tilt - _last_tilt_control) > 0.01f) {
|
} else if (fabsf(control_tilt - _last_tilt_control) > 0.01f) {
|
||||||
_updated = true;
|
_combined_tilt_updated = true;
|
||||||
_last_tilt_control = control_tilt;
|
_last_tilt_control = control_tilt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -55,7 +55,7 @@ public:
|
|||||||
ActuatorEffectivenessTiltrotorVTOL(ModuleParams *parent);
|
ActuatorEffectivenessTiltrotorVTOL(ModuleParams *parent);
|
||||||
virtual ~ActuatorEffectivenessTiltrotorVTOL() = default;
|
virtual ~ActuatorEffectivenessTiltrotorVTOL() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool getEffectivenessMatrix(Configuration &configuration, EffectivenessUpdateReason external_update) override;
|
||||||
|
|
||||||
int numMatrices() const override { return 2; }
|
int numMatrices() const override { return 2; }
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
|
|
||||||
uint32_t getStoppedMotors() const override { return _stopped_motors; }
|
uint32_t getStoppedMotors() const override { return _stopped_motors; }
|
||||||
protected:
|
protected:
|
||||||
bool _updated{true};
|
bool _combined_tilt_updated{true};
|
||||||
ActuatorEffectivenessRotors _mc_rotors;
|
ActuatorEffectivenessRotors _mc_rotors;
|
||||||
ActuatorEffectivenessControlSurfaces _control_surfaces;
|
ActuatorEffectivenessControlSurfaces _control_surfaces;
|
||||||
ActuatorEffectivenessTilts _tilts;
|
ActuatorEffectivenessTilts _tilts;
|
||||||
|
|||||||
@@ -84,12 +84,8 @@ void ActuatorEffectivenessTilts::updateParams()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActuatorEffectivenessTilts::getEffectivenessMatrix(Configuration &configuration, bool force)
|
bool ActuatorEffectivenessTilts::addActuators(Configuration &configuration)
|
||||||
{
|
{
|
||||||
if (!force) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < _count; i++) {
|
for (int i = 0; i < _count; i++) {
|
||||||
configuration.addActuator(ActuatorType::SERVOS, _torque[i], Vector3f{});
|
configuration.addActuator(ActuatorType::SERVOS, _torque[i], Vector3f{});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
ActuatorEffectivenessTilts(ModuleParams *parent);
|
ActuatorEffectivenessTilts(ModuleParams *parent);
|
||||||
virtual ~ActuatorEffectivenessTilts() = default;
|
virtual ~ActuatorEffectivenessTilts() = default;
|
||||||
|
|
||||||
bool getEffectivenessMatrix(Configuration &configuration, bool force) override;
|
bool addActuators(Configuration &configuration);
|
||||||
|
|
||||||
const char *name() const override { return "Tilts"; }
|
const char *name() const override { return "Tilts"; }
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ px4_add_library(ActuatorEffectiveness
|
|||||||
ActuatorEffectivenessFixedWing.hpp
|
ActuatorEffectivenessFixedWing.hpp
|
||||||
ActuatorEffectivenessMCTilt.cpp
|
ActuatorEffectivenessMCTilt.cpp
|
||||||
ActuatorEffectivenessMCTilt.hpp
|
ActuatorEffectivenessMCTilt.hpp
|
||||||
|
ActuatorEffectivenessMultirotor.cpp
|
||||||
|
ActuatorEffectivenessMultirotor.hpp
|
||||||
ActuatorEffectivenessTilts.cpp
|
ActuatorEffectivenessTilts.cpp
|
||||||
ActuatorEffectivenessTilts.hpp
|
ActuatorEffectivenessTilts.hpp
|
||||||
ActuatorEffectivenessRotors.cpp
|
ActuatorEffectivenessRotors.cpp
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ ControlAllocator::parameters_updated()
|
|||||||
_control_allocation[i]->updateParameters();
|
_control_allocation[i]->updateParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
update_effectiveness_matrix_if_needed(true);
|
update_effectiveness_matrix_if_needed(EffectivenessUpdateReason::CONFIGURATION_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -208,7 +208,7 @@ ControlAllocator::update_effectiveness_source()
|
|||||||
switch (source) {
|
switch (source) {
|
||||||
case EffectivenessSource::NONE:
|
case EffectivenessSource::NONE:
|
||||||
case EffectivenessSource::MULTIROTOR:
|
case EffectivenessSource::MULTIROTOR:
|
||||||
tmp = new ActuatorEffectivenessRotors(this);
|
tmp = new ActuatorEffectivenessMultirotor(this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EffectivenessSource::STANDARD_VTOL:
|
case EffectivenessSource::STANDARD_VTOL:
|
||||||
@@ -362,7 +362,7 @@ ControlAllocator::Run()
|
|||||||
if (do_update) {
|
if (do_update) {
|
||||||
_last_run = now;
|
_last_run = now;
|
||||||
|
|
||||||
update_effectiveness_matrix_if_needed();
|
update_effectiveness_matrix_if_needed(EffectivenessUpdateReason::NO_EXTERNAL_UPDATE);
|
||||||
|
|
||||||
// Set control setpoint vector(s)
|
// Set control setpoint vector(s)
|
||||||
matrix::Vector<float, NUM_AXES> c[ActuatorEffectiveness::MAX_NUM_MATRICES];
|
matrix::Vector<float, NUM_AXES> c[ActuatorEffectiveness::MAX_NUM_MATRICES];
|
||||||
@@ -414,15 +414,16 @@ ControlAllocator::Run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ControlAllocator::update_effectiveness_matrix_if_needed(bool force)
|
ControlAllocator::update_effectiveness_matrix_if_needed(EffectivenessUpdateReason reason)
|
||||||
{
|
{
|
||||||
ActuatorEffectiveness::Configuration config{};
|
ActuatorEffectiveness::Configuration config{};
|
||||||
|
|
||||||
if (!force && hrt_elapsed_time(&_last_effectiveness_update) < 100_ms) { // rate-limit updates
|
if (reason == EffectivenessUpdateReason::NO_EXTERNAL_UPDATE
|
||||||
|
&& hrt_elapsed_time(&_last_effectiveness_update) < 100_ms) { // rate-limit updates
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_actuator_effectiveness->getEffectivenessMatrix(config, force)) {
|
if (_actuator_effectiveness->getEffectivenessMatrix(config, reason)) {
|
||||||
_last_effectiveness_update = hrt_absolute_time();
|
_last_effectiveness_update = hrt_absolute_time();
|
||||||
|
|
||||||
memcpy(_control_allocation_selection_indexes, config.matrix_selection_indexes,
|
memcpy(_control_allocation_selection_indexes, config.matrix_selection_indexes,
|
||||||
@@ -496,7 +497,7 @@ ControlAllocator::update_effectiveness_matrix_if_needed(bool force)
|
|||||||
// Assign control effectiveness matrix
|
// Assign control effectiveness matrix
|
||||||
int total_num_actuators = config.num_actuators_matrix[i];
|
int total_num_actuators = config.num_actuators_matrix[i];
|
||||||
_control_allocation[i]->setEffectivenessMatrix(config.effectiveness_matrices[i], config.trim[i],
|
_control_allocation[i]->setEffectivenessMatrix(config.effectiveness_matrices[i], config.trim[i],
|
||||||
config.linearization_point[i], total_num_actuators, force);
|
config.linearization_point[i], total_num_actuators, reason == EffectivenessUpdateReason::CONFIGURATION_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
trims.timestamp = hrt_absolute_time();
|
trims.timestamp = hrt_absolute_time();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ActuatorEffectiveness.hpp>
|
#include <ActuatorEffectiveness.hpp>
|
||||||
#include <ActuatorEffectivenessRotors.hpp>
|
#include <ActuatorEffectivenessMultirotor.hpp>
|
||||||
#include <ActuatorEffectivenessStandardVTOL.hpp>
|
#include <ActuatorEffectivenessStandardVTOL.hpp>
|
||||||
#include <ActuatorEffectivenessTiltrotorVTOL.hpp>
|
#include <ActuatorEffectivenessTiltrotorVTOL.hpp>
|
||||||
#include <ActuatorEffectivenessTailsitterVTOL.hpp>
|
#include <ActuatorEffectivenessTailsitterVTOL.hpp>
|
||||||
@@ -125,7 +125,7 @@ private:
|
|||||||
void update_allocation_method(bool force);
|
void update_allocation_method(bool force);
|
||||||
bool update_effectiveness_source();
|
bool update_effectiveness_source();
|
||||||
|
|
||||||
void update_effectiveness_matrix_if_needed(bool force = false);
|
void update_effectiveness_matrix_if_needed(EffectivenessUpdateReason reason);
|
||||||
|
|
||||||
void publish_control_allocator_status();
|
void publish_control_allocator_status();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user