Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: betaflight/betaflight
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: wil3/neuroflight
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.3.x-neuroflight
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
Loading
Showing with 4,619 additions and 636 deletions.
  1. +0 −11 .github/pull_request_template.md
  2. +12 −1 .gitignore
  3. +11 −3 Makefile
  4. +154 −117 README.md
  5. +46 −0 docs/boards/Board - AikonF4.md
  6. +74 −0 docs/boards/Board - CrazyBeeF3FR.md
  7. +74 −0 docs/boards/Board - CrazyBeeF3FS.md
  8. +21 −0 docs/boards/Board - FOXEERF405.md
  9. +104 −0 docs/boards/Board - SpeedyBee F4 AIO-1.md
  10. BIN docs/boards/CrazyBeeF3FRbottom.jpg
  11. BIN docs/boards/CrazyBeeF3FRtop.jpg
  12. BIN docs/boards/CrazyBeeF3FSbottom.jpg
  13. BIN docs/boards/CrazyBeeF3FStop.jpg
  14. BIN docs/boards/aikon-f4-rev1-bottom.jpg
  15. BIN docs/boards/aikon-f4-rev1-top.jpg
  16. +4 −6 lib/main/STM32_USB_OTG_Driver/src/usb_core.c
  17. BIN logo.png
  18. +169 −0 make/neuroflight.mk
  19. +14 −0 make/source.mk
  20. +3 −1 make/targets.mk
  21. +11 −0 requirements.txt
  22. +19 −22 src/main/blackbox/blackbox.c
  23. +1 −2 src/main/blackbox/blackbox.h
  24. +1 −1 src/main/build/version.h
  25. +4 −4 src/main/cms/cms_menu_blackbox.c
  26. +1 −1 src/main/cms/cms_menu_imu.c
  27. +1 −0 src/main/common/maths.h
  28. +1 −2 src/main/drivers/accgyro/accgyro_mpu.c
  29. +3 −3 src/main/drivers/accgyro/accgyro_spi_mpu6000.c
  30. +2 −2 src/main/drivers/accgyro/accgyro_spi_mpu9250.c
  31. +23 −10 src/main/drivers/bus_i2c_hal.c
  32. +31 −15 src/main/drivers/bus_i2c_stm32f10x.c
  33. +1 −1 src/main/drivers/compass/compass_hmc5883l.c
  34. +0 −1 src/main/drivers/max7456.c
  35. +24 −19 src/main/drivers/pwm_output.c
  36. +3 −0 src/main/drivers/system_stm32f7xx.c
  37. +1 −1 src/main/drivers/vtx_common.h
  38. +7 −0 src/main/fc/config.c
  39. +7 −2 src/main/fc/fc_core.c
  40. +1 −1 src/main/flight/imu.c
  41. +33 −12 src/main/flight/mixer.c
  42. +1 −0 src/main/flight/mixer.h
  43. +22 −15 src/main/flight/pid.c
  44. +2 −2 src/main/flight/servos.c
  45. +32 −0 src/main/graph/graph_interface.cc
  46. +10 −0 src/main/graph/graph_interface.h
  47. +85 −0 src/main/graph/neuro.c
  48. +4 −0 src/main/graph/neuro.h
  49. +55 −42 src/main/interface/cli.c
  50. +47 −26 src/main/interface/msp.c
  51. +1 −1 src/main/interface/msp_protocol.h
  52. +11 −9 src/main/interface/settings.c
  53. +27 −7 src/main/io/osd.c
  54. +12 −4 src/main/io/spektrum_vtx_control.c
  55. +18 −8 src/main/io/vtx.c
  56. +20 −0 src/main/osd_slave/osd_slave_init.c
  57. +1 −1 src/main/pg/sdcard.c
  58. +0 −2 src/main/pg/sdcard.h
  59. +0 −4 src/main/platform.h
  60. +0 −1 src/main/rx/rx.c
  61. +5 −5 src/main/sensors/esc_sensor.h
  62. +6 −0 src/main/sensors/voltage.h
  63. 0 src/main/target/{REVO/REVOLT.mk → AG3X/AG3XF4.mk}
  64. 0 src/main/target/AG3X/AG3XF7.mk
  65. +50 −0 src/main/target/AG3X/config.c
  66. +58 −0 src/main/target/AG3X/target.c
  67. +171 −0 src/main/target/AG3X/target.h
  68. +20 −0 src/main/target/AG3X/target.mk
  69. +49 −0 src/main/target/AIKONF4/target.c
  70. +141 −0 src/main/target/AIKONF4/target.h
  71. +8 −0 src/main/target/AIKONF4/target.mk
  72. +0 −2 src/main/target/ALIENFLIGHTF1/target.h
  73. +0 −1 src/main/target/ALIENFLIGHTF3/target.h
  74. +0 −1 src/main/target/ALIENFLIGHTF4/target.h
  75. +11 −5 src/main/target/ALIENFLIGHTNGF7/target.h
  76. +2 −1 src/main/target/ALIENFLIGHTNGF7/target.mk
  77. +9 −8 src/main/target/ALIENWHOOP/config.c
  78. +9 −10 src/main/target/ALIENWHOOP/target.h
  79. +2 −1 src/main/target/ALIENWHOOP/target.mk
  80. +1 −0 src/main/target/BEEBRAIN_V2F/BEESTORM.mk
  81. +4 −0 src/main/target/BEEBRAIN_V2F/config.c
  82. +16 −2 src/main/target/BEEBRAIN_V2F/target.h
  83. +4 −1 src/main/target/BEEBRAIN_V2F/target.mk
  84. +2 −2 src/main/target/CLRACINGF7/CL_RACINGF7.md
  85. +6 −11 src/main/target/CLRACINGF7/target.c
  86. +38 −41 src/main/target/CLRACINGF7/target.h
  87. +1 −3 src/main/target/CLRACINGF7/target.mk
  88. +25 −0 src/main/target/COLIBRI_RACE/i2c_bst.c
  89. 0 src/main/target/CRAZYBEEF3FR/CRAZYBEEF3FS.mk
  90. +34 −0 src/main/target/CRAZYBEEF3FR/target.c
  91. +115 −0 src/main/target/CRAZYBEEF3FR/target.h
  92. +22 −0 src/main/target/CRAZYBEEF3FR/target.mk
  93. +2 −3 src/main/target/DALRCF405/target.h
  94. +0 −1 src/main/target/FF_PIKOBLX/target.h
  95. 0 src/main/target/FISHDRONEF4/STACKX.mk
  96. +13 −4 src/main/target/FISHDRONEF4/target.h
  97. +45 −0 src/main/target/FOXEERF405/target.c
  98. +163 −0 src/main/target/FOXEERF405/target.h
  99. +11 −0 src/main/target/FOXEERF405/target.mk
  100. +1 −5 src/main/target/KAKUTEF4/target.h
  101. +1 −1 src/main/target/KAKUTEF7/target.c
  102. +9 −22 src/main/target/KAKUTEF7/target.h
  103. +0 −1 src/main/target/KAKUTEF7/target.mk
  104. +1 −1 src/main/target/NAZE/config.c
  105. +0 −2 src/main/target/NOX/target.h
  106. +2 −0 src/main/target/NUCLEOF7/target.h
  107. +4 −2 src/main/target/OMNIBUS/target.h
  108. +10 −2 src/main/target/OMNIBUSF4/target.h
  109. +48 −0 src/main/target/OMNIBUSF4FW/config.c
  110. +54 −0 src/main/target/OMNIBUSF4FW/target.c
  111. +178 −0 src/main/target/OMNIBUSF4FW/target.h
  112. +12 −0 src/main/target/OMNIBUSF4FW/target.mk
  113. +1 −0 src/main/target/OMNIBUSF7/target.c
  114. +30 −3 src/main/target/OMNIBUSF7/target.h
  115. 0 src/main/target/OMNINXT/OMNINXT4.mk
  116. 0 src/main/target/OMNINXT/OMNINXT7.mk
  117. +34 −0 src/main/target/OMNINXT/config.c
  118. +300 −0 src/main/target/OMNINXT/hardware_revision.c
  119. +23 −0 src/main/target/OMNINXT/hardware_revision.h
  120. +66 −0 src/main/target/OMNINXT/target.c
  121. +196 −0 src/main/target/OMNINXT/target.h
  122. +26 −0 src/main/target/OMNINXT/target.mk
  123. +6 −19 src/main/target/REVO/target.h
  124. 0 src/main/target/REVOLT/REVOLTOSD.mk
  125. +40 −0 src/main/target/REVOLT/config.c
  126. +36 −0 src/main/target/REVOLT/target.c
  127. +172 −0 src/main/target/REVOLT/target.h
  128. +8 −0 src/main/target/REVOLT/target.mk
  129. +16 −1 src/main/target/REVONANO/target.h
  130. +1 −0 src/main/target/SITL/target.h
  131. +44 −0 src/main/target/SPEEDYBEEF4/config.c
  132. +39 −0 src/main/target/SPEEDYBEEF4/target.c
  133. +151 −0 src/main/target/SPEEDYBEEF4/target.h
  134. +10 −0 src/main/target/SPEEDYBEEF4/target.mk
  135. +0 −2 src/main/target/SPRACINGF3EVO/target.h
  136. +0 −2 src/main/target/SPRACINGF3MINI/target.h
  137. +5 −3 src/main/target/SPRACINGF3NEO/target.h
  138. +3 −3 src/main/target/SPRACINGF4NEO/target.c
  139. +2 −0 src/main/target/SPRACINGF4NEO/target.h
  140. +37 −0 src/main/target/STM32F4DISCOVERY/target.c
  141. +127 −0 src/main/target/STM32F4DISCOVERY/target.h
  142. +8 −0 src/main/target/STM32F4DISCOVERY/target.mk
  143. +3 −3 src/main/target/YUPIF4/target.c
  144. +2 −2 src/main/target/YUPIF4/target.h
  145. +0 −4 src/main/target/common_fc_post.h
  146. +3 −0 src/main/target/common_fc_pre.h
  147. +1 −45 src/main/telemetry/ibus_shared.c
  148. +45 −0 src/main/telemetry/ibus_shared.h
  149. +6 −1 src/main/telemetry/telemetry.c
  150. +51 −49 src/test/unit/blackbox_unittest.cc
  151. +1 −1 src/test/unit/osd_unittest.cc
  152. +69 −0 tools/graph-compiling/freeze-graph.py
  153. +44 −0 tools/graph-compiling/gen_graph_config_header.py
  154. +3 −0 tools/graph-compiling/gen_python_tf2xla_protobuf.sh
  155. +28 −0 tools/graph-compiling/get_graph_config_param.py
  156. +46 −0 tools/graph-compiling/proto/tensorflow/core/framework/tensor_shape.proto
  157. +75 −0 tools/graph-compiling/proto/tensorflow/core/framework/types.proto
  158. +50 −0 tools/graph-compiling/proto/tensorflow/tf2xla/tf2xla.proto
  159. +239 −0 tools/graph-compiling/python_protobuf/tensorflow/tf2xla/tf2xla_pb2.py
11 changes: 0 additions & 11 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
## Important: Feature freeze / release candidate phase for Betaflight 3.3

From 01/02/2018 until the release of Betaflight 3.3.0 (scheduled for 01/03/2018), the project is in a 'feature freeze / release candidate' phase. This means:

1. Pull requests can still be submitted as normal. Comments / discussions will probably be slower than normal due to shifted priorities;

2. If your pull request is a fix for an existing bug, or an update for a single target that has a low risk of side effect for other targets, it will be reviewed, and if accepted merged into `master` for the 3.3 release;

3. All other pull requests will be scheduled for 3.4, and discussed / reviewed / merged into `master` after 3.3.0 has been released. Please keep in mind that this will potentially mean that you will have to rebase your changes if they are broken by bugfixes made to 3.3.


## Important considerations when opening a pull request:

1. Pull requests will only be accepted if they are opened against the `master` branch. Pull requests opened against other branches without prior consent from the maintainers will be closed;
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -21,7 +21,12 @@ README.pdf

# artefacts of top-level Makefile
/downloads/
/tools/

# We have tools included for optimizaing and building the
# neuro-flight controller we need to version control
/tools/*
!/tools/graph-compiling/

/build/
# local changes only
make/local.mk
@@ -41,3 +46,9 @@ stm32.mak
.vagrant
ubuntu*.log
/.vs

# Auto-generated files
gen/

*.pyc
__pycache__/
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ FLASH_SIZE ?=
# Things that need to be maintained as the source changes
#

FORKNAME = betaflight
FORKNAME = neuroflight

# Working directories
ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
@@ -169,6 +169,7 @@ VPATH := $(VPATH):$(TARGET_DIR)

include $(ROOT)/make/source.mk


###############################################################################
# Things that might need changing to use different tools
#
@@ -216,6 +217,7 @@ CFLAGS += $(ARCH_FLAGS) \
-MMD -MP \
$(EXTRA_FLAGS)


ASFLAGS = $(ARCH_FLAGS) \
-x assembler-with-cpp \
$(addprefix -I,$(INCLUDE_DIRS)) \
@@ -242,6 +244,7 @@ endif
# No user-serviceable parts below
###############################################################################


CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
--std=c99 --inline-suppr --quiet --force \
$(addprefix -I,$(INCLUDE_DIRS)) \
@@ -264,6 +267,10 @@ CLEAN_ARTIFACTS += $(TARGET_HEX)
CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
CLEAN_ARTIFACTS += $(TARGET_LST)


# Neuroflight specifics
include $(ROOT)/make/neuroflight.mk

# Make sure build date and revision is updated on every incremental build
$(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)

@@ -281,9 +288,9 @@ $(TARGET_BIN): $(TARGET_ELF)
@echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
$(V1) $(OBJCOPY) -O binary $< $@

$(TARGET_ELF): $(TARGET_OBJS)
$(TARGET_ELF): $(TARGET_OBJS)
@echo "Linking $(TARGET)" "$(STDOUT)"
$(V1) $(CROSS_CC) -o $@ $^ $(LD_FLAGS)
$(V1) $(CROSS_CXX) -o $@ $^ $(LD_FLAGS)
$(V1) $(SIZE) $(TARGET_ELF)

# Compile
@@ -305,6 +312,7 @@ $(OBJECT_DIR)/$(TARGET)/%.o: %.c
$(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEFAULT_OPTIMISATION) $<))
endif


# Assemble
$(OBJECT_DIR)/$(TARGET)/%.o: %.s
$(V1) mkdir -p $(dir $@)
271 changes: 154 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,123 +1,160 @@
![BetaFlight Notice, version 3.2 will be the last version of Betaflight to support STM32F1 based flight controllers, this includes NAZE, CC3D (original) and CJMCU like flight controllers](https://raw.githubusercontent.com/wiki/betaflight/betaflight/images/betaflight/bf3_2_notice.png)

![BetaFlight](https://raw.githubusercontent.com/wiki/betaflight/betaflight/images/betaflight/bf_logo.png)

Betaflight is flight controller software (firmware) used to fly multi-rotor craft and fixed wing craft.

This fork differs from Baseflight and Cleanflight in that it focuses on flight performance, leading-edge feature additions, and wide target support.

## Events

| Date | Event |
| - | - |
| 01 February 2018 | Start of feature freeze / Release Candidate window for Betaflight 3.3 |
| 01 March 2018 | Planned [release](https://github.com/betaflight/betaflight/milestone/6) date for Betaflight 3.3 |
![Neuroflight](https://github.com/wil3/neuroflight/raw/v3.3.x-neuroflight/logo.png)

## WARNING
This is experimental firmware, use at your own risk! This repo is intended for academic
and research
purposes.

There is still a significant amount of research required to validate the
behavior of neuro-flight controllers. If the neural network is not trained properly, instabilities and unpredictable behaviors will occur.

## Neuroflight: Next Generation Flight Control Firmware

Neuroflight is the first open source neuro-flight controller software (firmware) for remotely piloting multi-rotors and fixed wing aircraft. Neuroflight's primary focus is to provide optimal flight performance.

Neuroflight aims to address limitations in PID control used in Betaflight
through the use of neural network flight control (neuro-flight control). Neuro-flight control has been actively researched for more than a decade. In contrast to traditional control algorithms, neuro-flight control has the ability to *adapt*, *plan*, and *learn*. To account for dynamic changes Betaflight has introduced gain scheduling to increase the I gain when certain conditions are met, for example low voltages or high throttle (anti-gravity). On the other hand, neuro-flight control learns the true underlying dynamics of the aircraft allowing for optimal control depending on the current aircraft state. For example neuro-flight control has the potential to learn the batteries discharge rates to dynamically adjust control signal outputs accordingly. The goal of this work is to provide the community with a
stable platform to innovate and advance development of neuro-flight control design for drones, and to take a step towards
making neuro-flight controllers mainstream. For further details refer to our
[preprint](https://wfk.io/docs/neuroflight.pdf) and please use the following BibTex
entry to cite our work,
```
@article{koch2019neuroflight,
title={Neuroflight: Next Generation Flight Control Firmware},
author={Koch, William and Mancuso, Renato and Bestavros, Azer},
journal={arXiv preprint arXiv:1901.06553},
year={2019}
}
```

## News

* 2019-08-09 Thesis defended, [Flight Controller Synthesis via Deep Reinforcement Learning](http://wfk.io/docs/WilliamKochThesisFINAL.pdf)
* 2019-08-06 Neuroflight reaches new level of performance
[https://www.youtube.com/watch?v=MByCyEnsYP0](https://www.youtube.com/watch?v=MByCyEnsYP0).
* 2018-11-14 Stable flight has been achieved with Neuroflight [https://youtu.be/c3aDDPasjjQ](https://youtu.be/c3aDDPasjjQ)

## Features

Betaflight has the following features:

* Multi-color RGB LED strip support (each LED can be a different color using variable length WS2811 Addressable RGB strips - use for Orientation Indicators, Low Battery Warning, Flight Mode Status, Initialization Troubleshooting, etc)
* DShot (150, 300, 600 and 1200), Multishot, and Oneshot (125 and 42) motor protocol support
* Blackbox flight recorder logging (to onboard flash or external microSD card where equipped)
* Support for targets that use the STM32 F7, F4, F3 and F1 processors
* PWM, PPM, and Serial (SBus, SumH, SumD, Spektrum 1024/2048, XBus, etc) RX connection with failsafe detection
* Multiple telemetry protocols (CSRF, FrSky, HoTT smart-port, MSP, etc)
* RSSI via ADC - Uses ADC to read PWM RSSI signals, tested with FrSky D4R-II, X8R, X4R-SB, & XSR
* OSD support & configuration without needing third-party OSD software/firmware/comm devices
* OLED Displays - Display information on: Battery voltage/current/mAh, profile, rate profile, mode, version, sensors, etc
* In-flight manual PID tuning and rate adjustment
* Rate profiles and in-flight selection of them
* Configurable serial ports for Serial RX, Telemetry, ESC telemetry, MSP, GPS, OSD, Sonar, etc - Use most devices on any port, softserial included
* VTX support for Unify Pro and IRC Tramp
* and MUCH, MUCH more.

## Installation & Documentation

See: https://github.com/betaflight/betaflight/wiki

## IRC Support and Developers Channel

There's a dedicated Slack chat channel here:

http://www.betaflight.ch/

Etiquette: Don't ask to ask and please wait around long enough for a reply - sometimes people are out flying, asleep or at work and can't answer immediately.

## Configuration Tool

To configure Betaflight you should use the Betaflight-configurator GUI tool (Windows/OSX/Linux) that can be found here:

https://chrome.google.com/webstore/detail/betaflight-configurator/kdaghagfopacdngbohiknlhcocjccjao

The source for it is here:

https://github.com/betaflight/betaflight-configurator

## Contributing

Contributions are welcome and encouraged. You can contribute in many ways:

* Documentation updates and corrections.
* How-To guides - received help? Help others!
* Bug reporting & fixes.
* New feature ideas & suggestions.

The best place to start is the IRC channel on gitter (see above), drop in, say hi. Next place is the github issue tracker:

https://github.com/betaflight/betaflight/issues
https://github.com/betaflight/betaflight-configurator/issues

Before creating new issues please check to see if there is an existing one, search first otherwise you waste peoples time when they could be coding instead!

## Developers

Please refer to the development section in the `docs/development` folder.

TravisCI is used to run automatic builds

https://travis-ci.org/betaflight/betaflight

[![Build Status](https://travis-ci.org/betaflight/betaflight.svg?branch=master)](https://travis-ci.org/betaflight/betaflight)

## Betaflight Releases

https://github.com/betaflight/betaflight/releases

## Open Source / Contributors

Betaflight is software that is **open source** and is available free of charge without warranty to all users.

Betaflight is forked from Cleanflight, so thanks goes to all those whom have contributed to Cleanflight and its origins.

Origins for this fork (Thanks!):
* **Alexinparis** (for MultiWii),
* **timecop** (for Baseflight),
* **Dominic Clifton** (for Cleanflight), and
* **Sambas** (for the original STM32F4 port).

The Betaflight Configurator is forked from Cleanflight Configurator and its origins.
In addition to features provided by Betaflight 3.3.3,

Origins for Betaflight Configurator:
* **Dominic Clifton** (for Cleanflight configurator), and
* **ctn** (for the original Configurator).
* Neural network based flight control
* Mixing replaced by neural network

Big thanks to current and past contributors:
* Budden, Martin (martinbudden)
* Bardwell, Joshua (joshuabardwell)
* Blackman, Jason (blckmn)
* ctzsnooze
* Höglund, Anders (andershoglund)
* Ledvina, Petr (ledvinap) - **IO code awesomeness!**
* kc10kevin
* Keeble, Gary (MadmanK)
* Keller, Michael (mikeller) - **Configurator brilliance**
* Kravcov, Albert (skaman82) - **Configurator brilliance**
* MJ666
* Nathan (nathantsoi)
* ravnav
* sambas - **bringing us the F4**
* savaga
* Stålheim, Anton (KiteAnton)
## Supported Neural Network Interfaces
Interfaces are defined for the sensors available on hardware. As models become
more sophisticated additional sensors will be used (e.g. ESC telemetry, voltage
sensor, etc.)

### Gyro-based Neuro-flight controller
Input (x) is of size 6, where x = [roll error, pitch error, yaw error, delta roll error, delta pitch error, delta yaw error]. Inputs are unbounded and in degrees/s. Output (y) of size N corresponding
to motor 1 ... motor N. Each output value is in range [-1, 1].

## Compiling

### Pre-requites

1) **Build Model** Use [GymFC](https://github.com/wil3/gymfc) to train and create a neural network in the
form of a Tensorflow checkpoint.

Place the generated checkpoint files (four of them: checkpoint, \*.data, \*.meta,
\*.index-\*) in a directory which can be independently version
controlled.

Create a file called `tf2xla.config.pbtxt` in the directory and define the
neural network configuration according to [https://www.tensorflow.org/xla/tfcompile](https://www.tensorflow.org/xla/tfcompile).
For example if building with OpenAI baselines PPO1 with angular rate error, and
delta angular rate error as input ,
```
feed {
id { node_name: "pi/ob" }
shape {
dim { size: 1}
dim { size: 6}
}
}
fetch {
id { node_name: "pi/pol/final/BiasAdd"}
}
```

2) **Install Tensorflow** Update: A patched version of Tensorflow is now
available [here](https://github.com/wil3/tensorflow-neuroflight). If you'd like
to patch your own copy of Tensorflow continue reading,

Neuroflight was developed using [Tensorflow-1.8.0](https://github.com/tensorflow/tensorflow/releases/tag/v1.8.0).
There appears to be a bug/issue in Tensorflow-1.8.0-rc1 preventing the ABI type from being passed to tfcompile used to compile the neural network. A quick hack to force the correct ABIType is to modify compiler/xla/service/llvm_ir/llvm_util.cc. At the end of the
function SetTargetOptions place,
```C++
target_options->FloatABIType = llvm::FloatABI::Hard;
```
Need to investigate whether these bugs have been fixed in newer versions or
come up with a better method to handle this. Install [Bazel](https://bazel.build/) and then build Tensorflow.

There appears to be a second bug in which `tensorflow/compiler/aot/runtime.cc` does not import `malloc.h`.

3) **Install Python Dependencies**

Use a virtual environment to isolate Python packages. In this directory,

```
python3 -m venv env
source env/bin/activate
pip3 install -r requirements.txt
```

### Neuroflight compilation
1) In `make/local.mk` define `TENSORFLOW_DIR` to the location where you have
installed Tensorflow or alternately export this as an environment variable.

2) In `make/local.mk` define `FC_MODEL_DIR` as the directory containing
your neural network checkpoint.

3) Refer to [Betaflight](https://github.com/betaflight/betaflight) or
src/main/target for list of supported FCs.

#### Current Tested Flight Controller Hardware
Any F7 should be fine. Flash memory is sufficient for F4's however it is unknown how the decreased processor speed will affect
execution of the neural network. Flight controllers known to work,

* Matek F722-STD

To build firmware,
```
make TARGET=MATEKF722
```
Flash FC with `obj/neuroflight_3.3.3_MATEKF722.hex`

## Configuration

Neuroflight is compatible with the [Betaflight
Configurator](https://chrome.google.com/webstore/detail/betaflight-configurator/kdaghagfopacdngbohiknlhcocjccjao)
however any modifications to the PID controller and mixer will not do anything
as they are not used by Neuroflight.

## Development
In order to reduce maintenance, avoid merge conflicts and keep as in sync with
upstream Betaflight, Neuroflight's architecture will maintain a minimal footprint and
isolate its code from Betaflight as much as possible. The following table
describes the files modified (M), and added (A) for Neuroflight,

| Delta | File | Description |
| --- | --- | --- |
| M | Makefile | Include neuroflight.mk |
| A | make/neuroflight.mk | Specifics for compiling the neural network |
| M | make/source.mk | Add new sources and Tensorflow dependencies |
| A | tools/graph-compiling/&ast; | Tools for compiling the neural network graph |
| M | src/main/fc/fc_core.c | Replace PID with neuro-flight controller|
| A | src/main/graph/&ast; | Source directory supporting interface and execution of the neuro-flight controller |
| M | src/main/flight/mixer.&ast; | Inclusion of throttle mixing |
| A | gen/&ast; | Auto-generated files to support neural network integration |
| M | src/main/platform.h | Remove poisoning of sprintf functions which is used deep in Tensorflow until we can find a better work around. |


At the time of
development Neuroflight was forked from Betaflight 3.3.3. Since then, newer versions
of Betaflight have increased in size as more features are packed in. Further
testing is needed to identify if the neural network will fit in newer versions
of the firmware.

And many many others who haven't been mentioned....
Loading