Skip to content

Commit

Permalink
Added limiter cruise mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jsphuebner committed Apr 5, 2024
1 parent dfb02b5 commit 0d8d3fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
PARAM_ENTRY(CAT_AUTOM, holdkp, "", -100, 0, -0.25, 138 ) \
PARAM_ENTRY(CAT_AUTOM, speedkp, "", 0, 100, 0.25, 53 ) \
PARAM_ENTRY(CAT_AUTOM, speedflt, "", 0, 16, 5, 57 ) \
PARAM_ENTRY(CAT_AUTOM, cruisemode, CRUISEMODS,0, 3, 0, 62 ) \
PARAM_ENTRY(CAT_AUTOM, cruisemode, CRUISEMODS,0, 4, 0, 62 ) \
PARAM_ENTRY(CAT_AUTOM, cruisethrotlim,"%", 0, 100, 50, 155 ) \
PARAM_ENTRY(CAT_CONTACT, udcsw, "V", 0, 1000, 330, 20 ) \
PARAM_ENTRY(CAT_CONTACT, udcswbuck, "V", 0, 1000, 540, 80 ) \
Expand Down Expand Up @@ -263,7 +263,7 @@
#define SNS_M "12=KTY83-110, 13=KTY84-130, 14=Leaf, 15=KTY81-110, 16=Toyota, 21=OutlanderFront, 22=EpcosB57861-S, 23=ToyotaGen2"
#define PWMFUNCS "0=tmpm, 1=tmphs, 2=speed, 3=speedfrq"
#define SINECURVES "0=VoltageSlip, 1=Simultaneous"
#define CRUISEMODS "0=Off, 1=Switch, 2=CAN, 3=ThrottlePot"
#define CRUISEMODS "0=Off, 1=Switch, 2=CAN, 3=ThrottlePot, 4=Limiter"
#define DIRMODES "0=Button, 1=Switch, 2=ButtonReversed, 3=SwitchReversed, 4=DefaultForward"
#define IDLEMODS "0=Always, 1=NoBrake, 2=Cruise, 3=Off, 4=HillHold"
#define ONOFF "0=Off, 1=On, 2=na"
Expand Down Expand Up @@ -306,7 +306,8 @@ enum cruisemodes
CRUISE_OFF = 0,
CRUISE_SWITCH = 1,
CRUISE_CAN = 2,
CRUISE_POT = 3
CRUISE_POT = 3,
CRUISE_LIMITER = 4
};

enum _potmodes
Expand Down
22 changes: 19 additions & 3 deletions src/vehiclecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ bool VehicleControl::CanReceive(uint32_t canId, uint32_t data[2], uint8_t)
}

seqCounter = ctr1;
int cruiseMode = Param::GetInt(Param::cruisemode);

//once we've reached maxerrors we cannot recover, inverter needs restarting.
if (canErrors < maxErrors)
Expand All @@ -129,7 +130,7 @@ bool VehicleControl::CanReceive(uint32_t canId, uint32_t data[2], uint8_t)
Param::SetInt(Param::pot2, pot2);
}

if (Param::GetInt(Param::cruisemode) == CRUISE_CAN)
if (CRUISE_CAN == cruiseMode || CRUISE_LIMITER == cruiseMode)
{
Param::SetInt(Param::cruisespeed, cruisespeed);
}
Expand All @@ -138,7 +139,7 @@ bool VehicleControl::CanReceive(uint32_t canId, uint32_t data[2], uint8_t)
{
Param::SetInt(Param::regenpreset, 0);

if (Param::GetInt(Param::cruisemode) == CRUISE_CAN)
if (CRUISE_CAN == cruiseMode || CRUISE_LIMITER == cruiseMode)
{
Param::SetInt(Param::cruisespeed, 0);
}
Expand All @@ -160,6 +161,19 @@ void VehicleControl::CruiseControl()
{
int cruisemode = Param::GetInt(Param::cruisemode);

//Special handling for limiter
if (CRUISE_LIMITER == cruisemode)
{
//Limiter never commands acceleration on its own so we can leave it running
//even if the brake pedal is pressed.
//We disable the limiter if cruise pin is low
if (Param::GetBool(Param::din_cruise))
Throttle::cruiseSpeed = Param::GetInt(Param::cruisespeed);
else
Throttle::cruiseSpeed = -1;
return;
}

//Always disable cruise control when brake pedal is pressed or forward signal goes away
if (Param::GetBool(Param::din_brake) || !Param::GetBool(Param::din_forward))
{
Expand Down Expand Up @@ -790,7 +804,9 @@ bool VehicleControl::GetCruiseCreepCommand(float& finalSpnt, float throtSpnt)

if (Throttle::cruiseSpeed > 0 && Throttle::cruiseSpeed > Throttle::idleSpeed)
{
if (throtSpnt <= 0)
if (Param::GetInt(Param::cruisemode) == CRUISE_LIMITER)
finalSpnt = MIN(cruiseSpnt, throtSpnt);
else if (throtSpnt <= 0)
finalSpnt = cruiseSpnt;
else if (throtSpnt > 0)
finalSpnt = MAX(cruiseSpnt, throtSpnt);
Expand Down

0 comments on commit 0d8d3fc

Please sign in to comment.