diff --git a/Makefile b/Makefile index aef6b7fd1..557d6b053 100644 --- a/Makefile +++ b/Makefile @@ -261,9 +261,9 @@ fw_$(1)_%: uavobjects_flight $(V1) $(MKDIR) -p $(BUILD_DIR)/fw_$(1)/dep $(V1) cd $(ROOT_DIR)/flight/targets/boards/$(1)/firmware && \ $$(MAKE) -r --no-print-directory \ + BUILD_TYPE=fw \ BOARD_NAME=$(1) \ BOARD_SHORT_NAME=$(2) \ - BUILD_TYPE=fw \ TOPDIR=$(ROOT_DIR)/flight/targets/boards/$(1)/firmware \ OUTDIR=$(BUILD_DIR)/fw_$(1) \ TARGET=fw_$(1) \ @@ -288,9 +288,9 @@ bl_$(1)_%: $(V1) $(MKDIR) -p $(BUILD_DIR)/bl_$(1)/dep $(V1) cd $(ROOT_DIR)/flight/targets/boards/$(1)/bootloader && \ $$(MAKE) -r --no-print-directory \ + BUILD_TYPE=bl \ BOARD_NAME=$(1) \ BOARD_SHORT_NAME=$(2) \ - BUILD_TYPE=bl \ TOPDIR=$(ROOT_DIR)/flight/targets/boards/$(1)/bootloader \ OUTDIR=$(BUILD_DIR)/bl_$(1) \ TARGET=bl_$(1) \ @@ -326,9 +326,9 @@ bu_$(1)_%: bl_$(1)_bino $(V1) $(MKDIR) -p $(BUILD_DIR)/bu_$(1)/dep $(V1) cd $(ROOT_DIR)/flight/targets/common/bootloader_updater && \ $$(MAKE) -r --no-print-directory \ + BUILD_TYPE=bu \ BOARD_NAME=$(1) \ BOARD_SHORT_NAME=$(2) \ - BUILD_TYPE=bu \ TOPDIR=$(ROOT_DIR)/flight/targets/common/bootloader_updater \ OUTDIR=$(BUILD_DIR)/bu_$(1) \ TARGET=bu_$(1) \ @@ -350,9 +350,9 @@ ef_$(1)_%: bl_$(1)_bin fw_$(1)_opfw $(V1) $(MKDIR) -p $(BUILD_DIR)/ef_$(1) $(V1) cd $(ROOT_DIR)/flight/targets/common/entire_flash && \ $$(MAKE) -r --no-print-directory \ + BUILD_TYPE=ef \ BOARD_NAME=$(1) \ BOARD_SHORT_NAME=$(2) \ - BUILD_TYPE=ef \ DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \ TOPDIR=$(ROOT_DIR)/flight/targets/common/entire_flash \ OUTDIR=$(BUILD_DIR)/ef_$(1) \ @@ -656,20 +656,9 @@ ut_$(1)_%: $$(UT_OUT_DIR) $(V1) cd $(ROOT_DIR)/flight/tests/$(1) && \ $$(MAKE) -r --no-print-directory \ BUILD_TYPE=ut \ - BOARD_SHORT_NAME=$(1) \ - TCHAIN_PREFIX="" \ - REMOVE_CMD="$(RM)" \ - \ - TARGET=$(1) \ + TOPDIR=$(ROOT_DIR)/flight/tests/$(1) \ OUTDIR="$(UT_OUT_DIR)/$(1)" \ - \ - PIOS=$(PIOS) \ - OPUAVOBJ=$(OPUAVOBJ) \ - OPUAVTALK=$(OPUAVTALK) \ - FLIGHTLIB=$(FLIGHTLIB) \ - \ - GTEST_DIR=$(GTEST_DIR) \ - \ + TARGET=$(1) \ $$* .PHONY: ut_$(1)_clean @@ -879,6 +868,7 @@ help: @$(ECHO) " nsis_install - Install the NSIS Unicode (Windows only)" @$(ECHO) " uncrustify_install - Install the Uncrustify source code beautifier" @$(ECHO) " doxygen_install - Install the Doxygen documentation generator" + @$(ECHO) " gtest_install - Install the GoogleTest framework" @$(ECHO) " These targets are not updated yet and are probably broken:" @$(ECHO) " openocd_install - Install the OpenOCD JTAG daemon" @$(ECHO) " stm32flash_install - Install the stm32flash tool for unbricking F1-based boards" @@ -886,6 +876,7 @@ help: @$(ECHO) " android_sdk_install - Install the Android SDK tools" @$(ECHO) " Install all available tools:" @$(ECHO) " all_sdk_install - Install all of above (platform-dependent)" + @$(ECHO) " build_sdk_install - Install only essential for build tools (platform-dependent)" @$(ECHO) @$(ECHO) " Other tool options are:" @$(ECHO) " _version - Display version" diff --git a/flight/modules/Attitude/attitude.c b/flight/modules/Attitude/attitude.c index a0ef1cdc1..6f4d348f5 100644 --- a/flight/modules/Attitude/attitude.c +++ b/flight/modules/Attitude/attitude.c @@ -92,6 +92,7 @@ static bool accel_filter_enabled = false; static float accels_filtered[3]; static float grot_filtered[3]; static float yawBiasRate = 0; +static float rollPitchBiasRate = 0.0f; static float gyroGain = 0.42; static int16_t accelbias[3]; static float q[4] = {1,0,0,0}; @@ -216,17 +217,19 @@ static void AttitudeTask(void *parameters) FlightStatusGet(&flightStatus); if((xTaskGetTickCount() < 7000) && (xTaskGetTickCount() > 1000)) { - // For first 7 seconds use accels to get gyro bias + // Use accels to initialise attitude and calculate gyro bias accelKp = 1; - accelKi = 0.9; + accelKi = 0.0f; yawBiasRate = 0.01; + rollPitchBiasRate = 0.01f; accel_filter_enabled = false; init = 0; } else if (zero_during_arming && (flightStatus.Armed == FLIGHTSTATUS_ARMED_ARMING)) { accelKp = 1; - accelKi = 0.9; + accelKi = 0.0f; yawBiasRate = 0.01; + rollPitchBiasRate = 0.01f; accel_filter_enabled = false; init = 0; } else if (init == 0) { @@ -234,6 +237,7 @@ static void AttitudeTask(void *parameters) AttitudeSettingsAccelKiGet(&accelKi); AttitudeSettingsAccelKpGet(&accelKp); AttitudeSettingsYawBiasRateGet(&yawBiasRate); + rollPitchBiasRate = 0.0f if (accel_alpha > 0.0f) accel_filter_enabled = true; init = 1; @@ -356,7 +360,11 @@ static int32_t updateSensors(AccelsData * accels, GyrosData * gyros) gyros->y += gyro_correct_int[1]; gyros->z += gyro_correct_int[2]; } - + + // Force the roll & pitch gyro rates to average to zero during initialisation + gyro_correct_int[0] += - gyros->x * rollPitchBiasRate; + gyro_correct_int[1] += - gyros->y * rollPitchBiasRate; + // Because most crafts wont get enough information from gravity to zero yaw gyro, we try // and make it average zero (weakly) gyro_correct_int[2] += - gyros->z * yawBiasRate; @@ -428,6 +436,10 @@ static int32_t updateSensorsCC3D(AccelsData * accelsData, GyrosData * gyrosData) gyrosData->z += gyro_correct_int[2]; } + // Force the roll & pitch gyro rates to average to zero during initialisation + gyro_correct_int[0] += - gyros->x * rollPitchBiasRate; + gyro_correct_int[1] += - gyros->y * rollPitchBiasRate; + // Because most crafts wont get enough information from gravity to zero yaw gyro, we try // and make it average zero (weakly) gyro_correct_int[2] += - gyrosData->z * yawBiasRate; diff --git a/flight/pios/common/pios_flash_jedec.c b/flight/pios/common/pios_flash_jedec.c index 8fa2f0297..935861484 100644 --- a/flight/pios/common/pios_flash_jedec.c +++ b/flight/pios/common/pios_flash_jedec.c @@ -387,12 +387,15 @@ static int32_t PIOS_Flash_Jedec_EraseChip(uintptr_t flash_id) while (PIOS_Flash_Jedec_Busy(flash_dev) != 0) { #if defined(FLASH_FREERTOS) vTaskDelay(1); - if ((i++) % 100 == 0) + if ((i++) % 100 == 0) { #else - if ((i++) % 10000 == 0) + if ((i++) % 10000 == 0) { #endif +#ifdef PIOS_LED_HEARTBEAT PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); +#endif + } } diff --git a/flight/pios/common/pios_flashfs_logfs.c b/flight/pios/common/pios_flashfs_logfs.c index 4fdef16db..6f7b59fae 100644 --- a/flight/pios/common/pios_flashfs_logfs.c +++ b/flight/pios/common/pios_flashfs_logfs.c @@ -193,7 +193,9 @@ static int32_t logfs_erase_all_arenas() uint16_t num_arenas = logfs.cfg->total_fs_size / logfs.cfg->arena_size; for (uint16_t arena = 0; arena < num_arenas; arena++) { - PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); +#ifdef PIOS_LED_HEARTBEAT + PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); +#endif if (logfs_erase_arena(arena) != 0) return -1; } diff --git a/flight/pios/pios.h b/flight/pios/pios.h index f1e7e7f4a..3e60ec735 100644 --- a/flight/pios/pios.h +++ b/flight/pios/pios.h @@ -49,11 +49,11 @@ #include /* STM32 Std Peripherals Lib */ -#ifdef STM32F4XX +#if defined(STM32F10X) +#include +#elif defined(STM32F4XX) #include #include -#else -#include #endif /* PIOS board specific feature selection */ diff --git a/flight/tests/logfs/Makefile b/flight/tests/logfs/Makefile index 3aabe0ed6..050a7efa4 100644 --- a/flight/tests/logfs/Makefile +++ b/flight/tests/logfs/Makefile @@ -1,6 +1,7 @@ ############################################################################### # @file Makefile # @author PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012 +# Copyright (c) 2013, The OpenPilot Team, http://www.openpilot.org # @addtogroup # @{ # @addtogroup @@ -23,21 +24,17 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -WHEREAMI := $(dir $(lastword $(MAKEFILE_LIST))) -TOP := $(realpath $(WHEREAMI)/../../../) -include $(TOP)/make/firmware-defs.mk +ifndef OPENPILOT_IS_COOL + $(error Top level Makefile must be used to build this target) +endif +include $(ROOT_DIR)/make/firmware-defs.mk + +EXTRAINCDIRS += $(TOPDIR) EXTRAINCDIRS += $(PIOS)/inc -CFLAGS += -O0 -CFLAGS += -Wall -Werror -CFLAGS += -g -CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. +SRC += $(PIOS)/common/pios_flashfs_logfs.c CFLAGS += "-DFLASH_IMAGE_FILE=\"$(OUTDIR)/theflash.bin\"" -CONLYFLAGS += -std=gnu99 - -SRC := $(PIOS)/common/pios_flashfs_logfs.c - -include $(TOP)/make/unittest.mk +include $(ROOT_DIR)/make/unittest.mk diff --git a/flight/tests/logfs/openpilot.h b/flight/tests/logfs/openpilot.h index 473f27b93..69f7874da 100644 --- a/flight/tests/logfs/openpilot.h +++ b/flight/tests/logfs/openpilot.h @@ -1,5 +1,9 @@ +#ifndef OPENPILOT_H +#define OPENPILOT_H + #include #define PIOS_Assert(x) if (!(x)) { while (1) ; } - #define PIOS_DEBUG_Assert(x) PIOS_Assert(x) + +#endif /* OPENPILOT_H */ diff --git a/flight/tests/logfs/pios.h b/flight/tests/logfs/pios.h index 23ec3250e..88a4914dc 100644 --- a/flight/tests/logfs/pios.h +++ b/flight/tests/logfs/pios.h @@ -1,4 +1,12 @@ -#if defined(PIOS_INCLUDE_FLASH) +#ifndef PIOS_H +#define PIOS_H + +/* PIOS board specific feature selection */ +#include "pios_config.h" + +#ifdef PIOS_INCLUDE_FLASH #include #include #endif + +#endif /* PIOS_H */ diff --git a/flight/tests/logfs/pios_config.h b/flight/tests/logfs/pios_config.h index 98eeb42a3..e473cd8ef 100644 --- a/flight/tests/logfs/pios_config.h +++ b/flight/tests/logfs/pios_config.h @@ -1 +1,7 @@ +#ifndef PIOS_CONFIG_H +#define PIOS_CONFIG_H + +/* Enable/Disable PiOS modules */ #define PIOS_INCLUDE_FLASH + +#endif /* PIOS_CONFIG_H */ diff --git a/make/tools.mk b/make/tools.mk index 599d1e21f..d1245ba17 100644 --- a/make/tools.mk +++ b/make/tools.mk @@ -14,6 +14,7 @@ # nsis_install (Windows only) # uncrustify_install # doxygen_install +# gtest_install # # TODO: # openocd_install @@ -24,7 +25,6 @@ # stm32flash_install # dfuutil_install # android_sdk_install -# gtest_install # # TODO: # help in the top Makefile @@ -79,6 +79,8 @@ else ifeq ($(UNAME), Windows) DOXYGEN_URL := http://wiki.openpilot.org/download/attachments/18612236/doxygen-1.8.3.1-windows.tar.bz2 endif +GTEST_URL := http://wiki.openpilot.org/download/attachments/18612236/gtest-1.6.0.zip + # Changing PYTHON_DIR, also update it in ground\openpilotgcs\src\app\gcsversioninfo.pri ARM_SDK_DIR := $(TOOLS_DIR)/gcc-arm-none-eabi-4_7-2013q1 QT_SDK_DIR := $(TOOLS_DIR)/qt-4.8.4 @@ -87,24 +89,30 @@ PYTHON_DIR := $(TOOLS_DIR)/python-2.7.4 NSIS_DIR := $(TOOLS_DIR)/nsis-2.46-unicode UNCRUSTIFY_DIR := $(TOOLS_DIR)/uncrustify-0.60 DOXYGEN_DIR := $(TOOLS_DIR)/doxygen-1.8.3.1 +GTEST_DIR := $(TOOLS_DIR)/gtest-1.6.0 ############################## # -# All toolchains available for the platform +# Build only and all toolchains available for the platform # ############################## -ALL_SDK_TARGETS := arm_sdk qt_sdk +BUILD_SDK_TARGETS := arm_sdk qt_sdk ifeq ($(UNAME), Windows) - ALL_SDK_TARGETS += mingw python nsis + BUILD_SDK_TARGETS += mingw python nsis endif -ALL_SDK_TARGETS += uncrustify doxygen +ALL_SDK_TARGETS := $(BUILD_SDK_TARGETS) gtest uncrustify doxygen -.PHONY: all_sdk_install all_sdk_clean all_sdk_distclean all_sdk_version -all_sdk_install: $(addsuffix _install,$(ALL_SDK_TARGETS)) -all_sdk_clean: $(addsuffix _clean,$(ALL_SDK_TARGETS)) -all_sdk_distclean: $(addsuffix _distclean,$(ALL_SDK_TARGETS)) -all_sdk_version: $(addsuffix _version,$(ALL_SDK_TARGETS)) +define GROUP_SDK_TEMPLATE +.PHONY: $(1)_install $(1)_clean $(1)_distclean $(1)_version +$(1)_install: $(addsuffix _install,$(2)) +$(1)_clean: $(addsuffix _clean,$(2)) +$(1)_distclean: $(addsuffix _distclean,$(2)) +$(1)_version: $(addsuffix _version,$(2)) +endef + +$(eval $(call GROUP_SDK_TEMPLATE,build_sdk,$(BUILD_SDK_TARGETS))) +$(eval $(call GROUP_SDK_TEMPLATE,all_sdk,$(ALL_SDK_TARGETS))) ############################## # @@ -122,14 +130,14 @@ export CUT := cut export SED := sed # Used only by this Makefile +GIT := git +CURL := curl TAR := tar +UNZIP := unzip +OPENSSL := openssl ANT := ant JAVAC := javac JAR := jar -GIT := git -CURL := curl -OPENSSL := openssl -DOXYGEN := doxygen # Echo in recipes is a bit tricky in a Windows Git Bash window in some cases. # It does not work if make started under msysGit installed into a path with spaces. @@ -171,11 +179,13 @@ MSG_NOTICE = $(QUOTE) NOTE $(QUOTE) # Verbosity level ifeq ($(V), 1) - CURL_OPTIONS := - MAKE_SILENT := + CURL_OPTIONS := + MAKE_SILENT := + UNZIP_SILENT := else - CURL_OPTIONS := --silent - MAKE_SILENT := --silent + CURL_OPTIONS := --silent + MAKE_SILENT := --silent + UNZIP_SILENT := -q endif # MSYS tar workaround @@ -237,7 +247,10 @@ $(1)_install: $(1)_clean | $(DL_DIR) $(TOOLS_DIR) @$(ECHO) $(MSG_EXTRACTING) $$(call toprel, $(2)) $(V1) $(MKDIR) -p $$(call toprel, $(dir $(2))) - $(V1) $(TAR) $(TAR_OPTIONS) -C $$(call toprel, $(dir $(2))) -xf $$(call toprel, $(DL_DIR)/$(4)) + $(if $(filter $(suffix $(4)), .zip), + $(V1) $(UNZIP) $(UNZIP_SILENT) -d $$(call toprel, $(dir $(2))) $$(call toprel, $(DL_DIR)/$(4)), + $(V1) $(TAR) $(TAR_OPTIONS) -C $$(call toprel, $(dir $(2))) -xf $$(call toprel, $(DL_DIR)/$(4)) + ) $(5) @@ -523,7 +536,19 @@ endif doxygen_version: -$(V1) $(ECHO) "Doxygen `$(DOXYGEN) --version`" +############################## +# +# GoogleTest +# +############################## +$(eval $(call TOOL_INSTALL_TEMPLATE,gtest,$(GTEST_DIR),$(GTEST_URL),$(notdir $(GTEST_URL)))) + +export GTEST_DIR + +.PHONY: gtest_version +gtest_version: + -$(V1) $(SED) -n "s/^PACKAGE_STRING='\(.*\)'/\1/p" < $(GTEST_DIR)/configure @@ -790,28 +815,6 @@ android_sdk_update: $(V0) @echo " UPDATE $(ANDROID_SDK_DIR)" $(ANDROID_SDK_DIR)/tools/android update sdk --no-ui -t platform-tools,android-16,addon-google_apis-google-16 -# Set up Google Test (gtest) tools -GTEST_DIR := $(TOOLS_DIR)/gtest-1.6.0 - -.PHONY: gtest_install -gtest_install: | $(DL_DIR) $(TOOLS_DIR) -gtest_install: GTEST_URL := http://googletest.googlecode.com/files/gtest-1.6.0.zip -gtest_install: GTEST_FILE := $(notdir $(GTEST_URL)) -gtest_install: gtest_clean - # download the file unconditionally since google code gives back 404 - # for HTTP HEAD requests which are used when using the wget -N option - $(V1) [ ! -f "$(DL_DIR)/$(GTEST_FILE)" ] || $(RM) -f "$(DL_DIR)/$(GTEST_FILE)" - $(V1) $(WGET) -P "$(DL_DIR)" --trust-server-name "$(GTEST_URL)" - - # extract the source - $(V1) [ ! -d "$(GTEST_DIR)" ] || $(RM) -rf "$(GTEST_DIR)" - $(V1) mkdir -p "$(GTEST_DIR)" - $(V1) unzip -q -d "$(TOOLS_DIR)" "$(DL_DIR)/$(GTEST_FILE)" - -.PHONY: gtest_clean -gtest_clean: - $(V0) @echo " CLEAN $(GTEST_DIR)" - $(V1) [ ! -d "$(GTEST_DIR)" ] || $(RM) -rf "$(GTEST_DIR)" ############################## # diff --git a/make/unittest.mk b/make/unittest.mk index 624864cab..5963f5567 100644 --- a/make/unittest.mk +++ b/make/unittest.mk @@ -1,6 +1,7 @@ ############################################################################### # @file unittest.mk # @author PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012 +# Copyright (c) 2013, The OpenPilot Team, http://www.openpilot.org # @addtogroup # @{ # @addtogroup @@ -23,40 +24,42 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# Flags passed to the preprocessor. -CPPFLAGS += -I$(GTEST_DIR)/include - -# Flags passed to the C++ compiler. -CXXFLAGS += -g -Wall -Wextra - -# Google Test needs the pthread library -LDFLAGS += -lpthread - -################################# -# -# Template to build the user test -# -################################# - -# Need to disable THUMB mode for unit tests +# Use native toolchain and disable THUMB mode for unit tests +override ARM_SDK_PREFIX := override THUMB := -EXTRAINCDIRS += . -ALLSRC := $(SRC) $(wildcard ./*.c) -ALLCPPSRC := $(wildcard ./*.cpp) $(GTEST_DIR)/src/gtest_main.cc -ALLSRCBASE := $(notdir $(basename $(ALLSRC) $(ALLCPPSRC))) -ALLOBJ := $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE))) +# Unit test source files +ALLSRC := $(SRC) $(wildcard ./*.c) +ALLCPPSRC := $(wildcard ./*.cpp) $(GTEST_DIR)/src/gtest_main.cc +ALLSRCBASE := $(notdir $(basename $(ALLSRC) $(ALLCPPSRC))) +ALLOBJ := $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE))) $(foreach src,$(ALLSRC),$(eval $(call COMPILE_C_TEMPLATE,$(src)))) $(foreach src,$(ALLCPPSRC),$(eval $(call COMPILE_CXX_TEMPLATE,$(src)))) - # Specific extensions to CPPFLAGS only for the google test library -$(OUTDIR)/gtest-all.o : CPPFLAGS += -I$(GTEST_DIR) -$(eval $(call COMPILE_CXX_TEMPLATE, $(GTEST_DIR)/src/gtest-all.cc)) +$(OUTDIR)/gtest-all.o: CPPFLAGS += -I$(GTEST_DIR) +$(eval $(call COMPILE_CXX_TEMPLATE, $(GTEST_DIR)/src/gtest-all.cc)) $(eval $(call LINK_CXX_TEMPLATE,$(OUTDIR)/$(TARGET).elf,$(ALLOBJ) $(OUTDIR)/gtest-all.o)) +# Flags passed to the preprocessor +CPPFLAGS += -I$(GTEST_DIR)/include + +# Flags passed to the C++ compiler +CXXFLAGS += -g -Wall -Wextra + +# Flags passed to the C compiler +CONLYFLAGS += -std=gnu99 + +# Common compiler flags +CFLAGS += -O0 -g +CFLAGS += -Wall -Werror +CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) + +# Google Test needs the pthread library +LDFLAGS += -lpthread + .PHONY: elf elf: $(OUTDIR)/$(TARGET).elf