Telemetry Stream

telemetry-stream is responsible for streaming telemetry data from the drone we are tracking to our kinematic-model which will then perform the necessary calculations needed by PTU-SDK to move the gimbal controlling the laser.

In this documentation, we (will) outline what is inside telemetry-stream, how telemetry-stream works, and more importantly how to use it.

telemetry_stream.cpp

As of 03/13/2024, telemetry_stream.cpp is functional.

We are currently working on streaming the specific fields needed by DAM. For now, we are streaming altitude only.

This is a C++ implementation for streaming telemetry data. We primarily utilize MAVSDK, a higher level API "that aims to be fully standards-compliant with MAVLink common microservices" such as telemetry, hence why we opted for it. There is no reason not to re-use already fast (C++) code that's already been written for this "basic" functionality (unless MAVSDK loses the wide community support it has as of today).

deprecated

The deprecated folder contains a python implementation for telemetry streaming which heavily utilizes pymavlink. Though still functional, we opted to refactor in C++ as performance must be optimized.

Prior Knowledge

Read the following pieces of documentation (in a BFS manner) before developing:

  1. MAVLink: read the Introduction section and its subsections

  2. MAVSDK: read the Introduction and C++ sections, but do not start the Quickstart section yet

  3. Telemetry Guide

  4. Telemetry Class

  5. Discrepancies: always watch out for discrepancies between the actual documentation and example code provided by a given tool. However, you should always reference both.

MAVSDK Setup

To begin developing, read the notes below as you follow the whole C++ Quickstart for your machine's OS.

After the Install MAVSDK library section, check its version. For example, if you're on macOS, then brew info mavsdk. You may run into a versioning discrepancy issue between the mavsdk library installed during the Install MAVSDK Library section and the mavsdk repository in the Build and Try Example section.

If the versions between the library and the repository differ, simply pull the whole version of the repo that matches the library, or alternatively copy and paste the takeoff_and_land example code from the version of the repo that matches the library. To switch to the appropiate version of the MAVSDK repo: 1. go to the MAVSDK repository 2. Click on "main" -> "Tags" 3. Select the appropriate version

Once you reach the Setting up a Simulator subsection, refer to "Test Simulation" within this documentation page.

Test Simulation

  1. Download QGroundControl and simply open it.

  2. Download PX-4 and build the simulation.

    Open a terminal. Run the following: git clone https://github.com/PX4/PX4-Autopilot.git --recursive cd PX4-Autopilot make px4_sitl jmavsim

  3. Ensure Proper Configurations

    Ensure QGroundControl ports and \<insert testing file from MAVSDK repo such as takeoff_and_land.cpp> ports are set to 14540 (Or, whatever port we want. Just have it be uniform.)

    Go to the top left of QGroundCountrol -> Application Settings -> MAVLink, and check if the hostname is localhost:14445

  4. Start up the simulation

    Simply follow the rest of the instructions outlined here.

Additional Steps for ARM Architecture/Apple Silicon

  1. Download Anaconda
  2. Create environment for x86_64 architecture CONDA_SUBDIR=osx-64 conda create -n px4_x86 python=3.9
  3. Activate conda activate px4_x86
  4. Set Environment conda config --env --set subdir osx-64

** JMavSim's GUI does not work within ARM, to run the simulation without a gui, HEADLESS=1 make px4_sitl jmavsim

How to use telemetry_stream.cpp

This section (will soon) outlines how to physically setup telemetry streaming from the drone to the ground station (us).

Ensure you have completed ALL sections above beforehand.

Installations

Run the command:

brew install nlohmann-json

You can use the deprecrated/stream_data.py as a quick validation that your baud and connection_string is correct. Simply plug in the aformentioned parameters into stream_data.py then run the file.

Otherwise, you can follow the steps from "Test Simulation" to setup a simulated drone rather than a physical drone to verify telemetry data streaming is working.

Run telemetry_stream.cpp

  1. Build the executable cmake -Bbuild -H. cmake --build build -j8
  2. Run the executable build/telemetry_stream udp://:14540

Run the main.cpp

  1. start up px4 jmav
  2. in this repo run the command: ./telemetry-stream

you can run commander takeoff commander land

this run simulation.py in agogos

Python Bindings

  1. Excecute CMake file in the root directory with cmake .
  2. Within /python_bindings, the module should be ready as a .so (shared object file)
  3. Within your Python File, you should know import _telemetry_stream

The Python File should be in the same directory as the .so file