1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-25 17:25:20 +03:00

Adding debug declaration to allow imu unit tests to compile.

This commit is contained in:
Dominic Clifton 2014-07-08 13:27:49 +01:00
parent 0f47c7e2be
commit f5baefea5b

View file

@ -1,113 +1,115 @@
/* /*
* This file is part of Cleanflight. * This file is part of Cleanflight.
* *
* Cleanflight is free software: you can redistribute it and/or modify * Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Cleanflight is distributed in the hope that it will be useful, * Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>. * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <limits.h> #include <limits.h>
#define BARO #define BARO
#include "common/axis.h" #include "common/axis.h"
#include "flight/flight.h" #include "flight/flight.h"
#include "sensors/sensors.h" #include "sensors/sensors.h"
#include "drivers/accgyro.h" #include "drivers/accgyro.h"
#include "sensors/gyro.h" #include "sensors/gyro.h"
#include "sensors/compass.h" #include "sensors/compass.h"
#include "sensors/acceleration.h" #include "sensors/acceleration.h"
#include "sensors/barometer.h" #include "sensors/barometer.h"
#include "config/runtime_config.h" #include "config/runtime_config.h"
#include "flight/mixer.h" #include "flight/mixer.h"
#include "flight/imu.h" #include "flight/imu.h"
#include "unittest_macros.h" #include "unittest_macros.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#define DOWNWARDS_THRUST true #define DOWNWARDS_THRUST true
#define UPWARDS_THRUST false #define UPWARDS_THRUST false
bool isThrustFacingDownwards(rollAndPitchInclination_t *inclinations); bool isThrustFacingDownwards(rollAndPitchInclination_t *inclinations);
typedef struct inclinationExpectation_s { typedef struct inclinationExpectation_s {
rollAndPitchInclination_t inclination; rollAndPitchInclination_t inclination;
bool expectDownwardsThrust; bool expectDownwardsThrust;
} inclinationExpectation_t; } inclinationExpectation_t;
TEST(FlightImuTest, IsThrustFacingDownwards) TEST(FlightImuTest, IsThrustFacingDownwards)
{ {
// given // given
inclinationExpectation_t inclinationExpectations[] = { inclinationExpectation_t inclinationExpectations[] = {
{ { 0, 0 }, DOWNWARDS_THRUST }, { { 0, 0 }, DOWNWARDS_THRUST },
{ { 799, 799 }, DOWNWARDS_THRUST }, { { 799, 799 }, DOWNWARDS_THRUST },
{ { 800, 799 }, UPWARDS_THRUST }, { { 800, 799 }, UPWARDS_THRUST },
{ { 799, 800 }, UPWARDS_THRUST }, { { 799, 800 }, UPWARDS_THRUST },
{ { 800, 800 }, UPWARDS_THRUST }, { { 800, 800 }, UPWARDS_THRUST },
{ { 801, 801 }, UPWARDS_THRUST }, { { 801, 801 }, UPWARDS_THRUST },
{ { -799, -799 }, DOWNWARDS_THRUST }, { { -799, -799 }, DOWNWARDS_THRUST },
{ { -800, -799 }, UPWARDS_THRUST }, { { -800, -799 }, UPWARDS_THRUST },
{ { -799, -800 }, UPWARDS_THRUST }, { { -799, -800 }, UPWARDS_THRUST },
{ { -800, -800 }, UPWARDS_THRUST }, { { -800, -800 }, UPWARDS_THRUST },
{ { -801, -801 }, UPWARDS_THRUST } { { -801, -801 }, UPWARDS_THRUST }
}; };
uint8_t testIterationCount = sizeof(inclinationExpectations) / sizeof(inclinationExpectation_t); uint8_t testIterationCount = sizeof(inclinationExpectations) / sizeof(inclinationExpectation_t);
// expect // expect
for (uint8_t index = 0; index < testIterationCount; index ++) { for (uint8_t index = 0; index < testIterationCount; index ++) {
inclinationExpectation_t *angleInclinationExpectation = &inclinationExpectations[index]; inclinationExpectation_t *angleInclinationExpectation = &inclinationExpectations[index];
printf("iteration: %d\n", index); printf("iteration: %d\n", index);
bool result = isThrustFacingDownwards(&angleInclinationExpectation->inclination); bool result = isThrustFacingDownwards(&angleInclinationExpectation->inclination);
EXPECT_EQ(angleInclinationExpectation->expectDownwardsThrust, result); EXPECT_EQ(angleInclinationExpectation->expectDownwardsThrust, result);
} }
} }
// STUBS // STUBS
uint16_t acc_1G; uint16_t acc_1G;
int16_t heading; int16_t heading;
flags_t f; flags_t f;
gyro_t gyro; gyro_t gyro;
int16_t magADC[XYZ_AXIS_COUNT]; int16_t magADC[XYZ_AXIS_COUNT];
int32_t BaroAlt; int32_t BaroAlt;
int16_t debug[4];
void gyroGetADC(void) {};
bool sensors(uint32_t mask)
{ void gyroGetADC(void) {};
UNUSED(mask); bool sensors(uint32_t mask)
return false; {
}; UNUSED(mask);
void updateAccelerationReadings(rollAndPitchTrims_t *rollAndPitchTrims) return false;
{ };
UNUSED(rollAndPitchTrims); void updateAccelerationReadings(rollAndPitchTrims_t *rollAndPitchTrims)
} {
UNUSED(rollAndPitchTrims);
uint32_t micros(void) { return 0; } }
bool isBaroCalibrationComplete(void) { return true; }
void performBaroCalibrationCycle(void) {} uint32_t micros(void) { return 0; }
int32_t baroCalculateAltitude(void) { return 0; } bool isBaroCalibrationComplete(void) { return true; }
int constrain(int amt, int low, int high) void performBaroCalibrationCycle(void) {}
{ int32_t baroCalculateAltitude(void) { return 0; }
UNUSED(amt); int constrain(int amt, int low, int high)
UNUSED(low); {
UNUSED(high); UNUSED(amt);
return 0; UNUSED(low);
} UNUSED(high);
return 0;
}