File size: 3,094 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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