1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 05:15:25 +03:00

Added new debug mode to time pidloop subtasks.

This commit is contained in:
Martin Budden 2016-05-05 10:28:26 +01:00
parent fa24d2950e
commit 825475fd43
10 changed files with 98 additions and 78 deletions

View file

@ -42,10 +42,13 @@ extern uint32_t sectionTimes[2][4];
#endif #endif
typedef enum { typedef enum {
DEBUG_CYCLETIME = 1, DEBUG_NONE,
DEBUG_CYCLETIME,
DEBUG_BATTERY, DEBUG_BATTERY,
DEBUG_GYRO, DEBUG_GYRO,
DEBUG_ACCELEROMETER, DEBUG_ACCELEROMETER,
DEBUG_MIXER, DEBUG_MIXER,
DEBUG_AIRMODE DEBUG_AIRMODE,
DEBUG_PIDLOOP,
DEBUG_COUNT
} debugType_e; } debugType_e;

View file

@ -62,9 +62,10 @@ int32_t axisPID_P[3], axisPID_I[3], axisPID_D[3];
uint8_t PIDweight[3]; uint8_t PIDweight[3];
static int32_t errorGyroI[3], errorGyroILimit[3]; static int32_t errorGyroI[3], errorGyroILimit[3];
#ifndef SKIP_PID_LUXFLOAT
static float errorGyroIf[3], errorGyroIfLimit[3]; static float errorGyroIf[3], errorGyroIfLimit[3];
static int32_t errorAngleI[2]; #endif
static float errorAngleIf[2];
static bool lowThrottlePidReduction; static bool lowThrottlePidReduction;
static void pidMultiWiiRewrite(pidProfile_t *pidProfile, controlRateConfig_t *controlRateConfig, static void pidMultiWiiRewrite(pidProfile_t *pidProfile, controlRateConfig_t *controlRateConfig,
@ -103,22 +104,15 @@ uint16_t getDynamicKp(int axis, pidProfile_t *pidProfile) {
return dynamicKp; return dynamicKp;
} }
void pidResetErrorAngle(void)
{
errorAngleI[ROLL] = 0;
errorAngleI[PITCH] = 0;
errorAngleIf[ROLL] = 0.0f;
errorAngleIf[PITCH] = 0.0f;
}
void pidResetErrorGyroState(uint8_t resetOption) void pidResetErrorGyroState(uint8_t resetOption)
{ {
if (resetOption >= RESET_ITERM) { if (resetOption >= RESET_ITERM) {
int axis; int axis;
for (axis = 0; axis < 3; axis++) { for (axis = 0; axis < 3; axis++) {
errorGyroI[axis] = 0; errorGyroI[axis] = 0;
#ifndef SKIP_PID_LUXFLOAT
errorGyroIf[axis] = 0.0f; errorGyroIf[axis] = 0.0f;
#endif
} }
} }
@ -141,6 +135,7 @@ const angle_index_t rcAliasToAngleIndexMap[] = { AI_ROLL, AI_PITCH };
static filterStatePt1_t deltaFilterState[3]; static filterStatePt1_t deltaFilterState[3];
static filterStatePt1_t yawFilterState; static filterStatePt1_t yawFilterState;
#ifndef SKIP_PID_LUXFLOAT
static void pidLuxFloat(pidProfile_t *pidProfile, controlRateConfig_t *controlRateConfig, static void pidLuxFloat(pidProfile_t *pidProfile, controlRateConfig_t *controlRateConfig,
uint16_t max_angle_inclination, rollAndPitchTrims_t *angleTrim, rxConfig_t *rxConfig) uint16_t max_angle_inclination, rollAndPitchTrims_t *angleTrim, rxConfig_t *rxConfig)
{ {
@ -280,6 +275,7 @@ static void pidLuxFloat(pidProfile_t *pidProfile, controlRateConfig_t *controlRa
#endif #endif
} }
} }
#endif
static void pidMultiWiiRewrite(pidProfile_t *pidProfile, controlRateConfig_t *controlRateConfig, uint16_t max_angle_inclination, static void pidMultiWiiRewrite(pidProfile_t *pidProfile, controlRateConfig_t *controlRateConfig, uint16_t max_angle_inclination,
rollAndPitchTrims_t *angleTrim, rxConfig_t *rxConfig) rollAndPitchTrims_t *angleTrim, rxConfig_t *rxConfig)
@ -426,8 +422,10 @@ void pidSetController(pidControllerType_e type)
case PID_CONTROLLER_MWREWRITE: case PID_CONTROLLER_MWREWRITE:
pid_controller = pidMultiWiiRewrite; pid_controller = pidMultiWiiRewrite;
break; break;
#ifndef SKIP_PID_LUXFLOAT
case PID_CONTROLLER_LUX_FLOAT: case PID_CONTROLLER_LUX_FLOAT:
pid_controller = pidLuxFloat; pid_controller = pidLuxFloat;
#endif
} }
} }

View file

@ -97,7 +97,6 @@ bool antiWindupProtection;
extern uint32_t targetPidLooptime; extern uint32_t targetPidLooptime;
void pidSetController(pidControllerType_e type); void pidSetController(pidControllerType_e type);
void pidResetErrorAngle(void);
void pidResetErrorGyroState(uint8_t resetOption); void pidResetErrorGyroState(uint8_t resetOption);
void setTargetPidLooptime(uint8_t pidProcessDenom); void setTargetPidLooptime(uint8_t pidProcessDenom);

View file

@ -22,6 +22,7 @@
#include "platform.h" #include "platform.h"
#include "version.h" #include "version.h"
#include "debug.h"
#include "build_config.h" #include "build_config.h"
@ -58,14 +59,16 @@
#include "flight/navigation.h" #include "flight/navigation.h"
#endif #endif
#include "config/runtime_config.h"
#include "config/config.h" #include "config/config.h"
#include "config/runtime_config.h"
#include "config/config_profile.h"
#include "display.h" #include "display.h"
#include "scheduler.h" #include "scheduler.h"
extern profile_t *currentProfile;
controlRateConfig_t *getControlRateConfig(uint8_t profileIndex); controlRateConfig_t *getControlRateConfig(uint8_t profileIndex);
#define MICROSECONDS_IN_A_SECOND (1000 * 1000) #define MICROSECONDS_IN_A_SECOND (1000 * 1000)
@ -317,13 +320,26 @@ void showProfilePage(void)
i2c_OLED_set_line(rowIndex++); i2c_OLED_set_line(rowIndex++);
i2c_OLED_send_string(lineBuffer); i2c_OLED_send_string(lineBuffer);
uint8_t currentRateProfileIndex = getCurrentControlRateProfile(); static const char* const axisTitles[3] = {"ROL", "PIT", "YAW"};
const pidProfile_t *pidProfile = &currentProfile->pidProfile;
for (int axis = 0; axis < 3; ++axis) {
tfp_sprintf(lineBuffer, "%s P:%3d I:%3d D:%3d",
axisTitles[axis],
pidProfile->P8[axis],
pidProfile->I8[axis],
pidProfile->D8[axis]
);
padLineBuffer();
i2c_OLED_set_line(rowIndex++);
i2c_OLED_send_string(lineBuffer);
}
const uint8_t currentRateProfileIndex = getCurrentControlRateProfile();
tfp_sprintf(lineBuffer, "Rate profile: %d", currentRateProfileIndex); tfp_sprintf(lineBuffer, "Rate profile: %d", currentRateProfileIndex);
i2c_OLED_set_line(rowIndex++); i2c_OLED_set_line(rowIndex++);
i2c_OLED_send_string(lineBuffer); i2c_OLED_send_string(lineBuffer);
controlRateConfig_t *controlRateConfig = getControlRateConfig(currentRateProfileIndex); const controlRateConfig_t *controlRateConfig = getControlRateConfig(currentRateProfileIndex);
tfp_sprintf(lineBuffer, "RCE: %d, RCR: %d", tfp_sprintf(lineBuffer, "RCE: %d, RCR: %d",
controlRateConfig->rcExpo8, controlRateConfig->rcExpo8,
controlRateConfig->rcRate8 controlRateConfig->rcRate8

View file

@ -15,7 +15,7 @@
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>. * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/ */
//#define ENABLE_DEBUG_OLED_PAGE #define ENABLE_DEBUG_OLED_PAGE
typedef enum { typedef enum {
PAGE_WELCOME, PAGE_WELCOME,

View file

@ -26,6 +26,7 @@
#include "platform.h" #include "platform.h"
#include "scheduler.h" #include "scheduler.h"
#include "version.h" #include "version.h"
#include "debug.h"
#include "build_config.h" #include "build_config.h"
@ -426,14 +427,15 @@ static const char * const lookupTableMagHardware[] = {
"AK8963" "AK8963"
}; };
static const char * const lookupTableDebug[] = { static const char * const lookupTableDebug[DEBUG_COUNT] = {
"NONE", "NONE",
"CYCLETIME", "CYCLETIME",
"BATTERY", "BATTERY",
"GYRO", "GYRO",
"ACCELEROMETER", "ACCELEROMETER",
"MIXER", "MIXER",
"AIRMODE" "AIRMODE",
"PIDLOOP",
}; };
static const char * const lookupTableSuperExpoYaw[] = { static const char * const lookupTableSuperExpoYaw[] = {

View file

@ -504,7 +504,6 @@ void processRx(void)
} else { } else {
pidResetErrorGyroState(RESET_ITERM_AND_REDUCE_PID); pidResetErrorGyroState(RESET_ITERM_AND_REDUCE_PID);
} }
pidResetErrorAngle();
} }
} else { } else {
pidResetErrorGyroState(RESET_DISABLE); pidResetErrorGyroState(RESET_DISABLE);
@ -655,6 +654,7 @@ void processRx(void)
void subTaskPidController(void) void subTaskPidController(void)
{ {
const uint32_t startTime = micros();
// PID - note this is function pointer set by setPIDController() // PID - note this is function pointer set by setPIDController()
pid_controller( pid_controller(
&currentProfile->pidProfile, &currentProfile->pidProfile,
@ -663,10 +663,13 @@ void subTaskPidController(void)
&masterConfig.accelerometerTrims, &masterConfig.accelerometerTrims,
&masterConfig.rxConfig &masterConfig.rxConfig
); );
if (debugMode == DEBUG_PIDLOOP) {debug[2] = micros() - startTime;}
} }
void subTaskMainSubprocesses(void) { void subTaskMainSubprocesses(void) {
const uint32_t startTime = micros();
if (masterConfig.rxConfig.rcSmoothing || flightModeFlags) { if (masterConfig.rxConfig.rcSmoothing || flightModeFlags) {
filterRc(); filterRc();
} }
@ -730,16 +733,18 @@ void subTaskMainSubprocesses(void) {
#ifdef TRANSPONDER #ifdef TRANSPONDER
updateTransponder(); updateTransponder();
#endif #endif
if (debugMode == DEBUG_PIDLOOP) {debug[1] = micros() - startTime;}
} }
void subTaskMotorUpdate(void) void subTaskMotorUpdate(void)
{ {
const uint32_t startTime = micros();
if (debugMode == DEBUG_CYCLETIME) { if (debugMode == DEBUG_CYCLETIME) {
static uint32_t previousMotorUpdateTime; static uint32_t previousMotorUpdateTime;
uint32_t currentDeltaTime = micros() - previousMotorUpdateTime; const uint32_t currentDeltaTime = startTime - previousMotorUpdateTime;
debug[2] = currentDeltaTime; debug[2] = currentDeltaTime;
debug[3] = currentDeltaTime - targetPidLooptime; debug[3] = currentDeltaTime - targetPidLooptime;
previousMotorUpdateTime = micros(); previousMotorUpdateTime = startTime;
} }
mixTable(); mixTable();
@ -752,6 +757,7 @@ void subTaskMotorUpdate(void)
if (motorControlEnable) { if (motorControlEnable) {
writeMotors(); writeMotors();
} }
if (debugMode == DEBUG_PIDLOOP) {debug[3] = micros() - startTime;}
} }
uint8_t setPidUpdateCountDown(void) { uint8_t setPidUpdateCountDown(void) {
@ -778,10 +784,12 @@ void taskMainPidLoopCheck(void)
debug[1] = averageSystemLoadPercent; debug[1] = averageSystemLoadPercent;
} }
const uint32_t startTime = micros();
while (true) { while (true) {
if (gyroSyncCheckUpdate() || ((currentDeltaTime + (micros() - previousTime)) >= (targetLooptime + GYRO_WATCHDOG_DELAY))) { if (gyroSyncCheckUpdate() || ((currentDeltaTime + (micros() - previousTime)) >= (targetLooptime + GYRO_WATCHDOG_DELAY))) {
static uint8_t pidUpdateCountdown; static uint8_t pidUpdateCountdown;
if (debugMode == DEBUG_PIDLOOP) {debug[0] = micros() - startTime;} // time spent busy waiting
if (runTaskMainSubprocesses) { if (runTaskMainSubprocesses) {
subTaskMainSubprocesses(); subTaskMainSubprocesses();
runTaskMainSubprocesses = false; runTaskMainSubprocesses = false;

View file

@ -44,14 +44,14 @@ typedef enum {
/* Actual tasks */ /* Actual tasks */
TASK_SYSTEM = 0, TASK_SYSTEM = 0,
TASK_GYROPID, TASK_GYROPID,
TASK_ATTITUDE,
TASK_ACCEL, TASK_ACCEL,
TASK_ATTITUDE,
TASK_RX,
TASK_SERIAL, TASK_SERIAL,
TASK_BATTERY,
#ifdef BEEPER #ifdef BEEPER
TASK_BEEPER, TASK_BEEPER,
#endif #endif
TASK_BATTERY,
TASK_RX,
#ifdef GPS #ifdef GPS
TASK_GPS, TASK_GPS,
#endif #endif

View file

@ -22,14 +22,15 @@
#include <platform.h> #include <platform.h>
#include "scheduler.h" #include "scheduler.h"
void taskSystem(void);
void taskMainPidLoopCheck(void); void taskMainPidLoopCheck(void);
void taskUpdateAccelerometer(void); void taskUpdateAccelerometer(void);
void taskHandleSerial(void);
void taskUpdateAttitude(void); void taskUpdateAttitude(void);
void taskUpdateBeeper(void);
void taskUpdateBattery(void);
bool taskUpdateRxCheck(uint32_t currentDeltaTime); bool taskUpdateRxCheck(uint32_t currentDeltaTime);
void taskUpdateRxMain(void); void taskUpdateRxMain(void);
void taskHandleSerial(void);
void taskUpdateBattery(void);
void taskUpdateBeeper(void);
void taskProcessGPS(void); void taskProcessGPS(void);
void taskUpdateCompass(void); void taskUpdateCompass(void);
void taskUpdateBaro(void); void taskUpdateBaro(void);
@ -39,7 +40,6 @@ void taskUpdateDisplay(void);
void taskTelemetry(void); void taskTelemetry(void);
void taskLedStrip(void); void taskLedStrip(void);
void taskTransponder(void); void taskTransponder(void);
void taskSystem(void);
#ifdef USE_BST #ifdef USE_BST
void taskBstReadWrite(void); void taskBstReadWrite(void);
void taskBstMasterProcess(void); void taskBstMasterProcess(void);
@ -61,13 +61,6 @@ cfTask_t cfTasks[TASK_COUNT] = {
.staticPriority = TASK_PRIORITY_REALTIME, .staticPriority = TASK_PRIORITY_REALTIME,
}, },
[TASK_ATTITUDE] = {
.taskName = "ATTITUDE",
.taskFunc = taskUpdateAttitude,
.desiredPeriod = 1000000 / 100,
.staticPriority = TASK_PRIORITY_MEDIUM,
},
[TASK_ACCEL] = { [TASK_ACCEL] = {
.taskName = "ACCEL", .taskName = "ACCEL",
.taskFunc = taskUpdateAccelerometer, .taskFunc = taskUpdateAccelerometer,
@ -75,6 +68,21 @@ cfTask_t cfTasks[TASK_COUNT] = {
.staticPriority = TASK_PRIORITY_MEDIUM, .staticPriority = TASK_PRIORITY_MEDIUM,
}, },
[TASK_ATTITUDE] = {
.taskName = "ATTITUDE",
.taskFunc = taskUpdateAttitude,
.desiredPeriod = 1000000 / 100,
.staticPriority = TASK_PRIORITY_MEDIUM,
},
[TASK_RX] = {
.taskName = "RX",
.checkFunc = taskUpdateRxCheck,
.taskFunc = taskUpdateRxMain,
.desiredPeriod = 1000000 / 50, // If event-based scheduling doesn't work, fallback to periodic scheduling
.staticPriority = TASK_PRIORITY_HIGH,
},
[TASK_SERIAL] = { [TASK_SERIAL] = {
.taskName = "SERIAL", .taskName = "SERIAL",
.taskFunc = taskHandleSerial, .taskFunc = taskHandleSerial,
@ -82,6 +90,13 @@ cfTask_t cfTasks[TASK_COUNT] = {
.staticPriority = TASK_PRIORITY_LOW, .staticPriority = TASK_PRIORITY_LOW,
}, },
[TASK_BATTERY] = {
.taskName = "BATTERY",
.taskFunc = taskUpdateBattery,
.desiredPeriod = 1000000 / 50, // 50 Hz
.staticPriority = TASK_PRIORITY_LOW,
},
#ifdef BEEPER #ifdef BEEPER
[TASK_BEEPER] = { [TASK_BEEPER] = {
.taskName = "BEEPER", .taskName = "BEEPER",
@ -91,21 +106,6 @@ cfTask_t cfTasks[TASK_COUNT] = {
}, },
#endif #endif
[TASK_BATTERY] = {
.taskName = "BATTERY",
.taskFunc = taskUpdateBattery,
.desiredPeriod = 1000000 / 50, // 50 Hz
.staticPriority = TASK_PRIORITY_LOW,
},
[TASK_RX] = {
.taskName = "RX",
.checkFunc = taskUpdateRxCheck,
.taskFunc = taskUpdateRxMain,
.desiredPeriod = 1000000 / 50, // If event-based scheduling doesn't work, fallback to periodic scheduling
.staticPriority = TASK_PRIORITY_HIGH,
},
#ifdef GPS #ifdef GPS
[TASK_GPS] = { [TASK_GPS] = {
.taskName = "GPS", .taskName = "GPS",

View file

@ -71,10 +71,6 @@
#define MAG #define MAG
#define USE_MAG_HMC5883 #define USE_MAG_HMC5883
#define INVERTER
#define BEEPER
#define DISPLAY
#define USE_VCP #define USE_VCP
#define USE_USART1 #define USE_USART1
#define USE_USART3 #define USE_USART3
@ -117,28 +113,26 @@
#define WS2811_DMA_TC_FLAG DMA1_FLAG_TC6 #define WS2811_DMA_TC_FLAG DMA1_FLAG_TC6
#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH6_HANDLER #define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH6_HANDLER
#define BLACKBOX
#define TELEMETRY
#define SERIAL_RX
#define SONAR
#define USE_SERVOS
#define USE_CLI
#define USE_SERIAL_4WAY_BLHELI_INTERFACE
#undef DISPLAY
#undef SONAR
//#if defined(OPBL) && defined(USE_SERIAL_1WIRE)
#undef BARO
//#undef BLACKBOX
#undef GPS
//#endif
#define SKIP_CLI_COMMAND_HELP
#define SPEKTRUM_BIND #define SPEKTRUM_BIND
// USART3, PB11 (Flexport) // USART3, PB11 (Flexport)
#define BIND_PORT GPIOB #define BIND_PORT GPIOB
#define BIND_PIN Pin_11 #define BIND_PIN Pin_11
#define USE_QUATERNION #define USE_SERIAL_4WAY_BLHELI_INTERFACE
#define INVERTER
#define BEEPER
#define DISPLAY
#define BLACKBOX
#define TELEMETRY
#define SERIAL_RX
#define USE_SERVOS
#define USE_CLI
//#define SONAR
//#define GPS
#undef BARO
#define SKIP_CLI_COMMAND_HELP
#define SKIP_PID_LUXFLOAT