mirror of
https://github.com/okalachev/flix.git
synced 2026-03-30 20:13:44 +00:00
Compare commits
2 Commits
cd953f24ad
...
dee4d97ab3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dee4d97ab3 | ||
|
|
ea35db37da |
@@ -11,8 +11,6 @@
|
|||||||
#define WEIGHT_ACC 0.003
|
#define WEIGHT_ACC 0.003
|
||||||
#define RATES_LFP_ALPHA 0.2 // cutoff frequency ~ 40 Hz
|
#define RATES_LFP_ALPHA 0.2 // cutoff frequency ~ 40 Hz
|
||||||
|
|
||||||
LowPassFilter<Vector> ratesFilter(RATES_LFP_ALPHA);
|
|
||||||
|
|
||||||
void estimate() {
|
void estimate() {
|
||||||
applyGyro();
|
applyGyro();
|
||||||
applyAcc();
|
applyAcc();
|
||||||
@@ -20,6 +18,7 @@ void estimate() {
|
|||||||
|
|
||||||
void applyGyro() {
|
void applyGyro() {
|
||||||
// filter gyro to get angular rates
|
// filter gyro to get angular rates
|
||||||
|
static LowPassFilter<Vector> ratesFilter(RATES_LFP_ALPHA);
|
||||||
rates = ratesFilter.update(gyro);
|
rates = ratesFilter.update(gyro);
|
||||||
|
|
||||||
// apply rates to attitude
|
// apply rates to attitude
|
||||||
|
|||||||
@@ -116,29 +116,31 @@ public:
|
|||||||
return euler;
|
return euler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float getRoll() const {
|
||||||
|
return toEuler().x;
|
||||||
|
}
|
||||||
|
|
||||||
|
float getPitch() const {
|
||||||
|
return toEuler().y;
|
||||||
|
}
|
||||||
|
|
||||||
float getYaw() const {
|
float getYaw() const {
|
||||||
// https://github.com/ros/geometry2/blob/589caf083cae9d8fae7effdb910454b4681b9ec1/tf2/include/tf2/impl/utils.h#L122
|
return toEuler().z;
|
||||||
float yaw;
|
}
|
||||||
float sqx = x * x;
|
|
||||||
float sqy = y * y;
|
void setRoll(float roll) {
|
||||||
float sqz = z * z;
|
Vector euler = toEuler();
|
||||||
float sqw = w * w;
|
*this = Quaternion::fromEuler(Vector(roll, euler.y, euler.z));
|
||||||
double sarg = -2 * (x * z - w * y) / (sqx + sqy + sqz + sqw);
|
}
|
||||||
if (sarg <= -0.99999) {
|
|
||||||
yaw = -2 * atan2(y, x);
|
void setPitch(float pitch) {
|
||||||
} else if (sarg >= 0.99999) {
|
Vector euler = toEuler();
|
||||||
yaw = 2 * atan2(y, x);
|
*this = Quaternion::fromEuler(Vector(euler.x, pitch, euler.z));
|
||||||
} else {
|
|
||||||
yaw = atan2(2 * (x * y + w * z), sqw + sqx - sqy - sqz);
|
|
||||||
}
|
|
||||||
return yaw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setYaw(float yaw) {
|
void setYaw(float yaw) {
|
||||||
// TODO: optimize?
|
|
||||||
Vector euler = toEuler();
|
Vector euler = toEuler();
|
||||||
euler.z = yaw;
|
*this = Quaternion::fromEuler(Vector(euler.x, euler.y, yaw));
|
||||||
(*this) = Quaternion::fromEuler(euler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion operator * (const Quaternion& q) const {
|
Quaternion operator * (const Quaternion& q) const {
|
||||||
|
|||||||
Reference in New Issue
Block a user