Skip to content

Commit

Permalink
Bugfix in emergency speed limiter
Browse files Browse the repository at this point in the history
Limit regenpreset to 100%
New SDO CAN mapping
  • Loading branch information
jsphuebner committed Sep 4, 2023
1 parent dacd3ea commit 462509f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ OBJDUMP = $(PREFIX)-objdump
MKDIR_P = mkdir -p
TERMINAL_DEBUG ?= 0
CFLAGS = -Os -ggdb3 -Wall -Wextra -Iinclude/ -Ilibopeninv/include -Ilibopencm3/include \
-fno-common -fno-builtin -pedantic -DSTM32F1 -DT_DEBUG=$(TERMINAL_DEBUG) \
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
-mcpu=cortex-m3 -mthumb -std=gnu99 -ffunction-sections -fdata-sections
-fno-common -fno-builtin -pedantic -DSTM32F1 -DT_DEBUG=$(TERMINAL_DEBUG) \
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
-mcpu=cortex-m3 -mthumb -std=gnu99 -ffunction-sections -fdata-sections
CPPFLAGS = -Os -ggdb3 -Wall -Wextra -Iinclude/ -Ilibopeninv/include -Ilibopencm3/include \
-fno-common -std=c++11 -pedantic -DSTM32F1 -DT_DEBUG=$(TERMINAL_DEBUG) \
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
-ffunction-sections -fdata-sections -fno-builtin -fno-rtti -fno-exceptions -fno-unwind-tables -mcpu=cortex-m3 -mthumb
-fno-common -std=c++11 -pedantic -DSTM32F1 -DT_DEBUG=$(TERMINAL_DEBUG) \
-DCONTROL=CTRL_$(CONTROL) -DCTRL_SINE=0 -DCTRL_FOC=1 \
-ffunction-sections -fdata-sections -fno-builtin -fno-rtti -fno-exceptions -fno-unwind-tables -mcpu=cortex-m3 -mthumb
LDSCRIPT = stm32_sine.ld
LDFLAGS = -Llibopencm3/lib -ggdb3 -T$(LDSCRIPT) -march=armv7 -nostartfiles -Wl,--gc-sections,-Map,linker.map
OBJSL = stm32_sine.o hwinit.o stm32scheduler.o params.o terminal.o terminal_prj.o \
my_string.o digio.o sine_core.o my_fp.o fu.o inc_encoder.o printf.o anain.o \
temp_meas.o param_save.o throttle.o errormessage.o pwmgeneration.o \
picontroller.o terminalcommands.o vehiclecontrol.o \
stm32_can.o canmap.o canhardware.o
stm32_can.o canmap.o canhardware.o cansdo.o

ifeq ($(CONTROL), SINE)
OBJSL += pwmgeneration-sine.o
Expand Down
2 changes: 1 addition & 1 deletion include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define VER 5.29.R
#define VER 5.32.R

/* Entries should be ordered as follows:
1. Saveable parameters
Expand Down
2 changes: 1 addition & 1 deletion libopeninv
2 changes: 2 additions & 0 deletions sinus.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<Unit filename="libopeninv/include/anain.h" />
<Unit filename="libopeninv/include/canhardware.h" />
<Unit filename="libopeninv/include/canmap.h" />
<Unit filename="libopeninv/include/cansdo.h" />
<Unit filename="libopeninv/include/crc8.h" />
<Unit filename="libopeninv/include/delay.h" />
<Unit filename="libopeninv/include/digio.h" />
Expand All @@ -100,6 +101,7 @@
<Unit filename="libopeninv/src/anain.cpp" />
<Unit filename="libopeninv/src/canhardware.cpp" />
<Unit filename="libopeninv/src/canmap.cpp" />
<Unit filename="libopeninv/src/cansdo.cpp" />
<Unit filename="libopeninv/src/crc8.cpp" />
<Unit filename="libopeninv/src/digio.cpp" />
<Unit filename="libopeninv/src/errormessage.cpp" />
Expand Down
12 changes: 8 additions & 4 deletions src/stm32_sine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "vehiclecontrol.h"
#include "stm32_can.h"
#include "canmap.h"
#include "cansdo.h"

#define PRINT_JSON 0

Expand All @@ -53,6 +54,7 @@ HWREV hwRev; //Hardware variant of board we are running on
static Stm32Scheduler* scheduler;
static CanHardware* can;
static CanMap* canMap;
static CanSdo* canSdo;
static Terminal* terminal;
static bool seenBrakePedal = false;

Expand Down Expand Up @@ -289,7 +291,7 @@ void Param::Change(Param::PARAM_NUM paramNum)
Throttle::brkmax = Param::GetFloat(Param::offthrotregen);
break;
case Param::nodeid:
canMap->SetNodeId(Param::GetInt(Param::nodeid));
canSdo->SetNodeId(Param::GetInt(Param::nodeid));
//terminal->SetNodeId(Param::GetInt(Param::nodeid));
break;
default:
Expand Down Expand Up @@ -397,8 +399,10 @@ extern "C" int main(void)
scheduler = &s;
Stm32Can c(CAN1, (CanHardware::baudrates)Param::GetInt(Param::canspeed));
CanMap cm(&c);
CanSdo sdo(&c, &cm);
can = &c;
canMap = &cm;
canSdo = &sdo;
VehicleControl::SetCan(can);
TerminalCommands::SetCanMap(canMap);

Expand All @@ -423,10 +427,10 @@ extern "C" int main(void)
{
char c = 0;
t.Run();
if (canMap->GetPrintRequest() == PRINT_JSON)
if (canSdo->GetPrintRequest() == PRINT_JSON)
{
TerminalCommands::PrintParamsJson(canMap, &c);
canMap->SignalPrintComplete();
TerminalCommands::PrintParamsJson(canSdo, &c);
canSdo->SignalPrintComplete();
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/vehiclecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void VehicleControl::SetCan(CanHardware* canHw)
seqCounter = 0; //Mainly useful for unit tests
canErrors = 0;
can = canHw;
can->AddReceiveCallback(&callback);
can->AddCallback(&callback);
CanClear();
}

Expand Down Expand Up @@ -116,7 +116,7 @@ bool VehicleControl::CanReceive(uint32_t canId, uint32_t data[2])
lastCanRxTime = rtc_get_counter_val();

Param::SetInt(Param::canio, canio);
Param::SetInt(Param::regenpreset, regenpreset);
Param::SetInt(Param::regenpreset, MIN(100, regenpreset));

if ((Param::GetInt(Param::potmode) & POTMODE_CAN) > 0)
{
Expand Down Expand Up @@ -315,11 +315,11 @@ float VehicleControl::ProcessThrottle()
else //inconsistency here: in slip control negative always means regen
finalSpnt *= Param::GetInt(Param::dir);

//At 110% fmax start derating field weakening current just in case it has a torque producing current
//At 110% fmax start derating field weakening current just in case it has a torque producing component
Throttle::fmax = Param::GetFloat(Param::fmax) * 1.1f;
float fwPercent = 100;
Throttle::FrequencyLimitCommand(fwPercent, fstat);
PwmGeneration::SetFwCurMax(fwPercent * Param::GetFloat(Param::fwcurmax));
PwmGeneration::SetFwCurMax(fwPercent * Param::GetFloat(Param::fwcurmax) / 100.0f);
#endif // CONTROL
}

Expand Down

0 comments on commit 462509f

Please sign in to comment.