Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the issue/feature this PR addresses
Parametrize Hackflight.
Current behavior before PR
An Arduino sketch has to be created where all the parameters (type of board, PID constants, type of receiver, mixer...) are defined when running Hackflight on a BonaDrone board.
As an example see SBUSAltHold.ino
Desired behavior after PR is merged
Instead of having to create an Arduino sketch for each configuration, a generic routine that loads parameters from the EEPROM will handle the instantiation of Hackflight with the specified parameters.
The Arduino sketch gets reduced to: Parametrized.ino
And all the initialization is delegated to HackflightWrapper
Setting parameters
Parameters are specified via MSP messages. There are currently 3 MSP messages used to set parameters:
SET_POSITIONING_BOARD
: message ID is 225 with a payload of 1byte. 0/1 flag indicating whether the positioning board is present or not.SET_MOSQUITO_VERSION
: message ID is 223 with a payload of 1byte. 0/1 flag indicating the Mosquito version (0 is Mosquito 150 and 1 is Mosquito 90).SET_PID_CONSTANTS
: message ID is 224 with a payload of 64 bytes (16 floats x 4 bytes each). 16 floats that specify the parameters of the PID controllers.When one of this messages is received its contents are stored in the appropriate EEPROM addresses. See BonaDrone's documentation (EEPROM usage chapter) for more details.
Loading parameters
A new class that acts as a wrapper for Hackflight has been implemented (see
HackflightWrapper
inmain.hpp
). This class reads and decodes EEPROM stored parameters and instantiates the required classes accordingly. After that Hackflight is initialized and ran as before.--
I confirm I have tested this PR thoroughly