Yet Another Implementation of Multiwii Serial Protocol Python Interface for Betaflight, iNAV, etc.
Project description
YAMSPy
Yet Another Implementation of Multiwii Serial Protocol Python Interface for Betaflight, iNAV, etc.
SAFETY FIRST!
This work is EXPERIMENTAL and it has been made publicly available expecting to be used only by responsible legally capable adults, etc, etc, etc. Since it's experimental, crazy things may happen mid-flight or even after the drone has landed or, even worse, while the drone is sitting on the floor! Drones, by default, can be VERY dangerous if not handled properly. Here are some links that may help you understand what I mean:
- https://www.tc.gc.ca/en/services/aviation/drone-safety.html
- https://store.dji.com/guides/10-drone-safety-tips-safe-flight/
- http://knowbeforeyoufly.org/
- LiPo batteries themselves need TLC to be safe
- Videos where they test drone impacts against... pork
- Finally, your classic Mythbusters video
Disclaimer (adapted from Wikipedia): None of the authors, contributors, supervisors administrators, employers, friends, family, vandals, or anyone else connected (or not) with this project, in any way whatsoever, can be made responsible for the use of the information (code) contained or linked from here.
Installation (Python3 because you should not use Python2 anymore):
Option #1: Clone the repo so you will have the examples
$ git clone https://github.com/ricardodeazambuja/YAMSPy.git
$ cd YAMSPy
$ sudo pip3 install .
Option #2: Install directly from git (the --upgrade
is to make sure it will install the last commit, even if the version number didn't increase)
$ sudo pip3 install git+git://github.com/ricardodeazambuja/yamspy --upgrade
On Linux you may need to add your user to the dialout group:
$ sudo usermod -a -G dialout $USER
Examples:
The directory Examples (duh!) has some commented examples showing how to use the library.
Setting up your flight controller (FC):
Until this point you should have installed YAMSPy, but it will not magically work without some extra steps. In order to make it work, you need to set up your FC correctly.
If you are just starting with iNAV or Betaflight you will need to install one of the configurators: inav-configurator or betaflight-configurator.
How to check which firmware is installed in your flight controller
In general, the most popular flight controllers (so far I have tested Heli-nation Talon F7 Fusion and Kakute F7 mini with success) come with some version of Betaflight and if you try to use inav-configurator it will only show the CLI (Command Line Interface) tab. The other way around, iNAV installed and betaflight-configurator, it will still allow you to use the CLI. The good thing is that using the CLI you can enter DFU (Device Firmware Update) mode to reflash the firmware by simply typing dfu
if iNAV firmware or bl
or dfu
if Betaflight. I noticed that my flight controlllers would only enter DFU mode if they were powered exclusivelly by the USB. To flash (install) a new firmware you can follow the instructions for Betaflight or iNAV. BTW, once you are using the CLI mode you can just type status
to receive a lot of useful info like firmware version.
More details about how YAMSPy works
YAMSPy was designed to communicate with or control a flight controller from a Single Board Computer (SBC) like a Raspberry Pi as well as a normal PC. It works by communicating with the flight controller through a serial connection using MSP (MultiWii Serial Protocol). Therefore, you need to have a free UART (Universal asynchronous receiver-transmitter, commonly just called "serial") that has MSP enabled on it. By default (AFAIK), the micro USB connector located on the flight controller will be seen as an UART and it comes configured as MSP, so it should allow you to use YAMSPy out of the box. You can easily enable MSP on other UART using the configurator software (see "Ports" tab).
Ok, the paragraph above covers the basics, but to be able to use YAMSPy to control your drone it is necessary to configure the flight controller to use a receiver that talks MSP. This is easily done using one of the configurators mentioned above. Connect to your flight controller using the configurator (inav or betaflight) and enter the "Configuration" tab. Inside this tab there's a field somewhere called "Receiver" or "Receiver Mode". Click on the pull-down list and select "MSP RX (control via MSP port)". After any changes you always need to click on the "Save and Reboot". When the FC reboots it will be expecting to receive commands from one of the UARTs with MSP enabled, but that is NOT all. You still need to make sure your receiver is configured to use the correct channel map. AETR (Aileron, Elevator, Throttle and Rudder) is the default for YAMSPy and all RC commands will be expected to start with Roll, Pitch, Throttle and Yaw, exactly in this order. Additionally, the auxiliary channels will come just after Yaw following their own numbering (Aux1, Aux2... for Betaflight or CH5, CH6... for iNAV).
Finally, I would strongly suggest you to set, at least, a channel exclusivelly for arming / disarming the drone instead of using stick commands. This can be done using the configurator and the "Modes" tab.
Advanced stuff
CLI
There are two possible ways to change the settings: using the configurator app (inav-configurator / betaflight-configurator) or using the CLI (Command Line Interface). The configurators are very handy, but the CLI allows you to automate stuff and save the settings in an easy to read text file.
Flight controllers using Betaflight or iNAV will allow you to connect to its CLI using the default MSP enabled port (normally the one with a micro USB connector) and a simple terminal emulator like PuTTy (on Linux you have many options, but PuTTy is super easy to install on Ubuntu) and setting the baud-rate to 115200 (the default value). After connecting it is necessary to type #
to start the CLI mode. The FC will NOT exit CLI mode if you disconnect your terminal session, what can be useful sometimes.
If you feel adventurous, you can try to connect using linux screen.
$ screen /dev/ttyACM0 115200
Screen can be as annoying as VIM sometimes, so my commands:
ctrl+a and then \
to exit.ctrl+a and the ESC key
to move around using the arrow keys (to stop this behaviour just press the ESC key again.ctrl+a, then : and finally H
to save everything printed on the screen after that point.
TODO:
Currently the main library is made of a HUGE single file. That is just terrible, but I didn't have time to split it and test. So if you want to help, please, be my guest. Talking about testing, I haven't implemented any automated test besides the example files, again, be my guest ;)
Acknowledgments:
Many people from MISTLab helped during the development of this library. Special thanks goes to Tom and Yann.
This work was possible thanks to the financial support from IVADO.ca (postdoctoral scholarship 2019/2020).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file yamspy-0.3.3.tar.gz
.
File metadata
- Download URL: yamspy-0.3.3.tar.gz
- Upload date:
- Size: 42.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3693c0f826d671dc969b8e7bf5abb76b8b0554eb3d81bf69ad96688fd509cc43 |
|
MD5 | b1dd565e2529a38555d412d7d7eed0f5 |
|
BLAKE2b-256 | ce2d9cacb99ba3f6700d83da047934b9cb712285ceb625419b105b4af286930b |