diff --git a/include/param_prj.h b/include/param_prj.h index 0412184..3edc1a3 100644 --- a/include/param_prj.h +++ b/include/param_prj.h @@ -25,7 +25,7 @@ 3. Display values */ //Next param id (increase when adding new parameter!): 158 -//Next value Id: 2052 +//Next value Id: 2053 /* category name unit min max default id */ #define MOTOR_PARAMETERS_COMMON \ @@ -179,7 +179,8 @@ VALUE_ENTRY(pot2, "dig", 2016 ) \ VALUE_ENTRY(regenpreset, "%", 2051 ) \ VALUE_ENTRY(potnom, "%", 2017 ) \ - VALUE_ENTRY(dir, DIRS, 2018 ) \ + VALUE_ENTRY(seldir, DIRS, 2018 ) \ + VALUE_ENTRY(rotordir, DIRS, 2053 ) \ VALUE_ENTRY(tmphs, "°C", 2019 ) \ VALUE_ENTRY(tmpm, "°C", 2020 ) \ VALUE_ENTRY(uaux, "V", 2021 ) \ diff --git a/libopeninv b/libopeninv index 614dc63..b6aa38e 160000 --- a/libopeninv +++ b/libopeninv @@ -1 +1 @@ -Subproject commit 614dc63d3cc414abf47403502fbe0b89a1ef8528 +Subproject commit b6aa38e2d0432c3c3d9f7c5e8c926b5c326817c8 diff --git a/src/pwmgeneration-foc.cpp b/src/pwmgeneration-foc.cpp index a46abe3..5324cb3 100644 --- a/src/pwmgeneration-foc.cpp +++ b/src/pwmgeneration-foc.cpp @@ -55,7 +55,7 @@ void PwmGeneration::Run() { static s32fp idcFiltered = 0; static int amplitudeErrFiltered; - int dir = Param::GetInt(Param::dir); + int dir = Param::GetInt(Param::seldir); s32fp id, iq; Encoder::UpdateRotorAngle(0); diff --git a/src/pwmgeneration-sine.cpp b/src/pwmgeneration-sine.cpp index 5df7919..9e12cc2 100644 --- a/src/pwmgeneration-sine.cpp +++ b/src/pwmgeneration-sine.cpp @@ -39,7 +39,7 @@ void PwmGeneration::Run() { if (opmode == MOD_MANUAL || opmode == MOD_RUN || opmode == MOD_SINE) { - int dir = Param::GetInt(Param::dir); + int dir = Param::GetInt(Param::seldir); Encoder::UpdateRotorAngle(dir); s32fp ampNomLimited = LimitCurrent(); @@ -134,7 +134,7 @@ void PwmGeneration::SetTorquePercent(float torque) } } } - else if (Encoder::GetRotorDirection() != Param::GetInt(Param::dir)) + else if (Encoder::GetRotorDirection() != Param::GetInt(Param::seldir)) { // Do not apply negative torque if we are already traveling backwards. fslipspnt = 0; diff --git a/src/stm32_sine.cpp b/src/stm32_sine.cpp index e28be38..3070171 100644 --- a/src/stm32_sine.cpp +++ b/src/stm32_sine.cpp @@ -136,6 +136,7 @@ static void Ms10Task(void) VehicleControl::GetDigInputs(); float torquePercent = VehicleControl::ProcessThrottle(); Param::SetInt(Param::speed, Encoder::GetSpeed()); + Param::SetInt(Param::rotordir, Encoder::GetRotorDirection()); if (MOD_RUN == opmode && initWait == -1) { @@ -248,25 +249,6 @@ static void Ms10Task(void) canMap->SendAll(); } -static void Ms1Task(void) -{ - static int speedCnt = 0; - - if (Param::GetInt(Param::pwmfunc) == PWM_FUNC_SPEEDFRQ) - { - int speed = Param::GetInt(Param::speed); - if (speedCnt == 0 && speed != 0) - { - DigIo::speed_out.Toggle(); - speedCnt = Param::GetInt(Param::pwmgain) / (2 * speed); - } - else if (speedCnt > 0) - { - speedCnt--; - } - } -} - /** This function is called when the user changes a parameter */ void Param::Change(Param::PARAM_NUM paramNum) { @@ -413,7 +395,6 @@ extern "C" int main(void) s.AddTask(Ms100Task, 100); s.AddTask(Ms10Task, 10); - s.AddTask(Ms1Task, 1); DigIo::prec_out.Set(); diff --git a/src/vehiclecontrol.cpp b/src/vehiclecontrol.cpp index fe571d7..d4424a0 100644 --- a/src/vehiclecontrol.cpp +++ b/src/vehiclecontrol.cpp @@ -81,11 +81,16 @@ bool VehicleControl::CanReceive(uint32_t canId, uint32_t data[2]) uint8_t ctr2 = (data[1] >> 14) & 0x3; uint8_t regenpreset = (data[1] >> 16) & 0xFF; uint8_t crc = (data[1] >> 24) & 0xFF; + uint8_t calcCrc = crc; - //Zero out CRC byte - data[1] &= 0x00FFFFFF; - crc_reset(); - uint32_t calcCrc = crc_calculate_block(data, 2) & 0xFF; + //Optional CRC check + if (Param::GetBool(Param::controlcheck)) + { + //Zero out CRC byte + data[1] &= 0x00FFFFFF; + crc_reset(); + calcCrc = crc_calculate_block(data, 2) & 0xFF; + } //We check for CRC and sequence counter errors. As long as we stay below maxErrors //we can heal bad frames with good frames. Once we've surpassed maxErrors we do @@ -206,7 +211,8 @@ void VehicleControl::CruiseControl() void VehicleControl::SelectDirection() { - int selectedDir = Param::GetInt(Param::dir); + int selectedDir = Param::GetInt(Param::seldir); + int rotorDir = Param::GetInt(Param::rotordir); int userDirSelection = 0; int dirSign = (Param::GetInt(Param::dirmode) & DIR_REVERSED) ? -1 : 1; bool potPressed = Param::GetInt(Param::potnom) > 0; @@ -247,10 +253,10 @@ void VehicleControl::SelectDirection() } /* Only change direction when below certain motor speed and throttle is not pressed */ - if ((int)Encoder::GetSpeed() < Param::GetInt(Param::dirchrpm) && !potPressed) + if (((int)Encoder::GetSpeed() < Param::GetInt(Param::dirchrpm) || userDirSelection == rotorDir) && !potPressed) selectedDir = userDirSelection; - Param::SetInt(Param::dir, selectedDir); + Param::SetInt(Param::seldir, selectedDir); } float VehicleControl::ProcessThrottle() @@ -313,7 +319,7 @@ float VehicleControl::ProcessThrottle() if (finalSpnt < 0) finalSpnt *= Encoder::GetRotorDirection(); else //inconsistency here: in slip control negative always means regen - finalSpnt *= Param::GetInt(Param::dir); + finalSpnt *= Param::GetInt(Param::seldir); //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; @@ -324,7 +330,7 @@ float VehicleControl::ProcessThrottle() } //Make sure we never command torque in neutral - if (Param::GetInt(Param::dir) == 0) + if (Param::GetInt(Param::seldir) == 0) finalSpnt = 0; return finalSpnt; @@ -683,16 +689,16 @@ float VehicleControl::GetUserThrottleCommand() if (bidirThrot == 0 || (requestedDirection != rotorDirection && speed > 30)) { bidirThrot = Throttle::brkmax; - Param::SetInt(Param::dir, rotorDirection); + Param::SetInt(Param::seldir, rotorDirection); } else if (bidirThrot < 0) { bidirThrot = -bidirThrot; - Param::SetInt(Param::dir, -1); + Param::SetInt(Param::seldir, -1); } else //bidirThrot > 0 { - Param::SetInt(Param::dir, 1); + Param::SetInt(Param::seldir, 1); } return bidirThrot; }