From 803e3c4d1e6e059b6a887887f658d42fde112405 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Wed, 5 Sep 2012 21:41:18 -0400 Subject: [PATCH 1/4] ef: Add fwinfo to entireflash (EF) images EF images were missing the firmware info blob that describes which firmware is installed on the board. The EF image is now padded out to fill the firmware bank and the info blob is properly placed at the tail end of the firmware bank. --- flight/EntireFlash/Makefile | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/flight/EntireFlash/Makefile b/flight/EntireFlash/Makefile index 548461a24..13aae597d 100644 --- a/flight/EntireFlash/Makefile +++ b/flight/EntireFlash/Makefile @@ -33,16 +33,23 @@ OUTDIR := $(TOP)/build/$(TARGET) .PHONY: bin bin: $(OUTDIR)/$(TARGET).bin -FW_PAD = $(shell echo $$[$(FW_BANK_BASE)-$(BL_BANK_BASE)-$(BL_BANK_SIZE)]) -$(OUTDIR)/$(TARGET).pad: +FW_PRE_PAD = $(shell echo $$[$(FW_BANK_BASE)-$(BL_BANK_BASE)-$(BL_BANK_SIZE)]) +$(OUTDIR)/$(TARGET).fw_pre.pad: $(V0) @echo $(MSG_PADDING) $@ - $(V1) dd status=noxfer if=/dev/zero count=$(FW_PAD) bs=1 2>/dev/null | tr '\000' '\377' > $@ + $(V1) dd status=noxfer if=/dev/zero count=$(FW_PRE_PAD) bs=1 2>/dev/null | tr '\000' '\377' > $@ + +FW_POST_PAD = $(shell echo $$[$(FW_BANK_SIZE)-$(FW_DESC_SIZE)-$$(stat -c%s $(FW_BIN))]) +$(OUTDIR)/$(TARGET).fw_post.pad: + $(V0) @echo $(MSG_PADDING) $@ + $(V1) dd status=noxfer if=/dev/zero count=$(FW_POST_PAD) bs=1 2>/dev/null | tr '\000' '\377' > $@ + BL_BIN = $(TOP)/build/bl_$(BOARD_NAME)/bl_$(BOARD_NAME).bin FW_BIN = $(TOP)/build/fw_$(BOARD_NAME)/fw_$(BOARD_NAME).bin -$(OUTDIR)/$(TARGET).bin: $(BL_BIN) $(FW_BIN) $(OUTDIR)/$(TARGET).pad +FWINFO_BIN = $(FW_BIN).firmwareinfo.bin +$(OUTDIR)/$(TARGET).bin: $(BL_BIN) $(FW_BIN) $(OUTDIR)/$(TARGET).fw_pre.pad $(OUTDIR)/$(TARGET).fw_post.pad $(V0) @echo $(MSG_FLASH_IMG) $@ - $(V1) cat $(BL_BIN) $(OUTDIR)/$(TARGET).pad $(FW_BIN) > $@ + $(V1) cat $(BL_BIN) $(OUTDIR)/$(TARGET).fw_pre.pad $(FW_BIN) $(OUTDIR)/$(TARGET).fw_post.pad $(FWINFO_BIN) > $@ .PHONY: dfu dfu: $(OUTDIR)/$(TARGET).bin From 97882dbef918db2016c08a0ecc38451509486f28 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Wed, 5 Sep 2012 22:17:04 -0400 Subject: [PATCH 2/4] pipx: ensure pipx BL image is padded to fill its bank This padding is required in order to properly align all of the sections in the EF images. --- flight/PiOS/STM32F10x/link_STM32103CB_PIPXTREME_BL_sections.ld | 1 + 1 file changed, 1 insertion(+) diff --git a/flight/PiOS/STM32F10x/link_STM32103CB_PIPXTREME_BL_sections.ld b/flight/PiOS/STM32F10x/link_STM32103CB_PIPXTREME_BL_sections.ld index 777e09aa6..19f70959d 100644 --- a/flight/PiOS/STM32F10x/link_STM32103CB_PIPXTREME_BL_sections.ld +++ b/flight/PiOS/STM32F10x/link_STM32103CB_PIPXTREME_BL_sections.ld @@ -75,6 +75,7 @@ SECTIONS { . = ALIGN(4); KEEP(*(.boardinfo)) + . = ALIGN(ORIGIN(BD_INFO)+LENGTH(BD_INFO)); } > BD_INFO /* Stabs debugging sections. */ From 4803dfe99c704edef1162d66d9ad33bd964b0b83 Mon Sep 17 00:00:00 2001 From: Werner Backes Date: Thu, 6 Sep 2012 13:13:58 +0200 Subject: [PATCH 3/4] Fix: yaw bias correction wasn't applied on CC3D. --- flight/Modules/Attitude/attitude.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flight/Modules/Attitude/attitude.c b/flight/Modules/Attitude/attitude.c index baa0c5453..6b0c16cec 100644 --- a/flight/Modules/Attitude/attitude.c +++ b/flight/Modules/Attitude/attitude.c @@ -420,6 +420,10 @@ static int32_t updateSensorsCC3D(AccelsData * accelsData, GyrosData * gyrosData) gyrosData->z += gyro_correct_int[2]; } + // 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; + GyrosSet(gyrosData); AccelsSet(accelsData); From 8ca99739ed4c97ae0d03f383386a8d293dbe3ec6 Mon Sep 17 00:00:00 2001 From: Igor Van Airde Date: Sun, 9 Sep 2012 13:07:25 +0200 Subject: [PATCH 4/4] Changed rate controller from PID to PIDT1 to improve flight stability. Low pass on D-Term makes the D-Term usable to improve flight stability. Affects rate and stabilize mode. --- flight/Modules/Stabilization/stabilization.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/flight/Modules/Stabilization/stabilization.c b/flight/Modules/Stabilization/stabilization.c index 43bb9b0d5..ae02dbeaa 100644 --- a/flight/Modules/Stabilization/stabilization.c +++ b/flight/Modules/Stabilization/stabilization.c @@ -68,6 +68,7 @@ typedef struct { float iLim; float iAccumulator; float lastErr; + float lastDer; } pid_type; // Private variables @@ -405,6 +406,7 @@ static void stabilizationTask(void* parameters) float ApplyPid(pid_type * pid, const float err, float dT) { float diff = (err - pid->lastErr); + float dterm = 0; pid->lastErr = err; // Scale up accumulator by 1000 while computing to avoid losing precision @@ -414,7 +416,16 @@ float ApplyPid(pid_type * pid, const float err, float dT) } else if (pid->iAccumulator < -(pid->iLim * 1000.0f)) { pid->iAccumulator = -pid->iLim * 1000.0f; } - return ((err * pid->p) + pid->iAccumulator / 1000.0f + (diff * pid->d / dT)); + + // Calculate DT1 term, fixed T1 timeconstant + if(pid->d) + { + dterm = pid->lastDer + (( dT / ( dT + 7.9577e-3)) * ((diff * pid->d / dT) - pid->lastDer)); + pid->lastDer = dterm; // ^ set constant to 1/(2*pi*f_cutoff) + // 7.9577e-3 means 20 Hz f_cutoff + } + + return ((err * pid->p) + pid->iAccumulator / 1000.0f + dterm); } @@ -423,6 +434,7 @@ static void ZeroPids(void) for(int8_t ct = 0; ct < PID_MAX; ct++) { pids[ct].iAccumulator = 0.0f; pids[ct].lastErr = 0.0f; + pids[ct].lastDer = 0.0f; } for(uint8_t i = 0; i < 3; i++) axis_lock_accum[i] = 0.0f;