mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 22:35:23 +03:00
De-duplicate mixer integration test code.
This commit is contained in:
parent
cfe0d770ac
commit
c5dbf16060
1 changed files with 31 additions and 61 deletions
|
@ -161,26 +161,44 @@ protected:
|
||||||
.mode = GIMBAL_MODE_NORMAL
|
.mode = GIMBAL_MODE_NORMAL
|
||||||
};
|
};
|
||||||
|
|
||||||
motorMixer_t customMixer[MAX_SUPPORTED_MOTORS];
|
motorMixer_t customMotorMixer[MAX_SUPPORTED_MOTORS];
|
||||||
servoMixer_t customServoMixer[MAX_SUPPORTED_SERVOS];
|
servoMixer_t customServoMixer[MAX_SUPPORTED_SERVOS];
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
updatedServoCount = 0;
|
updatedServoCount = 0;
|
||||||
|
updatedMotorCount = 0;
|
||||||
|
|
||||||
memset(&mixerConfig, 0, sizeof(mixerConfig));
|
memset(&mixerConfig, 0, sizeof(mixerConfig));
|
||||||
memset(&rxConfig, 0, sizeof(rxConfig));
|
memset(&rxConfig, 0, sizeof(rxConfig));
|
||||||
memset(&escAndServoConfig, 0, sizeof(escAndServoConfig));
|
memset(&escAndServoConfig, 0, sizeof(escAndServoConfig));
|
||||||
memset(&servoConf, 0, sizeof(servoConf));
|
memset(&servoConf, 0, sizeof(servoConf));
|
||||||
|
|
||||||
|
memset(rcData, 0, sizeof(rcData));
|
||||||
memset(rcCommand, 0, sizeof(rcCommand));
|
memset(rcCommand, 0, sizeof(rcCommand));
|
||||||
memset(axisPID, 0, sizeof(axisPID));
|
memset(axisPID, 0, sizeof(axisPID));
|
||||||
|
|
||||||
memset(&customMixer, 0, sizeof(customMixer));
|
memset(&customMotorMixer, 0, sizeof(customMotorMixer));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void withDefaultEscAndServoConfiguration(void) {
|
virtual void withDefaultEscAndServoConfiguration(void) {
|
||||||
escAndServoConfig.mincommand = TEST_MIN_COMMAND;
|
escAndServoConfig.mincommand = TEST_MIN_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void withDefaultRxConfig(void) {
|
||||||
|
rxConfig.midrc = 1500;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void configureMixer(void) {
|
||||||
|
mixerUseConfigs(
|
||||||
|
servoConf,
|
||||||
|
&gimbalConfig,
|
||||||
|
NULL,
|
||||||
|
&escAndServoConfig,
|
||||||
|
&mixerConfig,
|
||||||
|
NULL,
|
||||||
|
&rxConfig
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(BasicMixerIntegrationTest, TestTricopterServo)
|
TEST_F(BasicMixerIntegrationTest, TestTricopterServo)
|
||||||
|
@ -191,6 +209,7 @@ TEST_F(BasicMixerIntegrationTest, TestTricopterServo)
|
||||||
mixerConfig.tri_unarmed_servo = 1;
|
mixerConfig.tri_unarmed_servo = 1;
|
||||||
|
|
||||||
withDefaultEscAndServoConfiguration();
|
withDefaultEscAndServoConfiguration();
|
||||||
|
withDefaultRxConfig();
|
||||||
|
|
||||||
servoConf[5].min = DEFAULT_SERVO_MIN;
|
servoConf[5].min = DEFAULT_SERVO_MIN;
|
||||||
servoConf[5].max = DEFAULT_SERVO_MAX;
|
servoConf[5].max = DEFAULT_SERVO_MAX;
|
||||||
|
@ -198,17 +217,9 @@ TEST_F(BasicMixerIntegrationTest, TestTricopterServo)
|
||||||
servoConf[5].rate = 100;
|
servoConf[5].rate = 100;
|
||||||
servoConf[5].forwardFromChannel = CHANNEL_FORWARDING_DISABLED;
|
servoConf[5].forwardFromChannel = CHANNEL_FORWARDING_DISABLED;
|
||||||
|
|
||||||
mixerUseConfigs(
|
configureMixer();
|
||||||
servoConf,
|
|
||||||
&gimbalConfig,
|
|
||||||
NULL,
|
|
||||||
&escAndServoConfig,
|
|
||||||
&mixerConfig,
|
|
||||||
NULL,
|
|
||||||
&rxConfig
|
|
||||||
);
|
|
||||||
|
|
||||||
mixerInit(MIXER_TRI, customMixer, customServoMixer);
|
mixerInit(MIXER_TRI, customMotorMixer, customServoMixer);
|
||||||
|
|
||||||
// and
|
// and
|
||||||
pwmOutputConfiguration_t pwmOutputConfiguration = {
|
pwmOutputConfiguration_t pwmOutputConfiguration = {
|
||||||
|
@ -233,21 +244,11 @@ TEST_F(BasicMixerIntegrationTest, TestTricopterServo)
|
||||||
TEST_F(BasicMixerIntegrationTest, TestQuadMotors)
|
TEST_F(BasicMixerIntegrationTest, TestQuadMotors)
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
updatedMotorCount = 0;
|
|
||||||
|
|
||||||
withDefaultEscAndServoConfiguration();
|
withDefaultEscAndServoConfiguration();
|
||||||
|
|
||||||
mixerUseConfigs(
|
configureMixer();
|
||||||
servoConf,
|
|
||||||
&gimbalConfig,
|
|
||||||
NULL,
|
|
||||||
&escAndServoConfig,
|
|
||||||
&mixerConfig,
|
|
||||||
NULL,
|
|
||||||
&rxConfig
|
|
||||||
);
|
|
||||||
|
|
||||||
mixerInit(MIXER_QUADX, customMixer, customServoMixer);
|
mixerInit(MIXER_QUADX, customMotorMixer, customServoMixer);
|
||||||
|
|
||||||
// and
|
// and
|
||||||
pwmOutputConfiguration_t pwmOutputConfiguration = {
|
pwmOutputConfiguration_t pwmOutputConfiguration = {
|
||||||
|
@ -279,30 +280,12 @@ TEST_F(BasicMixerIntegrationTest, TestQuadMotors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CustomMixerTest : public ::testing::Test {
|
class CustomMixerIntegrationTest : public BasicMixerIntegrationTest {
|
||||||
protected:
|
protected:
|
||||||
// given
|
|
||||||
mixerConfig_t mixerConfig;
|
|
||||||
|
|
||||||
rxConfig_t rxConfig;
|
|
||||||
|
|
||||||
servoParam_t servoConf[MAX_SUPPORTED_SERVOS];
|
|
||||||
|
|
||||||
escAndServoConfig_t escAndServoConfig;
|
|
||||||
|
|
||||||
gimbalConfig_t gimbalConfig;
|
|
||||||
motorMixer_t customMotorMixer[MAX_SUPPORTED_MOTORS];
|
|
||||||
servoMixer_t customServoMixer[MAX_SUPPORTED_SERVOS];
|
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
updatedServoCount = 0;
|
|
||||||
updatedMotorCount = 0;
|
|
||||||
|
|
||||||
memset(&rcData, 0, sizeof(rcData));
|
BasicMixerIntegrationTest::SetUp();
|
||||||
memset(&rcCommand, 0, sizeof(rcCommand));
|
|
||||||
memset(&mixerConfig, 0, sizeof(mixerConfig));
|
|
||||||
memset(&rxConfig, 0, sizeof(rxConfig));
|
|
||||||
rxConfig.midrc = 1500;
|
|
||||||
|
|
||||||
memset(&servoConf, 0, sizeof(servoConf));
|
memset(&servoConf, 0, sizeof(servoConf));
|
||||||
for (int i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
|
for (int i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
|
||||||
|
@ -313,30 +296,18 @@ protected:
|
||||||
servoConf[i].forwardFromChannel = CHANNEL_FORWARDING_DISABLED;
|
servoConf[i].forwardFromChannel = CHANNEL_FORWARDING_DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&escAndServoConfig, 0, sizeof(escAndServoConfig));
|
withDefaultEscAndServoConfiguration();
|
||||||
|
withDefaultRxConfig();
|
||||||
|
|
||||||
escAndServoConfig.mincommand = TEST_MIN_COMMAND;
|
configureMixer();
|
||||||
|
|
||||||
gimbalConfig.mode = GIMBAL_MODE_NORMAL;
|
|
||||||
|
|
||||||
mixerUseConfigs(
|
|
||||||
servoConf,
|
|
||||||
&gimbalConfig,
|
|
||||||
NULL,
|
|
||||||
&escAndServoConfig,
|
|
||||||
&mixerConfig,
|
|
||||||
NULL,
|
|
||||||
&rxConfig
|
|
||||||
);
|
|
||||||
|
|
||||||
memset(&customMotorMixer, 0, sizeof(customMotorMixer));
|
memset(&customMotorMixer, 0, sizeof(customMotorMixer));
|
||||||
|
|
||||||
memset(&customServoMixer, 0, sizeof(customServoMixer));
|
memset(&customServoMixer, 0, sizeof(customServoMixer));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TEST_F(CustomMixerTest, TestCustomMixer)
|
TEST_F(CustomMixerIntegrationTest, TestCustomMixer)
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
enum {
|
enum {
|
||||||
|
@ -360,7 +331,6 @@ TEST_F(CustomMixerTest, TestCustomMixer)
|
||||||
};
|
};
|
||||||
memcpy(customMotorMixer, testMotorMixer, sizeof(testMotorMixer));
|
memcpy(customMotorMixer, testMotorMixer, sizeof(testMotorMixer));
|
||||||
|
|
||||||
|
|
||||||
mixerInit(MIXER_CUSTOM_AIRPLANE, customMotorMixer, customServoMixer);
|
mixerInit(MIXER_CUSTOM_AIRPLANE, customMotorMixer, customServoMixer);
|
||||||
|
|
||||||
pwmOutputConfiguration_t pwmOutputConfiguration = {
|
pwmOutputConfiguration_t pwmOutputConfiguration = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue