Add gravity and thrust force

This commit is contained in:
Alex Selimov 2026-11-01 23:38:25 -05:00
parent 8f4d61f820
commit 8904c223cb
4 changed files with 67 additions and 3 deletions

View file

@ -1,4 +1,5 @@
#include "./drone.h"
#include "drone.h"
#include "forces.h"
#include <math.h>
#include <stdio.h>
@ -24,7 +25,7 @@ int test_body_position_to_inertial(void) {
struct Vec3 expected_x_noop = {2.0, 1.0, 1.0};
struct Vec3 x_o2p_i_noop =
body_position_to_intertial(x_o2cg_i, identity, x_cg2p_b);
body_position_to_inertial(x_o2cg_i, identity, x_cg2p_b);
if (!vec3_eql_tol(expected_x_noop, x_o2p_i_noop, 1e-12)) {
return 0;
@ -32,11 +33,34 @@ int test_body_position_to_inertial(void) {
return 1;
}
int test_gravity(void) {
double mass = 10.0;
struct Vec3 expected_fg = {0, 0, 98.0665};
struct Vec3 fg = gravity(mass);
return vec3_eql_tol(expected_fg, fg, 1e-12);
}
int test_thrust(void) {
struct Quat attitude = yaw_pitch_roll_to_quat(0.0, 0.0, -M_PI_2);
struct Propeller p = {(struct Vec3){1.0, 1.0, 0.0}, 100.0, 1.0, 2.0, CW};
struct Vec3 expected_thrust = {0.0, -100.0 * 100.0, 0.0};
struct Vec3 expected_moment = {-100.0 * 100.0, 100.0 * 100, 100 * 100 * 2};
struct ThrustAndMoment tm = thrust(attitude, &p);
return vec3_eql_tol(expected_thrust, tm.thrust_inertial, 1e-11) &&
vec3_eql_tol(expected_moment, tm.moment_body, 1e-11);
}
int main(void) {
int tests_total = 0;
int tests_passed = 0;
run_test(test_body_position_to_inertial);
run_test(test_gravity);
run_test(test_thrust);
if (tests_total == tests_passed) {
printf("\033[92mAll tests passed!\033[0m");