1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 08:15:30 +03:00

Rebased on to master

This commit is contained in:
jflyper 2017-06-19 19:43:18 +09:00
commit 8e2ebcf026
120 changed files with 1018 additions and 851 deletions

View file

@ -68,13 +68,18 @@ encoding_unittest_SRC := \
flight_failsafe_unittest_SRC := \
$(USER_DIR)/common/bitarray.c \
$(USER_DIR)/fc/rc_modes.c \
$(USER_DIR)/flight/failsafe.c
flight_imu_unittest_SRC := \
$(USER_DIR)/flight/imu.c \
$(USER_DIR)/common/bitarray.c \
$(USER_DIR)/common/maths.c \
$(USER_DIR)/config/feature.c \
$(USER_DIR)/fc/rc_modes.c \
$(USER_DIR)/flight/altitude.c \
$(USER_DIR)/common/maths.c
$(USER_DIR)/flight/imu.c
flight_mixer_unittest := \
@ -93,6 +98,8 @@ io_serial_unittest_SRC := \
ledstrip_unittest_SRC := \
$(USER_DIR)/common/bitarray.c \
$(USER_DIR)/fc/rc_modes.c \
$(USER_DIR)/io/ledstrip.c
@ -106,7 +113,11 @@ parameter_groups_unittest_SRC := \
rc_controls_unittest_SRC := \
$(USER_DIR)/fc/rc_controls.c \
$(USER_DIR)/common/maths.c
$(USER_DIR)/config/parameter_group.c \
$(USER_DIR)/common/bitarray.c \
$(USER_DIR)/common/maths.c \
$(USER_DIR)/fc/rc_adjustments.c \
$(USER_DIR)/fc/rc_modes.c \
rx_crsf_unittest_SRC := \
@ -119,12 +130,16 @@ rx_ibus_unittest_SRC := \
rx_ranges_unittest_SRC := \
$(USER_DIR)/rx/rx.c \
$(USER_DIR)/common/maths.c
$(USER_DIR)/common/bitarray.c \
$(USER_DIR)/common/maths.c \
$(USER_DIR)/fc/rc_modes.c \
$(USER_DIR)/rx/rx.c
rx_rx_unittest_SRC := \
$(USER_DIR)/rx/rx.c \
$(USER_DIR)/fc/rc_modes.c \
$(USER_DIR)/common/bitarray.c \
$(USER_DIR)/common/maths.c \
$(USER_DIR)/config/feature.c

View file

@ -29,15 +29,20 @@ extern "C" {
#include "common/axis.h"
#include "common/maths.h"
#include "common/bitarray.h"
#include "fc/runtime_config.h"
#include "fc/rc_modes.h"
#include "fc/rc_controls.h"
#include "flight/failsafe.h"
#include "io/beeper.h"
#include "fc/rc_controls.h"
#include "drivers/io.h"
#include "rx/rx.h"
#include "flight/failsafe.h"
extern boxBitmask_t rcModeActivationMask;
}
#include "unittest_macros.h"
@ -305,7 +310,11 @@ TEST(FlightFailsafeTest, TestFailsafeDetectsKillswitchEvent)
// and
throttleStatus = THROTTLE_HIGH; // throttle HIGH to go for a failsafe landing procedure
failsafeConfigMutable()->failsafe_kill_switch = true; // configure AUX switch as kill switch
ACTIVATE_RC_MODE(BOXFAILSAFE); // and activate it
boxBitmask_t newMask;
bitArraySet(&newMask, BOXFAILSAFE);
rcModeUpdate(&newMask); // activate BOXFAILSAFE mode
sysTickUptime = 0; // restart time from 0
failsafeOnValidDataReceived(); // set last valid sample at current time
sysTickUptime = PERIOD_RXDATA_FAILURE + 1; // adjust time to point just past the failure time to
@ -325,7 +334,8 @@ TEST(FlightFailsafeTest, TestFailsafeDetectsKillswitchEvent)
sysTickUptime += PERIOD_RXDATA_RECOVERY + 1; // adjust time to point just past the recovery time to
failsafeOnValidDataReceived(); // cause a recovered link
rcModeActivationMask = DE_ACTIVATE_ALL_BOXES; // BOXFAILSAFE must be off (kill switch)
memset(&newMask, 0, sizeof(newMask));
rcModeUpdate(&newMask); // BOXFAILSAFE must be off (kill switch)
// when
failsafeUpdateState();
@ -405,7 +415,6 @@ extern "C" {
int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
uint8_t armingFlags;
float rcCommand[4];
uint32_t rcModeActivationMask;
int16_t debug[DEBUG16_VALUE_COUNT];
bool isUsingSticksToArm = true;

View file

@ -28,6 +28,7 @@ extern "C" {
#include "common/axis.h"
#include "common/maths.h"
#include "config/feature.h"
#include "config/parameter_group_ids.h"
#include "drivers/accgyro/accgyro.h"
@ -42,6 +43,7 @@ extern "C" {
#include "fc/runtime_config.h"
#include "fc/rc_controls.h"
#include "fc/rc_modes.h"
#include "rx/rx.h"
@ -57,6 +59,12 @@ extern "C" {
PG_REGISTER(rcControlsConfig_t, rcControlsConfig, PG_RC_CONTROLS_CONFIG, 0);
PG_REGISTER(barometerConfig_t, barometerConfig, PG_BAROMETER_CONFIG, 0);
PG_REGISTER_WITH_RESET_TEMPLATE(featureConfig_t, featureConfig, PG_FEATURE_CONFIG, 0);
PG_RESET_TEMPLATE(featureConfig_t, featureConfig,
.enabledFeatures = 0
);
}
#include "unittest_macros.h"

View file

@ -36,6 +36,7 @@ extern "C" {
#include "fc/config.h"
#include "fc/rc_controls.h"
#include "fc/rc_modes.h"
#include "fc/runtime_config.h"
#include "drivers/light_ws2811strip.h"

View file

@ -48,7 +48,7 @@ PG_RESET_TEMPLATE(motorConfig_t, motorConfig,
TEST(ParameterGroupsfTest, Test_pgResetAll)
{
memset(motorConfigMutable(), 0, sizeof(motorConfig_t));
pgResetAll(0);
pgResetAll();
EXPECT_EQ(1150, motorConfig()->minthrottle);
EXPECT_EQ(1850, motorConfig()->maxthrottle);
EXPECT_EQ(1000, motorConfig()->mincommand);
@ -59,7 +59,7 @@ TEST(ParameterGroupsfTest, Test_pgFind)
{
memset(motorConfigMutable(), 0, sizeof(motorConfig_t));
const pgRegistry_t *pgRegistry = pgFind(PG_MOTOR_CONFIG);
pgResetCurrent(pgRegistry);
pgReset(pgRegistry);
EXPECT_EQ(1150, motorConfig()->minthrottle);
EXPECT_EQ(1850, motorConfig()->maxthrottle);
EXPECT_EQ(1000, motorConfig()->mincommand);
@ -68,7 +68,7 @@ TEST(ParameterGroupsfTest, Test_pgFind)
motorConfig_t motorConfig2;
memset(&motorConfig2, 0, sizeof(motorConfig_t));
motorConfigMutable()->dev.motorPwmRate = 500;
pgStore(pgRegistry, &motorConfig2, sizeof(motorConfig_t), 0);
pgStore(pgRegistry, &motorConfig2, sizeof(motorConfig_t));
EXPECT_EQ(1150, motorConfig2.minthrottle);
EXPECT_EQ(1850, motorConfig2.maxthrottle);
EXPECT_EQ(1000, motorConfig2.mincommand);

View file

@ -26,121 +26,124 @@ extern "C" {
#include "common/maths.h"
#include "common/axis.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "blackbox/blackbox.h"
#include "drivers/sensor.h"
#include "drivers/accgyro.h"
#include "sensors/sensors.h"
#include "sensors/acceleration.h"
#include "io/beeper.h"
#include "io/escservo.h"
#include "io/rc_controls.h"
#include "rx/rx.h"
#include "flight/pid.h"
#include "fc/controlrate_profile.h"
#include "fc/rc_modes.h"
#include "fc/rc_adjustments.h"
#include "fc/rc_controls.h"
}
#include "unittest_macros.h"
#include "gtest/gtest.h"
extern "C" {
extern void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, escAndServoConfig_t *escAndServoConfig, pidProfile_t *pidProfile);
}
class RcControlsModesTest : public ::testing::Test {
protected:
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
virtual void SetUp() {
memset(&modeActivationConditions, 0, sizeof(modeActivationConditions));
}
};
TEST_F(RcControlsModesTest, updateActivatedModesWithAllInputsAtMidde)
{
// given
rcModeActivationMask = 0;
boxBitmask_t mask;
memset(&mask, 0, sizeof(mask));
rcModeUpdate(&mask);
// and
memset(&rxRuntimeConfig, 0, sizeof(rxRuntimeConfig_t));
rxRuntimeConfig.auxChannelCount = MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT;
rxRuntimeConfig.channelCount = MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT;
// and
uint8_t index;
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
for (int index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
rcData[index] = PWM_RANGE_MIDDLE;
}
// when
updateActivatedModes(modeActivationConditions);
updateActivatedModes();
// then
for (index = 0; index < CHECKBOX_ITEM_COUNT; index++) {
for (int index = 0; index < CHECKBOX_ITEM_COUNT; index++) {
#ifdef DEBUG_RC_CONTROLS
printf("iteration: %d\n", index);
#endif
EXPECT_EQ(false, IS_RC_MODE_ACTIVE(index));
EXPECT_EQ(false, IS_RC_MODE_ACTIVE((boxId_e)index));
}
}
TEST_F(RcControlsModesTest, updateActivatedModesUsingValidAuxConfigurationAndRXValues)
{
// given
modeActivationConditions[0].modeId = (boxId_e)0;
modeActivationConditions[0].auxChannelIndex = AUX1 - NON_AUX_CHANNEL_COUNT;
modeActivationConditions[0].range.startStep = CHANNEL_VALUE_TO_STEP(1700);
modeActivationConditions[0].range.endStep = CHANNEL_VALUE_TO_STEP(2100);
modeActivationConditionsMutable(0)->modeId = (boxId_e)0;
modeActivationConditionsMutable(0)->auxChannelIndex = AUX1 - NON_AUX_CHANNEL_COUNT;
modeActivationConditionsMutable(0)->range.startStep = CHANNEL_VALUE_TO_STEP(1700);
modeActivationConditionsMutable(0)->range.endStep = CHANNEL_VALUE_TO_STEP(2100);
modeActivationConditions[1].modeId = (boxId_e)1;
modeActivationConditions[1].auxChannelIndex = AUX2 - NON_AUX_CHANNEL_COUNT;
modeActivationConditions[1].range.startStep = CHANNEL_VALUE_TO_STEP(1300);
modeActivationConditions[1].range.endStep = CHANNEL_VALUE_TO_STEP(1700);
modeActivationConditionsMutable(1)->modeId = (boxId_e)1;
modeActivationConditionsMutable(1)->auxChannelIndex = AUX2 - NON_AUX_CHANNEL_COUNT;
modeActivationConditionsMutable(1)->range.startStep = CHANNEL_VALUE_TO_STEP(1300);
modeActivationConditionsMutable(1)->range.endStep = CHANNEL_VALUE_TO_STEP(1700);
modeActivationConditions[2].modeId = (boxId_e)2;
modeActivationConditions[2].auxChannelIndex = AUX3 - NON_AUX_CHANNEL_COUNT;
modeActivationConditions[2].range.startStep = CHANNEL_VALUE_TO_STEP(900);
modeActivationConditions[2].range.endStep = CHANNEL_VALUE_TO_STEP(1200);
modeActivationConditionsMutable(2)->modeId = (boxId_e)2;
modeActivationConditionsMutable(2)->auxChannelIndex = AUX3 - NON_AUX_CHANNEL_COUNT;
modeActivationConditionsMutable(2)->range.startStep = CHANNEL_VALUE_TO_STEP(900);
modeActivationConditionsMutable(2)->range.endStep = CHANNEL_VALUE_TO_STEP(1200);
modeActivationConditions[3].modeId = (boxId_e)3;
modeActivationConditions[3].auxChannelIndex = AUX4 - NON_AUX_CHANNEL_COUNT;
modeActivationConditions[3].range.startStep = CHANNEL_VALUE_TO_STEP(900);
modeActivationConditions[3].range.endStep = CHANNEL_VALUE_TO_STEP(2100);
modeActivationConditionsMutable(3)->modeId = (boxId_e)3;
modeActivationConditionsMutable(3)->auxChannelIndex = AUX4 - NON_AUX_CHANNEL_COUNT;
modeActivationConditionsMutable(3)->range.startStep = CHANNEL_VALUE_TO_STEP(900);
modeActivationConditionsMutable(3)->range.endStep = CHANNEL_VALUE_TO_STEP(2100);
modeActivationConditions[4].modeId = (boxId_e)4;
modeActivationConditions[4].auxChannelIndex = AUX5 - NON_AUX_CHANNEL_COUNT;
modeActivationConditions[4].range.startStep = CHANNEL_VALUE_TO_STEP(900);
modeActivationConditions[4].range.endStep = CHANNEL_VALUE_TO_STEP(925);
modeActivationConditionsMutable(4)->modeId = (boxId_e)4;
modeActivationConditionsMutable(4)->auxChannelIndex = AUX5 - NON_AUX_CHANNEL_COUNT;
modeActivationConditionsMutable(4)->range.startStep = CHANNEL_VALUE_TO_STEP(900);
modeActivationConditionsMutable(4)->range.endStep = CHANNEL_VALUE_TO_STEP(925);
EXPECT_EQ(0, modeActivationConditions[4].range.startStep);
EXPECT_EQ(1, modeActivationConditions[4].range.endStep);
EXPECT_EQ(0, modeActivationConditions(4)->range.startStep);
EXPECT_EQ(1, modeActivationConditions(4)->range.endStep);
modeActivationConditions[5].modeId = (boxId_e)5;
modeActivationConditions[5].auxChannelIndex = AUX6 - NON_AUX_CHANNEL_COUNT;
modeActivationConditions[5].range.startStep = CHANNEL_VALUE_TO_STEP(2075);
modeActivationConditions[5].range.endStep = CHANNEL_VALUE_TO_STEP(2100);
modeActivationConditionsMutable(5)->modeId = (boxId_e)5;
modeActivationConditionsMutable(5)->auxChannelIndex = AUX6 - NON_AUX_CHANNEL_COUNT;
modeActivationConditionsMutable(5)->range.startStep = CHANNEL_VALUE_TO_STEP(2075);
modeActivationConditionsMutable(5)->range.endStep = CHANNEL_VALUE_TO_STEP(2100);
EXPECT_EQ(47, modeActivationConditions[5].range.startStep);
EXPECT_EQ(48, modeActivationConditions[5].range.endStep);
EXPECT_EQ(47, modeActivationConditions(5)->range.startStep);
EXPECT_EQ(48, modeActivationConditions(5)->range.endStep);
modeActivationConditions[6].modeId = (boxId_e)6;
modeActivationConditions[6].auxChannelIndex = AUX7 - NON_AUX_CHANNEL_COUNT;
modeActivationConditions[6].range.startStep = CHANNEL_VALUE_TO_STEP(925);
modeActivationConditions[6].range.endStep = CHANNEL_VALUE_TO_STEP(950);
modeActivationConditionsMutable(6)->modeId = (boxId_e)6;
modeActivationConditionsMutable(6)->auxChannelIndex = AUX7 - NON_AUX_CHANNEL_COUNT;
modeActivationConditionsMutable(6)->range.startStep = CHANNEL_VALUE_TO_STEP(925);
modeActivationConditionsMutable(6)->range.endStep = CHANNEL_VALUE_TO_STEP(950);
EXPECT_EQ(1, modeActivationConditions[6].range.startStep);
EXPECT_EQ(2, modeActivationConditions[6].range.endStep);
EXPECT_EQ(1, modeActivationConditions(6)->range.startStep);
EXPECT_EQ(2, modeActivationConditions(6)->range.endStep);
// and
rcModeActivationMask = 0;
boxBitmask_t mask;
memset(&mask, 0, sizeof(mask));
rcModeUpdate(&mask);
// and
memset(&rxRuntimeConfig, 0, sizeof(rxRuntimeConfig_t));
rxRuntimeConfig.auxChannelCount = MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT;
rxRuntimeConfig.channelCount = MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT;
// and
uint8_t index;
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
for (int index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
rcData[index] = PWM_RANGE_MIDDLE;
}
@ -163,33 +166,28 @@ TEST_F(RcControlsModesTest, updateActivatedModesUsingValidAuxConfigurationAndRXV
expectedMask |= (0 << 6);
// when
updateActivatedModes(modeActivationConditions);
updateActivatedModes();
// then
for (index = 0; index < CHECKBOX_ITEM_COUNT; index++) {
for (int index = 0; index < CHECKBOX_ITEM_COUNT; index++) {
#ifdef DEBUG_RC_CONTROLS
printf("iteration: %d\n", index);
#endif
EXPECT_EQ(expectedMask & (1 << index), rcModeActivationMask & (1 << index));
EXPECT_EQ((bool)(expectedMask & (1 << index)), IS_RC_MODE_ACTIVE((boxId_e)index));
}
}
enum {
COUNTER_GENERATE_PITCH_ROLL_CURVE = 0,
COUNTER_QUEUE_CONFIRMATION_BEEP,
COUNTER_CHANGE_CONTROL_RATE_PROFILE
};
#define CALL_COUNT_ITEM_COUNT 3
#define CALL_COUNT_ITEM_COUNT 2
static int callCounts[CALL_COUNT_ITEM_COUNT];
#define CALL_COUNTER(item) (callCounts[item])
extern "C" {
void generatePitchRollCurve(controlRateConfig_t *) {
callCounts[COUNTER_GENERATE_PITCH_ROLL_CURVE]++;
}
void beeperConfirmationBeeps(uint8_t) {
callCounts[COUNTER_QUEUE_CONFIRMATION_BEEP]++;
}
@ -223,17 +221,19 @@ void resetMillis(void) {
#define DEFAULT_MIN_CHECK 1100
#define DEFAULT_MAX_CHECK 1900
rxConfig_t rxConfig;
extern "C" {
PG_REGISTER(rxConfig_t, rxConfig, PG_RX_CONFIG, 0);
void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, const adjustmentConfig_t *adjustmentConfig);
extern uint8_t adjustmentStateMask;
extern adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT];
static const adjustmentConfig_t rateAdjustmentConfig = {
.adjustmentFunction = ADJUSTMENT_RC_RATE,
.mode = ADJUSTMENT_MODE_STEP,
.data = { { 1 } }
};
extern uint8_t adjustmentStateMask;
extern adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT];
static const adjustmentConfig_t rateAdjustmentConfig = {
.adjustmentFunction = ADJUSTMENT_RC_RATE,
.mode = ADJUSTMENT_MODE_STEP,
.data = { 1 }
};
}
class RcControlsAdjustmentsTest : public ::testing::Test {
protected:
controlRateConfig_t controlRateConfig = {
@ -251,10 +251,10 @@ protected:
adjustmentStateMask = 0;
memset(&adjustmentStates, 0, sizeof(adjustmentStates));
memset(&rxConfig, 0, sizeof (rxConfig));
rxConfig.mincheck = DEFAULT_MIN_CHECK;
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
rxConfig.midrc = 1500;
PG_RESET(rxConfig);
rxConfigMutable()->mincheck = DEFAULT_MIN_CHECK;
rxConfigMutable()->maxcheck = DEFAULT_MAX_CHECK;
rxConfigMutable()->midrc = 1500;
controlRateConfig.rcRate8 = 90;
controlRateConfig.rcExpo8 = 0;
@ -276,8 +276,7 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsSticksInMiddle)
configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &rateAdjustmentConfig);
// and
uint8_t index;
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
for (int index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
rcData[index] = PWM_RANGE_MIDDLE;
}
@ -286,11 +285,10 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsSticksInMiddle)
resetMillis();
// when
processRcAdjustments(&controlRateConfig, &rxConfig);
processRcAdjustments(&controlRateConfig);
// then
EXPECT_EQ(controlRateConfig.rcRate8, 90);
EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 0);
EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 0);
EXPECT_EQ(adjustmentStateMask, 0);
}
@ -310,10 +308,10 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
};
// and
memset(&rxConfig, 0, sizeof (rxConfig));
rxConfig.mincheck = DEFAULT_MIN_CHECK;
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
rxConfig.midrc = 1500;
PG_RESET(rxConfig);
rxConfigMutable()->mincheck = DEFAULT_MIN_CHECK;
rxConfigMutable()->maxcheck = DEFAULT_MAX_CHECK;
rxConfigMutable()->midrc = 1500;
// and
adjustmentStateMask = 0;
@ -321,8 +319,7 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &rateAdjustmentConfig);
// and
uint8_t index;
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
for (int index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
rcData[index] = PWM_RANGE_MIDDLE;
}
@ -341,15 +338,13 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
fixedMillis = 496;
// when
processRcAdjustments(&controlRateConfig, &rxConfig);
processRcAdjustments(&controlRateConfig);
// then
EXPECT_EQ(controlRateConfig.rcRate8, 91);
EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 1);
EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 1);
EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
//
// now pretend a short amount of time has passed, but not enough time to allow the value to have been increased
//
@ -358,7 +353,7 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
fixedMillis = 497;
// when
processRcAdjustments(&controlRateConfig, &rxConfig);
processRcAdjustments(&controlRateConfig);
EXPECT_EQ(controlRateConfig.rcRate8, 91);
EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
@ -380,7 +375,7 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
~(1 << 0);
// when
processRcAdjustments(&controlRateConfig, &rxConfig);
processRcAdjustments(&controlRateConfig);
EXPECT_EQ(controlRateConfig.rcRate8, 91);
EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
@ -400,11 +395,10 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
fixedMillis = 499;
// when
processRcAdjustments(&controlRateConfig, &rxConfig);
processRcAdjustments(&controlRateConfig);
// then
EXPECT_EQ(controlRateConfig.rcRate8, 92);
EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 2);
EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 2);
EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
@ -417,7 +411,7 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
fixedMillis = 500;
// when
processRcAdjustments(&controlRateConfig, &rxConfig);
processRcAdjustments(&controlRateConfig);
// then
EXPECT_EQ(controlRateConfig.rcRate8, 92);
@ -431,7 +425,7 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
fixedMillis = 997;
// when
processRcAdjustments(&controlRateConfig, &rxConfig);
processRcAdjustments(&controlRateConfig);
// then
EXPECT_EQ(controlRateConfig.rcRate8, 92);
@ -447,11 +441,10 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
fixedMillis = 998;
// when
processRcAdjustments(&controlRateConfig, &rxConfig);
processRcAdjustments(&controlRateConfig);
// then
EXPECT_EQ(controlRateConfig.rcRate8, 93);
EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 3);
EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 3);
EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
}
@ -459,7 +452,7 @@ TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp
static const adjustmentConfig_t rateProfileAdjustmentConfig = {
.adjustmentFunction = ADJUSTMENT_RATE_PROFILE,
.mode = ADJUSTMENT_MODE_SELECT,
.data = { { 3 } }
.data = { 3 }
};
TEST_F(RcControlsAdjustmentsTest, processRcRateProfileAdjustments)
@ -469,8 +462,7 @@ TEST_F(RcControlsAdjustmentsTest, processRcRateProfileAdjustments)
configureAdjustment(adjustmentIndex, AUX4 - NON_AUX_CHANNEL_COUNT, &rateProfileAdjustmentConfig);
// and
uint8_t index;
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
for (int index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
rcData[index] = PWM_RANGE_MIDDLE;
}
@ -486,7 +478,7 @@ TEST_F(RcControlsAdjustmentsTest, processRcRateProfileAdjustments)
(1 << adjustmentIndex);
// when
processRcAdjustments(&controlRateConfig, &rxConfig);
processRcAdjustments(&controlRateConfig);
// then
EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 1);
@ -497,61 +489,54 @@ TEST_F(RcControlsAdjustmentsTest, processRcRateProfileAdjustments)
static const adjustmentConfig_t pidPitchAndRollPAdjustmentConfig = {
.adjustmentFunction = ADJUSTMENT_PITCH_ROLL_P,
.mode = ADJUSTMENT_MODE_STEP,
.data = { { 1 } }
.data = { 1 }
};
static const adjustmentConfig_t pidPitchAndRollIAdjustmentConfig = {
.adjustmentFunction = ADJUSTMENT_PITCH_ROLL_I,
.mode = ADJUSTMENT_MODE_STEP,
.data = { { 1 } }
.data = { 1 }
};
static const adjustmentConfig_t pidPitchAndRollDAdjustmentConfig = {
.adjustmentFunction = ADJUSTMENT_PITCH_ROLL_D,
.mode = ADJUSTMENT_MODE_STEP,
.data = { { 1 } }
.data = { 1 }
};
static const adjustmentConfig_t pidYawPAdjustmentConfig = {
.adjustmentFunction = ADJUSTMENT_YAW_P,
.mode = ADJUSTMENT_MODE_STEP,
.data = { { 1 } }
.data = { 1 }
};
static const adjustmentConfig_t pidYawIAdjustmentConfig = {
.adjustmentFunction = ADJUSTMENT_YAW_I,
.mode = ADJUSTMENT_MODE_STEP,
.data = { { 1 } }
.data = { 1 }
};
static const adjustmentConfig_t pidYawDAdjustmentConfig = {
.adjustmentFunction = ADJUSTMENT_YAW_D,
.mode = ADJUSTMENT_MODE_STEP,
.data = { { 1 } }
.data = { 1 }
};
TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController0)
{
// given
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
memset(&modeActivationConditions, 0, sizeof (modeActivationConditions));
escAndServoConfig_t escAndServoConfig;
memset(&escAndServoConfig, 0, sizeof (escAndServoConfig));
pidProfile_t pidProfile;
memset(&pidProfile, 0, sizeof (pidProfile));
pidProfile.pidController = 0;
pidProfile.P8[PIDPITCH] = 0;
pidProfile.P8[PIDROLL] = 5;
pidProfile.P8[YAW] = 7;
pidProfile.I8[PIDPITCH] = 10;
pidProfile.I8[PIDROLL] = 15;
pidProfile.I8[YAW] = 17;
pidProfile.D8[PIDPITCH] = 20;
pidProfile.D8[PIDROLL] = 25;
pidProfile.D8[YAW] = 27;
pidProfile.pid[PID_PITCH].P = 0;
pidProfile.pid[PID_PITCH].I = 10;
pidProfile.pid[PID_PITCH].D = 20;
pidProfile.pid[PID_ROLL].P = 5;
pidProfile.pid[PID_ROLL].I = 15;
pidProfile.pid[PID_ROLL].D = 25;
pidProfile.pid[PID_YAW].P = 7;
pidProfile.pid[PID_YAW].I = 17;
pidProfile.pid[PID_YAW].D = 27;
useAdjustmentConfig(&pidProfile);
// and
controlRateConfig_t controlRateConfig;
memset(&controlRateConfig, 0, sizeof (controlRateConfig));
@ -564,8 +549,7 @@ TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController0)
configureAdjustment(5, AUX3 - NON_AUX_CHANNEL_COUNT, &pidYawDAdjustmentConfig);
// and
uint8_t index;
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
for (int index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
rcData[index] = PWM_RANGE_MIDDLE;
}
@ -588,34 +572,30 @@ TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController0)
(1 << 5);
// when
useRcControlsConfig(modeActivationConditions, &escAndServoConfig, &pidProfile);
processRcAdjustments(&controlRateConfig, &rxConfig);
useRcControlsConfig(&pidProfile);
processRcAdjustments(&controlRateConfig);
// then
EXPECT_EQ(CALL_COUNTER(COUNTER_QUEUE_CONFIRMATION_BEEP), 6);
EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
// and
EXPECT_EQ(1, pidProfile.P8[PIDPITCH]);
EXPECT_EQ(6, pidProfile.P8[PIDROLL]);
EXPECT_EQ(8, pidProfile.P8[YAW]);
EXPECT_EQ(11, pidProfile.I8[PIDPITCH]);
EXPECT_EQ(16, pidProfile.I8[PIDROLL]);
EXPECT_EQ(18, pidProfile.I8[YAW]);
EXPECT_EQ(21, pidProfile.D8[PIDPITCH]);
EXPECT_EQ(26, pidProfile.D8[PIDROLL]);
EXPECT_EQ(28, pidProfile.D8[YAW]);
EXPECT_EQ(1, pidProfile.pid[PID_PITCH].P);
EXPECT_EQ(11, pidProfile.pid[PID_PITCH].I);
EXPECT_EQ(21, pidProfile.pid[PID_PITCH].D);
EXPECT_EQ(6, pidProfile.pid[PID_ROLL].P);
EXPECT_EQ(16, pidProfile.pid[PID_ROLL].I);
EXPECT_EQ(26, pidProfile.pid[PID_ROLL].D);
EXPECT_EQ(8, pidProfile.pid[PID_YAW].P);
EXPECT_EQ(18, pidProfile.pid[PID_YAW].I);
EXPECT_EQ(28, pidProfile.pid[PID_YAW].D);
}
#if 0 // only one PID controller
TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController2)
{
// given
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
memset(&modeActivationConditions, 0, sizeof (modeActivationConditions));
escAndServoConfig_t escAndServoConfig;
memset(&escAndServoConfig, 0, sizeof (escAndServoConfig));
pidProfile_t pidProfile;
memset(&pidProfile, 0, sizeof (pidProfile));
pidProfile.pidController = 2;
@ -628,6 +608,7 @@ TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController2)
pidProfile.D_f[PIDPITCH] = 20.0f;
pidProfile.D_f[PIDROLL] = 25.0f;
pidProfile.D_f[PIDYAW] = 27.0f;
useAdjustmentConfig(&pidProfile);
// and
controlRateConfig_t controlRateConfig;
@ -641,8 +622,7 @@ TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController2)
configureAdjustment(5, AUX3 - NON_AUX_CHANNEL_COUNT, &pidYawDAdjustmentConfig);
// and
uint8_t index;
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
for (int index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
rcData[index] = PWM_RANGE_MIDDLE;
}
@ -665,7 +645,7 @@ TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController2)
(1 << 5);
// when
useRcControlsConfig(modeActivationConditions, &escAndServoConfig, &pidProfile);
useRcControlsConfig(&escAndServoConfig, &pidProfile);
processRcAdjustments(&controlRateConfig, &rxConfig);
// then
@ -685,33 +665,39 @@ TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController2)
}
#endif
extern "C" {
void saveConfigAndNotify(void) {}
void generateThrottleCurve(controlRateConfig_t *, escAndServoConfig_t *) {}
void changeProfile(uint8_t) {}
void generateThrottleCurve(void) {}
void changePidProfile(uint8_t) {}
void pidInitConfig(const pidProfile_t *) {}
void accSetCalibrationCycles(uint16_t) {}
void gyroSetCalibrationCycles(uint16_t) {}
void gyroStartCalibration(void) {}
void applyAndSaveAccelerometerTrimsDelta(rollAndPitchTrims_t*) {}
void handleInflightCalibrationStickPosition(void) {}
bool feature(uint32_t) { return false;}
bool sensors(uint32_t) { return false;}
void mwArm(void) {}
void mwDisarm(void) {}
void displayDisablePageCycling() {}
void displayEnablePageCycling() {}
void dashboardDisablePageCycling() {}
void dashboardEnablePageCycling() {}
bool failsafeIsActive() { return false; }
bool rxIsReceivingSignal() { return true; }
uint8_t getCurrentControlRateProfile(void) {
uint8_t getCurrentControlRateProfileIndex(void) {
return 0;
}
void GPS_reset_home_position(void) {}
void baroSetCalibrationCycles(uint16_t) {}
void blackboxLogEvent(FlightLogEvent, flightLogEventData_t *) {}
uint8_t armingFlags = 0;
int16_t heading;
uint8_t stateFlags = 0;
int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
rxRuntimeConfig_t rxRuntimeConfig;
PG_REGISTER(blackboxConfig_t, blackboxConfig, PG_BLACKBOX_CONFIG, 0);
}

View file

@ -28,6 +28,7 @@ extern "C" {
#include "telemetry/ibus_shared.h"
#include "telemetry/telemetry.h"
#include "fc/rc_controls.h"
#include "fc/rc_modes.h"
#include "sensors/barometer.h"
#include "sensors/battery.h"
}

View file

@ -27,6 +27,7 @@ extern "C" {
#include "common/maths.h"
#include "config/parameter_group_ids.h"
#include "fc/rc_controls.h"
#include "fc/rc_modes.h"
#include "rx/rx.h"
}
@ -39,8 +40,6 @@ extern "C" {
uint32_t rcModeActivationMask;
extern uint16_t applyRxChannelRangeConfiguraton(int sample, const rxChannelRangeConfig_t *range);
PG_REGISTER_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions, PG_MODE_ACTIVATION_PROFILE, 0);
}
#define RANGE_CONFIGURATION(min, max) new (rxChannelRangeConfig_t) {min, max}

View file

@ -25,11 +25,13 @@ extern "C" {
#include "drivers/io.h"
#include "rx/rx.h"
#include "fc/rc_controls.h"
#include "fc/rc_modes.h"
#include "common/maths.h"
#include "common/utils.h"
#include "config/feature.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "io/beeper.h"
uint32_t rcModeActivationMask;
@ -43,8 +45,6 @@ extern "C" {
PG_RESET_TEMPLATE(featureConfig_t, featureConfig,
.enabledFeatures = 0
);
PG_REGISTER_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions, PG_MODE_ACTIVATION_PROFILE, 0);
}
#include "unittest_macros.h"

View file

@ -63,6 +63,7 @@
#define SERIAL_PORT_COUNT 8
#define DEFAULT_AUX_CHANNEL_COUNT MAX_AUX_CHANNEL_COUNT
#define MAX_SIMULTANEOUS_ADJUSTMENT_COUNT 6 // needed for unittest
#define TARGET_BOARD_IDENTIFIER "TEST"