Skip to content

Commit

Permalink
Import updates
Browse files Browse the repository at this point in the history
  • Loading branch information
OloFuchs committed Jan 26, 2024
1 parent 4f71082 commit 7739aae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
22 changes: 8 additions & 14 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import Literal

from farm_ng.canbus.canbus_pb2 import Twist2d
from farm_ng.canbus.packet import AmigaControlState
from farm_ng.canbus.packet import AmigaTpdo1
from farm_ng.core.event_client import EventClient
from farm_ng.core.event_service_pb2 import EventServiceConfig
Expand All @@ -19,7 +18,6 @@
from farm_ng.core.events_file_reader import proto_from_json_file
from farm_ng.core.uri_pb2 import Uri
from turbojpeg import TurboJPEG

from virtual_joystick.joystick import VirtualJoystickWidget

# import internal libs
Expand Down Expand Up @@ -92,7 +90,6 @@ def update_view(self, view_name: str):
self.view_name = view_name

async def app_func(self):

async def run_wrapper() -> None:
# we don't actually need to set asyncio as the lib because it is
# the default, but it doesn't hurt to be explicit
Expand All @@ -107,19 +104,15 @@ async def run_wrapper() -> None:
oak0_client: EventClient | None = None
canbus_client: EventClient | None = None


for config in config_list.configs:
if config.name == "oak0":
oak0_client = EventClient(config)
elif config.name == "canbus":
canbus_client = EventClient(config)


# Confirm that EventClients were created for all required services
if None in [oak0_client,canbus_client]:
raise RuntimeError(
f"No {config} service config in {self.service_config}"
)
if None in [oak0_client, canbus_client]:
raise RuntimeError(f"No {config} service config in {self.service_config}")

# Camera task
self.tasks: list[asyncio.Task] = [
Expand All @@ -129,7 +122,7 @@ async def run_wrapper() -> None:

self.tasks.append(asyncio.create_task(self.pose_generator(canbus_client)))

return await asyncio.gather(run_wrapper(),*self.tasks)
return await asyncio.gather(run_wrapper(), *self.tasks)

async def stream_camera(
self,
Expand All @@ -144,11 +137,12 @@ async def stream_camera(
rate = oak_client.config.subscriptions[0].every_n

async for event, payload in oak_client.subscribe(
SubscribeRequest(
uri=Uri(path=f"/{view_name}"), every_n=rate
),
SubscribeRequest(uri=Uri(path=f"/{view_name}"), every_n=rate),
decode=False,
):

self.view_name = self.root.ids["tab_root"].current_tab.text

if view_name == self.view_name:
message = payload_to_protobuf(event, payload)
try:
Expand Down Expand Up @@ -177,7 +171,7 @@ async def pose_generator(self, canbus_client: EventClient, period: float = 0.02)
await asyncio.sleep(0.01)

twist = Twist2d()

joystick: VirtualJoystickWidget = self.root.ids["joystick"]

rate = canbus_client.config.subscriptions[0].every_n
Expand Down
13 changes: 5 additions & 8 deletions src/res/main.kv
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,20 @@ RelativeLayout:
id: joystick
TabbedPanel:
do_default_tab: False
id: tab_root
TabbedPanelItem:
text: "Rgb"
on_press: app.update_view('rgb')
text: "rgb"
Image:
id: rgb
TabbedPanelItem:
text: "Disparity"
on_press: app.update_view('disparity')
text: "disparity"
Image:
id: disparity
TabbedPanelItem:
text: "Left"
on_press: app.update_view('left')
text: "left"
Image:
id: left
TabbedPanelItem:
text: "Right"
on_press: app.update_view('right')
text: "right"
Image:
id: right

0 comments on commit 7739aae

Please sign in to comment.