Skip to content

Commit

Permalink
[scheduling] harmonize efficiency scheduling modules
Browse files Browse the repository at this point in the history
- harmonize name
- make a 'generic' module with basic linear scheduling
- old ctrl_effectiveness_scheduling was very specific to cyfoam, so
  renamed
- add falcon scheduler, related airframe will come later
  • Loading branch information
gautierhattenberger committed Nov 22, 2023
1 parent 7b54c09 commit 19a7e57
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 76 deletions.
2 changes: 1 addition & 1 deletion conf/airframes/ENAC/cyfoam.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<define name="RADIO_KILL_SWITCH" value="RADIO_GAIN1"/>
</module>

<module name="ctrl_effectiveness_scheduling">
<module name="eff_scheduling_cyfoam">
<define name="SQUARED_ROLL_EFF" value="0.0018"/>
<define name="PITCH_EFF_AT_60" value="4.0"/>
<define name="YAW_EFF_AT_60" value="8.0"/>
Expand Down
2 changes: 1 addition & 1 deletion conf/airframes/tudelft/cyfoam.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<define name="RADIO_KILL_SWITCH" value="5"/>
</module>

<module name="ctrl_effectiveness_scheduling">
<module name="eff_scheduling_cyfoam">
<define name="SQUARED_ROLL_EFF" value="0.0018"/>
<define name="PITCH_EFF_AT_60" value="4.0"/>
<define name="YAW_EFF_AT_60" value="8.0"/>
Expand Down
22 changes: 0 additions & 22 deletions conf/modules/ctrl_effectiveness_scheduling.xml

This file was deleted.

20 changes: 20 additions & 0 deletions conf/modules/eff_scheduling_cyfoam.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="eff_scheduling_cyfoam" dir="ctrl">
<doc>
<description>
Interpolation of control effectiveness matrix for Cyfoam tailsitter.

Two scheduling functions are available, controlled by the flag
INDI_FUNCTIONS_RC_CHANNEL, which indicates the RC channel to be used.
</description>
</doc>
<header>
<file name="eff_scheduling_cyfoam.h"/>
</header>
<init fun="eff_scheduling_cyfoam_init()"/>
<periodic fun="eff_scheduling_cyfoam_periodic()" freq="20"/>
<makefile>
<file name="eff_scheduling_cyfoam.c"/>
</makefile>
</module>
18 changes: 18 additions & 0 deletions conf/modules/eff_scheduling_falcon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE module SYSTEM "module.dtd">
<module name="eff_scheduling_falcon" dir="ctrl">
<doc>
<description>
Interpolation of control effectivenss matrix of the Falcon hybride plane
</description>
</doc>

<header>
<file name="eff_scheduling_falcon.h"/>
</header>
<init fun="eff_scheduling_falcon_init()"/>
<periodic fun="eff_scheduling_falcon_periodic()" freq="20.0"/>
<periodic fun="eff_scheduling_falcon_report()" freq="0.5" autorun="FALSE"/> <!-- TRUE FALSE-->
<makefile target="ap|nps" firmware="rotorcraft" >
<file name="eff_scheduling_falcon.c"/>
</makefile>
</module>
24 changes: 24 additions & 0 deletions conf/modules/eff_scheduling_generic.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="eff_scheduling_generic" dir="ctrl">
<doc>
<description>
Interpolation of control effectivenss matrix.
This is necessary if the vehicle has different operating points,
with significantly different control effectivenss.
Interpolation is linear between two points, usually hover and
forward conditions.

If instead using online adaptation is an option, be sure to
not use this module at the same time!
</description>
</doc>
<header>
<file name="eff_scheduling_generic.h"/>
</header>
<init fun="eff_scheduling_generic_init()"/>
<periodic fun="eff_scheduling_generic_periodic()" freq="20"/>
<makefile>
<file name="eff_scheduling_generic.c"/>
</makefile>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* 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.c
* Module that interpolates gainsets in flight based on the transition percentage
*/

#include "modules/ctrl/ctrl_effectiveness_scheduling.h"
#include "modules/ctrl/eff_scheduling_cyfoam.h"
#include "firmwares/rotorcraft/stabilization/stabilization_indi.h"
#include "firmwares/rotorcraft/guidance/guidance_h.h"
#include "generated/airframe.h"
Expand All @@ -38,18 +37,23 @@
#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_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 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

//Get the specified gains in the gainlibrary
void ctrl_eff_scheduling_init(void)
void eff_scheduling_cyfoam_init(void)
{
//sum of G1 and G2
int8_t i;
Expand All @@ -67,31 +71,7 @@ void ctrl_eff_scheduling_init(void)
}
}

void ctrl_eff_scheduling_periodic(void)
{
if(radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0) {
ctrl_eff_scheduling_periodic_b();
} else {
ctrl_eff_scheduling_periodic_a();
}

#ifdef INDI_THRUST_ON_PITCH_EFF
//State prioritization {W Roll, W pitch, W yaw, TOTAL THRUST}
if(radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0 && (actuator_state_filt_vect[0] < -7000) && (actuator_state_filt_vect[1] > 7000)) {
Bwls[1][2] = INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
Bwls[1][3] = INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
} else if(radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0 && (actuator_state_filt_vect[0] > 7000) && (actuator_state_filt_vect[1] < -7000)) {
Bwls[1][2] = -INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
Bwls[1][3] = -INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
} else {
Bwls[1][2] = 0.0;
Bwls[1][3] = 0.0;
}
#endif

}

void ctrl_eff_scheduling_periodic_a(void)
static void eff_scheduling_periodic_a(void)
{
// Go from transition percentage to ratio
float ratio = FLOAT_OF_BFP(transition_percentage, INT32_PERCENTAGE_FRAC) / 100;
Expand All @@ -105,7 +85,7 @@ void ctrl_eff_scheduling_periodic_a(void)
}
}

void ctrl_eff_scheduling_periodic_b(void)
static void eff_scheduling_periodic_b(void)
{
float airspeed = stateGetAirspeed_f();
struct FloatEulers eulers_zxy;
Expand Down Expand Up @@ -149,3 +129,26 @@ void ctrl_eff_scheduling_periodic_b(void)

}

void eff_scheduling_cyfoam_periodic(void)
{
if (radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0) {
eff_scheduling_periodic_b();
} else {
eff_scheduling_periodic_a();
}

#ifdef INDI_THRUST_ON_PITCH_EFF
//State prioritization {W Roll, W pitch, W yaw, TOTAL THRUST}
if(radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0 && (actuator_state_filt_vect[0] < -7000) && (actuator_state_filt_vect[1] > 7000)) {
Bwls[1][2] = INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
Bwls[1][3] = INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
} else if(radio_control.values[INDI_FUNCTIONS_RC_CHANNEL] > 0 && (actuator_state_filt_vect[0] > 7000) && (actuator_state_filt_vect[1] < -7000)) {
Bwls[1][2] = -INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
Bwls[1][3] = -INDI_THRUST_ON_PITCH_EFF/INDI_G_SCALING;
} else {
Bwls[1][2] = 0.0;
Bwls[1][3] = 0.0;
}
#endif
}

39 changes: 39 additions & 0 deletions sw/airborne/modules/ctrl/eff_scheduling_cyfoam.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) Gautier Hattenberger <gautier.hattenberger@enac.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_cyfoam.h
*/

#ifndef EFF_SCHEDULING_CYFOAM_H
#define EFF_SCHEDULING_CYFOAM_H

/**
* Initialises periodic loop;
*/
extern void eff_scheduling_cyfoam_init(void);

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

#endif /* EFF_SCHEDULING_CYFOAM_H */

118 changes: 118 additions & 0 deletions sw/airborne/modules/ctrl/eff_scheduling_falcon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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.c"
* Interpolation of control effectivenss matrix of the Falcon hybrid plane
*/

#include "modules/ctrl/eff_scheduling_falcon.h"
#include "firmwares/rotorcraft/stabilization/stabilization_indi.h"
#include "firmwares/rotorcraft/guidance/guidance_h.h"
#include "state.h"

#include "modules/datalink/downlink.h"

// Airspeed at which only with motor
#ifndef EFF_SCHEDULING_FALCON_LOW_AIRSPEED
#define EFF_SCHEDULING_FALCON_LOW_AIRSPEED 8.0f
#endif

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
};

void eff_scheduling_falcon_init(void)
{
for (int8_t i = 0; i < INDI_OUTPUTS; i++) {
for (int8_t j = 0; j < INDI_NUM_ACT; j++) {
g1g2[i][j] = g1g2_hover[i][j] / INDI_G_SCALING;
}
}
}

void eff_scheduling_falcon_periodic(void)
{
// calculate squared airspeed
float airspeed = stateGetAirspeed_f();

if (airspeed > EFF_SCHEDULING_FALCON_LOW_AIRSPEED) {
airspeed -= EFF_SCHEDULING_FALCON_LOW_AIRSPEED; //offset for start eff at zero!
struct FloatEulers eulers_zxy;
float_eulers_of_quat_zxy(&eulers_zxy, stateGetNedToBodyQuat_f());

float pitch_ratio = 0.0f;
if (eulers_zxy.theta > -M_PI_4) {
pitch_ratio = 0.0f;
}
else {
pitch_ratio = fabsf(1.0f - eulers_zxy.theta/(float)(-M_PI_4));
}
Bound(pitch_ratio, 0.0f, 1.0f);


Bound(airspeed, 0.0f, 30.0f);
float airspeed2 = airspeed*airspeed;

// not effect of elevon on body roll axis
g1g2[0][4] = 0;
g1g2[0][5] = 0;

float pitch_eff = pitch_ratio * EFF_PITCH_A * airspeed2;
g1g2[1][4] = pitch_eff / 1000; // elevon_right
g1g2[1][5] = -pitch_eff / 1000; // elevon_left

float yaw_eff = pitch_ratio * EFF_YAW_A * airspeed2;
g1g2[2][4] = -yaw_eff / 1000; // elevon_right
g1g2[2][5] = -yaw_eff / 1000; // elevon_left

// No thrust generated by elevon, maybe take drag in accout for the future ?
g1g2[3][4] = 0;
g1g2[3][5] = 0;
}
else {
//Come back to motor control
g1g2[0][4] = 0; // elevon_left
g1g2[0][5] = 0; // elevon_right

g1g2[1][4] = 0; // elevon_left
g1g2[1][5] = 0; // elevon_right

g1g2[2][4] = 0; // elevon_left
g1g2[2][5] = 0; // elevon_right

g1g2[3][4] = 0; // elevon_left
g1g2[3][5] = 0; // elevon_right
}
}

extern void eff_scheduling_falcon_report(void)
{
float f[6] = {
g1g2[1][4], g1g2[1][5],
g1g2[2][4], g1g2[2][5],
g1g2[1][0], g1g2[2][0]
};
DOWNLINK_SEND_PAYLOAD_FLOAT(DefaultChannel, DefaultDevice, 6, f);
}

0 comments on commit 19a7e57

Please sign in to comment.