haixuantao's picture
Adding policy node for controlling the robot
fe79d42
raw
history blame
1.2 kB
from dora import DoraStatus
import numpy as np
import pyarrow as pa
from idefics2_utils import ask_vlm
import pyttsx3
KITCHEN = np.array([[0.5, 0], [0.5, -0.5], [1.0, -1.0]]).ravel()
HOME = np.array([[0.5, -0.5], [0, 0]]).ravel()
## Policy Operator
class Operator:
def __init__(self):
engine = pyttsx3.init("espeak")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[3].id)
self.engine = engine
def speak(self, text: str):
self.engine.say(text)
# Ask vision model for information
def ask_model(self, image: np.ndarray, text: str) -> str:
text = ask_vlm(image, text)
return "Yes, " in text
def on_event(
self,
dora_event: dict,
send_output,
) -> DoraStatus:
if dora_event["type"] == "INPUT":
id = dora_event["id"]
# On initialization
if id == "init":
send_output("set_goal", pa.array([]))
# On destination goal reached
elif id == "goal_reached":
image = dora_event["value"].to_numpy().reshape((540, 960, 3))
pass
return DoraStatus.CONTINUE