Skip to content

Commit

Permalink
Okon Abstract Base Class (#9)
Browse files Browse the repository at this point in the history
* Creating Okon Abstract Base Class

* Converting okon_client into okon_sim_client with Okon ABC usage
  • Loading branch information
mpfmorawski authored Aug 6, 2022
1 parent a1f7ab7 commit 6b0c96a
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 13 deletions.
4 changes: 2 additions & 2 deletions go_to_starting_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"""
import time

from okon_client import OkonClient
from okon_sim_client import OkonSimClient

oc = OkonClient(ip="127.0.0.1", port=44210, sync_interval=0.05, debug=False)
oc = OkonSimClient(ip="127.0.0.1", port=44210, sync_interval=0.05, debug=False)
okon = oc.okon

sim = oc.simulation
Expand Down
44 changes: 44 additions & 0 deletions okon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
""" Implementation of an Abstract Base Class (ABC) Okon
Okon ABC implementation provides unified communication between
the autonomy module and simulation/TCM.
"""
from abc import ABC, abstractmethod


class Okon(ABC):
@abstractmethod
def set_depth(self, depth: float, add: bool = False) -> None:
pass

@abstractmethod
def set_stable_vel(self, x: float = None, y: float = None, z: float = None) -> None:
pass

@abstractmethod
def arm_motors(self) -> None:
pass

@abstractmethod
def disarm_motors(self) -> None:
pass

@abstractmethod
def setMode(self, mode: str) -> None:
pass

@abstractmethod
def reachedTargetRotation(self, delta):
pass

@abstractmethod
def reachedTargetDepth(self, delta):
pass

@abstractmethod
def get_detection(self, className: str):
pass

@abstractmethod
def set_stable_rot(self, x: float = None, y: float = None, z: float = None, add=False) -> None:
pass
2 changes: 1 addition & 1 deletion okon_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import py_trees

from okon_client import Okon
from okon_sim_client import Okon


class Status:
Expand Down
4 changes: 2 additions & 2 deletions okon_actions_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import py_trees

from okon_actions import Rotate, SetDepth
from okon_client import OkonClient
from okon_sim_client import OkonSimClient

oc = OkonClient(ip="127.0.0.1", port=44210, sync_interval=0.05, debug=False)
oc = OkonSimClient(ip="127.0.0.1", port=44210, sync_interval=0.05, debug=False)
oc.connect()
time.sleep(1.0)

Expand Down
8 changes: 4 additions & 4 deletions okon_client.py → okon_sim_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from queue import Queue
from threading import Thread

from numpy import number
from okon import Okon


class PacketType: # PacketType.PING
Expand Down Expand Up @@ -61,7 +61,7 @@ def get(val: int) -> str: # PacketFlag.get(1|2)
return flags


class Okon:
class OkonSim(Okon):
def __init__(self, okon_client) -> None:
self._okon_client = okon_client
self.sens = {
Expand Down Expand Up @@ -218,9 +218,9 @@ def angle_norm(a: dict) -> dict:
return {"x": x, "y": y, "z": z}


class OkonClient:
class OkonSimClient:
def __init__(self, ip, port, options=None, sync_interval=0.05, debug=True) -> None:
self.okon = Okon(self)
self.okon = OkonSim(self)
self.simulation = Simulation(self)

self.ip = ip
Expand Down
4 changes: 2 additions & 2 deletions okon_client_example.py → okon_sim_client_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time

from okon_client import OkonClient, PacketFlag, PacketType
from okon_sim_client import OkonSimClient, PacketFlag, PacketType


def handle_simulation_reset(args=None) -> None:
Expand All @@ -14,7 +14,7 @@ def handle_ping(args=None) -> None:
n += 1


oc = OkonClient(
oc = OkonSimClient(
ip="127.0.0.1", port=44210, sync_interval=0.05, debug=False
) # ping simRST hitNGZ hitFZ packet error disconnect # run on separate thread
oc.on_event("simRST", handle_simulation_reset)
Expand Down
4 changes: 2 additions & 2 deletions qualification_task_behavior_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
TryDetectNTimes,
Wait,
)
from okon_client import OkonClient
from okon_sim_client import OkonSimClient

oc = OkonClient(ip="127.0.0.1", port=44210, sync_interval=0.05, debug=False)
oc = OkonSimClient(ip="127.0.0.1", port=44210, sync_interval=0.05, debug=False)
oc.connect()
time.sleep(1.0)

Expand Down

0 comments on commit 6b0c96a

Please sign in to comment.