Skip to content

Commit

Permalink
v9.8.0: switchable crawler mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDIYGuy999 committed Jun 17, 2022
1 parent 4189aff commit b7d3434
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 35 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions data/trailer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test!!
2 changes: 1 addition & 1 deletion src/2_adjustmentsRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!) **********************************************************************************************************
Expand Down
21 changes: 15 additions & 6 deletions src/3_adjustmentsESC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/4_adjustmentsTransmission.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/6_adjustmentsLights.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
*/

// 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)

// Choose the mode you want
//#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


Expand Down
2 changes: 1 addition & 1 deletion src/7_adjustmentsServos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/8_adjustmentsSound.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
55 changes: 34 additions & 21 deletions src/src.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Arduino.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 **************
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b7d3434

Please sign in to comment.