Skip to content

Interfaces

Common interface definitions

AdapterProtocol

Bases: Protocol

interface for communication bridge

Source code in roxbot/interfaces.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class AdapterProtocol(Protocol):
    """interface for communication bridge"""

    async def publish(self, topic: str, msg: JsonSerializableType) -> None:
        """send a message to a topic"""

    async def register_callback(self, topic: str, callback: Callable) -> None:
        """register a callback for a topic, subscribe to topic if required"""

    async def remove_callback(self, topic: str) -> None:
        """remove callback for a topic and unsubscribe if required"""

    async def main(self) -> None:
        """main loop for the bridge"""

main() async

main loop for the bridge

Source code in roxbot/interfaces.py
91
92
async def main(self) -> None:
    """main loop for the bridge"""

publish(topic, msg) async

send a message to a topic

Source code in roxbot/interfaces.py
82
83
async def publish(self, topic: str, msg: JsonSerializableType) -> None:
    """send a message to a topic"""

register_callback(topic, callback) async

register a callback for a topic, subscribe to topic if required

Source code in roxbot/interfaces.py
85
86
async def register_callback(self, topic: str, callback: Callable) -> None:
    """register a callback for a topic, subscribe to topic if required"""

remove_callback(topic) async

remove callback for a topic and unsubscribe if required

Source code in roxbot/interfaces.py
88
89
async def remove_callback(self, topic: str) -> None:
    """remove callback for a topic and unsubscribe if required"""

HeadingData

Bases: NamedTuple

heading data

Source code in roxbot/interfaces.py
44
45
46
47
48
49
50
51
52
53
class HeadingData(NamedTuple):
    """heading data"""

    heading: float
    heading_stdev: float
    theta: float
    ts: float

    def to_dict(self) -> dict:
        return self._asdict()  # type: ignore # pylint: disable=no-member

MachineProtocol

Bases: Protocol

generic machine interface, provides a uniform interface for different machine types such as trikes, differential drives, etc.

Source code in roxbot/interfaces.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class MachineProtocol(Protocol):
    """generic machine interface, provides a uniform interface for
    different machine types such as trikes, differential drives, etc."""

    def get_pose(self) -> Pose:
        """return current pose (x, y, theta), in meters.
        Pose class provides a method for converting to GPS coordinates."""

    def cmd_vel(self, linear_velocity: float, angular_velocity: float) -> None:
        """send velocity commands to the machine"""

    def cmd_curvature(self, v_linear: float, curvature: float) -> None:
        """motion command by curvature

        Args:
            v_linear (float): driving velocity
            curvature (float): driving curvature (1/radius)
        """

cmd_curvature(v_linear, curvature)

motion command by curvature

Parameters:

Name Type Description Default
v_linear float

driving velocity

required
curvature float

driving curvature (1/radius)

required
Source code in roxbot/interfaces.py
70
71
72
73
74
75
76
def cmd_curvature(self, v_linear: float, curvature: float) -> None:
    """motion command by curvature

    Args:
        v_linear (float): driving velocity
        curvature (float): driving curvature (1/radius)
    """

cmd_vel(linear_velocity, angular_velocity)

send velocity commands to the machine

Source code in roxbot/interfaces.py
67
68
def cmd_vel(self, linear_velocity: float, angular_velocity: float) -> None:
    """send velocity commands to the machine"""

get_pose()

return current pose (x, y, theta), in meters. Pose class provides a method for converting to GPS coordinates.

Source code in roxbot/interfaces.py
63
64
65
def get_pose(self) -> Pose:
    """return current pose (x, y, theta), in meters.
    Pose class provides a method for converting to GPS coordinates."""

Pose

Bases: NamedTuple

Represents a pose in 2D space

Source code in roxbot/interfaces.py
12
13
14
15
16
17
18
19
20
21
class Pose(NamedTuple):
    """Represents a pose in 2D space"""

    x: float = 0.0
    y: float = 0.0
    theta: float = 0.0

    @property
    def xy(self) -> Vector:
        return Vector(self.x, self.y)

PositionData

Bases: NamedTuple

latitude and longitude data

Source code in roxbot/interfaces.py
29
30
31
32
33
34
35
36
37
38
39
40
41
class PositionData(NamedTuple):
    """latitude and longitude data"""

    lat: float
    lon: float
    x: float
    y: float
    gps_qual: int
    time: str
    ts: float  # system time (epoch)

    def to_dict(self) -> dict:
        return self._asdict()  # type: ignore # pylint: disable=no-member