File size: 1,670 Bytes
b98ffbb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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
|