From defb936d335dfd6b5f65076a44b7574292d3b58b Mon Sep 17 00:00:00 2001 From: bsongis Date: Wed, 2 Oct 2013 18:00:32 +0000 Subject: [PATCH] [all] Mixer bug when a MULTIPLY mix used with a slow --- src/gtests.cpp | 32 ++++++++++++++++++++++++++++++++ src/myeeprom.h | 7 ++++--- src/opentx.cpp | 10 +++++----- src/simpgmspace.cpp | 1 + 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/gtests.cpp b/src/gtests.cpp index 4d229be71..0aed3093e 100644 --- a/src/gtests.cpp +++ b/src/gtests.cpp @@ -533,6 +533,12 @@ TEST(Mixer, RecursiveAddChannelAfterInactivePhase) EXPECT_EQ(chans[1], CHANNEL_MAX); } +#define CHECK_NO_MOVEMENT(channel, value, duration) \ + for (int i=1; i<=(duration); i++) { \ + perOut(e_perout_mode_normal, 1); \ + EXPECT_EQ(chans[(channel)], (value)); \ + } + #define CHECK_SLOW_MOVEMENT(channel, sign, duration) \ do { \ for (int i=1; i<=(duration); i++) { \ @@ -723,6 +729,32 @@ TEST(Mixer, NoTrimOnInactiveMix) simuSetSwitch(0, 0); CHECK_SLOW_MOVEMENT(0, -1, 100); } + +TEST(Mixer, SlowOnMultiply) +{ + MODEL_RESET(); + MIXER_RESET(); + g_model.mixData[0].destCh = 0; + g_model.mixData[0].mltpx = MLTPX_ADD; + g_model.mixData[0].srcRaw = MIXSRC_MAX; + g_model.mixData[0].weight = 100; + g_model.mixData[1].destCh = 0; + g_model.mixData[1].mltpx = MLTPX_MUL; + g_model.mixData[1].srcRaw = MIXSRC_MAX; + g_model.mixData[1].weight = 100; + g_model.mixData[1].swtch = SWSRC_THR; + g_model.mixData[1].speedUp = 10; + g_model.mixData[1].speedDown = 10; + + simuSetSwitch(0, 1); + CHECK_SLOW_MOVEMENT(0, 1, 250); + + simuSetSwitch(0, 0); + CHECK_NO_MOVEMENT(0, CHANNEL_MAX, 250); + + simuSetSwitch(0, 1); + CHECK_NO_MOVEMENT(0, CHANNEL_MAX, 250); +} #endif TEST(Curves, LinearIntpol) diff --git a/src/myeeprom.h b/src/myeeprom.h index a53d57ff5..e6b9cf0c2 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -1008,8 +1008,10 @@ PACK(typedef struct t_PhaseData { enum SwitchSources { SWSRC_NONE = 0, + SWSRC_FIRST_SWITCH, + #if defined(PCBTARANIS) - SWSRC_SA0, + SWSRC_SA0 = SWSRC_FIRST_SWITCH, SWSRC_SA1, SWSRC_SA2, SWSRC_SB0, @@ -1032,7 +1034,7 @@ enum SwitchSources { SWSRC_SH0, SWSRC_SH2, #else - SWSRC_ID0, + SWSRC_ID0 = SWSRC_FIRST_SWITCH, SWSRC_ID1, SWSRC_ID2, #if defined(EXTRA_3POS) @@ -1040,7 +1042,6 @@ enum SwitchSources { SWSRC_ID4, SWSRC_ID5, #endif - SWSRC_THR, SWSRC_RUD, SWSRC_ELE, diff --git a/src/opentx.cpp b/src/opentx.cpp index 315b2186f..415137e6c 100644 --- a/src/opentx.cpp +++ b/src/opentx.cpp @@ -2964,7 +2964,7 @@ void perOut(uint8_t mode, uint8_t tick10ms) else if (!mixEnabled) { if (md->speedDown && md->mltpx!=MLTPX_REP) { if (mixCondition) { - v = 0; + v = (md->mltpx == MLTPX_ADD ? 0 : RESX); apply_offset_and_curve = false; } } @@ -3020,16 +3020,16 @@ void perOut(uint8_t mode, uint8_t tick10ms) int32_t rate = (int32_t) tick10ms << (DEL_MULT_SHIFT+11); // = DEL_MULT*2048*tick10ms // rate equals a full range for one second; if less time is passed rate is accordingly smaller // if one second passed, rate would be 2048 (full motion)*256(recalculated weight)*100(100 ticks needed for one second) - int32_t currentValue=((int32_t) v<0) { - if (md->speedUp>0) { + int32_t currentValue = ((int32_t) v< 0) { + if (md->speedUp > 0) { // if a speed upwards is defined recalculate the new value according configured speed; the higher the speed the smaller the add value is int32_t newValue = tact+rate/((int16_t)(100/SLOW_STEP)*md->speedUp); if (newValuespeedDown>0) { + if (md->speedDown > 0) { // see explanation in speedUp int32_t newValue = tact-rate/((int16_t)(100/SLOW_STEP)*md->speedDown); if (newValue>currentValue) currentValue = newValue; // Endposition; prevent toggling around the destination diff --git a/src/simpgmspace.cpp b/src/simpgmspace.cpp index b9d9010f1..75e7b91d6 100644 --- a/src/simpgmspace.cpp +++ b/src/simpgmspace.cpp @@ -178,6 +178,7 @@ void simuSetTrim(uint8_t trim, bool state) } } +// TODO use a better numbering to allow google tests to work on Taranis void simuSetSwitch(uint8_t swtch, int8_t state) { // printf("swtch=%d state=%d\n", swtch, state); fflush(stdout);