Created
January 20, 2020 19:43
-
-
Save trickeydan/edef235cf2386c05c026097c88d53814 to your computer and use it in GitHub Desktop.
Print markers using j5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
from typing import Set | |
from j5 import BaseRobot, BoardGroup | |
from j5.boards import Board | |
from j5.boards.zoloto import ZolotoCameraBoard | |
from j5.backends.hardware.zoloto.camera_board import ZolotoCameraBoardHardwareBackend | |
from zoloto.cameras import Camera | |
from zoloto.marker_dict import MarkerDict | |
class SbotCamera(Camera): | |
"""Camera definition for SourceBots kit.""" | |
marker_dict = MarkerDict.DICT_APRILTAG_36H11 | |
def __init__(self, camera_id: int): | |
super().__init__( | |
camera_id, | |
calibration_file=Path(__file__).parent.joinpath('C270.xml'), | |
) | |
def get_marker_size(self, marker_id: int) -> int: | |
"""Get the size of a marker, given it's ID.""" | |
if marker_id in range(0, 40): | |
# WALL_MARKER | |
return 250 | |
else: | |
return 100 | |
class SbotCameraBackend(ZolotoCameraBoardHardwareBackend): | |
"""Camera Backend to override the settings.""" | |
@classmethod | |
def discover(cls) -> Set[Board]: # type: ignore | |
"""Discover boards, overriding the parent classes method.""" | |
return ZolotoCameraBoardHardwareBackend.discover(SbotCamera) | |
class Robot(BaseRobot): | |
def __init__(self) -> None: | |
self._cameras = BoardGroup.get_board_group(ZolotoCameraBoard, SbotCameraBackend) | |
self.camera = self._cameras.singular() | |
r = Robot() | |
while True: | |
ml = r.camera.camera.see() | |
for m in ml: | |
print(m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment