# QGC Integration of winch data

**URL:** <https://discuss.bluerobotics.com/t/qgc-integration-of-winch-data/12771>\
**Category:** QGroundControl\
**Created:** [August 18, 2022, 5:06am UTC](https://discuss.bluerobotics.com/t/qgc-integration-of-winch-data/12771 "2022-08-18T05:06:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [August 19, 2022, 2:05am UTC](https://discuss.bluerobotics.com/t/qgc-integration-of-winch-data/12771/2 "2022-08-19T02:05:39Z")

</div>

Hi @RURAS,

QGC is open source, so it’s definitely possible, but because of how the MAVLink protocol and the QGC codebase are structured it can be somewhat complicated to add things to the interface, and doing so requires [building your own custom version of QGC](https://dev.qgroundcontrol.com/master/en/getting_started/index.html).

A couple of years ago I did a write up about [adding a sensor to a MAVLink stream](https://discuss.bluerobotics.com/t/adding-a-sensor-to-mavlink-stream/7985/22). Most likely the simplest approach is something similar to that, using `NAMED_VALUE_FLOAT` messages. I’ve just tested and it worked for me to make [these modifications](https://github.com/mavlink/qgroundcontrol/compare/Stable_V4.2...ES-Alexander:qgroundcontrol:winch_test?expand=1) to the latest stable version of QGC (`Stable_V4.2` branch), which could then receive MAVLink messages from a program sending the relevant message, like this Pymavlink script:

```python
import time
from pymavlink import mavutil

def wait_conn(device):
    """ Sends a ping to develop UDP communication and waits for a response. """
    while not (msg := device.recv_match()):
        device.mav.ping_send(
            int((time.time() - BOOT_TIME) * 1e6), # Unix time since boot (microseconds)
            0, # Ping number
            0, # Request ping of all systems
            0 # Request ping of all components
        )
        time.sleep(0.5)

class Winch:
    def __init__ (self):
        ... # TODO: implement connection details
        # this is the name QGC is searching for, and MUST be 9 characters or shorter
        self.message_name = b'WinchTrns'
    
    def get_value(self):
        """ Returns the next value from the winch. """
        # TODO: implement actual data fetching
        # pretend to be a slow sensor, with some random output values
        from random import randint
        time.sleep(0.5)
        return randint(-50, 50)

if __name__ == ' __main__':
    BOOT_TIME = time.time()
    # establish connection to top-side computer
    direction = 'udpout'
    device_ip = 'localhost'
    port = 14550
    print(f'connecting to {device_ip} via {direction} on {port=}.')
    qgc = mavutil.mavlink_connection(f'{direction}:{device_ip}:{port}', source_system=1)
    
    print('waiting for confirmation... ', end='')
    wait_conn(qgc)
    print('connection success!')
    
    # TODO: connect to winch
    winch = Winch()
    
    while 'reading data':
        qgc.mav.named_value_float_send(
            int((time.time() - BOOT_TIME) * 1e3),
            winch.message_name,
            winch.get_value()
        )

```

From there you can modify the telemetry display (hover over it then click the edit pencil at the top left corner), and add it:

 ![Screen Shot 2022-08-19 at 12.01.30 pm](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/5/58137f9266b6f695531ce5138992e383862909e4.png)  
 ![Screen Shot 2022-08-19 at 12.02.42 pm](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/c/c045322ee41a9399ecd6490ef9e1988ded7c0cdd.png)

* * *

> **As something of a side note, it seems the \`Stable\_V4.2\` branch has a couple of warnings when trying to build, which I ignored to enable the build to complete (click to see details, if relevant)**
>
> by adding
> 
> ```auto
> QMAKE_CXXFLAGS_WARN_ON+=-Wno-unused-but-set-variable QMAKE_CXXFLAGS_WARN_ON+=-Wno-deprecated-declarations
> 
> ```
> 
> as additional build arguments:
> 
> ![Screen Shot 2022-08-19 at 12.11.02 pm](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/6/6643897d02fbd13a9061fc364fbbfffd7191a886.png)
> 
> Ordinarily warnings shouldn’t be ignored, but given the code causing the warnings was from a supposedly stable version I decided to leave it alone, since it’s unlikely to cause issues.

---

_[View the full topic](https://discuss.bluerobotics.com/t/qgc-integration-of-winch-data/12771)._
