**************
Under The Hood
**************

This page contains information about the architecture of the driver and different techniques used for its development.

Automatic Code Generation
=========================

TBA

Threading Model
===============

TBA

Publishing the States
=====================

TBA

.. _sec-dev-dyn:

Configuring the Drone
=====================

TBA

.. _sec-dev-test:

Tests
=====

Enabling Bebop In The Loop Tests
--------------------------------

.. code-block:: bash

  $ cd /path/to/bebop_ws
  $ catkin clean --cmake-cache
  $ catkin build bebop_driver --cmake-args -DRUN_HARDWARE_TESTS=ON

Running Bebop In The Loop Tests
-------------------------------

.. warning:: Bebop in the loop tests perform live unit tests with a real robot. Please proceed with caution and execute the tests in an area with at least 5 meters of clearance radius (empty space) around the Bebop.

.. code-block:: bash

  $ cd /path/to/bebop_ws/build/bebop_driver
  $ make tests
  $ rostest --text bebop_driver bebop_itl_test.test

Upgrading the Bebop SDK
=======================

.. warning:: Since version 0.6, `Parrot ARSDK <http://developer.parrot.com/docs/SDK3/>`_, the main underlying dependency of  *bebop_autonomy* is not build inline anymore. Instead, the slightly patched and catkinized version of it, called `parrot_arsdk <https://github.com/AutonomyLab/parrot_arsdk>`_, is fetched as a dependency. **The following documentation needs to be updated**.

1. Update the ``GIT_TAG`` of ``ARDroneSDK3`` in ``bebop_driver/CMakeLists.txt::add_custom_target::./repo init ... -b GIT_TAG`` to your desired commit hash, branch or tag (release). The official upstream repository is hosted `here <https://github.com/Parrot-Developers/arsdk_manifests>`_.
2. Checkout (or browse) the upstream repository at the same hash used in step (1) and open ``release.xml`` file. From this file, extract the commit hash of ``arsdk-xml`` from the ``revision`` property of this XML tag: ``<project name="arsdk-xml" ... revision="" />``.
3. Open ``bebop_driver/scripts/meta/generate.py`` and update ``LIBARCOMMANDS_GIT_HASH`` variable to the hash obtained in step (2).
4. Change the working diretory to ``bebop_driver/scripts/meta``, then execute ``generate.py`` from the command line. This will regenerate all automatically generated message definitions, header files and documentations.
5. Copy the generated files to their target locations by calling ``./install.sh``.
6. In ``bebop_driver/include/bebop_driver/autogenerated/ardrone3_setting_callbacks.h`` change the following varialbles:

  - ``ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSETTINGSSTATE_MAXDISTANCECHANGED_VALUE`` to ``ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSETTINGSSTATE_MAXDISTANCECHANGED_CURRENT``.
  - ``ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSETTINGSSTATE_BANKEDTURNCHANGED_VALUE`` to ``ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSETTINGSSTATE_BANKEDTURNCHANGED_STATE``
  - ``ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSETTINGSSTATE_CIRCLINGRADIUSCHANGED_VALUE`` to ``ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSETTINGSSTATE_CIRCLINGRADIUSCHANGED_CURRENT``
  - ``ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSETTINGSSTATE_CIRCLINGALTITUDECHANGED_VALUE`` to ``ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_PILOTINGSETTINGSSTATE_CIRCLINGALTITUDECHANGED_CURRENT``

In ``bebop_driver/include/bebop_driver/autogenerated/ardrone3_state_callbacks.h`` remove the following lines:

  ``arg = NULL;
    HASH_FIND_STR (arguments, ARCONTROLLER_DICTIONARY_KEY_ARDRONE3_ACCESSORYSTATE_CONNECTEDACCESSORIES_LIST_FLAGS, arg);
    if (arg)
    {
      msg_ptr->list_flags = arg->value.U8;
    }``

In ``bebop_msgs/msg/autogenerated/Ardrone3AccessoryStateConnectedAccessories.msg`` remove the following lines:
  ``# List entry attribute Bitfield. 0x01: First: indicate its the first element of the list. 0x02: Last: indicate its the last element of the list. 0x04: Empty: indicate the list is empty (implies First/Last). All other arguments should be ignored. 0x08: Remove: This value should be removed from the existing list.
    uint8 list_flags``

These changes are required because the upstream XML file is inconsistent for a couple of variable names.

7. Remove ``build`` and ``devel`` space of your ``catkin`` workspace, then re-build it.
