forked from simondlevy/Hackflight
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
Transmitter calibration #70
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
juangallostra
added
enhancement
New feature or request
not ready for merge
next release
labels
Feb 28, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Note: I think this is possibly one of the most complex pieces of software I have ever developed. This might be due to either the problem being actually complex or me lacking programming experience (or a bit of both).
TO DO List
Linked issue: #56
The implementation of the transmitter calibration has been developed with the following idea in mind: That it has to be self-contained. Why? These are the main reasons that come off the top of my head:
Hackflight
class, which is the main class of the firmware that includes the core functionalities that allow the Mosquitos to fly. Keeping this class simple is a must to avoid bugs and make it easy to understand and follow. This means that any unnecessary variables and methods should be avoided at all costs. Ideally handlers will be moved away from theHackflight
class, but this is not the case yet.Principle of operation (It is a good idea to read the code with the following diagram at hand)
were the calibration stage is controlled by a
switch
construction, looping and processing new frames is achieved with awhile
and switching between calibration stages via recursive calls tohandle_RC_CALIBRATION_Request
.Please read this carefully to fully understand the code:
There are some subtleties in the modifications contained in this PR that deserve an explanation. Each of them has its own reasons to exist, reasons that are explained below.
Including a new method that enables polling for new transmitter frames:
New transmitter frames are obtained via the
SerialEvent
call that occurs whenever new data comes in the hardware serial RX. This routine is run between each timeloop()
runs, so if the program gets stuck in awhile
indefinitely, new TX frames will never be obtained. This is why we need a way to poll the hardware serial to see if new data is available.See 1 and 2 for further reference.
Moving the assignation
_state = IDLE
inmspparser.hpp
before the checksum validation:We are recursively calling the
dispatchRequestMessage
inmspparser.hpp
, which means that the call to theparse
method does not return until the calibration process ends. If the assignation of the parser state toIDLE
is done after the call todispatchRequestMessage
, once we enter the TX calibration process the parser status will be left atHEADER_CMD
. This means that the next MSP message will not be processed properly - since the parser state is not properly set- and hence we might lose relevant data. To solve this and enable recursive calls in MSP message handlers, the parser state should be set toIDLE
before dispatching the request.Description of the issue/feature this PR addresses
Linked issue: #56
Include in the firmware a new process/feature/task that allows to calibrate transmitter values when requested by the platform (via MSP). The goal is to properly map the specific MAX / CENTER / MIN values of each of the sticks of a particular transmitter to the range of values the firmware expects (-1 for MIN, 0 for CENTER and 1 for MAX).
Current behavior before PR
Transmitter calibration cannot be performed because the feature is not implemented.
Desired behavior after PR is merged
The firmware includes a new functionality that can be triggered from the platform via MSP and that enables transmitter calibration. Once the transmitter has been calibrated, stick inputs are mapped to the correct and expected range.