import time import numpy as np import pyarrow as pa from dora import DoraStatus # front-back and left-right movement(float) with min: -1 and max: 1 POSITION_GOAL = [0, 0] # pitch and yaw axis angle in degrees(int) with min: -55 and max: 55 GIMBAL_GOAL = [0, 0] CAMERA_WIDTH = 960 CAMERA_HEIGHT = 540 class Operator: def __init__(self): self.bboxs = np.array([]) self.time = time.time() self.position = [0, 0, 0] def on_event( self, dora_event: dict, send_output, ) -> DoraStatus: global POSITION_GOAL, GIMBAL_GOAL if dora_event["type"] == "INPUT": id = dora_event["id"] if id == "tick": self.time = time.time() elif id == "bbox": value = dora_event["value"].to_numpy() bboxs = value self.bboxs = np.reshape( bboxs, (-1, 6) ) # min_x, min_y, max_x, max_y, confidence, label elif id == "position": value = dora_event["value"].to_numpy() [x, y, _pitch, _yaw] = value self.position = [x, y] direction = np.clip( np.array(POSITION_GOAL) - np.array(self.position), -1, 1 ) send_output( "control", pa.array(direction), dora_event["metadata"], ) send_output( "gimbal_control", pa.array(GIMBAL_GOAL), dora_event["metadata"], ) return DoraStatus.CONTINUE