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

Transmitter calibration #70

Merged
merged 25 commits into from Mar 4, 2019
Merged

Conversation

juangallostra
Copy link
Member

@juangallostra juangallostra commented Feb 28, 2019

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

  • After TX calibration, set the successful/error flag depending on the calibration result.
  • Compute mappings and apply them when getting new demands.
  • If the transmitter has not been calibrated bypass the mapping

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:

  1. It seems reasonable to, if possible, perform all the actions that are related with a particular MSP message inside its respective handler. Even more when the action to perform does not affect the global behavior of the drone and is just an additional feature.
  2. Furthermore, MSP message handling is currently done inside the 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 the Hackflight class, but this is not the case yet.
  3. Since it is a specific feature that will be only used from time to time, having helper methods and variables hanging around only adds noise and makes code harder to understand.

Principle of operation (It is a good idea to read the code with the following diagram at hand)

tx_calibration

were the calibration stage is controlled by a switch construction, looping and processing new frames is achieved with a while and switching between calibration stages via recursive calls to handle_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.

  1. 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 time loop() runs, so if the program gets stuck in a while 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.

  2. Moving the assignation _state = IDLE in mspparser.hpp before the checksum validation:
    We are recursively calling the dispatchRequestMessage in mspparser.hpp, which means that the call to the parse method does not return until the calibration process ends. If the assignation of the parser state to IDLE is done after the call to dispatchRequestMessage, once we enter the TX calibration process the parser status will be left at HEADER_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 to IDLE 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.

@juangallostra juangallostra merged commit 0ae13d7 into filter-integration Mar 4, 2019
@juangallostra juangallostra deleted the transmitter-calibration branch March 4, 2019 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant