Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non dynamic biquad/refactored sharpness #35

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d3dc885
fix crc, add ardu versioning
rs2k Jan 4, 2019
6d8d024
compile error fix
rs2k Jan 4, 2019
e3760aa
Merge remote-tracking branch 'origin/ardu' into HEAD
robert-b May 8, 2019
3369123
Merge branch 'bubi'
robert-b May 8, 2019
3dcd275
last changes.
bubi-007 May 12, 2019
38c5726
bumb version
bubi-007 May 12, 2019
000ae25
configurable acc filter.
bubi-007 May 16, 2019
f83ce38
change calculation of Q.
bubi-007 Sep 1, 2019
2b1d306
Filter multiplier fix
AndreySemjonov Sep 8, 2019
0d8861b
Revert "Filter multiplier fix"
AndreySemjonov Sep 8, 2019
d5187ad
Revert "change calculation of Q."
AndreySemjonov Sep 8, 2019
c76cd27
RC9b
AndreySemjonov Sep 8, 2019
bac8f85
209
AndreySemjonov Sep 15, 2019
4b9eb11
RC11
AndreySemjonov Nov 17, 2019
d496175
q multiplier change
Quick-Flash Nov 26, 2019
7821579
rc213
Quick-Flash Dec 16, 2019
e6d2844
combining parts of 209 and 213 should be cool
Quick-Flash Jan 4, 2020
67e6e47
ErrorMultiplier 216
Quick-Flash Jan 9, 2020
14e8525
Update version.h
Quick-Flash Jan 9, 2020
828ffb7
fix bug so postive/negative act the same
Quick-Flash Jan 11, 2020
85f0719
make 217 way less dynamic.
Quick-Flash Jan 14, 2020
fe74f9e
219 (apparently some ABS gave issues)
Quick-Flash Jan 14, 2020
4b98250
222 similar to 220
Quick-Flash Jan 24, 2020
85ce861
223 get a little bit more aggressive again
Quick-Flash Jan 27, 2020
7cae9ac
224 add a ff bit :)
Quick-Flash Jan 29, 2020
22ca51f
Update version.h
Quick-Flash Jan 29, 2020
eb771ef
225
Quick-Flash Feb 15, 2020
9780c11
IMUF 226
Quick-Flash Feb 29, 2020
b330fff
IMUF 227
Quick-Flash Feb 29, 2020
8547dd9
Update filter.c
Quick-Flash Feb 29, 2020
870f737
Merge pull request #1 from emuflight/RC11
Quick-Flash Mar 4, 2020
66db730
Making IMUF more efficient
Quick-Flash Mar 10, 2020
868b59a
add a workflow for github actions to build (#3)
gretel Mar 19, 2020
acc7392
Imuf230 (#5)
AndreySemjonov May 18, 2020
87a8a44
make it work linux (#6)
nerdCopter Jun 15, 2020
2fe8356
github workflow building (#7)
nerdCopter Jun 19, 2020
faa7f0b
20200614 backport pawel correctly compute kalman covariance (#8)
nerdCopter Jun 24, 2020
f96cbe1
Update README.md
AndreySemjonov Jul 14, 2020
1c0d173
new sharpness
Quick-Flash Sep 19, 2020
fb028e4
update the sharpness code
Quick-Flash Sep 28, 2020
db21332
Update version.h
Quick-Flash Oct 7, 2020
71997d0
version as imuf_250
nerdCopter Oct 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on:
push:
tags:
- '*'
pull_request:
branches:
- '*'
# repository_dispatch is a newer github-actions feature that will allow building from triggers other than code merge/PR
repository_dispatch:
types: [build]

name: Build IMU-F
jobs:
build:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:

# curl, by default, may timeout easily
- name: curl fix
run: function curl () { command curl --connect-timeout 30 --retry 10 "$@" ; }

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 15

- name: ARM SDK
uses: fiam/[email protected]
with:
release: '6-2017-q1'

- name: Setup Python
uses: actions/setup-python@v1

- name: Make
run: ./make.py -T=F3

- name: Rename Binary
id: file_version
run: |
VER=$(grep FIRMWARE_VERSION ./src/version.h | awk '{print $3}')
mv output/F3.bin output/IMUF_${VER}.bin
echo "::set-output name=VER::${VER}"

- name: Upload artifcats
uses: actions/upload-artifact@v2-preview
with:
name: IMUF_${{steps.file_version.outputs.VER}}
path: output/*.bin
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ redirection
redirection.junk
kalman/test
.exe
gcc-arm*
55 changes: 42 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
# IMU-F
IMU-F flight controller project

# setup
clone the project

```bash
brew install openocd python
curl -o ~/Downloads/gcc_arm-6-2017-q1.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/6_1-2017q1/gcc-arm-none-eabi-6-2017-q1-update-mac.tar.bz2
tar -zxvf ~/Downloads/gcc_arm-6-2017-q1.tar.bz2
sudo mkdir /usr/local/gcc_arm-6-2017-q1
sudo mv ~/Downloads/gcc_arm-6-2017-q1 /usr/local/gcc_arm-6-2017-q1
sudo ln -s /usr/local/gcc_arm-6-2017-q1 /usr/local/gcc_arm
echo 'export PATH="$PATH:/usr/local/gcc_arm/bin"' >> ~/.bash_profile
IMU-F firmware for Helio/Strix/Mode2Flux

## Prerequisites

Linux:
```shell
sudo apt -y install git python3 openocd #(or python2 should work)
```

MacOSX:

```shell
brew install git openocd python
```


## Clone repository
```shell
git clone https://github.com/emuflight/imu-f.git
```

## Download ARMv6:
```
cd imu-f

case $(uname) in
"Linux" )
OS="linux"
;;
"Darwin" )
OS="mac"
;;
esac
echo ${OS}

curl -L -s "https://developer.arm.com/-/media/Files/downloads/gnu-rm/6_1-2017q1/gcc-arm-none-eabi-6-2017-q1-update-${OS}.tar.bz2" | tar xjv
```

## Build
```shell
export PATH="$PATH:$(pwd)/gcc-arm-none-eabi-6-2017-q1-update/bin"
python make.py -C -T F3
```
9 changes: 6 additions & 3 deletions make.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def __getattr__(self, attr):

try:
from colorama import init, Fore, Back, Style
init(convert=True)
if platform.system() == 'Windows':
init(convert=True)
else:
init(convert=False)
except ImportError:
Fore = Style = ColorFallback()

Expand Down Expand Up @@ -176,7 +179,7 @@ def configure_target(TARGET):
#extra source files to include not in the below dirs
SOURCE_FILES = [
this_dir + "/assembly/startup/startup_stm32f303xc.s",
LIBRARY_PATH + "/CMSIS_std/DSP_Lib/Source/TransformFunctions/arm_bitreversal2.s"
LIBRARY_PATH + "/CMSIS_std/DSP_Lib/Source/TransformFunctions/arm_bitreversal2.S"
]

#All include dirs
Expand Down Expand Up @@ -524,7 +527,7 @@ def ProcessList(fileNames, target_config):

linkerObjs.append(os.path.join("output", makeObject(fileName, target_config.target)))
if FileModified(fileName, target_config):
if fileName[-2:] == ".s":
if (fileName[-2:] == ".s") or ((fileName[-2:] == ".S")):
commands.append(asm_command.format(
INPUT_FILE=fileName.path,
OUTPUT_FILE=makeObject(fileName.path, target_config.target),
Expand Down
25 changes: 19 additions & 6 deletions src/board_comm/board_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void board_comm_init(void)
#ifndef BOARD_COMM_CS_TYPE
//exti is used for NSS
gpio_exti_init(BOARD_COMM_EXTI_PORT, BOARD_COMM_EXTI_PORT_SRC, BOARD_COMM_EXTI_PIN, BOARD_COMM_EXTI_PIN_SRC, BOARD_COMM_EXTI_LINE, EXTI_Trigger_Rising, BOARD_COMM_EXTI_IRQn, BOARD_COMM_EXTI_ISR_PRE_PRI, BOARD_COMM_EXTI_ISR_SUB_PRI);
spi_init(&boardCommSpiInitStruct, &boardCommDmaInitStruct, BOARD_COMM_SPI, SPI_Mode_Slave, SPI_NSS_Soft, SPI_CPOL_Low, SPI_CPHA_1Edge, SPI_BaudRatePrescaler_2);
spi_init(&boardCommSpiInitStruct, &boardCommDmaInitStruct, BOARD_COMM_SPI, SPI_Mode_Slave, SPI_NSS_Soft, SPI_CPOL_Low, SPI_CPHA_1Edge, SPI_BaudRatePrescaler_2);
#else
single_gpio_init(BOARD_COMM_CS_PORT, BOARD_COMM_CS_PIN_SRC, BOARD_COMM_CS_PIN, BOARD_COMM_CS_ALTERNATE, BOARD_COMM_CS_TYPE, GPIO_OType_PP, GPIO_PuPd_NOPULL);
spi_init(&boardCommSpiInitStruct, &boardCommDmaInitStruct, BOARD_COMM_SPI, SPI_Mode_Slave, BOARD_COMM_CS_TYPE, SPI_CPOL_Low, SPI_CPHA_1Edge, SPI_BaudRatePrescaler_2);
Expand All @@ -66,7 +66,7 @@ int parse_imuf_command(volatile imufCommand_t* command)

void start_listening(void)
{
spiDoneFlag = 0; //flag for use during runtime to limit ISR overhead, might be able to remove this completely
spiDoneFlag = 0; //flag for use during runtime to limit ISR overhead, might be able to remove this completely
append_crc_to_data_v((volatile uint32_t *)bcTxPtr, 11); //11 will put the crc at the location it needs to be which is imufCommand.crc
//this takes 0.78us to run
cleanup_spi(BOARD_COMM_SPI, BOARD_COMM_TX_DMA, BOARD_COMM_RX_DMA, BOARD_COMM_SPI_RST_MSK);
Expand All @@ -90,8 +90,8 @@ void board_comm_spi_callback_function(void)
{
//command checks out
//run the command and generate the reply
run_command(&bcRx,&bcTx);
run_command(&bcRx,&bcTx);

}
else if ( (bcTx.command == BC_IMUF_SETUP) ) //we just replied that we got proper setup commands, let's activate them now
{
Expand All @@ -103,7 +103,7 @@ void board_comm_spi_callback_function(void)
reset_matrix(); //reset oreintation matrix in case it's been changes
reset_loop(); //set loop speed
}
else
else
{
//bad command, listen for another
bcTx.command = BC_IMUF_LISTENING;
Expand Down Expand Up @@ -148,9 +148,22 @@ static void run_command(volatile imufCommand_t* command, volatile imufCommand_t*
filterConfig.i_pitch_q = (int16_t)(command->param3 & 0xFFFF);
filterConfig.i_yaw_q = (int16_t)(command->param4 >> 16);
gyroSettingsConfig.orientation = (uint32_t)((uint16_t)(command->param8 & 0xFFFF));
filterConfig.i_roll_lpf_hz = (int16_t)(command->param4 & 0xFFFF);
filterConfig.i_pitch_lpf_hz = (int16_t)(command->param5 >> 16);
filterConfig.i_yaw_lpf_hz = (int16_t)(command->param5 & 0xFFFF);
gyroSettingsConfig.smallX = (int32_t) ((int16_t)(command->param8 >> 16));
gyroSettingsConfig.smallY = (int32_t) ((int16_t)(command->param9 & 0xFFFF));
gyroSettingsConfig.smallZ = (int32_t) ((int16_t)(command->param9 >> 16));
filterConfig.sharpness = (int16_t) ((int16_t)(command->param10 >> 16));
if (!filterConfig.sharpness)
{
filterConfig.sharpness = 2500;
}
filterConfig.acc_lpf_hz = (int16_t)(command->param10 & 0xFFFF);
if (!filterConfig.acc_lpf_hz)
{
filterConfig.acc_lpf_hz = 256;
}

memset((uint8_t *)reply, 0, sizeof(imufCommand_t));
reply->command = BC_IMUF_SETUP;
Expand All @@ -166,4 +179,4 @@ static void run_command(volatile imufCommand_t* command, volatile imufCommand_t*
default:
break;
}
}
}
41 changes: 21 additions & 20 deletions src/filter/biquad.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,42 @@ void biquad_init(float filterCutFreq, biquad_axis_state_t *state, float refreshR

float dbGain = 4.0;

samplingRate = (1 / refreshRateSeconds);
samplingRate = (1.0f / refreshRateSeconds);

omega = 2 * (float)M_PI_FLOAT * (float) filterCutFreq / samplingRate;
omega = 2.0f * (float)M_PI_FLOAT * (float) filterCutFreq / samplingRate;
sn = (float)sinf((float)omega);
cs = (float)cosf((float)omega);
alpha = sn * (float)sinf( (float)((float)M_LN2_FLOAT / 2 * (float)bandwidth * (omega / sn)) );
alpha = sn * (float)sinf( (float)((float)M_LN2_FLOAT / 2.0f * (float)bandwidth * (omega / sn)) );

(void)(beta);

switch (filterType)
{
case FILTER_TYPE_LOWPASS:
b0 = (1 - cs) /2;
b1 = 1 - cs;
b2 = (1 - cs) /2;
a0 = 1 + alpha;
a1 = -2 * cs;
a2 = 1 - alpha;
b0 = (1.0f - cs) *0.5f;
b1 = 1.0f - cs;
b2 = (1.0f - cs) *0.5f;
a0 = 1.0f + alpha;
a1 = -2.0f * cs;
a2 = 1.0f - alpha;
break;
case FILTER_TYPE_NOTCH:
b0 = 1;
b1 = -2 * cs;
b2 = 1;
a0 = 1 + alpha;
a1 = -2 * cs;
a2 = 1 - alpha;
b0 = 1.0f;
b1 = -2.0f * cs;
b2 = 1.0f;
a0 = 1.0f + alpha;
a1 = -2.0f * cs;
a2 = 1.0f - alpha;
break;
}
//don't let these states be used until they're updated
__disable_irq();
state->a0 = b0 / a0;
state->a1 = b1 / a0;
state->a2 = b2 / a0;
state->a3 = a1 / a0;
state->a4 = a2 / a0;
const float a0r = 1.0f / a0;
state->a0 = b0 * a0r;
state->a1 = b1 * a0r;
state->a2 = b2 * a0r;
state->a3 = a1 * a0r;
state->a4 = a2 * a0r;
__enable_irq();
}

Expand Down
Loading