transfered settings.bleSettings and settings.controllerHardware

This commit is contained in:
CommanderRedYT
2022-01-02 01:40:32 +01:00
parent a4a530b2a3
commit 45cd8903df
11 changed files with 136 additions and 215 deletions

View File

@ -9,11 +9,6 @@
#include "accessorhelpers.h"
#include "newsettings.h"
// Bms
#ifdef FEATURE_BMS
struct AutoConnectBmsAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.autoConnectBms; } };
#endif
// Bluetooth
struct BluetoothNameAccessor : public NewSettingsAccessor<std::string> { ConfigWrapper<std::string> &getConfig() const override { return configs.bluetoothName; } };
@ -42,14 +37,9 @@ struct NMotMaxRpmAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &g
struct FieldWeakMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.fieldWeakMax; } };
struct PhaseAdvMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.phaseAdvMax; } };
// Bluetooth
#ifdef FEATURE_BLUETOOTH
struct AutoBluetoothModeAccessor : public RefAccessorSaveSettings<BluetoothMode> { BluetoothMode &getRef() const override { return settings.bluetoothSettings.autoBluetoothMode; } };
#endif
// Bluetooth Low Energy
#ifdef FEATURE_BLE
struct BleEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.bleSettings.bleEnabled; } };
struct BleEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.bleSettings.bleEnabled; } };
#endif
// Cloud
@ -81,32 +71,38 @@ struct FrontRightInvertedAccessor : public RefAccessorSaveSettings<bool> { bool
struct BackLeftInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.invertBackLeft; } };
struct BackRightInvertedAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.invertBackRight; } };
struct WheelDiameterMmAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.controllerHardware.wheelDiameter; } };
struct WheelDiameterMmAccessor : public NewSettingsAccessor<int16_t> { ConfigWrapper<int16_t> &getConfig() const override { return configs.controllerHardware.wheelDiameter; } };
struct WheelDiameterInchAccessor : public virtual espgui::AccessorInterface<float>
{
float getValue() const override { return convertToInch(settings.controllerHardware.wheelDiameter); }
float getValue() const override { return convertToInch(configs.controllerHardware.wheelDiameter.value); }
espgui::AccessorInterface<int16_t>::setter_result_t setValue(float value) override
{
settings.controllerHardware.wheelDiameter = convertFromInch(value);
if (!saveSettings())
return tl::make_unexpected("saveSettings() failed!");
return {};
// settings.controllerHardware.wheelDiameter = convertFromInch(value);
// if (!saveSettings())
// return tl::make_unexpected("saveSettings() failed!");
// return {};
return configs.write_config(configs.controllerHardware.wheelDiameter, convertFromInch(value));
}
};
struct NumMagnetPolesAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.controllerHardware.numMagnetPoles; } };
struct SwapFrontBackAccessor : public RefAccessorSaveSettings<bool> {
bool &getRef() const override { return settings.controllerHardware.swapFrontBack; }
struct NumMagnetPolesAccessor : public NewSettingsAccessor<int16_t> { ConfigWrapper<int16_t> &getConfig() const override { return configs.controllerHardware.numMagnetPoles; } };
struct SwapFrontBackAccessor : public virtual espgui::AccessorInterface<bool> {
bool getValue() const override { return configs.controllerHardware.swapFrontBack.value; }
setter_result_t setValue(bool value) override
{
const auto err = configs.write_config(configs.controllerHardware.swapFrontBack, value);
#ifdef FEATURE_SERIAL
void setValue(bool value) override { RefAccessorSaveSettings<bool>::setValue(value); updateSwapFrontBack(); };
updateSwapFrontBack();
#endif
return err;
}
};
// CAN
#ifdef FEATURE_CAN
struct SendFrontCanCmdAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.sendFrontCanCmd; } };
struct SendBackCanCmdAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.sendBackCanCmd; } };
struct CanTransmitTimeoutAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.controllerHardware.canTransmitTimeout; } };
struct CanReceiveTimeoutAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.controllerHardware.canReceiveTimeout; } };
struct SendFrontCanCmdAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.controllerHardware.sendFrontCanCmd; } };
struct SendBackCanCmdAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.controllerHardware.sendBackCanCmd; } };
struct CanTransmitTimeoutAccessor : public NewSettingsAccessor<int16_t> { ConfigWrapper<int16_t> &getConfig() const override { return configs.controllerHardware.canTransmitTimeout; } };
struct CanReceiveTimeoutAccessor : public NewSettingsAccessor<int16_t> { ConfigWrapper<int16_t> &getConfig() const override { return configs.controllerHardware.canReceiveTimeout; } };
#endif
// Input devices

View File

@ -109,14 +109,14 @@ void destroyBle()
void initBle()
{
if (settings.bleSettings.bleEnabled)
if (configs.bleSettings.bleEnabled.value)
createBle();
}
void handleBle()
{
if (settings.bleSettings.bleEnabled)
if (configs.bleSettings.bleEnabled.value)
{
if (!pServer)
createBle();

View File

@ -1,5 +1,7 @@
#include "bluetooth_bobby.h"
// compilation will be broken as there is no config parameter
// local includes
#ifdef FEATURE_BLUETOOTH
#include "actions/bluetoothbeginaction.h"
@ -7,24 +9,25 @@
#ifdef FEATURE_BMS
#include "actions/bluetoothconnectbmsaction.h"
#endif
#include "bluetoothmode.h"
#endif
#ifdef FEATURE_BLUETOOTH
void bluetooth_init()
{
if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Master)
if (configs.bluetooth.autoBluetoothMode.value == BluetoothMode::Master)
{
bootLabel.redraw("bluetooth begin master");
BluetoothBeginMasterAction{}.triggered();
#ifdef FEATURE_BMS
if (settings.autoConnectBms)
if (configs.autoConnectBms.value)
{
bootLabel.redraw("connect BMS");
BluetoothConnectBmsAction{}.triggered();
}
#endif
}
else if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Slave)
else if (configs.bluetooth.autoBluetoothMode.value == BluetoothMode::Slave)
{
bootLabel.redraw("bluetooth begin");
BluetoothBeginAction{}.triggered();

View File

@ -1,12 +1,9 @@
#pragma once
#include <cstdint>
#ifdef FEATURE_BLUETOOTH
enum class BluetoothMode : uint8_t
{
Off,
Master,
Slave
};
#endif

View File

@ -193,7 +193,7 @@ bool parseBoardcomputerCanMessage(const twai_message_t &message)
bool tryParseCanInput()
{
twai_message_t message;
const auto timeout = std::chrono::ceil<espcpputils::ticks>(espchrono::milliseconds32{settings.controllerHardware.canReceiveTimeout}).count();
const auto timeout = std::chrono::ceil<espcpputils::ticks>(espchrono::milliseconds32{configs.controllerHardware.canReceiveTimeout.value}).count();
if (const auto result = twai_receive(&message, timeout); result != ESP_OK)
{
if (result != ESP_ERR_TIMEOUT)
@ -210,8 +210,8 @@ bool tryParseCanInput()
return false;
}
Controller &front = settings.controllerHardware.swapFrontBack ? controllers.back : controllers.front;
Controller &back = settings.controllerHardware.swapFrontBack ? controllers.front : controllers.back;
Controller &front = configs.controllerHardware.swapFrontBack.value ? controllers.back : controllers.front;
Controller &back = configs.controllerHardware.swapFrontBack.value ? controllers.front : controllers.back;
if (parseMotorControllerCanMessage<false>(message, front))
{
@ -269,7 +269,7 @@ void sendCanCommands()
std::fill(std::begin(message.data), std::end(message.data), 0);
std::memcpy(message.data, &value, sizeof(value));
const auto timeout = std::chrono::ceil<espcpputils::ticks>(espchrono::milliseconds32{settings.controllerHardware.canTransmitTimeout}).count();
const auto timeout = std::chrono::ceil<espcpputils::ticks>(espchrono::milliseconds32{configs.controllerHardware.canTransmitTimeout.value}).count();
const auto timestamp_before = espchrono::millis_clock::now();
const auto result = twai_transmit(&message, timeout);
@ -313,13 +313,13 @@ void sendCanCommands()
return result;
};
const bool swap = settings.controllerHardware.swapFrontBack;
const bool swap = configs.controllerHardware.swapFrontBack.value;
const Controller *front =
(swap ? settings.controllerHardware.sendBackCanCmd : settings.controllerHardware.sendFrontCanCmd ) ?
(swap ? configs.controllerHardware.sendBackCanCmd.value : configs.controllerHardware.sendFrontCanCmd.value ) ?
(swap ? &controllers.back : &controllers.front) :
nullptr;
const Controller *back =
(swap ? settings.controllerHardware.sendFrontCanCmd : settings.controllerHardware.sendBackCanCmd ) ?
(swap ? configs.controllerHardware.sendFrontCanCmd.value : configs.controllerHardware.sendBackCanCmd.value ) ?
(swap ? &controllers.front : &controllers.back) :
nullptr;

View File

@ -1,5 +1,7 @@
#pragma once
// compilation will be broken as there is no config parameter
// local includes
#include "changevaluedisplay.h"
#ifdef FEATURE_BLUETOOTH
@ -27,13 +29,13 @@ namespace {
#ifdef FEATURE_BLUETOOTH
class BluetoothSettingsMenu;
using AutoBluetoothModeChangeDisplay = makeComponent<
ChangeValueDisplay<BluetoothMode>,
StaticText<TEXT_AUTOBLUETOOTHMODE>,
AutoBluetoothModeAccessor,
BackActionInterface<SwitchScreenAction<BluetoothSettingsMenu>>,
SwitchScreenAction<BluetoothSettingsMenu>
>;
//using AutoBluetoothModeChangeDisplay = makeComponent<
// ChangeValueDisplay<BluetoothMode>,
// StaticText<TEXT_AUTOBLUETOOTHMODE>,
// AutoBluetoothModeAccessor,
// BackActionInterface<SwitchScreenAction<BluetoothSettingsMenu>>,
// SwitchScreenAction<BluetoothSettingsMenu>
//>;
class BluetoothSettingsMenu :
public BobbyMenuDisplay,
@ -53,7 +55,7 @@ public:
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BLUETOOTHFLUSH>, BluetoothFlushAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BLUETOOTHEND>, BluetoothEndAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BLUETOOTHDISCONNECT>, BluetoothDisconnectAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_AUTOBLUETOOTHMODE>, SwitchScreenAction<AutoBluetoothModeChangeDisplay>>>();
// constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_AUTOBLUETOOTHMODE>, SwitchScreenAction<AutoBluetoothModeChangeDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
}
};

View File

@ -110,9 +110,9 @@ SettingsMenu::SettingsMenu()
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_MODESSETTINGS>, SwitchScreenAction<ModesSettingsMenu>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_CONTROLLERHARDWARESETTINGS>, SwitchScreenAction<ControllerHardwareSettingsMenu>, StaticMenuItemIcon<&bobbyicons::hardware>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BOARDCOMPUTERHARDWARESETTINGS>, SwitchScreenAction<BoardcomputerHardwareSettingsMenu>, StaticMenuItemIcon<&bobbyicons::hardware>>>();
#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS)
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_AUTOCONNECTBMS>, BobbyCheckbox, AutoConnectBmsAccessor>>();
#endif
//#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS)
// constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_AUTOCONNECTBMS>, BobbyCheckbox, AutoConnectBmsAccessor>>();
//#endif
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BUZZER>, SwitchScreenAction<BuzzerMenu>, StaticMenuItemIcon<&bobbyicons::buzzer>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_FRONTLED>, BobbyCheckbox, FrontLedAccessor>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACKLED>, BobbyCheckbox, BackLedAccessor>>();

View File

@ -20,6 +20,9 @@
#include <espchrono.h>
#include <makearray.h>
// local includes
#include "bluetoothmode.h"
using namespace espconfig;
std::string defaultHostname();
@ -176,6 +179,21 @@ public:
ConfigWrapper<std::string> dns_announce_key {std::string{}, DoReset, {}, "dnsAnnounceKey" };
ConfigWrapper<std::string> webserverPassword {std::string{}, DoReset, {}, "websPassword" };
// old settings
struct {
ConfigWrapper<bool> bleEnabled {true, DoReset, {}, "bleEnabled" };
} bleSettings;
struct {
ConfigWrapper<int16_t> wheelDiameter {DEFAULT_WHEELDIAMETER, DoReset, {}, "wheelDiameter" };
ConfigWrapper<int16_t> numMagnetPoles {15, DoReset, {}, "numMagnetPoles" };
ConfigWrapper<bool> swapFrontBack {false, DoReset, {}, "swapFrontBack" };
ConfigWrapper<bool> sendFrontCanCmd {true, DoReset, {}, "sendFrontCanCmd" };
ConfigWrapper<bool> sendBackCanCmd {true, DoReset, {}, "sendBackCanCmd" };
ConfigWrapper<int16_t> canTransmitTimeout {200, DoReset, {}, "canTransmitTime" };
ConfigWrapper<int16_t> canReceiveTimeout {0, DoReset, {}, "canReceiveTimeo" };
} controllerHardware;
// end old settings
ConfigWrapper<uint32_t> ledStripMaxMilliamps {3000, DoReset, {}, "ledMaxMilliamps" };
#define NEW_SETTINGS(x) \
@ -365,6 +383,15 @@ public:
x(dns_announce_key) \
x(webserverPassword) \
\
x(bleSettings.bleEnabled) \
\
x(controllerHardware.wheelDiameter) \
x(controllerHardware.numMagnetPoles) \
x(controllerHardware.swapFrontBack) \
x(controllerHardware.sendFrontCanCmd) \
x(controllerHardware.sendBackCanCmd) \
x(controllerHardware.canTransmitTimeout) \
x(controllerHardware.canReceiveTimeout) \
//x(ledStripMaxMilliamps)
template<typename T>

View File

@ -18,11 +18,11 @@ using namespace std::chrono_literals;
namespace presets {
constexpr Settings::Limits defaultLimits {
.iMotMax = DEFAULT_IMOTMAX,
.iDcMax = DEFAULT_IDCMAX,
.nMotMax = DEFAULT_NMOTMAX,
.fieldWeakMax = DEFAULT_FIELDWEAKMAX,
.phaseAdvMax = DEFAULT_FIELDADVMAX
.iMotMax = DEFAULT_IMOTMAX, // profileSetting
.iDcMax = DEFAULT_IDCMAX, // profileSetting
.nMotMax = DEFAULT_NMOTMAX, // profileSetting
.fieldWeakMax = DEFAULT_FIELDWEAKMAX, // profileSetting
.phaseAdvMax = DEFAULT_FIELDADVMAX // profileSetting
};
constexpr Settings::Limits kidsLimits {
@ -34,25 +34,15 @@ constexpr Settings::Limits kidsLimits {
};
constexpr Settings::ControllerHardware defaultControllerHardware {
.enableFrontLeft = true,
.enableFrontRight = true,
.enableBackLeft = true,
.enableBackRight = true,
.enableFrontLeft = true, // profileSetting
.enableFrontRight = true, // profileSetting
.enableBackLeft = true, // profileSetting
.enableBackRight = true, // profileSetting
.invertFrontLeft = DEFAULT_INVERTFRONTLEFT,
.invertFrontRight = DEFAULT_INVERTFRONTRIGHT,
.invertBackLeft = DEFAULT_INVERTBACKLEFT,
.invertBackRight = DEFAULT_INVERTBACKRIGHT,
.wheelDiameter = DEFAULT_WHEELDIAMETER,
.numMagnetPoles = 15,
.swapFrontBack = false,
#ifdef FEATURE_CAN
.sendFrontCanCmd = true,
.sendBackCanCmd = true,
.canTransmitTimeout = 200,
.canReceiveTimeout = 0,
#endif
.invertFrontLeft = DEFAULT_INVERTFRONTLEFT, // profileSetting
.invertFrontRight = DEFAULT_INVERTFRONTRIGHT, // profileSetting
.invertBackLeft = DEFAULT_INVERTBACKLEFT, // profileSetting
.invertBackRight = DEFAULT_INVERTBACKRIGHT, // profileSetting
};
constexpr Settings::ControllerHardware mosfetsOffControllerHardware {
@ -65,30 +55,8 @@ constexpr Settings::ControllerHardware mosfetsOffControllerHardware {
.invertFrontRight = DEFAULT_INVERTFRONTRIGHT,
.invertBackLeft = DEFAULT_INVERTBACKLEFT,
.invertBackRight = DEFAULT_INVERTBACKRIGHT,
.wheelDiameter = 165,
.numMagnetPoles = 15,
.swapFrontBack = false,
#ifdef FEATURE_CAN
.sendFrontCanCmd = true,
.sendBackCanCmd = true,
.canTransmitTimeout = 200,
.canReceiveTimeout = 0,
#endif
};
#ifdef FEATURE_BLUETOOTH
constexpr Settings::BluetoothSettings defaultBluetoothSettings {
.autoBluetoothMode = BluetoothMode::Master
};
#endif
#ifdef FEATURE_BLE
constexpr Settings::BleSettings defaultBleSettings {
.bleEnabled = true
};
#endif
constexpr Settings::ControllerHardware spinnerControllerHardware {
.enableFrontLeft = true,
.enableFrontRight = true,
@ -99,16 +67,6 @@ constexpr Settings::ControllerHardware spinnerControllerHardware {
.invertFrontRight = !DEFAULT_INVERTFRONTRIGHT,
.invertBackLeft = DEFAULT_INVERTBACKLEFT,
.invertBackRight = !DEFAULT_INVERTBACKRIGHT,
.wheelDiameter = 165,
.numMagnetPoles = 15,
.swapFrontBack = false,
#ifdef FEATURE_CAN
.sendFrontCanCmd = true,
.sendBackCanCmd = true,
.canTransmitTimeout = 200,
.canReceiveTimeout = 0,
#endif
};
constexpr Settings::BoardcomputerHardware::TimersSettings defaultTimersSettings {
@ -151,22 +109,22 @@ constexpr Settings::UdpCloudSettings defaultUdpCloudSettings {
#endif
constexpr Settings::DefaultMode defaultDefaultMode {
.modelMode = UnifiedModelMode::FocTorque,
.modelMode = UnifiedModelMode::FocTorque, // profileSetting
.squareGas = true,
.squareBrems = true,
.enableSmoothingUp = true,
.enableSmoothingDown = true,
.enableFieldWeakSmoothingUp = false,
.enableFieldWeakSmoothingDown = false,
.smoothing = 20,
.frontPercentage = 100,
.backPercentage = 100,
.add_schwelle = 750,
.gas1_wert = 1250,
.gas2_wert = 1250,
.brems1_wert = 250,
.brems2_wert = 750,
.fwSmoothLowerLimit = 800
.enableSmoothingUp = true, // profileSetting
.enableSmoothingDown = true, // profileSetting
.enableFieldWeakSmoothingUp = false, // profileSetting
.enableFieldWeakSmoothingDown = false, // profileSetting
.smoothing = 20, // profileSetting
.frontPercentage = 100, // profileSetting
.backPercentage = 100, // profileSetting
.add_schwelle = 750, // profileSetting
.gas1_wert = 1250, // profileSetting
.gas2_wert = 1250, // profileSetting
.brems1_wert = 250, // profileSetting
.brems2_wert = 750, // profileSetting
.fwSmoothLowerLimit = 800 // profileSetting
};
constexpr Settings::DefaultMode sinusoidalDefaultMode {
@ -189,13 +147,13 @@ constexpr Settings::DefaultMode sinusoidalDefaultMode {
};
constexpr Settings::TempomatMode defaultTempomatMode {
.modelMode = UnifiedModelMode::FocSpeed
.modelMode = UnifiedModelMode::FocSpeed // profileSetting
};
constexpr Settings::LarsmMode defaultLarsmMode {
.modelMode = UnifiedModelMode::Commutation,
.mode = LarsmModeMode::Mode4,
.iterations = 100
.modelMode = UnifiedModelMode::Commutation, // profileSetting
.mode = LarsmModeMode::Mode4, // profileSetting
.iterations = 100 // profileSetting
};
constexpr Settings::MotortestMode defaultMotortestMode {
@ -283,16 +241,7 @@ constexpr Settings::ESPNOW defaultEspNowSettings {
#endif
constexpr Settings defaultSettings {
#ifdef FEATURE_BMS
.autoConnectBms = false,
#endif
.limits = defaultLimits,
#ifdef FEATURE_BLUETOOTH
.bluetoothSettings = defaultBluetoothSettings,
#endif
#ifdef FEATURE_BLE
.bleSettings = defaultBleSettings,
#endif
.controllerHardware = defaultControllerHardware,
.boardcomputerHardware = defaultBoardcomputerHardware,
#ifdef FEATURE_CLOUD

View File

@ -17,9 +17,6 @@
// local includes
#include "bobbycar-common.h"
#ifdef FEATURE_BLUETOOTH
#include "bluetoothmode.h"
#endif
#include "unifiedmodelmode.h"
#include "handbremse.h"
#include "ledstrip.h"
@ -27,45 +24,17 @@
struct Settings
{
#ifdef FEATURE_BMS
bool autoConnectBms;
#endif
struct Limits {
int16_t iMotMax; // [A] Maximum motor current limit
int16_t iDcMax; // [A] Maximum DC Link current limit (This is the current protection. Above this value, current chopping is applied. To avoid this make sure that I_DC_MAX = I_MOT_MAX + 2A)
int16_t nMotMax; // [rpm] Maximum motor speed limit
int16_t fieldWeakMax; // [A] Maximum Field Weakening D axis current (only for FOC). Higher current results in higher maximum speed.
int16_t phaseAdvMax; // [deg] Maximum Phase Advance angle (only for SIN). Higher angle results in higher maximum speed.
int16_t iMotMax; // [A] Maximum motor current limit // profileSetting
int16_t iDcMax; // [A] Maximum DC Link current limit (This is the current protection. Above this value, current chopping is applied. To avoid this make sure that I_DC_MAX = I_MOT_MAX + 2A) // profileSetting
int16_t nMotMax; // [rpm] Maximum motor speed limit // profileSetting
int16_t fieldWeakMax; // [A] Maximum Field Weakening D axis current (only for FOC). Higher current results in higher maximum speed. // profileSetting
int16_t phaseAdvMax; // [deg] Maximum Phase Advance angle (only for SIN). Higher angle results in higher maximum speed. // profileSetting
} limits;
#ifdef FEATURE_BLUETOOTH
struct BluetoothSettings {
BluetoothMode autoBluetoothMode;
} bluetoothSettings;
#endif
#ifdef FEATURE_BLE
struct BleSettings {
bool bleEnabled;
} bleSettings;
#endif
struct ControllerHardware {
bool enableFrontLeft, enableFrontRight, enableBackLeft, enableBackRight;
bool invertFrontLeft, invertFrontRight, invertBackLeft, invertBackRight;
int16_t wheelDiameter; // in mm
int16_t numMagnetPoles; // virtual RPM per one real RPM
bool swapFrontBack;
#ifdef FEATURE_CAN
bool sendFrontCanCmd;
bool sendBackCanCmd;
int16_t canTransmitTimeout; // in ms
int16_t canReceiveTimeout; // in ms
#endif
bool enableFrontLeft, enableFrontRight, enableBackLeft, enableBackRight; // profileSetting
bool invertFrontLeft, invertFrontRight, invertBackLeft, invertBackRight; // profileSetting
} controllerHardware;
struct BoardcomputerHardware {
@ -102,32 +71,32 @@ struct Settings
#endif
struct DefaultMode {
UnifiedModelMode modelMode;
UnifiedModelMode modelMode; // profileSetting
bool squareGas;
bool squareBrems;
bool enableSmoothingUp;
bool enableSmoothingDown;
bool enableFieldWeakSmoothingUp;
bool enableFieldWeakSmoothingDown;
int16_t smoothing;
int16_t frontPercentage;
int16_t backPercentage;
int16_t add_schwelle;
int16_t gas1_wert;
int16_t gas2_wert;
int16_t brems1_wert;
int16_t brems2_wert;
int16_t fwSmoothLowerLimit;
bool enableSmoothingUp; // profileSetting
bool enableSmoothingDown; // profileSetting
bool enableFieldWeakSmoothingUp; // profileSetting
bool enableFieldWeakSmoothingDown; // profileSetting
int16_t smoothing; // profileSetting
int16_t frontPercentage; // profileSetting
int16_t backPercentage; // profileSetting
int16_t add_schwelle; // profileSetting
int16_t gas1_wert; // profileSetting
int16_t gas2_wert; // profileSetting
int16_t brems1_wert; // profileSetting
int16_t brems2_wert; // profileSetting
int16_t fwSmoothLowerLimit; // profileSetting
} defaultMode;
struct TempomatMode {
UnifiedModelMode modelMode;
UnifiedModelMode modelMode; // profileSetting
} tempomatMode;
struct LarsmMode {
UnifiedModelMode modelMode;
LarsmModeMode mode;
uint8_t iterations;
UnifiedModelMode modelMode; // profileSetting
LarsmModeMode mode; // profileSetting
uint8_t iterations; // profileSetting
} larsmMode;
struct MotortestMode {
@ -214,28 +183,6 @@ struct Settings
template<typename T>
void Settings::executeForEveryCommonSetting(T &&callable)
{
#ifdef FEATURE_BMS
callable("autoConnectBms", autoConnectBms);
#endif
#ifdef FEATURE_BLUETOOTH
callable("autoBluetoothMo", bluetoothSettings.autoBluetoothMode);
#endif
#ifdef FEATURE_BLE
callable("bleEnabled", bleSettings.bleEnabled);
#endif
callable("wheelDiameter", controllerHardware.wheelDiameter);
callable("numMagnetPoles", controllerHardware.numMagnetPoles);
callable("swapFrontBack", controllerHardware.swapFrontBack);
#ifdef FEATURE_CAN
callable("sendFrontCanCmd", controllerHardware.sendFrontCanCmd);
callable("sendBackCanCmd", controllerHardware.sendBackCanCmd);
callable("canTransmitTime", controllerHardware.canTransmitTimeout);
callable("canReceiveTimeo", controllerHardware.canReceiveTimeout);
#endif
#ifdef FEATURE_GAMETRAK
callable("gametrakXMin", boardcomputerHardware.gametrakXMin);
callable("gametrakXMax", boardcomputerHardware.gametrakXMax);

View File

@ -12,12 +12,12 @@ espchrono::millis_clock::time_point lastReverseBeepToggle;
float convertToKmh(float val)
{
return val /* / settings.controllerHardware.numMagnetPoles */ / 60.f * settings.controllerHardware.wheelDiameter / 1000.f * 3.14159265359f * 3.6f;
return val /* / settings.controllerHardware.numMagnetPoles */ / 60.f * configs.controllerHardware.wheelDiameter.value / 1000.f * 3.14159265359f * 3.6f;
}
float convertFromKmh(float val)
{
return val /* * settings.controllerHardware.numMagnetPoles */ * 60.f / settings.controllerHardware.wheelDiameter * 1000.f / 3.14159265359f / 3.6f;
return val /* * settings.controllerHardware.numMagnetPoles */ * 60.f / configs.controllerHardware.wheelDiameter.value * 1000.f / 3.14159265359f / 3.6f;
}
float convertToInch(float val)
@ -192,8 +192,8 @@ void sendCommands()
#ifdef FEATURE_SERIAL
void updateSwapFrontBack()
{
controllers.front.serial = settings.controllerHardware.swapFrontBack ? Serial2 : Serial1;
controllers.back.serial = settings.controllerHardware.swapFrontBack ? Serial1 : Serial2;
controllers.front.serial = configs.controllerHardware.swapFrontBack.value ? Serial2 : Serial1;
controllers.back.serial = configs.controllerHardware.swapFrontBack.value ? Serial1 : Serial2;
}
#endif