Fix issue with drag calculation and update expected final value
This commit is contained in:
parent
6332e3d770
commit
3a47ce9383
2 changed files with 27 additions and 8 deletions
|
|
@ -34,9 +34,9 @@ pub fn drag(
|
||||||
velocity: vec3.Vec3F64,
|
velocity: vec3.Vec3F64,
|
||||||
) vec3.Vec3F64 {
|
) vec3.Vec3F64 {
|
||||||
return .init(
|
return .init(
|
||||||
velocity.x() * drag_coefficient,
|
-velocity.x() * drag_coefficient,
|
||||||
velocity.y() * drag_coefficient,
|
-velocity.y() * drag_coefficient,
|
||||||
velocity.z() * drag_coefficient,
|
-velocity.z() * drag_coefficient,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ test "drag is correct" {
|
||||||
const velocity = vec3.Vec3F64.init(0, 1, 1);
|
const velocity = vec3.Vec3F64.init(0, 1, 1);
|
||||||
const f_drag = drag(0.5, velocity);
|
const f_drag = drag(0.5, velocity);
|
||||||
|
|
||||||
try std.testing.expectApproxEqAbs(0, f_drag.x(), 1e-11);
|
try std.testing.expectApproxEqAbs(-0.0, f_drag.x(), 1e-11);
|
||||||
try std.testing.expectApproxEqAbs(0.5, f_drag.y(), 1e-11);
|
try std.testing.expectApproxEqAbs(-0.5, f_drag.y(), 1e-11);
|
||||||
try std.testing.expectApproxEqAbs(0.5, f_drag.z(), 1e-11);
|
try std.testing.expectApproxEqAbs(-0.5, f_drag.z(), 1e-11);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,14 @@ pub fn timestep(dt: f64, d: drone.Drone, props: []const drone.Propeller, s: *dro
|
||||||
);
|
);
|
||||||
|
|
||||||
s.omega = vec3.vec3Add(s.omega, vec3.vec3Scale(omega_dot, dt));
|
s.omega = vec3.vec3Add(s.omega, vec3.vec3Scale(omega_dot, dt));
|
||||||
const half_omege_quat: vec3.QuatF64 = .init(
|
const half_omega_quat: vec3.QuatF64 = .init(
|
||||||
s.omega.x() * 0.5,
|
s.omega.x() * 0.5,
|
||||||
s.omega.y() * 0.5,
|
s.omega.y() * 0.5,
|
||||||
s.omega.z() * 0.5,
|
s.omega.z() * 0.5,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const qdot = vec3.quatMul(half_omege_quat, s.q);
|
const qdot = vec3.quatMul(half_omega_quat, s.q);
|
||||||
s.q = vec3.quatAdd(s.q, vec3.quatScale(qdot, dt)).normalized();
|
s.q = vec3.quatAdd(s.q, vec3.quatScale(qdot, dt)).normalized();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -85,4 +85,23 @@ test "Validate timesteps" {
|
||||||
try std.testing.expectApproxEqAbs(0.12403234937465502, state.q.y(), 1e-12);
|
try std.testing.expectApproxEqAbs(0.12403234937465502, state.q.y(), 1e-12);
|
||||||
try std.testing.expectApproxEqAbs(0.006201617468732751, state.q.z(), 1e-11);
|
try std.testing.expectApproxEqAbs(0.006201617468732751, state.q.z(), 1e-11);
|
||||||
try std.testing.expectApproxEqAbs(0.9922587949972401, state.q.w(), 1e-11);
|
try std.testing.expectApproxEqAbs(0.9922587949972401, state.q.w(), 1e-11);
|
||||||
|
|
||||||
|
timestep(0.005, d, &props, &state);
|
||||||
|
|
||||||
|
try std.testing.expectApproxEqAbs(-1.23072190e+01, state.v.x(), 1e-7);
|
||||||
|
try std.testing.expectApproxEqAbs(-7.69201185e-02, state.v.y(), 1e-8);
|
||||||
|
try std.testing.expectApproxEqAbs(-9.83635311e+01, state.v.z(), 1e-7);
|
||||||
|
|
||||||
|
try std.testing.expectApproxEqAbs(-6.15360950e-02, state.x_cg.x(), 1e-9);
|
||||||
|
try std.testing.expectApproxEqAbs(-3.84600592e-04, state.x_cg.y(), 1e-9);
|
||||||
|
try std.testing.expectApproxEqAbs(-7.41572489e-01, state.x_cg.z(), 1e-9);
|
||||||
|
|
||||||
|
try std.testing.expectApproxEqAbs(-0.46875, state.omega.x(), 1e-12);
|
||||||
|
try std.testing.expectApproxEqAbs(100, state.omega.y(), 1e-12);
|
||||||
|
try std.testing.expectApproxEqAbs(5, state.omega.z(), 1e-11);
|
||||||
|
|
||||||
|
try std.testing.expectApproxEqAbs(-0.0011280012096230429, state.q.x(), 1e-12);
|
||||||
|
try std.testing.expectApproxEqAbs(0.36096743708693396, state.q.y(), 1e-12);
|
||||||
|
try std.testing.expectApproxEqAbs(0.01790701920276581, state.q.z(), 1e-12);
|
||||||
|
try std.testing.expectApproxEqAbs(0.9324057998744074, state.q.w(), 1e-12);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue