haixuantao
commited on
Commit
·
c3afd26
1
Parent(s):
c641eb7
Simplify planning
Browse files- operators/planning_op.py +32 -46
- operators/policy.py +13 -19
operators/planning_op.py
CHANGED
@@ -3,10 +3,6 @@ import numpy as np
|
|
3 |
import pyarrow as pa
|
4 |
from dora import DoraStatus
|
5 |
|
6 |
-
GOAL = np.array([10, 20])
|
7 |
-
|
8 |
-
HOME_TO_KITCHEN = np.array([[0.5, 0], [0.5, -5.0], [1.0, 7.0]])
|
9 |
-
KITCHEN_TO_HOME = np.array([[2.0, 0.0], [0.0, 0.0]])
|
10 |
|
11 |
CAMERA_WIDTH = 960
|
12 |
CAMERA_HEIGHT = 540
|
@@ -89,12 +85,9 @@ class Operator:
|
|
89 |
dora_event: dict,
|
90 |
send_output,
|
91 |
) -> DoraStatus:
|
92 |
-
global POSITION_GOAL, GIMBAL_GOAL
|
93 |
if dora_event["type"] == "INPUT":
|
94 |
id = dora_event["id"]
|
95 |
-
if id == "
|
96 |
-
self.time = time.time()
|
97 |
-
elif id == "image":
|
98 |
value = dora_event["value"].to_numpy()
|
99 |
|
100 |
self.image = value.reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3))
|
@@ -108,6 +101,7 @@ class Operator:
|
|
108 |
if len(dora_event["value"]) > 0:
|
109 |
self.waypoints = dora_event["value"].to_numpy().reshape((-1, 2))
|
110 |
elif id == "position":
|
|
|
111 |
## No bounding box yet
|
112 |
if self.waypoints is None:
|
113 |
print("no waypoint", flush=True)
|
@@ -122,7 +116,7 @@ class Operator:
|
|
122 |
# Remove waypoints if completed
|
123 |
if (
|
124 |
len(self.waypoints) > 0
|
125 |
-
and np.linalg.norm(self.waypoints[0] - [x, y]) < 0.
|
126 |
):
|
127 |
self.waypoints = self.waypoints[1:]
|
128 |
print("removing waypoints", flush=True)
|
@@ -134,7 +128,7 @@ class Operator:
|
|
134 |
|
135 |
z = np.deg2rad(z)
|
136 |
self.tf = np.array([[np.cos(z), -np.sin(z)], [np.sin(z), np.cos(z)]])
|
137 |
-
goal = self.tf.dot(self.waypoints[0])
|
138 |
goal_camera_x = (
|
139 |
CAMERA_WIDTH * np.arctan2(goal[1], goal[0]) / np.pi
|
140 |
) + CAMERA_WIDTH / 2
|
@@ -155,41 +149,33 @@ class Operator:
|
|
155 |
flush=True,
|
156 |
)
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
#
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
0.0, # 50,
|
187 |
-
],
|
188 |
-
"action": "control",
|
189 |
-
},
|
190 |
-
]
|
191 |
-
),
|
192 |
-
dora_event["metadata"],
|
193 |
-
)
|
194 |
|
195 |
return DoraStatus.CONTINUE
|
|
|
3 |
import pyarrow as pa
|
4 |
from dora import DoraStatus
|
5 |
|
|
|
|
|
|
|
|
|
6 |
|
7 |
CAMERA_WIDTH = 960
|
8 |
CAMERA_HEIGHT = 540
|
|
|
85 |
dora_event: dict,
|
86 |
send_output,
|
87 |
) -> DoraStatus:
|
|
|
88 |
if dora_event["type"] == "INPUT":
|
89 |
id = dora_event["id"]
|
90 |
+
if id == "image":
|
|
|
|
|
91 |
value = dora_event["value"].to_numpy()
|
92 |
|
93 |
self.image = value.reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3))
|
|
|
101 |
if len(dora_event["value"]) > 0:
|
102 |
self.waypoints = dora_event["value"].to_numpy().reshape((-1, 2))
|
103 |
elif id == "position":
|
104 |
+
print("got position:", dora_event["value"], flush=True)
|
105 |
## No bounding box yet
|
106 |
if self.waypoints is None:
|
107 |
print("no waypoint", flush=True)
|
|
|
116 |
# Remove waypoints if completed
|
117 |
if (
|
118 |
len(self.waypoints) > 0
|
119 |
+
and np.linalg.norm(self.waypoints[0] - [x, y]) < 0.1
|
120 |
):
|
121 |
self.waypoints = self.waypoints[1:]
|
122 |
print("removing waypoints", flush=True)
|
|
|
128 |
|
129 |
z = np.deg2rad(z)
|
130 |
self.tf = np.array([[np.cos(z), -np.sin(z)], [np.sin(z), np.cos(z)]])
|
131 |
+
goal = self.tf.dot(self.waypoints[0] - np.array([x, y]))
|
132 |
goal_camera_x = (
|
133 |
CAMERA_WIDTH * np.arctan2(goal[1], goal[0]) / np.pi
|
134 |
) + CAMERA_WIDTH / 2
|
|
|
149 |
flush=True,
|
150 |
)
|
151 |
|
152 |
+
self.count += 1
|
153 |
+
self.completed = False
|
154 |
+
|
155 |
+
message = pa.array(
|
156 |
+
[
|
157 |
+
{
|
158 |
+
"action": "gimbal",
|
159 |
+
"value": [0.0, goal_angle],
|
160 |
+
"count": self.count,
|
161 |
+
},
|
162 |
+
{
|
163 |
+
"value": [
|
164 |
+
self.waypoints[0][0] - x,
|
165 |
+
self.waypoints[0][1] - y,
|
166 |
+
0.0, # -goal_angle,
|
167 |
+
0.6,
|
168 |
+
0.0, # 50,
|
169 |
+
],
|
170 |
+
"action": "control",
|
171 |
+
},
|
172 |
+
]
|
173 |
+
)
|
174 |
+
print("sending:", message, flush=True)
|
175 |
+
send_output(
|
176 |
+
"control",
|
177 |
+
message,
|
178 |
+
dora_event["metadata"],
|
179 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
return DoraStatus.CONTINUE
|
operators/policy.py
CHANGED
@@ -2,10 +2,10 @@ import numpy as np
|
|
2 |
import pyarrow as pa
|
3 |
from dora import DoraStatus
|
4 |
from utils import ask_vlm, speak
|
|
|
5 |
|
6 |
-
|
7 |
-
KITCHEN = np.array([[0.
|
8 |
-
HOME = np.array([[0.5, 0.0], [0.0, 0.0]]).ravel()
|
9 |
|
10 |
|
11 |
## Policy Operator
|
@@ -17,21 +17,15 @@ class Operator:
|
|
17 |
text = ask_vlm(image, text)
|
18 |
return "Yes, " in text
|
19 |
|
20 |
-
def on_event(self,
|
21 |
-
if
|
22 |
-
id =
|
23 |
if id == "init":
|
24 |
-
send_output("go_to", pa.array(
|
25 |
-
elif id == "
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
self.speak("I'm going to the kitchen.")
|
32 |
-
else:
|
33 |
-
self.speak("There's no one with a bruise shirt.")
|
34 |
-
send_output("go_to", pa.array(COUCH))
|
35 |
-
self.speak("I'm going to the couch.")
|
36 |
-
|
37 |
return DoraStatus.CONTINUE
|
|
|
2 |
import pyarrow as pa
|
3 |
from dora import DoraStatus
|
4 |
from utils import ask_vlm, speak
|
5 |
+
from time import sleep
|
6 |
|
7 |
+
LIVING_ROOM = np.array([[1.0, 0.0]]).ravel()
|
8 |
+
KITCHEN = np.array([[0.0, -0.2], [-1.0, -0.3], [-2.0, -0.5]]).ravel()
|
|
|
9 |
|
10 |
|
11 |
## Policy Operator
|
|
|
17 |
text = ask_vlm(image, text)
|
18 |
return "Yes, " in text
|
19 |
|
20 |
+
def on_event(self, event: dict, send_output) -> DoraStatus:
|
21 |
+
if event["type"] == "INPUT":
|
22 |
+
id = event["id"]
|
23 |
if id == "init":
|
24 |
+
send_output("go_to", pa.array([]))
|
25 |
+
elif id == "reached_living_room":
|
26 |
+
image = event["value"].to_numpy().reshape((540, 960, 3))
|
27 |
+
pass
|
28 |
+
elif id == "reached_kitchen":
|
29 |
+
image = event["value"].to_numpy().reshape((540, 960, 3))
|
30 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
return DoraStatus.CONTINUE
|