Skip to content

Commit

Permalink
Created packets for boat-drone communication (#1301)
Browse files Browse the repository at this point in the history
* Created packets for boat-drone communication

* fixed PR comments

* navigator_drone_comm: Add packet listing to docs, export packet members in __init__, make catkin package python-centered

---------

Co-authored-by: Cameron Brown <[email protected]>
  • Loading branch information
alexoj46 and cbrxyz authored Oct 29, 2024
1 parent 9d91aa6 commit a62159b
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 0 deletions.
14 changes: 14 additions & 0 deletions NaviGator/hardware_drivers/navigator_drone_comm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.0.2)
project(navigator_drone_comm)

find_package(catkin REQUIRED COMPONENTS
rospy
)

catkin_python_setup()
catkin_package()

include_directories(
# include
${catkin_INCLUDE_DIRS}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .packets import (
Color,
EStopPacket,
GPSDronePacket,
HeartbeatReceivePacket,
HeartbeatSetPacket,
StartPacket,
StopPacket,
TargetPacket,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from dataclasses import dataclass
from enum import Enum

from electrical_protocol import Packet


@dataclass
class HeartbeatReceivePacket(
Packet,
class_id=0x20,
subclass_id=0x00,
payload_format="",
):
"""
Heartbeat packet sent from the drone.
"""


@dataclass
class HeartbeatSetPacket(Packet, class_id=0x20, subclass_id=0x01, payload_format=""):
"""
Heartbeat packet sent from the boat.
"""


@dataclass
class GPSDronePacket(Packet, class_id=0x20, subclass_id=0x02, payload_format="<fff"):
"""
GPS location of drone packet.
Attributes:
lat (float): The latitude of the drone.
lon (float): The longitude of the drone.
alt (float): The altitude of the drone.
"""

lat: float
lon: float
alt: float


@dataclass
class EStopPacket(Packet, class_id=0x20, subclass_id=0x03, payload_format=""):
"""
Emergency stop drone packet.
"""


@dataclass
class StartPacket(Packet, class_id=0x20, subclass_id=0x04, payload_format="<20s"):
"""
Start drone mission packet.
Attributes:
name (str): The name of the mission to run on the drone. Limited to 20 characters.
"""

name: str


@dataclass
class StopPacket(Packet, class_id=0x20, subclass_id=0x05, payload_format=""):
"""
Stop drone and return packet.
"""


class Color(Enum):
"""
Enum to represent the color of a target.
"""

BLUE = "b"
GREEN = "g"
RED = "r"


@dataclass
class TargetPacket(Packet, class_id=0x20, subclass_id=0x06, payload_format="<ffc"):
"""
GPS of drone-identified target packet.
Attributes:
lat (float): The latitude of the target.
lon (float): The longitude of the target.
color (Color): The color of the target.
"""

lat: float
lon: float
color: Color
15 changes: 15 additions & 0 deletions NaviGator/hardware_drivers/navigator_drone_comm/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<package format="2">
<name>navigator_drone_comm</name>
<version>0.0.0</version>
<description>The navigator_drone_comm package</description>

<maintainer email="[email protected]">Alex Johnson</maintainer>

<license>TODO</license>

<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<build_export_depend>rospy</build_export_depend>
<exec_depend>rospy</exec_depend>
</package>
11 changes: 11 additions & 0 deletions NaviGator/hardware_drivers/navigator_drone_comm/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD

from catkin_pkg.python_setup import generate_distutils_setup
from setuptools import setup

# Fetch values from package.xml
setup_args = generate_distutils_setup(
packages=["navigator_drone_comm"],
)

setup(**setup_args)
62 changes: 62 additions & 0 deletions docs/navigator/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,65 @@ SetSpinPacket

.. autoclass:: navigator_ball_launcher.SetSpinPacket
:members:

:mod:`navigator_drone_comm` - Boat-drone communication standard
---------------------------------------------------------------

.. automodule:: navigator_drone_comm
:members:

HeartbeatReceivePacket
^^^^^^^^^^^^^^^^^^^^^^
.. attributetable:: navigator_drone_comm.HeartbeatReceivePacket

.. autoclass:: navigator_drone_comm.HeartbeatReceivePacket
:members:

HeartbeatSetPacket
^^^^^^^^^^^^^^^^^^
.. attributetable:: navigator_drone_comm.HeartbeatSetPacket

.. autoclass:: navigator_drone_comm.HeartbeatSetPacket
:members:

GPSDronePacket
^^^^^^^^^^^^^^
.. attributetable:: navigator_drone_comm.GPSDronePacket

.. autoclass:: navigator_drone_comm.GPSDronePacket
:members:

EStopPacket
^^^^^^^^^^^
.. attributetable:: navigator_drone_comm.EStopPacket

.. autoclass:: navigator_drone_comm.EStopPacket
:members:

StopPacket
^^^^^^^^^^
.. attributetable:: navigator_drone_comm.StopPacket

.. autoclass:: navigator_drone_comm.StopPacket
:members:

StartPacket
^^^^^^^^^^^
.. attributetable:: navigator_drone_comm.StartPacket

.. autoclass:: navigator_drone_comm.StartPacket
:members:

Color
^^^^^
.. attributetable:: navigator_drone_comm.Color

.. autoclass:: navigator_drone_comm.Color
:members:

TargetPacket
^^^^^^^^^^^^
.. attributetable:: navigator_drone_comm.TargetPacket

.. autoclass:: navigator_drone_comm.TargetPacket
:members:
14 changes: 14 additions & 0 deletions docs/reference/electrical_protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ byte length.
| Launcher | | | |
| Board) | | | |
+------------+--------------+----------------+-------------------------------------------------------------------------+
| 0x20 | 0x00 | Empty | :class:`navigator_drone_comm.HeartbeatReceivePacket` |
| (Drone) +--------------+----------------+-------------------------------------------------------------------------+
| | 0x01 | Empty | :class:`navigator_drone_comm.HeartbeatSetPacket` |
+ +--------------+----------------+-------------------------------------------------------------------------+
| | 0x02 | ``fff`` | :class:`navigator_drone_comm.GPSDronePacket` |
+ +--------------+----------------+-------------------------------------------------------------------------+
| | 0x03 | Empty | :class:`navigator_drone_comm.EStopPacket` |
+ +--------------+----------------+-------------------------------------------------------------------------+
| | 0x04 | ``20s`` | :class:`navigator_drone_comm.StartPacket` |
+ +--------------+----------------+-------------------------------------------------------------------------+
| | 0x05 | Empty | :class:`navigator_drone_comm.StopPacket` |
+ +--------------+----------------+-------------------------------------------------------------------------+
| | 0x06 | ``ffc`` | :class:`navigator_drone_comm.TargetPacket` |
+------------+--------------+----------------+-------------------------------------------------------------------------+

Exceptions
~~~~~~~~~~
Expand Down

0 comments on commit a62159b

Please sign in to comment.