mirror of
https://github.com/okalachev/flix.git
synced 2025-07-27 09:39:33 +00:00
Simplify code using angularRatesBetweenVectors
This commit is contained in:
parent
24b62e5145
commit
4fcf2109ce
@ -115,12 +115,10 @@ void controlAttitude()
|
||||
Vector upActual = attitude.rotate(up);
|
||||
Vector upTarget = attitudeTarget.rotate(up);
|
||||
|
||||
float angle = Vector::angleBetweenVectors(upTarget, upActual);
|
||||
Vector ratesTargetDir = Vector::angularRatesBetweenVectors(upTarget, upActual);
|
||||
ratesTargetDir.normalize();
|
||||
Vector error = Vector::angularRatesBetweenVectors(upTarget, upActual);
|
||||
|
||||
ratesTarget.x = rollPID.update(ratesTargetDir.x * angle, dt);
|
||||
ratesTarget.y = pitchPID.update(ratesTargetDir.y * angle, dt);
|
||||
ratesTarget.x = rollPID.update(error.x, dt);
|
||||
ratesTarget.y = pitchPID.update(error.y, dt);
|
||||
|
||||
if (yawMode == YAW) {
|
||||
ratesTarget.z = yawPID.update(wrapAngle(attitudeTarget.getYaw() - attitude.getYaw()), dt);
|
||||
|
@ -36,12 +36,10 @@ void applyAcc()
|
||||
|
||||
// calculate accelerometer correction
|
||||
Vector up = attitude.rotate(Vector(0, 0, -1));
|
||||
Vector accCorrDirection = Vector::angularRatesBetweenVectors(acc, up);
|
||||
accCorrDirection.normalize();
|
||||
Vector accCorr = accCorrDirection * Vector::angleBetweenVectors(up, acc) * dt * WEIGHT_ACC;
|
||||
Vector correction = Vector::angularRatesBetweenVectors(acc, up) * dt * WEIGHT_ACC;
|
||||
|
||||
// apply correction
|
||||
attitude *= Quaternion::fromAngularRates(accCorr);
|
||||
attitude *= Quaternion::fromAngularRates(correction);
|
||||
attitude.normalize();
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,10 @@ public:
|
||||
|
||||
static Vector angularRatesBetweenVectors(const Vector& u, const Vector& v)
|
||||
{
|
||||
return cross(u, v);
|
||||
Vector direction = cross(u, v);
|
||||
direction.normalize();
|
||||
float angle = angleBetweenVectors(u, v);
|
||||
return direction * angle;
|
||||
}
|
||||
|
||||
size_t printTo(Print& p) const {
|
||||
|
Loading…
x
Reference in New Issue
Block a user