diff --git a/include/param_prj.h b/include/param_prj.h index b1b6b8f..2e25cc4 100644 --- a/include/param_prj.h +++ b/include/param_prj.h @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#define VER 5.26.R +#define VER 5.27.R /* Entries should be ordered as follows: 1. Saveable parameters @@ -25,7 +25,7 @@ 3. Display values */ //Next param id (increase when adding new parameter!): 153 -//Next value Id: 2051 +//Next value Id: 2052 /* category name unit min max default id */ #define MOTOR_PARAMETERS_COMMON \ @@ -172,6 +172,7 @@ VALUE_ENTRY(angle, "°", 2014 ) \ VALUE_ENTRY(pot, "dig", 2015 ) \ VALUE_ENTRY(pot2, "dig", 2016 ) \ + VALUE_ENTRY(regenpreset, "%", 2051 ) \ VALUE_ENTRY(potnom, "%", 2017 ) \ VALUE_ENTRY(dir, DIRS, 2018 ) \ VALUE_ENTRY(tmphs, "°C", 2019 ) \ diff --git a/libopeninv b/libopeninv index 0eefc35..b16314e 160000 --- a/libopeninv +++ b/libopeninv @@ -1 +1 @@ -Subproject commit 0eefc357b7f0cb8a60c299e23f618babd2e046a3 +Subproject commit b16314edfc61888038a08c2dfb231061415d3156 diff --git a/src/stm32_sine.cpp b/src/stm32_sine.cpp index 1108f4b..89b80ea 100644 --- a/src/stm32_sine.cpp +++ b/src/stm32_sine.cpp @@ -342,6 +342,7 @@ static void UpgradeParameters() { Param::SetInt(Param::version, 4); //backward compatibility Param::SetInt(Param::hwver, hwRev); + Param::SetInt(Param::regenpreset, 100); //default to 100% regen if not CAN mapped if (Param::GetInt(Param::snsm) < 12) Param::SetInt(Param::snsm, Param::GetInt(Param::snsm) + 10); //upgrade parameter diff --git a/src/vehiclecontrol.cpp b/src/vehiclecontrol.cpp index 52f9086..bd55210 100644 --- a/src/vehiclecontrol.cpp +++ b/src/vehiclecontrol.cpp @@ -114,6 +114,7 @@ void VehicleControl::SelectDirection() int selectedDir = Param::GetInt(Param::dir); int userDirSelection = 0; int dirSign = (Param::GetInt(Param::dirmode) & DIR_REVERSED) ? -1 : 1; + bool potPressed = Param::GetInt(Param::potnom) > 0; //When in bidirection throttle mode, direction is determined by that if (Param::GetInt(Param::potmode) & POTMODE_BIDIR) return; @@ -150,14 +151,10 @@ void VehicleControl::SelectDirection() userDirSelection = -1 * dirSign; } - /* Only change direction when below certain motor speed */ - if ((int)Encoder::GetSpeed() < Param::GetInt(Param::dirchrpm)) + /* Only change direction when below certain motor speed and throttle is not pressed */ + if ((int)Encoder::GetSpeed() < Param::GetInt(Param::dirchrpm) && !potPressed) selectedDir = userDirSelection; - /* Current direction doesn't match selected direction -> neutral */ - //if (selectedDir != userDirSelection) - // selectedDir = 0; - Param::SetInt(Param::dir, selectedDir); } @@ -517,7 +514,7 @@ void VehicleControl::GetTemps(float& tmphs, float &tmpm) float VehicleControl::GetUserThrottleCommand() { - float potnom1, potnom2; + float potnom1, potnom2, regenPreset; int potval, pot2val; bool brake = Param::GetBool(Param::din_brake); int potmode = Param::GetInt(Param::potmode); @@ -557,6 +554,16 @@ float VehicleControl::GetUserThrottleCommand() potnom1 = Throttle::DigitsToPercent(potval, 0); potnom2 = Throttle::DigitsToPercent(pot2val, 1); + if (potmode == POTMODE_REGENADJ) + { + regenPreset = potnom2; + Param::SetFloat(Param::regenpreset, regenPreset); + } + else + { + regenPreset = Param::GetFloat(Param::regenpreset); + } + if ((potmode & POTMODE_BIDIR) > 0) { if (!inRange1) return 0; @@ -614,10 +621,10 @@ float VehicleControl::GetUserThrottleCommand() return 0; } - if (Param::GetInt(Param::dir) == 0) - return 0; + //if (Param::GetInt(Param::dir) == 0) + // return 0; - return Throttle::CalcThrottle(potnom1, potnom2, brake); + return Throttle::CalcThrottle(potnom1, regenPreset, brake); } bool VehicleControl::GetCruiseCreepCommand(float& finalSpnt, float throtSpnt)