mc_pos_control: moved responsibility of the x,y stick deadzone to a mathematical function

to prevent a setpoint step when moving the stick over the border of the deadzone
and to enable very small inputs even from a control stick that needs a big deadzone
This commit is contained in:
Matthias Grob
2017-02-22 11:53:05 +01:00
committed by Lorenz Meier
parent ad3d0391ab
commit 8fd27fddcd
2 changed files with 28 additions and 6 deletions
+23 -1
View File
@@ -35,7 +35,7 @@
* @file Expo.hpp
*
* So called exponential curve function implementation.
* It's essentially a linear combination between a linear and a cubic function.
* It is essentially a linear combination between a linear and a cubic function.
*/
#pragma once
@@ -46,6 +46,11 @@
namespace math
{
// Type-safe signum function
template<typename T> int sign(T val) {
return (T(0) < val) - (val < T(0));
}
template<typename _Tp>
inline const _Tp expo(const _Tp &value, const _Tp &e)
{
@@ -53,4 +58,21 @@ inline const _Tp expo(const _Tp &value, const _Tp &e)
return (1-e)*x + e*x*x*x;
}
template<typename _Tp>
inline const _Tp deadzone(const _Tp &value, const _Tp &dz)
{
_Tp x = constrain(value ,(_Tp)-1, (_Tp)1);
// Rescale the input such that we get a piecewise linear function that will be continuous with applied deadzone
_Tp out = (x-sign(x)*dz)/(1-dz);
// apply the deadzone (values zero around the middle)
return out * (fabsf(x) > dz);
}
template<typename _Tp>
inline const _Tp expo_deadzone(const _Tp &value, const _Tp &e, const _Tp &dz)
{
_Tp x = constrain(value ,(_Tp)-1, (_Tp)1);
return expo(deadzone(x, dz),e);
}
}