haixuantao
commited on
Commit
•
c641eb7
1
Parent(s):
1a7150e
Simplifying robot control behavior
Browse files- graphs/dataflow_robot_basic.yml +51 -0
- graphs/dataflow_robot_vlm.yml +3 -1
- operators/robot.py +12 -107
graphs/dataflow_robot_basic.yml
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
nodes:
|
2 |
+
### Camera
|
3 |
+
- id: plot_bot
|
4 |
+
operator:
|
5 |
+
python: ../operators/plot.py
|
6 |
+
inputs:
|
7 |
+
image: webcam/image
|
8 |
+
position: robot/position
|
9 |
+
|
10 |
+
- id: robot
|
11 |
+
operator:
|
12 |
+
python: ../operators/robot.py
|
13 |
+
inputs:
|
14 |
+
tick: dora/timer/millis/750
|
15 |
+
planning_control: planning/control
|
16 |
+
outputs:
|
17 |
+
- control_reply
|
18 |
+
- position
|
19 |
+
|
20 |
+
- id: webcam
|
21 |
+
custom:
|
22 |
+
source: ../operators/opencv_stream.py
|
23 |
+
outputs:
|
24 |
+
- image
|
25 |
+
|
26 |
+
- id: policy
|
27 |
+
operator:
|
28 |
+
python: ../operators/policy.py
|
29 |
+
inputs:
|
30 |
+
init: dora/timer/millis/750
|
31 |
+
goal_reached: planning/goal_reached
|
32 |
+
outputs:
|
33 |
+
- go_to
|
34 |
+
- reloaded
|
35 |
+
|
36 |
+
- id: planning
|
37 |
+
operator:
|
38 |
+
python: ../operators/planning_op.py
|
39 |
+
inputs:
|
40 |
+
position: robot/position
|
41 |
+
control_reply: robot/control_reply
|
42 |
+
set_goal: policy/go_to
|
43 |
+
image:
|
44 |
+
source: webcam/image
|
45 |
+
queue_size: 1
|
46 |
+
outputs:
|
47 |
+
- control
|
48 |
+
- goal_reached
|
49 |
+
|
50 |
+
|
51 |
+
|
graphs/dataflow_robot_vlm.yml
CHANGED
@@ -60,7 +60,9 @@ nodes:
|
|
60 |
position: robot/position
|
61 |
control_reply: robot/control_reply
|
62 |
set_goal: policy/go_to
|
63 |
-
image:
|
|
|
|
|
64 |
outputs:
|
65 |
- control
|
66 |
- goal_reached
|
|
|
60 |
position: robot/position
|
61 |
control_reply: robot/control_reply
|
62 |
set_goal: policy/go_to
|
63 |
+
image:
|
64 |
+
source: webcam/image
|
65 |
+
queue_size: 1
|
66 |
outputs:
|
67 |
- control
|
68 |
- goal_reached
|
operators/robot.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from robomaster import robot
|
2 |
-
from typing import Callable, Optional
|
3 |
-
from enum import Enum
|
4 |
from dora import DoraStatus
|
5 |
|
6 |
import numpy as np
|
@@ -9,101 +8,38 @@ import pyarrow as pa
|
|
9 |
|
10 |
CONN = "ap"
|
11 |
|
12 |
-
|
13 |
-
class Command(Enum):
|
14 |
-
NOD_YES = [
|
15 |
-
{"action": "gimbal", "value": [20.0, 0.0]},
|
16 |
-
{"action": "gimbal", "value": [0.0, 0.0]},
|
17 |
-
]
|
18 |
-
NOD_NO = [
|
19 |
-
{"action": "gimbal", "value": [0, -55.0]},
|
20 |
-
{"action": "gimbal", "value": [0.0, 0.0]},
|
21 |
-
]
|
22 |
-
FORWARD = [
|
23 |
-
{
|
24 |
-
"action": "control",
|
25 |
-
"value": [2.0, 0.0, 0.0, 0.8, 0],
|
26 |
-
}
|
27 |
-
]
|
28 |
-
BACKWARD = [
|
29 |
-
{"action": "gimbal", "value": [0, -180.0]},
|
30 |
-
{
|
31 |
-
"action": "control",
|
32 |
-
"value": [-2.0, 0, 180.0, 0.8, 50],
|
33 |
-
},
|
34 |
-
]
|
35 |
-
LEFT = [
|
36 |
-
{"action": "gimbal", "value": [0, -90.0]},
|
37 |
-
{
|
38 |
-
"action": "control",
|
39 |
-
"value": [0.0, -1.0, 90.0, 0.6, 50],
|
40 |
-
},
|
41 |
-
]
|
42 |
-
SLIGHT_LEFT = [
|
43 |
-
{"action": "gimbal", "value": [0.0, -30.0]},
|
44 |
-
{
|
45 |
-
"action": "control",
|
46 |
-
"value": [1.0, -0.5, 30.0, 0.6, 50],
|
47 |
-
},
|
48 |
-
]
|
49 |
-
RIGHT = [
|
50 |
-
{"action": "gimbal", "value": [0.0, 90.0]},
|
51 |
-
{
|
52 |
-
"value": [0.0, 1.0, -90.0, 0.6, 50],
|
53 |
-
"action": "control",
|
54 |
-
},
|
55 |
-
]
|
56 |
-
SLIGHT_RIGHT = [
|
57 |
-
{"action": "gimbal", "value": [0.0, 30.0]},
|
58 |
-
{
|
59 |
-
"value": [1.0, 0.5, -30.0, 0.6, 50],
|
60 |
-
"action": "control",
|
61 |
-
},
|
62 |
-
]
|
63 |
-
UNKNOWN = []
|
64 |
-
# STOP = [0, 0, 0, 0]
|
65 |
-
# COMPLETED = [0, 0, 0, 0]
|
66 |
-
|
67 |
-
@classmethod
|
68 |
-
def parse(cls, value):
|
69 |
-
for k, v in cls.__members__.items():
|
70 |
-
if k == value:
|
71 |
-
return v
|
72 |
-
return cls.UNKNOWN
|
73 |
|
74 |
|
75 |
class Operator:
|
76 |
def __init__(self):
|
77 |
self.ep_robot = robot.Robot()
|
78 |
-
print("Initializing robot...")
|
79 |
assert self.ep_robot.initialize(conn_type=CONN), "Could not initialize ep_robot"
|
80 |
assert self.ep_robot.camera.start_video_stream(
|
81 |
display=False
|
82 |
), "Could not start video stream"
|
83 |
|
84 |
self.ep_robot.gimbal.recenter().wait_for_completed()
|
85 |
-
self.event = self.ep_robot.gimbal.moveto(
|
86 |
-
pitch=-5, yaw=0, pitch_speed=50.0, yaw_speed=50.0
|
87 |
-
)
|
88 |
self.backlog = []
|
89 |
self.last_control = ""
|
90 |
-
self.position = np.array([0, 0, 0])
|
91 |
self.count = -1
|
|
|
92 |
|
93 |
def execute_backlog(self):
|
94 |
if len(self.backlog) > 0:
|
95 |
command = self.backlog.pop(0)
|
|
|
96 |
if command["action"] == "control":
|
97 |
[x, y, z, xy_speed, z_speed] = command["value"]
|
98 |
-
|
99 |
self.event = self.ep_robot.chassis.move(
|
100 |
x=x, y=y, z=z, xy_speed=xy_speed, z_speed=z_speed
|
101 |
)
|
102 |
-
self.position = np.array([x, y, z])
|
103 |
|
104 |
elif command["action"] == "gimbal":
|
105 |
[pitch, yaw] = command["value"]
|
106 |
-
print(command, flush=True)
|
107 |
self.event = self.ep_robot.gimbal.moveto(
|
108 |
pitch=pitch, yaw=yaw, pitch_speed=50.0, yaw_speed=50.0
|
109 |
)
|
@@ -124,45 +60,14 @@ class Operator:
|
|
124 |
if len(self.backlog) > 0:
|
125 |
self.execute_backlog()
|
126 |
else:
|
127 |
-
print(f"sending control reply: {self.
|
128 |
send_output("position", pa.array(self.position))
|
129 |
send_output("control_reply", pa.array([self.count]))
|
130 |
-
|
131 |
-
|
|
|
|
|
132 |
|
133 |
-
elif dora_event["id"] == "control":
|
134 |
-
raw_command = dora_event["value"][0].as_py()
|
135 |
-
print(raw_command, flush=True)
|
136 |
-
self.last_control = raw_command
|
137 |
-
if "slight right" in raw_command:
|
138 |
-
cmd = Command.BACKWARD
|
139 |
-
elif "slight left" in raw_command:
|
140 |
-
cmd = Command.BACKWARD
|
141 |
-
elif "right" in raw_command:
|
142 |
-
cmd = Command.RIGHT
|
143 |
-
elif "left" in raw_command:
|
144 |
-
cmd = Command.LEFT
|
145 |
-
elif "forward" in raw_command:
|
146 |
-
cmd = Command.FORWARD
|
147 |
-
elif "backward" in raw_command:
|
148 |
-
cmd = Command.BACKWARD
|
149 |
-
else:
|
150 |
-
cmd = Command.UNKNOWN
|
151 |
-
if len(self.backlog) == 0:
|
152 |
-
self.backlog += cmd.value
|
153 |
-
self.execute_backlog()
|
154 |
-
elif dora_event["id"] == "assistant_message":
|
155 |
-
raw_command = dora_event["value"][0].as_py()
|
156 |
-
print(raw_command, flush=True)
|
157 |
-
self.last_control = raw_command
|
158 |
-
if "No, " in raw_command:
|
159 |
-
cmd = Command.NOD_NO
|
160 |
-
elif "Yes, " in raw_command:
|
161 |
-
cmd = Command.NOD_YES
|
162 |
-
else:
|
163 |
-
cmd = Command.UNKNOWN
|
164 |
-
self.backlog += cmd.value
|
165 |
-
self.execute_backlog()
|
166 |
elif dora_event["id"] == "planning_control":
|
167 |
command = dora_event["value"].to_pylist()
|
168 |
self.count = command[0]["count"]
|
|
|
1 |
from robomaster import robot
|
2 |
+
from typing import Callable, Optional
|
|
|
3 |
from dora import DoraStatus
|
4 |
|
5 |
import numpy as np
|
|
|
8 |
|
9 |
CONN = "ap"
|
10 |
|
11 |
+
print("Initialization...", flush=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
class Operator:
|
15 |
def __init__(self):
|
16 |
self.ep_robot = robot.Robot()
|
17 |
+
print("Initializing robot...", flush=True)
|
18 |
assert self.ep_robot.initialize(conn_type=CONN), "Could not initialize ep_robot"
|
19 |
assert self.ep_robot.camera.start_video_stream(
|
20 |
display=False
|
21 |
), "Could not start video stream"
|
22 |
|
23 |
self.ep_robot.gimbal.recenter().wait_for_completed()
|
|
|
|
|
|
|
24 |
self.backlog = []
|
25 |
self.last_control = ""
|
26 |
+
self.position = np.array([0.0, 0.0, 0.0])
|
27 |
self.count = -1
|
28 |
+
self.event = None
|
29 |
|
30 |
def execute_backlog(self):
|
31 |
if len(self.backlog) > 0:
|
32 |
command = self.backlog.pop(0)
|
33 |
+
print(command, flush=True)
|
34 |
if command["action"] == "control":
|
35 |
[x, y, z, xy_speed, z_speed] = command["value"]
|
36 |
+
self.position += np.array([x, y, z])
|
37 |
self.event = self.ep_robot.chassis.move(
|
38 |
x=x, y=y, z=z, xy_speed=xy_speed, z_speed=z_speed
|
39 |
)
|
|
|
40 |
|
41 |
elif command["action"] == "gimbal":
|
42 |
[pitch, yaw] = command["value"]
|
|
|
43 |
self.event = self.ep_robot.gimbal.moveto(
|
44 |
pitch=pitch, yaw=yaw, pitch_speed=50.0, yaw_speed=50.0
|
45 |
)
|
|
|
60 |
if len(self.backlog) > 0:
|
61 |
self.execute_backlog()
|
62 |
else:
|
63 |
+
print(f"sending control reply: {self.count}", flush=True)
|
64 |
send_output("position", pa.array(self.position))
|
65 |
send_output("control_reply", pa.array([self.count]))
|
66 |
+
return DoraStatus.CONTINUE
|
67 |
+
|
68 |
+
print("sending position", flush=True)
|
69 |
+
send_output("position", pa.array(self.position))
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
elif dora_event["id"] == "planning_control":
|
72 |
command = dora_event["value"].to_pylist()
|
73 |
self.count = command[0]["count"]
|