diff --git a/README.md b/README.md index c459abb..df37497 100755 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ LCD dashboard (original by Gamadril) - ESP-NOW based 2.4 GHz wireless trailer control support - An An RZ7886 motor driver IC can be used instead of a standard crawler type RC ESC - Battery low discharge protection options +- Switchable crawler mode (with just minimal virtual inertia) ## On the todo list: - cornering lights (on the beacon outputs) @@ -514,6 +515,11 @@ const uint8_t shakerStop = 60; // Shaker power while engine stop (max. 255, abou ## Changelog (newest on top): +### New in V 9.8.0: +- Adjustable RECOVERY_HYSTERESIS for battery protection +- 8_adjustmentsSound.h (masterVolumeCrawlerThreshold) and 3_adjustmentsESC.h (crawlerEscRampTime): switchable crawler mode with just minimal inertia for gearbox protection. Allows to have a "show mode" and a "competition mode" +- 3_adjustmentsESC.h: Additional comments in battery low dischgarge section, according to neo2001 + ### New in V 9.7.0: - NEOPIXEL_KNIGHT_RIDER scanner optimized, synchrone with sound - NEOPIXEL_BLUELIGHT: red & blue bluelight animation for fire trucks etc. diff --git a/data/trailer.txt b/data/trailer.txt new file mode 100644 index 0000000..eedd24f --- /dev/null +++ b/data/trailer.txt @@ -0,0 +1 @@ +This is a test!! \ No newline at end of file diff --git a/src/2_adjustmentsRemote.h b/src/2_adjustmentsRemote.h index bf95efd..0c17c1a 100644 --- a/src/2_adjustmentsRemote.h +++ b/src/2_adjustmentsRemote.h @@ -38,7 +38,7 @@ uint32_t sbusBaud = 100000; // Standard is 100000. Try to lower it, if your chan // CHANNEL LINEARITY SETTINGS **************************************************************************************************************** -//#define EXPONENTIAL_THROTTLE // Exponential throttle curve. Ideal for enhanced slow speed control in crawlers +#define EXPONENTIAL_THROTTLE // Exponential throttle curve. Ideal for enhanced slow speed control in crawlers //#define EXPONENTIAL_STEERING // Exponential steering curve. More steering accuracy around center position // CHANNEL AVERAGING (EXPERIMENTAL!) ********************************************************************************************************** diff --git a/src/3_adjustmentsESC.h b/src/3_adjustmentsESC.h index 7644377..13943b3 100644 --- a/src/3_adjustmentsESC.h +++ b/src/3_adjustmentsESC.h @@ -58,7 +58,7 @@ // General options //#define QUICRUN_FUSION // Linearity compensation for HOBBYWING Quicrun Fusion motor / ESC combo -#define ESC_DIR // uncomment this, if your motor is spinning in the wrong direction +//#define ESC_DIR // uncomment this, if your motor is spinning in the wrong direction /* RZ7886 motor driver IC instead of ESC. Not in combination with #define THIRD_BRAKELIGHT or #define TRAILER_LIGHTS_TRAILER_PRESENCE_SWITCH_DEPENDENT Wiring: @@ -114,14 +114,23 @@ const uint16_t escReversePlus = 0; // Warning: vehicle may be unable to stop, if too high, especially when driving downhill! NEVER more than 20! const uint16_t brakeMargin = 0; // For RZ7886 motor driver and 370 motor = 10 -// Battery low discharge protection (only for boards with voltage divider resistors): -// IMPORTANT: adjust RESISTOR_TO_BATTTERY_PLUS & DIODE_DROP until your readings are correct! +// Crawler mode escRampTime (see "8_adjustmentsSound.h") WARNING: a very low setting may damage your transmission! +const uint8_t crawlerEscRampTime = 10; // about 10, less = more direct control = less virtual inertia + +/* Battery low discharge protection (only for boards with voltage divider resistors): +* IMPORTANT: Enter used resistor values in Ohms (Ω) and THEN adjust DIODE_DROP, until your readings match the actual battery voltage! */ //#define BATTERY_PROTECTION // This will disable the ESC output, if the battery cutout voltage is reached const float CUTOFF_VOLTAGE = 3.3; // Usually 3.3 V per LiPo cell. NEVER below 3.2 V! const float FULLY_CHARGED_VOLTAGE = 4.2; // Usually 4.2 V per LiPo cell, NEVER above! -const uint16_t RESISTOR_TO_BATTTERY_PLUS = 10000; // 10000 Ohms (9900 for switch mode test board, 9650 for Ural, 9500 for Landy) -const uint16_t RESISTOR_TO_GND = 1000; // 1000 Ohms -const float DIODE_DROP = 0.34; // About 0.34V for SS34 diode on switch mode board (0 for Ural & Landy) +const float RECOVERY_HYSTERESIS = 0.2; // around 0.2 V +/* Note on resistor values: These values will be used to calculate the actual ratio between these two resistors (which is also called a "voltage divider"). + * When selecting resistors, always use two of the same magnitude: Like, for example, 10k/2k, 20k/4k or 100k/20k. NEVER exceed a ratio LOWER than (4:1 = 4)! + * WARNING: If the ratio is too LOW, like 10k/5k (2:1 = 2), the battery voltage will most likely DAMAGE the controller permanently! + * Example calculation: 2000 / (2000 + 10000) = 0.166 666 666 7; 7.4 V * 0.167 = 1.2358 V (of 3.3 V maximum on GPIO Pin). */ +const uint16_t RESISTOR_TO_BATTTERY_PLUS = 10000; // Value in Ohms (Ω), for example 10000 +const uint16_t RESISTOR_TO_GND = 2000; // Value in Ohms (Ω), for example 1000. Measuring exact resistor values before soldering, if possible is recommended! +const float DIODE_DROP = 0.34; // Fine adjust measured value and/or consider diode voltage drop (about 0.34V for SS34 diode) +/* It is recommended to add a sticker to your ESP32, which includes the 3 calibration values above */ volatile int outOfFuelVolumePercentage = 80; // Adjust the message volume in % // Select the out of fuel message you want: #include "vehicles/sounds/OutOfFuelEnglish.h" diff --git a/src/4_adjustmentsTransmission.h b/src/4_adjustmentsTransmission.h index b894a82..864d179 100644 --- a/src/4_adjustmentsTransmission.h +++ b/src/4_adjustmentsTransmission.h @@ -20,7 +20,7 @@ // Additional transmission options ========================================================================================================= // Automatic transmission with overdrive (lower RPM in top gear, gear ratio lower than 1:1, 4 & 6 speed only) // Also usable in combination with VIRTUAL_3_SPEED. The 4th gear is switched automatically in this case, if driving in 3rd gear @ full throttle -//#define OVERDRIVE // Don't use it for: doubleClutch. Not working with SEMI_AUTOMATIC, but you can leave it on in this case. +#define OVERDRIVE // Don't use it for: doubleClutch. Not working with SEMI_AUTOMATIC, but you can leave it on in this case. // In some cases we want a different reverse acceleration for automatic transmission vehicles. uint16_t automaticReverseAccelerationPercentage = 100; diff --git a/src/6_adjustmentsLights.h b/src/6_adjustmentsLights.h index 818f4bf..e608780 100644 --- a/src/6_adjustmentsLights.h +++ b/src/6_adjustmentsLights.h @@ -7,7 +7,7 @@ */ // Neopixel settings ----------------------------------------------------------------------------------------------------------------------------- -#define NEOPIXEL_ENABLED // GPIO0 used for WS2812 Neopixel control, if defined! +//#define NEOPIXEL_ENABLED // GPIO0 used for WS2812 Neopixel control, if defined! #define NEOPIXEL_COUNT 8 // How many Neopixels? 8 for Knight Rider, 3 for B33lz3bub #define NEOPIXEL_BRIGHTNESS 127 // Brightness (255 is the maximum) @@ -15,7 +15,7 @@ //#define NEOPIXEL_DEMO // Demo //#define NEOPIXEL_KNIGHT_RIDER // Knight Rider scanner animation for 8 LED (use it in combination with "kittScanner.h" "siren" sound in your vehicle file) #define NEOPIXEL_BLUELIGHT // Bluelight animation for 8 LED -#define NEOPIXEL_HIGHBEAM // Neopixel bar is used as high beam as well, if defined. Also usable in combination with NEOPIXEL_KNIGHT_RIDER & NEOPIXEL_BLUELIGHT +//#define NEOPIXEL_HIGHBEAM // Neopixel bar is used as high beam as well, if defined. Also usable in combination with NEOPIXEL_KNIGHT_RIDER & NEOPIXEL_BLUELIGHT //#define NEOPIXEL_B33LZ3BUB // B33lz3bub Austria animation for 3 LED: https://www.rc-modellbau-portal.de/index.php?threads/baubericht-mercedes-actros-1851-gigaspace-tamiya.14349/page-3 diff --git a/src/7_adjustmentsServos.h b/src/7_adjustmentsServos.h index 45c5e0d..1051b2b 100644 --- a/src/7_adjustmentsServos.h +++ b/src/7_adjustmentsServos.h @@ -56,7 +56,7 @@ const uint8_t SERVO_FREQUENCY = 50; // usually 50Hz, some servos may run smoothe // WARNING: never connect receiver PWM signals to the "CH" pins in BUS communication mode! // Servo limits -const uint16_t CH1L = 1880, CH1C = 1480, CH1R = 1080; // CH1 steering left 1875, center 1475, right 1075 +const uint16_t CH1L = 1840, CH1C = 1485, CH1R = 1090; // CH1 steering left 1880, center 1480, right 1080 const uint16_t CH2L = 978, CH2C = 1833, CH2R = 1833; // CH2 transmission gear 1 978, 2 1833, 3 1833 const uint16_t CH3L = 1300, CH3C = 1450, CH3R = 1600; // CH3 winch pull, off, release const uint16_t CH4L = 1300, CH4R = 1700; // CH4 trailer coupler (5th. wheel) locked, unlocked diff --git a/src/8_adjustmentsSound.h b/src/8_adjustmentsSound.h index ff0e444..a42ceeb 100644 --- a/src/8_adjustmentsSound.h +++ b/src/8_adjustmentsSound.h @@ -7,6 +7,13 @@ */ //#define NO_SIREN // siren sound is not played, if defined - -const uint8_t numberOfVolumeSteps = 3; // The mumber of volume steps below -const uint8_t masterVolumePercentage[] = {100, 66, 44}; // loud, medium, silent (more than 100% may cause distortions) + +// Volume adjustment +//const uint8_t numberOfVolumeSteps = 3; // The mumber of volume steps below +//const uint8_t masterVolumePercentage[] = {100, 66, 44}; // loud, medium, silent (more than 100% may cause distortions) + +const uint8_t numberOfVolumeSteps = 4; // The mumber of volume steps below +const uint8_t masterVolumePercentage[] = {100, 66, 44, 0}; // loud, medium, silent, no sound (more than 100% may cause distortions) + +// Crawler mode +const uint8_t masterVolumeCrawlerThreshold = 44; // If master volume is <= this threshold, crawler mode (without virtual inertia) is active diff --git a/src/src.ino b/src/src.ino index 847570f..1e59bec 100644 --- a/src/src.ino +++ b/src/src.ino @@ -18,7 +18,7 @@ Arduino IDE is supported as before, but stuff was renamed and moved to different folders! */ -char codeVersion[] = "9.7.0"; // Software revision. +char codeVersion[] = "9.8.0"; // Software revision. // This stuff is required for Visual Studio Code IDE, if .ino is renamed into .cpp! #include @@ -69,7 +69,7 @@ float batteryVolts(); #include "10_adjustmentsTrailer.h" // <<------- Trailer related adjustments // DEBUG options can slow down the playback loop! Only uncomment them for debugging, may slow down your system! -#define CHANNEL_DEBUG // uncomment it for input signal & general debugging informations +//#define CHANNEL_DEBUG // uncomment it for input signal & general debugging informations //#define ESC_DEBUG // uncomment it to debug the ESC //#define AUTO_TRANS_DEBUG // uncomment it to debug the automatic transmission //#define MANUAL_TRANS_DEBUG // uncomment it to debug the manual transmission @@ -438,6 +438,7 @@ uint16_t escPulseMin = 1000; uint16_t escPulseMaxNeutral = 1500; uint16_t escPulseMinNeutral = 1500; uint16_t currentSpeed = 0; // 0 - 500 (current ESC power) +volatile bool crawlerMode = false; // Crawler mode intended for crawling competitons (withouth sound and virtual inertia) // Lights int8_t lightsState = 0; // for lights state machine @@ -2983,21 +2984,23 @@ void gearboxDetection() { #else // only active, if not in TRACKED_MODE ------------------------------------------------------------- #if defined OVERDRIVE && defined VIRTUAL_3_SPEED // Additional 4th gear mode for virtual 3 speed ******************************** - // The 4th gear (overdrive) is engaged automatically, if driving @ full throttle in 3rd gear - if (currentRpm > 490 && selectedGear == 3 && engineLoad < 5 && currentThrottle > 490 && millis() - lastShiftingMillis > 2000) { - overdrive = true; - } - if (!escIsBraking) { // Lower downshift point, if not braking - if (currentRpm < 200 && millis() - lastShiftingMillis > 2000) { - overdrive = false; + if (!crawlerMode) { + // The 4th gear (overdrive) is engaged automatically, if driving @ full throttle in 3rd gear + if (currentRpm > 490 && selectedGear == 3 && engineLoad < 5 && currentThrottle > 490 && millis() - lastShiftingMillis > 2000) { + overdrive = true; } - } - else { // Higher downshift point, if braking - if ((currentRpm < 400 || engineLoad > 150) && millis() - lastShiftingMillis > 2000) { - overdrive = false; + if (!escIsBraking) { // Lower downshift point, if not braking + if (currentRpm < 200 && millis() - lastShiftingMillis > 2000) { + overdrive = false; + } } + else { // Higher downshift point, if braking + if ((currentRpm < 400 || engineLoad > 150) && millis() - lastShiftingMillis > 2000) { + overdrive = false; + } + } + if (selectedGear < 3) overdrive = false; } - if (selectedGear < 3) overdrive = false; #endif // End of overdrive ****************************************************************************************************** #if not defined VIRTUAL_16_SPEED_SEQUENTIAL && not defined SEMI_AUTOMATIC// 3 gears, selected by 3 position switch ************** @@ -3210,7 +3213,7 @@ void esc() { // ESC main function ================================ Serial.printf("Disconnect battery to prevent it from overdischarging!\n", batteryVoltage, batteryCutoffvoltage); batteryProtection = true; } - if (batteryVoltage > batteryCutoffvoltage + (0.05 * numberOfCells)) { // Recovery hysteresis + if (batteryVoltage > batteryCutoffvoltage + (FULLY_CHARGED_VOLTAGE * numberOfCells)) { // Recovery hysteresis batteryProtection = false; } // Out of fuel message triggering @@ -3227,7 +3230,6 @@ void esc() { // ESC main function ================================ escRampTime = escRampTimeThirdGear * 10 / virtualManualGearRatio[selectedGear]; #elif defined VIRTUAL_16_SPEED_SEQUENTIAL - //escRampTime = escRampTimeThirdGear;// * 10 / map(virtualManualGearRatio[selectedGear], 155, 10, 23, 10); escRampTime = escRampTimeThirdGear * virtualManualGearRatio[selectedGear] / 5; #else // TAMIYA 3 speed shifting transmission @@ -3241,9 +3243,20 @@ void esc() { // ESC main function ================================ if (escInReverse) escRampTime = escRampTime * 100 / automaticReverseAccelerationPercentage; // faster acceleration in automatic reverse, EXPERIMENTAL, TODO! } - // calulate throttle dependent brake & acceleration steps - brakeRampRate = map (currentThrottle, 0, 500, 1, escBrakeSteps); - driveRampRate = map (currentThrottle, 0, 500, 1, escAccelerationSteps); + // Drive mode ------------------------------------------- + // Crawler mode for direct control ----- + crawlerMode = (masterVolume <= masterVolumeCrawlerThreshold); // Direct control, depending on master volume + + if (crawlerMode) { // almost no virtual inertia (just for drive train protection), for crawling competitions + escRampTime = crawlerEscRampTime; + brakeRampRate = map (currentThrottle, 0, 500, 1, 10); + driveRampRate = 10; + } + else { // Virtual inertia mode ----- + // calulate throttle dependent brake & acceleration steps + brakeRampRate = map (currentThrottle, 0, 500, 1, escBrakeSteps); + driveRampRate = map (currentThrottle, 0, 500, 1, escAccelerationSteps); + } // ---------------------------------------------------- // Emergency ramp rates for falisafe if (failSafe) { @@ -4079,7 +4092,7 @@ void updateRGBLEDs() { rgbLEDs[6] = CRGB::Red; rgbLEDs[7] = CRGB::Blue; } - if (millis() - lastNeopixelBluelightTime > 80) { // Step 2 + if (millis() - lastNeopixelBluelightTime > 160) { // Step 2 fill_solid(rgbLEDs, NEOPIXEL_COUNT, CRGB::Black); } if (millis() - lastNeopixelBluelightTime > 300) { // Step 3 @@ -4090,7 +4103,7 @@ void updateRGBLEDs() { rgbLEDs[6] = CRGB::Blue; rgbLEDs[7] = CRGB::Red; } - if (millis() - lastNeopixelBluelightTime > 380) { // Step 4 + if (millis() - lastNeopixelBluelightTime > 460) { // Step 4 fill_solid(rgbLEDs, NEOPIXEL_COUNT, CRGB::Black); } if (millis() - lastNeopixelBluelightTime > 600) { // Step 5