1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-24 16:55:29 +03:00

Replaced Sonar magic numbers with #defines. Added first cut of Sonar test code. Corrected spelling in comments. Minor improvements to comments.

This commit is contained in:
Martin Budden 2015-11-24 23:26:58 +00:00
parent 230cc3c90e
commit 3e95ecbba9
7 changed files with 102 additions and 22 deletions

View file

@ -535,6 +535,37 @@ $(OBJECT_DIR)/baro_bmp280_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/drivers/sonar_hcsr04.o : \
$(USER_DIR)/drivers/sonar_hcsr04.c \
$(USER_DIR)/drivers/sonar_hcsr04.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/drivers/sonar_hcsr04.c -o $@
$(OBJECT_DIR)/sensors/sonar.o : \
$(USER_DIR)/sensors/sonar.c \
$(USER_DIR)/sensors/sonar.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/sensors/sonar.c -o $@
$(OBJECT_DIR)/sonar_unittest.o : \
$(TEST_DIR)/sonar_unittest.cc \
$(USER_DIR)/drivers/sonar_hcsr04.h \
$(USER_DIR)/sensors/sonar.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/sonar_unittest.cc -o $@
$(OBJECT_DIR)/sonar_unittest : \
$(OBJECT_DIR)/drivers/sonar_hcsr04.o \
$(OBJECT_DIR)/sensors/sonar.o \
$(OBJECT_DIR)/sonar_unittest.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/sensors/boardalignment.o : \
$(USER_DIR)/sensors/boardalignment.c \
$(USER_DIR)/sensors/boardalignment.h \

View file

@ -0,0 +1,40 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
extern "C" {
#include "drivers/sonar_hcsr04.h"
#include "sensors/sonar.h"
#include "build_config.h"
}
#include "unittest_macros.h"
#include "gtest/gtest.h"
TEST(SonarUnittest, TestConstants)
{
// SONAR_OUT_OF_RANGE must be negative
EXPECT_LE(SONAR_OUT_OF_RANGE, 0);
// Check reasonable values for maximum tilt
EXPECT_GE(SONAR_MAX_TILT_ANGLE, 0);
EXPECT_LE(SONAR_MAX_TILT_ANGLE, 450);
// Check against gross errors in max range constants
EXPECT_LE(SONAR_MAX_RANGE_WITH_TILT, SONAR_MAX_RANGE);
EXPECT_LE(SONAR_MAX_RANGE_ACCURACY_HIGH, SONAR_MAX_RANGE);
}