diff --git a/CMakeLists.txt b/CMakeLists.txt index e7326fc..89028a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,7 @@ target_compile_options(motortest.elf PRIVATE # -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON # -DPETERS_PLATINE +# -DSHUNT_4_MILLIOHM # -DHUART2 # -DHUART3 # -DFEATURE_SERIAL_CONTROL @@ -106,6 +107,7 @@ target_compile_options(motortest_peter.elf PRIVATE # -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON -DPETERS_PLATINE +# -DSHUNT_4_MILLIOHM # -DFEATURE_INVERT_HALL # -DHUART2 # -DHUART3 @@ -134,6 +136,7 @@ target_compile_options(feedcode-front.elf PRIVATE # -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON -DPETERS_PLATINE +# -DSHUNT_4_MILLIOHM # -DHUART2 # -DHUART3 # -DFEATURE_SERIAL_CONTROL @@ -160,6 +163,7 @@ target_compile_options(feedcode-back.elf PRIVATE # -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON -DPETERS_PLATINE +# -DSHUNT_4_MILLIOHM # -DHUART2 # -DHUART3 # -DFEATURE_SERIAL_CONTROL @@ -186,6 +190,7 @@ target_compile_options(greyhash.elf PRIVATE -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON -DPETERS_PLATINE +# -DSHUNT_4_MILLIOHM # -DHUART2 -DHUART3 -DFEATURE_SERIAL_CONTROL @@ -212,6 +217,7 @@ target_compile_options(pcbv2_front.elf PRIVATE # -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON -DPETERS_PLATINE + # -DSHUNT_4_MILLIOHM # -DHUART2 # -DHUART3 # -DFEATURE_SERIAL_CONTROL @@ -239,6 +245,7 @@ target_compile_options(pcbv2_back.elf PRIVATE # -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON -DPETERS_PLATINE + # -DSHUNT_4_MILLIOHM # -DHUART2 # -DHUART3 # -DFEATURE_SERIAL_CONTROL @@ -266,6 +273,7 @@ target_compile_options(pcbv2_test.elf PRIVATE # -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON -DPETERS_PLATINE + # -DSHUNT_4_MILLIOHM # -DHUART2 # -DHUART3 # -DFEATURE_SERIAL_CONTROL @@ -316,6 +324,7 @@ target_compile_options(commander_v2_front.elf PRIVATE # -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON -DPETERS_PLATINE + -DSHUNT_4_MILLIOHM # -DHUART2 # -DHUART3 # -DFEATURE_SERIAL_CONTROL @@ -366,6 +375,7 @@ target_compile_options(commander_v2_back.elf PRIVATE # -DPWM_FREQ_12KHZ # -DFEATURE_BUTTON -DPETERS_PLATINE + -DSHUNT_4_MILLIOHM # -DHUART2 # -DHUART3 # -DFEATURE_SERIAL_CONTROL diff --git a/main.cpp b/main.cpp index c229ac9..a706bc4 100644 --- a/main.cpp +++ b/main.cpp @@ -464,15 +464,15 @@ void updateMotors() static int16_t offsetdcl{2000}; static int16_t offsetdcr{2000}; - if (offsetcount < 2000) // calibrate ADC offsets + if (offsetcount < 20000) // calibrate ADC offsets { offsetcount++; - offsetrl1 = (adc_buffer.rl1 + offsetrl1) / 2; - offsetrl2 = (adc_buffer.rl2 + offsetrl2) / 2; - offsetrr1 = (adc_buffer.rr1 + offsetrr1) / 2; - offsetrr2 = (adc_buffer.rr2 + offsetrr2) / 2; - offsetdcl = (adc_buffer.dcl + offsetdcl) / 2; - offsetdcr = (adc_buffer.dcr + offsetdcr) / 2; + offsetrl1 = (adc_buffer.rl1 + offsetrl1 * 9) / 10; + offsetrl2 = (adc_buffer.rl2 + offsetrl2 * 9) / 10; + offsetrr1 = (adc_buffer.rr1 + offsetrr1 * 9) / 10; + offsetrr2 = (adc_buffer.rr2 + offsetrr2 * 9) / 10; + offsetdcl = (adc_buffer.dcl + offsetdcl * 9) / 10; + offsetdcr = (adc_buffer.dcr + offsetdcr * 9) / 10; return; } @@ -496,6 +496,12 @@ void updateMotors() #endif int16_t curR_DC = (int16_t)(offsetdcr - adc_buffer.dcr); + +#ifdef SHUNT_4_MILLIOHM + curL_DC *= 2.276; + curR_DC *= 2.276; +#endif + const bool chopL = std::abs(curL_DC) > (left.iDcMax.load() * AMPERE2BIT_CONV); if (chopL) left.chops++;