Removed copyFromSettings(); Added deadband
This commit is contained in:
@@ -10,23 +10,11 @@ WheelchairMode wheelchairMode;
|
|||||||
void WheelchairMode::start()
|
void WheelchairMode::start()
|
||||||
{
|
{
|
||||||
Base::start();
|
Base::start();
|
||||||
|
|
||||||
copyFromSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// left_right gas
|
// left_right gas
|
||||||
// front_back brems
|
// front_back brems
|
||||||
|
|
||||||
void WheelchairMode::copyFromSettings()
|
|
||||||
{
|
|
||||||
m_gasMitte = configs.gasMitte.value;
|
|
||||||
m_gasMin = configs.gasMin.value;
|
|
||||||
m_gasMax = configs.gasMax.value;
|
|
||||||
m_bremsMitte = configs.bremsMitte.value;
|
|
||||||
m_bremsMin = configs.bremsMin.value;
|
|
||||||
m_bremsMax = configs.bremsMax.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WheelchairMode::update()
|
void WheelchairMode::update()
|
||||||
{
|
{
|
||||||
auto pair = split(profileSettings.defaultMode.modelMode);
|
auto pair = split(profileSettings.defaultMode.modelMode);
|
||||||
@@ -45,8 +33,8 @@ void WheelchairMode::update()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto left_right = m_gasMin == m_gasMax ? 0 : map_analog_stick(m_gasMitte, m_gasMin, m_gasMax, *raw_gas);
|
const auto left_right = configs.gasMin.value == configs.gasMax.value ? 0 : map_analog_stick(configs.gasMitte.value, configs.gasMin.value, configs.gasMax.value, *raw_gas);
|
||||||
const auto front_back = m_bremsMin == m_bremsMax ? 0 : map_analog_stick(m_bremsMitte, m_bremsMin, m_bremsMax, *raw_brems);
|
const auto front_back = configs.bremsMin.value == configs.bremsMax.value ? 0 : map_analog_stick(configs.bremsMitte.value, configs.bremsMin.value, configs.bremsMax.value, *raw_brems);
|
||||||
|
|
||||||
float local_gas = 0;
|
float local_gas = 0;
|
||||||
float local_brems = 0;
|
float local_brems = 0;
|
||||||
|
@@ -26,14 +26,10 @@ public:
|
|||||||
bool waitForGasLoslass{false};
|
bool waitForGasLoslass{false};
|
||||||
bool waitForBremsLoslass{false};
|
bool waitForBremsLoslass{false};
|
||||||
|
|
||||||
void copyFromSettings();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
espchrono::millis_clock::time_point m_lastTime{espchrono::millis_clock::now()};
|
espchrono::millis_clock::time_point m_lastTime{espchrono::millis_clock::now()};
|
||||||
float m_x{0};
|
float m_x{0};
|
||||||
float m_lastPwm{0};
|
float m_lastPwm{0};
|
||||||
|
|
||||||
int16_t m_gasMin, m_gasMax, m_bremsMin, m_bremsMax, m_gasMitte, m_bremsMitte;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace modes {
|
namespace modes {
|
||||||
|
@@ -134,6 +134,7 @@ public:
|
|||||||
ConfigWrapper<int16_t> bremsMin {0, DoReset, MinMaxValue<int16_t, 0, 4095>, "bremsMin" };
|
ConfigWrapper<int16_t> bremsMin {0, DoReset, MinMaxValue<int16_t, 0, 4095>, "bremsMin" };
|
||||||
ConfigWrapper<int16_t> bremsMax {4096, DoReset, MinMaxValue<int16_t, 0, 4095>, "bremsMax" };
|
ConfigWrapper<int16_t> bremsMax {4096, DoReset, MinMaxValue<int16_t, 0, 4095>, "bremsMax" };
|
||||||
ConfigWrapper<int16_t> bremsMitte {2048, DoReset, MinMaxValue<int16_t, 0, 4095>, "bremsMiddle" };
|
ConfigWrapper<int16_t> bremsMitte {2048, DoReset, MinMaxValue<int16_t, 0, 4095>, "bremsMiddle" };
|
||||||
|
ConfigWrapper<uint16_t> deadband {20, DoReset, MinMaxValue<uint16_t, 0, 4095>,"deadband" };
|
||||||
|
|
||||||
ConfigWrapper<uint8_t> dpadDebounce {25, DoReset, {}, "dpadDebounce" };
|
ConfigWrapper<uint8_t> dpadDebounce {25, DoReset, {}, "dpadDebounce" };
|
||||||
|
|
||||||
@@ -427,6 +428,7 @@ public:
|
|||||||
x(bremsMin) \
|
x(bremsMin) \
|
||||||
x(bremsMax) \
|
x(bremsMax) \
|
||||||
x(bremsMitte) \
|
x(bremsMitte) \
|
||||||
|
x(deadband) \
|
||||||
\
|
\
|
||||||
x(dpadDebounce) \
|
x(dpadDebounce) \
|
||||||
\
|
\
|
||||||
|
@@ -285,8 +285,15 @@ std::string local_clock_string()
|
|||||||
|
|
||||||
int16_t map_analog_stick(uint16_t middle, uint16_t start, uint16_t end, uint16_t raw)
|
int16_t map_analog_stick(uint16_t middle, uint16_t start, uint16_t end, uint16_t raw)
|
||||||
{
|
{
|
||||||
|
if (abs(raw - middle) < configs.deadband.value)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (raw < middle)
|
if (raw < middle)
|
||||||
{
|
{
|
||||||
|
raw += configs.deadband.value;
|
||||||
|
end += configs.deadband.value;
|
||||||
const auto return_val = map(raw, start, middle, -1000, 0);
|
const auto return_val = map(raw, start, middle, -1000, 0);
|
||||||
if (return_val > 0)
|
if (return_val > 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -296,6 +303,8 @@ int16_t map_analog_stick(uint16_t middle, uint16_t start, uint16_t end, uint16_t
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
raw -= configs.deadband.value;
|
||||||
|
end -= configs.deadband.value;
|
||||||
const auto return_val = map(raw, middle, end, 0, 1000);
|
const auto return_val = map(raw, middle, end, 0, 1000);
|
||||||
if (return_val < 0)
|
if (return_val < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user