BluEye-Robotics / blueye.sdk

A Python package for remote control of Blueye underwater drones.
GNU Lesser General Public License v3.0
17 stars 4 forks source link

Add example showing how to forward position as NMEA over UDP #171

Closed sindrehan closed 1 week ago

sindrehan commented 1 week ago

I'm not really familiar with the NMEA stuff, so would be great if you @aviggen or @haavardsyslak could take a look and see if everything makes sense.

Fixes #170

codecov[bot] commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 73.77%. Comparing base (149ee93) to head (ae0557e). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #171 +/- ## ======================================= Coverage 73.77% 73.77% ======================================= Files 11 11 Lines 1266 1266 ======================================= Hits 934 934 Misses 332 332 ``` | [Flag](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | Coverage Δ | | |---|---|---| | [macos-latest_3.10](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.77% <ø> (ø)` | | | [macos-latest_3.11](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.77% <ø> (ø)` | | | [macos-latest_3.12](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.77% <ø> (ø)` | | | [macos-latest_3.9](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.75% <ø> (ø)` | | | [ubuntu-latest_3.10](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.77% <ø> (ø)` | | | [ubuntu-latest_3.11](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.77% <ø> (ø)` | | | [ubuntu-latest_3.12](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.77% <ø> (ø)` | | | [ubuntu-latest_3.9](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.75% <ø> (ø)` | | | [windows-latest_3.10](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.75% <ø> (ø)` | | | [windows-latest_3.11](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.75% <ø> (ø)` | | | [windows-latest_3.12](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.75% <ø> (ø)` | | | [windows-latest_3.9](https://app.codecov.io/gh/BluEye-Robotics/blueye.sdk/pull/171/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics) | `73.73% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=BluEye-Robotics#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sindrehan commented 1 week ago

I don't have an actual device to test with, but I (CoPilot really) made a test script that uses an parser to check the validity and it seems to work fine with that.

import socket
import pynmea2

# UDP configuration
UDP_IP = "0.0.0.0"
UDP_PORT = 10111

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))

print(f"Listening for UDP packets on {UDP_IP}:{UDP_PORT}")

def validate_nmea_sentence(sentence: str) -> bool:
    """Validate the NMEA sentence using pynmea2."""
    try:
        parsed_sentence = pynmea2.parse(sentence)
        return isinstance(parsed_sentence, pynmea2.types.talker.GLL)
    except pynmea2.nmea.ChecksumError:
        print("Checksum error")
        return False
    except pynmea2.nmea.ParseError:
        print("Parse error")
        return False

try:
    while True:
        data, addr = sock.recvfrom(1024)  # Buffer size is 1024 bytes
        message = data.decode("utf-8").strip()
        print(f"Received message: {message} from {addr}")

        if validate_nmea_sentence(message):
            print("Valid NMEA sentence")
        else:
            print("Invalid NMEA sentence")

except KeyboardInterrupt:
    print("Exiting...")
finally:
    sock.close()