Skip to content

Commit

Permalink
Do not set potnom=0 when neutral is selected
Browse files Browse the repository at this point in the history
Do not allow changing direction when throttle is pressed
New value regenpreset that either displays the preset governed by pot2 or can be CAN-mapped
  • Loading branch information
jsphuebner committed Jun 1, 2023
1 parent bf87921 commit 2f76c84
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
5 changes: 3 additions & 2 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define VER 5.26.R
#define VER 5.27.R

/* Entries should be ordered as follows:
1. Saveable parameters
2. Temporary parameters
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 \
Expand Down Expand Up @@ -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 ) \
Expand Down
2 changes: 1 addition & 1 deletion libopeninv
Submodule libopeninv updated 1 files
+2 −2 src/param_save.cpp
1 change: 1 addition & 0 deletions src/stm32_sine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 17 additions & 10 deletions src/vehiclecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2f76c84

Please sign in to comment.