Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/betaflight' into ra…
Browse files Browse the repository at this point in the history
…ceflight_merge_bf

# Conflicts:
#	Makefile
#	src/main/config/config.c
#	src/main/drivers/accgyro_mpu.c
#	src/main/drivers/accgyro_mpu6500.c
#	src/main/drivers/gyro_sync.c
#	src/main/flight/imu.c
#	src/main/io/serial_1wire.c
#	src/main/io/serial_cli.c
#	src/main/sensors/gyro.c
#	src/main/sensors/gyro.h
  • Loading branch information
rs2k committed Dec 9, 2015
2 parents eb7b44b + 0a2444f commit b2e9ea8
Show file tree
Hide file tree
Showing 76 changed files with 4,069 additions and 857 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.project
.settings
.cproject
obj/main
obj/
patches/
startup_stm32f10x_md_gcc.s

Expand Down
5 changes: 3 additions & 2 deletions .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ TARGET_FILE=obj/cleanflight_${TARGET}
TRAVIS_REPO_SLUG=${TRAVIS_REPO_SLUG:=$USER/undefined}
BUILDNAME=${BUILDNAME:=travis}
TRAVIS_BUILD_NUMBER=${TRAVIS_BUILD_NUMBER:=undefined}
MAKEFILE="-f Makefile"

CURL_BASEOPTS=(
"--retry" "10"
Expand Down Expand Up @@ -51,7 +52,7 @@ elif [ $PUBLISHMETA ] ; then

else
if [ $PUBLISH_URL ] ; then
make -j2
make -j2 $MAKEFILE
if [ -f ${TARGET_FILE}.bin ] ; then
TARGET_FILE=${TARGET_FILE}.bin
elif [ -f ${TARGET_FILE}.hex ] ; then
Expand All @@ -64,6 +65,6 @@ else
curl -k "${CURL_BASEOPTS[@]}" "${CURL_PUB_BASEOPTS[@]}" --form "file=@${TARGET_FILE}" ${PUBLISH_URL} || true
exit 0;
else
make -j2
make -j2 $MAKEFILE
fi
fi
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ env:
- PUBLISHMETA=True
- PUBLISHDOCS=True
- TARGET=CC3D
- TARGET=CC3D OPBL=yes
- TARGET=CC3D_OPBL
- TARGET=CC3D_BP6
- TARGET=CC3D_OPBL_BP6
- TARGET=COLIBRI_RACE
- TARGET=CHEBUZZF3
- TARGET=CJMCU
Expand Down
26 changes: 26 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"

# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", inline: <<-SHELL
apt-get remove -y binutils-arm-none-eabi gcc-arm-none-eabi
add-apt-repository ppa:terry.guo/gcc-arm-embedded
apt-get update
apt-get install -y git gcc-arm-none-eabi=4.9.3.2015q3-1trusty1
SHELL
end
10 changes: 8 additions & 2 deletions docs/1wire.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ Currently supported on the SPRACINGF3, STM32F3DISCOVERY, NAZE32 (including clone

## Wiring

- For the NAZE, no external wiring is necessary. Simply plugin the board via USB cable.
- For the NAZE, no external wiring is necessary. Simply plug in the board via USB cable.

- For the CC3D, connect [a USB to UART adapter](http://bit.ly/cf-cp2102) to the main port. If you need one, I prefer the [CP2102](http://bit.ly/cf-cp2102) as it is cheap and [the driver](https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx) is readily available.
- For the CC3D, connect [a USB to UART adapter](http://bit.ly/cf-cp2102) to the flex port.

- Ensure MSP is enabled on the flex port. Unfortunatly the main port cannot be used in the current configuration due to the inverter on this port.

- You'll only need this connection to the CC3D, do not plug in the normal USB connection.

- If you need one, I prefer the [CP2102](http://bit.ly/cf-cp2102) as it is cheap and [the driver](https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx) is readily available.

- In the case that your board does not power on fully without a battery attached, it is OK to attach the battery before following the steps below. However, it may not be necessary in all cases.

Expand Down
2 changes: 1 addition & 1 deletion docs/Board - RMDO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The DoDo board is a clone of the SPRacingF3 board in terms of CPU pin mappings.

Hardware differences compared to SPRacingF3 are as follows:

* The CPU is the cheaper version of the F3 with only 128KB FLASH.
* Rev 1 and Rev 2: the CPU is the cheaper version of the F3 with only 128KB FLASH. Rev 3: the CPU is a F3 version with 256KB FLASH.
* The external flash rom is the same size as found on the Naze32 (2MBit)
* The barometer is the cheaper BMP280.
* It does not have any compass sensor.
Expand Down
24 changes: 12 additions & 12 deletions docs/Cli.md

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions docs/USB Flashing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# USB Flashing
Some newer boards with full USB support must be flashed in USB DFU mode. This is a straightforward process in Configurator versions 0.67 and newer. The standard flashing procedure should work successfully with the caveat of some platform specific problems as noted below. The "No reboot sequence" checkbox has no effect as the device will automatically be detected when already in bootloader mode (a DFU device will appear in the connect dropdown if this is the case). The Full chip erase checkbox operates as normal. The baudrate checkbox is ignored as it has no relevance to USB.

## Platform Specific: Linux
Linux requires udev rules to allow write access to USB devices for users. An example shell command to acheive this on Ubuntu is shown here:
```
(echo '# DFU (Internal bootloader for STM32 MCUs)'
echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE="0664", GROUP="plugdev"') | sudo tee /etc/udev/rules.d/45-stdfu-permissions.rules > /dev/null
```

This assigns the device to the plugdev group(a standard group in Ubuntu). To check that your account is in the plugdev group type `groups` in the shell and ensure plugdev is listed. If not you can add yourself as shown (replacing `<username>` with your username):
```
sudo usermod -a -G plugdev <username>
```

## Platform Specific: Windows
Chrome can have problems accessing USB devices on Windows. A driver should be automatically installed by Windows for the ST Device in DFU Mode but this doesn't always allow access for Chrome. The solution is to replace the ST driver with a libusb driver. The easiest way to do that is to download [Zadig](http://zadig.akeo.ie/).
With the board connected and in bootloader mode (reset it by sending the character R via serial, or simply attempt to flash it with the correct serial port selected in Configurator):
* Open Zadig
* Choose Options > List All Devices
* Select `STM32 BOOTLOADER` in the device list
* Choose `WinUSB (v6.x.x.x)` in the right hand box
![Zadig Driver Procedure](assets/images/zadig-dfu.png)
* Click Replace Driver
* Restart Chrome (make sure it is completely closed, logout and login if unsure)
* Now the DFU device should be seen by Configurator
Binary file added docs/assets/images/zadig-dfu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions fake_travis_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
targets=("PUBLISHMETA=True" \
"RUNTESTS=True" \
"TARGET=CC3D" \
"TARGET=CC3D OPBL=yes" \
"TARGET=CC3D_OPBL" \
"TARGET=CC3D_BP6" \
"TARGET=CC3D_OPBL_BP6" \
"TARGET=CHEBUZZF3" \
"TARGET=CJMCU" \
"TARGET=COLIBRI_RACE" \
Expand All @@ -28,8 +30,8 @@ export TRAVIS_REPO_SLUG=${TRAVIS_REPO_SLUG:=$USER/simulated}

for target in "${targets[@]}"
do
unset RUNTESTS PUBLISHMETA TARGET OPBL
unset RUNTESTS PUBLISHMETA TARGET
eval "export $target"
make clean
make -f Makefile clean
./.travis.sh
done
10 changes: 10 additions & 0 deletions src/main/blackbox/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ static const blackboxDeltaFieldDefinition_t blackboxMainFields[] = {
{"accSmooth", 0, SIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(ALWAYS)},
{"accSmooth", 1, SIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(ALWAYS)},
{"accSmooth", 2, SIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(ALWAYS)},
{"attitude", 0, SIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(ALWAYS)},
{"attitude", 1, SIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(ALWAYS)},
{"attitude", 2, SIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(ALWAYS)},
/* Motors only rarely drops under minthrottle (when stick falls below mincommand), so predict minthrottle for it and use *unsigned* encoding (which is large for negative numbers but more compact for positive ones): */
{"motor", 0, UNSIGNED, .Ipredict = PREDICT(MINTHROTTLE), .Iencode = ENCODING(UNSIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_MOTORS_1)},
/* Subsequent motors base their I-frame values on the first one, P-frame values on the average of last two frames: */
Expand Down Expand Up @@ -275,6 +278,7 @@ typedef struct blackboxMainState_s {
int16_t rcCommand[4];
int16_t gyroADC[XYZ_AXIS_COUNT];
int16_t accSmooth[XYZ_AXIS_COUNT];
int16_t attitude[XYZ_AXIS_COUNT];
int16_t motor[MAX_SUPPORTED_MOTORS];
int16_t servo[MAX_SUPPORTED_SERVOS];

Expand Down Expand Up @@ -549,6 +553,7 @@ static void writeIntraframe(void)

blackboxWriteSigned16VBArray(blackboxCurrent->gyroADC, XYZ_AXIS_COUNT);
blackboxWriteSigned16VBArray(blackboxCurrent->accSmooth, XYZ_AXIS_COUNT);
blackboxWriteSigned16VBArray(blackboxCurrent->attitude, XYZ_AXIS_COUNT);

//Motors can be below minthrottle when disarmed, but that doesn't happen much
blackboxWriteUnsignedVB(blackboxCurrent->motor[0] - masterConfig.escAndServoConfig.minthrottle);
Expand Down Expand Up @@ -675,6 +680,7 @@ static void writeInterframe(void)
//Since gyros, accs and motors are noisy, base their predictions on the average of the history:
blackboxWriteMainStateArrayUsingAveragePredictor(offsetof(blackboxMainState_t, gyroADC), XYZ_AXIS_COUNT);
blackboxWriteMainStateArrayUsingAveragePredictor(offsetof(blackboxMainState_t, accSmooth), XYZ_AXIS_COUNT);
blackboxWriteMainStateArrayUsingAveragePredictor(offsetof(blackboxMainState_t, attitude), XYZ_AXIS_COUNT);
blackboxWriteMainStateArrayUsingAveragePredictor(offsetof(blackboxMainState_t, motor), motorCount);

if (testBlackboxCondition(FLIGHT_LOG_FIELD_CONDITION_TRICOPTER)) {
Expand Down Expand Up @@ -923,6 +929,10 @@ static void loadMainState(void)
blackboxCurrent->accSmooth[i] = accSmooth[i];
}

blackboxCurrent->attitude[0] = attitude.values.roll;
blackboxCurrent->attitude[1] = attitude.values.pitch;
blackboxCurrent->attitude[2] = attitude.values.yaw;

for (i = 0; i < motorCount; i++) {
blackboxCurrent->motor[i] = motor[i];
}
Expand Down
36 changes: 25 additions & 11 deletions src/main/common/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include <stdlib.h>
#include <math.h>

#include "common/axis.h"
#include "common/filter.h"
#include "common/axis.h"
#include "common/maths.h"


// PT1 Low Pass filter (when no dT specified it will be calculated from the cycleTime)
Expand All @@ -27,23 +29,35 @@ float filterApplyPt1(float input, filterStatePt1_t *filter, uint8_t f_cut, float
return filter->state;
}

// 7 Tap FIR filter as described here:
// Thanks to Qcopter
void filterApply7TapFIR(int16_t data[]) {
int16_t FIRcoeff[7] = { 12, 23, 40, 51, 52, 40, 38 }; // TODO - More coefficients needed. Now fixed to 1khz
static int16_t gyro_delay[3][7] = { {0}, {0}, {0} };
/**
* Typical quadcopter motor noise frequency (at 50% throttle):
* 450-sized, 920kv, 9.4x4.3 props, 3S : 4622rpm = 77Hz
* 250-sized, 2300kv, 5x4.5 props, 4S : 14139rpm = 235Hz
*/
static int8_t gyroFIRCoeff_1000[3][9] = { { 0, 0, 12, 23, 40, 51, 52, 40, 38 }, // 1khz; group delay 2.5ms; -0.5db = 32Hz ; -1db = 45Hz; -5db = 97Hz; -10db = 132Hz
{ 18, 30, 42, 46, 40, 34, 22, 8, 8}, // 1khz; group delay 3ms; -0.5db = 18Hz ; -1db = 33Hz; -5db = 81Hz; -10db = 113Hz
{ 18, 12, 28, 40, 44, 40, 32, 22, 20} }; // 1khz; group delay 4ms; -0.5db = 23Hz ; -1db = 35Hz; -5db = 75Hz; -10db = 103Hz

int8_t * filterGetFIRCoefficientsTable(uint8_t filter_level)
{
return gyroFIRCoeff_1000[filter_level];
}

// 9 Tap FIR filter as described here:
// Thanks to Qcopter & BorisB & DigitalEntity
void filterApply9TapFIR(int16_t data[3], int16_t state[3][9], int8_t coeff[9])
{
int32_t FIRsum;
int axis, i;

// 7 tap FIR, <-20dB at >170Hz with looptime 1ms, groupdelay = 2.5ms
for (axis = 0; axis < XYZ_AXIS_COUNT; axis++) {
FIRsum = 0;
for (i = 0; i <= 5; i++) {
gyro_delay[axis][i] = gyro_delay[axis][i + 1];
FIRsum += gyro_delay[axis][i] * FIRcoeff[i];
for (i = 0; i <= 7; i++) {
state[axis][i] = state[axis][i + 1];
FIRsum += state[axis][i] * (int16_t)coeff[i];
}
gyro_delay[axis][6] = data[axis];
FIRsum += gyro_delay[axis][6] * FIRcoeff[6];
state[axis][8] = data[axis];
FIRsum += state[axis][8] * coeff[8];
data[axis] = FIRsum / 256;
}
}
6 changes: 3 additions & 3 deletions src/main/common/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* Author: borisb
*/

#define YAW_PTERM_FILTER 30


typedef struct filterStatePt1_s {
float state;
float RC;
} filterStatePt1_t;

float filterApplyPt1(float input, filterStatePt1_t *filter, uint8_t f_cut, float dt);

void filterApply7TapFIR(int16_t data[]);
int8_t * filterGetFIRCoefficientsTable(uint8_t filter_level);
void filterApply9TapFIR(int16_t data[3], int16_t state[3][9], int8_t coeff[9]);
Loading

0 comments on commit b2e9ea8

Please sign in to comment.