csg-robomaster / examples /hf-operator /robot_minimize_ap.py
cistine's picture
Upload 490 files
b98ffbb verified
raw
history blame
3.09 kB
from robomaster import robot
import robomaster
from time import sleep
from dora import Node
import numpy as np
import pyarrow as pa
# import robomaster
def wait(event):
if event is not None and not (event._event.isSet() and event.is_completed):
sleep(1)
# robomaster.config.LOCAL_IP_STR = "192.168.2.1"
# ep_robot = robot.Robot()
# ep_robot.initialize(conn_type="ap")
# assert ep_robot.initialize(conn_type="sta")
# assert ep_robot.initialize(conn_type="ap"), "Could not initialize ep_robot"
# assert ep_robot.camera.start_video_stream(display=False), "Could not start video stream"
CONN = "ap"
ep_robot = robot.Robot()
robomaster.config.LOCAL_IP_STR=""
robomaster.config.ROBOT_IP_STR="192.168.2.1"
ep_robot.initialize(conn_type="ap")
print(ep_robot.get_sn())
print(ep_robot.camera.audio_stream_addr)
ep_robot.camera.start_video_stream(display=False)
node = Node()
ep_robot.gimbal.recenter().wait_for_completed()
TCP_STREAM_URL = "tcp://192.168.2.1:40922"
# cap = cv2.VideoCapture(TCP_STREAM_URL)
# Check if the VideoCapture object opened successfully
# assert cap.isOpened(), "Error: Could not open video capture."
# print(cap.isOpened())
current_location = "HOME"
LOCATION = {
"HOME": {
"KITCHEN": np.array([[0.5, 0.0, 0.0, 0.8, 0.0, 0.0, 0.0]]),
"OFFICE": np.array([[0.5, 0.0, 0.0, 0.8, 0.0, 0.0, 0.0]]),
},
"KITCHEN": {
"OFFICE": np.array([[-0.5, 0.0, 0.0, 0.8, 0.0, 0.0, -180.0]]),
},
"OFFICE": {
"KITCHEN": np.array([[-0.5, 0.0, 0.0, 0.8, 0.0, 0.0, -180.0]]),
},
}
# for dora_event in node:
# if dora_event["type"] == "INPUT" and dora_event["id"] == "control":
# [x, y, z, xy_speed, z_speed, pitch, yaw] = dora_event["value"].to_numpy()
# print(dora_event["value"].to_numpy(), flush=True)
# if any([pitch, yaw]):
# event = ep_robot.gimbal.moveto(
# pitch=pitch, yaw=yaw, pitch_speed=60.0, yaw_speed=50.0
# )
# wait(event)
# sleep(2)
# if any([x, y, z]):
# event = ep_robot.chassis.move(
# x=x, y=y, z=z, xy_speed=xy_speed, z_speed=z_speed
# )
# wait(event)
# sleep(6)
# if dora_event["type"] == "INPUT" and dora_event["id"] == "go_to":
# destination = dora_event["value"][0].as_py()
# commands = LOCATION[current_location][destination]
# for command in commands:
# [x, y, z, xy_speed, z_speed, pitch, yaw] = command
# if any([pitch, yaw]):
# event = ep_robot.gimbal.moveto(
# pitch=pitch, yaw=yaw, pitch_speed=60.0, yaw_speed=50.0
# )
# wait(event)
# sleep(2)
# if any([x, y, z]):
# event = ep_robot.chassis.move(
# x=x, y=y, z=z, xy_speed=xy_speed, z_speed=z_speed
# )
# wait(event)
# sleep(3)
# node.send_output(f"reached_{destination.lower()}", pa.array([]))
# current_location = destination