33 changes: 33 additions & 0 deletions sw/airborne/modules/ctrl/eff_scheduling_falcon.h
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2023 Florian Sansou <florian.sansou@enac.fr>
* Copyright (C) 2023 Gautier Hattenberger <gautier.hattenberger.fr>
*
* This file is part of paparazzi
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/

/** @file "modules/ctrl/eff_scheduling_falcon.h"
* Interpolation of control effectivenss matrix of the Falcon hybrid plane
*/

#ifndef EFF_SCHEDULING_FALCON_H
#define EFF_SCHEDULING_FALCON_H

extern void eff_scheduling_falcon_init(void);
extern void eff_scheduling_falcon_periodic(void);
extern void eff_scheduling_falcon_report(void);

#endif // EFF_SCHEDULING_FALCON_H
86 changes: 86 additions & 0 deletions sw/airborne/modules/ctrl/eff_scheduling_generic.c
@@ -0,0 +1,86 @@
/*
* Copyright (C) 2017 Ewoud Smeur <ewoud_smeur@msn.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/

/** @file modules/ctrl/eff_scheduling_generic.c
* Module that interpolates gainsets in flight based on the transition percentage
*/

#include "modules/ctrl/ctrl_effectiveness_scheduling.h"
#include "firmwares/rotorcraft/stabilization/stabilization_indi.h"
#include "firmwares/rotorcraft/guidance/guidance_h.h"
#include "generated/airframe.h"
#include "state.h"
#include "modules/radio_control/radio_control.h"

#if STABILIZATION_INDI_ALLOCATION_PSEUDO_INVERSE
#error "You need to use WLS control allocation for this module"
#endif

#ifndef INDI_FUNCTIONS_RC_CHANNEL
#error "You need to define an RC channel to switch between simple and advanced scheduling"
#endif

static float g1g2_forward[INDI_OUTPUTS][INDI_NUM_ACT] = {
FWD_G1_ROLL,
FWD_G1_PITCH,
FWD_G1_YAW,
FWD_G1_THRUST
};

static float g1g2_hover[INDI_OUTPUTS][INDI_NUM_ACT] = {
STABILIZATION_INDI_G1_ROLL,
STABILIZATION_INDI_G1_PITCH,
STABILIZATION_INDI_G1_YAW,
STABILIZATION_INDI_G1_THRUST
};

static float g2_both[INDI_NUM_ACT] = STABILIZATION_INDI_G2; //scaled by INDI_G_SCALING

void eff_scheduling_generic_init(void)
{
//sum of G1 and G2
int8_t i;
int8_t j;
for (i = 0; i < INDI_OUTPUTS; i++) {
for (j = 0; j < INDI_NUM_ACT; j++) {
if (i != 2) {
g1g2_hover[i][j] = g1g2_hover[i][j] / INDI_G_SCALING;
g1g2_forward[i][j] = g1g2_forward[i][j] / INDI_G_SCALING;
} else {
g1g2_forward[i][j] = (g1g2_forward[i][j] + g2_both[j]) / INDI_G_SCALING;
g1g2_hover[i][j] = (g1g2_hover[i][j] + g2_both[j]) / INDI_G_SCALING;
}
}
}
}

void eff_scheduling_generic_periodic(void)
{
// Go from transition percentage to ratio
float ratio = FLOAT_OF_BFP(transition_percentage, INT32_PERCENTAGE_FRAC) / 100;
int8_t i;
int8_t j;
for (i = 0; i < INDI_OUTPUTS; i++) {
for (j = 0; j < INDI_NUM_ACT; j++) {
g1g2[i][j] = g1g2_hover[i][j] * (1.0 - ratio) + g1g2_forward[i][j] * ratio;
}
}
}

Expand Up @@ -14,32 +14,26 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/

/**
* @file modules/ctrl/ctrl_effectiveness_scheduling.h
* @file modules/ctrl/eff_scheduling_generic.h
*/

#ifndef CTRL_EFFECTIVENESS_SCHEDULING_H
#define CTRL_EFFECTIVENESS_SCHEDULING_H

#include "generated/airframe.h"
#include "firmwares/rotorcraft/stabilization/stabilization_indi.h"
#ifndef EFF_SCHEDULING_GENERIC_H
#define EFF_SCHEDULING_GENERIC_H

/**
* Initialises periodic loop;
*/
extern void ctrl_eff_scheduling_init(void);
extern void eff_scheduling_generic_init(void);

/**
* Periodic function that interpolates between gain sets depending on the scheduling variable.
*/
extern void ctrl_eff_scheduling_periodic(void);
extern void ctrl_eff_scheduling_periodic_a(void);
extern void ctrl_eff_scheduling_periodic_b(void);
extern void eff_scheduling_generic_periodic(void);

#endif /* CTRL_EFFECTIVENESS_SCHEDULING_H */
#endif /* EFF_SCHEDULING_GENERIC_H */