| 1 | #include "testYASimGear.hxx" |
| 2 | |
| 3 | #include "test_suite/FGTestApi/testGlobals.hxx" |
| 4 | |
| 5 | #include "FDM/YASim/Gear.hpp" |
| 6 | |
| 7 | #include <simgear/debug/logstream.hxx> |
| 8 | |
| 9 | #include <sstream> |
| 10 | |
| 11 | |
| 12 | void YASimGearTests::setUp() |
| 13 | { |
| 14 | FGTestApi::setUp::initTestGlobals(""); |
| 15 | } |
| 16 | |
| 17 | void YASimGearTests::tearDown() |
| 18 | { |
| 19 | FGTestApi::tearDown::shutdownTestGlobals(); |
| 20 | } |
| 21 | |
| 22 | |
| 23 | void YASimGearTests::test() |
| 24 | { |
| 25 | /* Check we get expected values for a particular set of inputs. */ |
| 26 | |
| 27 | float ground[4] = { -0.22097, 0.00507429, -0.975263, 2.35943}; |
| 28 | float wheel_pos[3] = { -0.953044, 2.20823, -2.00883}; |
| 29 | yasim::GearVector wheel_axle( -0, 0.16383, -0.114715); |
| 30 | float wheel_radius = 0.261257; |
| 31 | float tyre_radius = 0.130629; |
| 32 | yasim::GearVector compression( -0.139389, -0, 0.480178); |
| 33 | |
| 34 | float contact[3]; |
| 35 | float compress_distance_vertical; |
| 36 | float compress_norm; |
| 37 | |
| 38 | bool on_ground = yasim::gearCompression( |
| 39 | ground, |
| 40 | compression, |
| 41 | wheel_pos, |
| 42 | wheel_axle, |
| 43 | wheel_radius, |
| 44 | tyre_radius, |
| 45 | [] () { return 0; }, |
| 46 | |
| 47 | /* output params: */ |
| 48 | contact, |
| 49 | compress_distance_vertical, |
| 50 | compress_norm |
| 51 | ); |
| 52 | |
| 53 | SG_LOG( SG_GENERAL, SG_ALERT, "on_ground=" << on_ground); |
| 54 | SG_LOG( SG_GENERAL, SG_ALERT, "contact=(" << contact[0] << ", " << contact[1] << ", " << contact[1] << ")"); |
| 55 | SG_LOG( SG_GENERAL, SG_ALERT, "compress_distance_vertical=" << compress_distance_vertical); |
| 56 | SG_LOG( SG_GENERAL, SG_ALERT, "compress_norm=" << compress_norm); |
| 57 | |
| 58 | double e = 0.0001; |
| 59 | CPPUNIT_ASSERT( on_ground); |
| 60 | CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.1053, contact[0], e); |
| 61 | CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0645, contact[1], e); |
| 62 | CPPUNIT_ASSERT_DOUBLES_EQUAL( -2.1581, contact[2], e); |
| 63 | CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.167955, compress_distance_vertical, e); |
| 64 | CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.383887, compress_norm, e); |
| 65 | |
| 66 | |
| 67 | /* Now check we get same results as old point-contact algorithm, when using |
| 68 | wheel_radius=0 and tyre_radius=0. */ |
| 69 | |
| 70 | /* For this test we set gear contact point to bottom of what was the wheel, |
| 71 | so that it will be approximately in same position as earlier contact point, |
| 72 | and so slightly underground. */ |
| 73 | wheel_pos[2] -= wheel_radius + tyre_radius; |
| 74 | |
| 75 | float bump_altitude_override = 0.1; |
| 76 | |
| 77 | on_ground = yasim::gearCompression( |
| 78 | ground, |
| 79 | compression, |
| 80 | wheel_pos /* contact point. */, |
| 81 | wheel_axle /* values don't matter. */, |
| 82 | 0 /*wheel_radius*/, |
| 83 | 0 /*tyre_radius*/, |
| 84 | [bump_altitude_override] () { return bump_altitude_override; }, |
| 85 | |
| 86 | /* output params: */ |
| 87 | contact, |
| 88 | compress_distance_vertical, |
| 89 | compress_norm |
| 90 | ); |
| 91 | |
| 92 | float contact_old[3]; |
| 93 | float compress_distance_vertical_old; |
| 94 | float compress_norm_old; |
| 95 | |
| 96 | bool on_ground_old = yasim::gearCompressionOld( |
| 97 | ground, |
| 98 | compression, |
| 99 | wheel_pos /* contact point. */, |
| 100 | [bump_altitude_override] () { return bump_altitude_override; }, |
| 101 | |
| 102 | /* output params: */ |
| 103 | contact_old, |
| 104 | compress_distance_vertical_old, |
| 105 | compress_norm_old |
| 106 | ); |
| 107 | |
| 108 | SG_LOG( SG_GENERAL, SG_ALERT, "comparing with old algorithm."); |
| 109 | SG_LOG( SG_GENERAL, SG_ALERT, "old:"); |
| 110 | SG_LOG( SG_GENERAL, SG_ALERT, " on_ground_old=" << on_ground_old); |
| 111 | SG_LOG( SG_GENERAL, SG_ALERT, " contact=(" << contact_old[0] << ", " << contact_old[1] << ", " << contact_old[1] << ")"); |
| 112 | SG_LOG( SG_GENERAL, SG_ALERT, " compress_distance_vertical=" << compress_distance_vertical_old); |
| 113 | SG_LOG( SG_GENERAL, SG_ALERT, " compress_norm=" << compress_norm_old); |
| 114 | SG_LOG( SG_GENERAL, SG_ALERT, "new:"); |
| 115 | SG_LOG( SG_GENERAL, SG_ALERT, " on_ground=" << on_ground); |
| 116 | SG_LOG( SG_GENERAL, SG_ALERT, " contact=(" << contact[0] << ", " << contact[1] << ", " << contact[1] << ")"); |
| 117 | SG_LOG( SG_GENERAL, SG_ALERT, " compress_distance_vertical=" << compress_distance_vertical); |
| 118 | SG_LOG( SG_GENERAL, SG_ALERT, " compress_norm=" << compress_norm); |
| 119 | |
| 120 | CPPUNIT_ASSERT( on_ground); |
| 121 | CPPUNIT_ASSERT_EQUAL( on_ground_old, on_ground); |
| 122 | CPPUNIT_ASSERT_DOUBLES_EQUAL( contact_old[0], contact[0], e); |
| 123 | CPPUNIT_ASSERT_DOUBLES_EQUAL( contact_old[1], contact[1], e); |
| 124 | CPPUNIT_ASSERT_DOUBLES_EQUAL( contact_old[2], contact[2], e); |
| 125 | CPPUNIT_ASSERT_DOUBLES_EQUAL( compress_distance_vertical_old, compress_distance_vertical, e); |
| 126 | CPPUNIT_ASSERT_DOUBLES_EQUAL( compress_norm_old, compress_norm, e); |
| 127 | } |
| 128 |