Commit ·
37584e0
1
Parent(s): 10e96ef
Simplify planning node
Browse files- graphs/dataflow.yml +30 -36
- operators/keyboard_op.py +2 -31
- operators/llm_op.py +4 -4
- operators/object_detection.py +1 -2
- operators/planning_op.py +25 -38
- operators/plot.py +17 -4
- operators/robot.py +13 -16
graphs/dataflow.yml
CHANGED
|
@@ -4,13 +4,13 @@ nodes:
|
|
| 4 |
python: ../operators/robot.py
|
| 5 |
inputs:
|
| 6 |
blaster:
|
| 7 |
-
source:
|
| 8 |
queue_size: 1
|
| 9 |
led:
|
| 10 |
-
source:
|
| 11 |
queue_size: 1
|
| 12 |
control:
|
| 13 |
-
source:
|
| 14 |
queue_size: 1
|
| 15 |
gimbal_control:
|
| 16 |
source: planning/gimbal_control
|
|
@@ -59,9 +59,12 @@ nodes:
|
|
| 59 |
python: ../operators/plot.py
|
| 60 |
inputs:
|
| 61 |
image: bot_webcam/image
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
bbox: object_detection/bbox
|
| 64 |
-
|
|
|
|
| 65 |
- id: planning
|
| 66 |
operator:
|
| 67 |
python: ../operators/planning_op.py
|
|
@@ -78,23 +81,22 @@ nodes:
|
|
| 78 |
## Speech to text
|
| 79 |
- id: keyboard
|
| 80 |
custom:
|
| 81 |
-
source: ../operators/
|
| 82 |
outputs:
|
| 83 |
-
-
|
| 84 |
-
-
|
| 85 |
-
-
|
| 86 |
-
-
|
|
|
|
|
|
|
| 87 |
inputs:
|
| 88 |
-
|
| 89 |
-
source: dora/timer/millis/50
|
| 90 |
-
queue_size: 1
|
| 91 |
-
|
| 92 |
|
| 93 |
- id: microphone
|
| 94 |
operator:
|
| 95 |
python: ../operators/microphone_op.py
|
| 96 |
inputs:
|
| 97 |
-
|
| 98 |
outputs:
|
| 99 |
- audio
|
| 100 |
|
|
@@ -111,39 +113,32 @@ nodes:
|
|
| 111 |
operator:
|
| 112 |
python: ../operators/sentence_transformers_op.py
|
| 113 |
inputs:
|
| 114 |
-
query:
|
| 115 |
saved_file: file_saver/saved_file
|
| 116 |
outputs:
|
| 117 |
- raw_file
|
| 118 |
|
| 119 |
-
- id:
|
| 120 |
operator:
|
| 121 |
-
python: ../operators/
|
| 122 |
inputs:
|
| 123 |
-
|
|
|
|
|
|
|
| 124 |
outputs:
|
| 125 |
-
-
|
|
|
|
|
|
|
| 126 |
- control
|
| 127 |
- led
|
| 128 |
- blaster
|
|
|
|
| 129 |
|
| 130 |
-
- id: chatgpt
|
| 131 |
-
operator:
|
| 132 |
-
python: ../operators/chatgpt_op.py
|
| 133 |
-
inputs:
|
| 134 |
-
raw_file: vectordb/raw_file
|
| 135 |
-
outputs:
|
| 136 |
-
- output_file
|
| 137 |
-
|
| 138 |
- id: file_saver
|
| 139 |
operator:
|
| 140 |
python: ../operators/file_saver_op.py
|
| 141 |
inputs:
|
| 142 |
-
|
| 143 |
-
mistral_output_file: mistral/output_file
|
| 144 |
-
error: keyboard/error
|
| 145 |
-
revert: keyboard/revert
|
| 146 |
-
failed: keyboard/failed
|
| 147 |
outputs:
|
| 148 |
- saved_file
|
| 149 |
|
|
@@ -151,8 +146,7 @@ nodes:
|
|
| 151 |
custom:
|
| 152 |
source: dora-record
|
| 153 |
inputs:
|
| 154 |
-
|
| 155 |
-
mistral_output_file: mistral/output_file
|
| 156 |
raw_file: vectordb/raw_file
|
| 157 |
saved_file: file_saver/saved_file
|
| 158 |
audio: microphone/audio
|
|
@@ -170,4 +164,4 @@ nodes:
|
|
| 170 |
inputs:
|
| 171 |
image: bot_webcam/image
|
| 172 |
outputs:
|
| 173 |
-
- encoded_image
|
|
|
|
| 4 |
python: ../operators/robot.py
|
| 5 |
inputs:
|
| 6 |
blaster:
|
| 7 |
+
source: llm/blaster
|
| 8 |
queue_size: 1
|
| 9 |
led:
|
| 10 |
+
source: llm/led
|
| 11 |
queue_size: 1
|
| 12 |
control:
|
| 13 |
+
source: planning/control
|
| 14 |
queue_size: 1
|
| 15 |
gimbal_control:
|
| 16 |
source: planning/gimbal_control
|
|
|
|
| 59 |
python: ../operators/plot.py
|
| 60 |
inputs:
|
| 61 |
image: bot_webcam/image
|
| 62 |
+
keyboard_buffer: keyboard/buffer
|
| 63 |
+
user_message: keyboard/submitted
|
| 64 |
+
assistant_message: llm/assistant_message
|
| 65 |
bbox: object_detection/bbox
|
| 66 |
+
|
| 67 |
+
|
| 68 |
- id: planning
|
| 69 |
operator:
|
| 70 |
python: ../operators/planning_op.py
|
|
|
|
| 81 |
## Speech to text
|
| 82 |
- id: keyboard
|
| 83 |
custom:
|
| 84 |
+
source: ../operators/keyboard_op.py
|
| 85 |
outputs:
|
| 86 |
+
- buffer
|
| 87 |
+
- submitted
|
| 88 |
+
- record
|
| 89 |
+
- ask
|
| 90 |
+
- send
|
| 91 |
+
- change
|
| 92 |
inputs:
|
| 93 |
+
recording: whisper/text
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
- id: microphone
|
| 96 |
operator:
|
| 97 |
python: ../operators/microphone_op.py
|
| 98 |
inputs:
|
| 99 |
+
record: keyboard/record
|
| 100 |
outputs:
|
| 101 |
- audio
|
| 102 |
|
|
|
|
| 113 |
operator:
|
| 114 |
python: ../operators/sentence_transformers_op.py
|
| 115 |
inputs:
|
| 116 |
+
query: keyboard/change
|
| 117 |
saved_file: file_saver/saved_file
|
| 118 |
outputs:
|
| 119 |
- raw_file
|
| 120 |
|
| 121 |
+
- id: llm
|
| 122 |
operator:
|
| 123 |
+
python: ../operators/llm_op.py
|
| 124 |
inputs:
|
| 125 |
+
code_modifier: vectordb/raw_file
|
| 126 |
+
assistant: keyboard/ask
|
| 127 |
+
message_sender: keyboard/send
|
| 128 |
outputs:
|
| 129 |
+
- modified_file
|
| 130 |
+
- assistant_message
|
| 131 |
+
- line
|
| 132 |
- control
|
| 133 |
- led
|
| 134 |
- blaster
|
| 135 |
+
- rotation
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
- id: file_saver
|
| 138 |
operator:
|
| 139 |
python: ../operators/file_saver_op.py
|
| 140 |
inputs:
|
| 141 |
+
llm_output_file: llm/modified_file
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
outputs:
|
| 143 |
- saved_file
|
| 144 |
|
|
|
|
| 146 |
custom:
|
| 147 |
source: dora-record
|
| 148 |
inputs:
|
| 149 |
+
llm_output_file: llm/modified_file
|
|
|
|
| 150 |
raw_file: vectordb/raw_file
|
| 151 |
saved_file: file_saver/saved_file
|
| 152 |
audio: microphone/audio
|
|
|
|
| 164 |
inputs:
|
| 165 |
image: bot_webcam/image
|
| 166 |
outputs:
|
| 167 |
+
- encoded_image
|
operators/keyboard_op.py
CHANGED
|
@@ -2,8 +2,6 @@ from pynput import keyboard
|
|
| 2 |
from pynput.keyboard import Key, Events
|
| 3 |
import pyarrow as pa
|
| 4 |
from dora import Node
|
| 5 |
-
from tkinter import Tk
|
| 6 |
-
import tkinter as tk
|
| 7 |
|
| 8 |
|
| 9 |
node = Node()
|
|
@@ -30,35 +28,8 @@ with keyboard.Events() as events:
|
|
| 30 |
if event is not None and isinstance(event, Events.Press):
|
| 31 |
if hasattr(event.key, "char"):
|
| 32 |
cursor = 0
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
r.update()
|
| 36 |
-
try:
|
| 37 |
-
selection = r.clipboard_get()
|
| 38 |
-
r.withdraw()
|
| 39 |
-
r.update()
|
| 40 |
-
except tk.TclError:
|
| 41 |
-
selection = ""
|
| 42 |
-
r.destroy()
|
| 43 |
-
buffer_text += selection
|
| 44 |
-
node.send_output("buffer", pa.array([buffer_text]))
|
| 45 |
-
elif ctrl and event.key.char == "c":
|
| 46 |
-
r = Tk()
|
| 47 |
-
r.clipboard_clear()
|
| 48 |
-
r.clipboard_append(buffer_text)
|
| 49 |
-
r.update()
|
| 50 |
-
r.destroy()
|
| 51 |
-
elif ctrl and event.key.char == "x":
|
| 52 |
-
r = Tk()
|
| 53 |
-
r.clipboard_clear()
|
| 54 |
-
r.clipboard_append(buffer_text)
|
| 55 |
-
r.update()
|
| 56 |
-
r.destroy()
|
| 57 |
-
buffer_text = ""
|
| 58 |
-
node.send_output("buffer", pa.array([buffer_text]))
|
| 59 |
-
else:
|
| 60 |
-
buffer_text += event.key.char
|
| 61 |
-
node.send_output("buffer", pa.array([buffer_text]))
|
| 62 |
else:
|
| 63 |
if event.key == Key.backspace:
|
| 64 |
buffer_text = buffer_text[:-1]
|
|
|
|
| 2 |
from pynput.keyboard import Key, Events
|
| 3 |
import pyarrow as pa
|
| 4 |
from dora import Node
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
node = Node()
|
|
|
|
| 28 |
if event is not None and isinstance(event, Events.Press):
|
| 29 |
if hasattr(event.key, "char"):
|
| 30 |
cursor = 0
|
| 31 |
+
buffer_text += event.key.char
|
| 32 |
+
node.send_output("buffer", pa.array([buffer_text]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
else:
|
| 34 |
if event.key == Key.backspace:
|
| 35 |
buffer_text = buffer_text[:-1]
|
operators/llm_op.py
CHANGED
|
@@ -13,7 +13,7 @@ MODEL_NAME_OR_PATH = "TheBloke/deepseek-coder-6.7B-instruct-GPTQ"
|
|
| 13 |
|
| 14 |
CODE_MODIFIER_TEMPLATE = """
|
| 15 |
### Instruction
|
| 16 |
-
Respond with the
|
| 17 |
|
| 18 |
```python
|
| 19 |
{code}
|
|
@@ -318,19 +318,19 @@ if __name__ == "__main__":
|
|
| 318 |
# Directory of the current file
|
| 319 |
current_directory = os.path.dirname(current_file_path)
|
| 320 |
|
| 321 |
-
path = current_directory + "
|
| 322 |
with open(path, "r", encoding="utf8") as f:
|
| 323 |
raw = f.read()
|
| 324 |
|
| 325 |
op.on_event(
|
| 326 |
{
|
| 327 |
"type": "INPUT",
|
| 328 |
-
"id": "
|
| 329 |
"value": pa.array(
|
| 330 |
[
|
| 331 |
{
|
| 332 |
"path": path,
|
| 333 |
-
"user_message": "
|
| 334 |
},
|
| 335 |
]
|
| 336 |
),
|
|
|
|
| 13 |
|
| 14 |
CODE_MODIFIER_TEMPLATE = """
|
| 15 |
### Instruction
|
| 16 |
+
Respond with the modified code only in ```python block. No explaination.
|
| 17 |
|
| 18 |
```python
|
| 19 |
{code}
|
|
|
|
| 318 |
# Directory of the current file
|
| 319 |
current_directory = os.path.dirname(current_file_path)
|
| 320 |
|
| 321 |
+
path = current_directory + "/planning_op.py"
|
| 322 |
with open(path, "r", encoding="utf8") as f:
|
| 323 |
raw = f.read()
|
| 324 |
|
| 325 |
op.on_event(
|
| 326 |
{
|
| 327 |
"type": "INPUT",
|
| 328 |
+
"id": "code_modifier",
|
| 329 |
"value": pa.array(
|
| 330 |
[
|
| 331 |
{
|
| 332 |
"path": path,
|
| 333 |
+
"user_message": "change planning to make gimbal follow bounding box ",
|
| 334 |
},
|
| 335 |
]
|
| 336 |
),
|
operators/object_detection.py
CHANGED
|
@@ -27,8 +27,7 @@ class Operator:
|
|
| 27 |
dora_event["value"].to_numpy().reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3))
|
| 28 |
)
|
| 29 |
frame = frame[:, :, ::-1] # OpenCV image (BGR to RGB)
|
| 30 |
-
results =
|
| 31 |
-
# Process results for "ABC" only
|
| 32 |
boxes = np.array(results[0].boxes.xyxy.cpu())
|
| 33 |
conf = np.array(results[0].boxes.conf.cpu())
|
| 34 |
label = np.array(results[0].boxes.cls.cpu())
|
|
|
|
| 27 |
dora_event["value"].to_numpy().reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3))
|
| 28 |
)
|
| 29 |
frame = frame[:, :, ::-1] # OpenCV image (BGR to RGB)
|
| 30 |
+
results = model(frame, verbose=False) # includes NMS
|
|
|
|
| 31 |
boxes = np.array(results[0].boxes.xyxy.cpu())
|
| 32 |
conf = np.array(results[0].boxes.conf.cpu())
|
| 33 |
label = np.array(results[0].boxes.cls.cpu())
|
operators/planning_op.py
CHANGED
|
@@ -3,22 +3,10 @@ import numpy as np
|
|
| 3 |
import pyarrow as pa
|
| 4 |
from dora import DoraStatus
|
| 5 |
|
| 6 |
-
# front-back:
|
| 7 |
-
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
SPEED = 0.5
|
| 11 |
-
Z = 0
|
| 12 |
-
# pitch-axis angle in degrees(int): [-55, 55]
|
| 13 |
-
PITCH = 0
|
| 14 |
-
# yaw-axis angle in degrees(int): [-55, 55]
|
| 15 |
-
ROTATION = 0
|
| 16 |
-
# RGB LED(int) [0, 255]
|
| 17 |
-
RGB = [0, 0, 0]
|
| 18 |
-
BRIGHTNESS = [0] # [0, 128]
|
| 19 |
-
|
| 20 |
-
GOAL_OBJECTIVES = [X, Y, Z]
|
| 21 |
-
GIMBAL_POSITION_GOAL = [PITCH, ROTATION]
|
| 22 |
|
| 23 |
CAMERA_WIDTH = 960
|
| 24 |
CAMERA_HEIGHT = 540
|
|
@@ -26,7 +14,7 @@ CAMERA_HEIGHT = 540
|
|
| 26 |
|
| 27 |
class Operator:
|
| 28 |
def __init__(self):
|
| 29 |
-
self.bboxs = []
|
| 30 |
self.time = time.time()
|
| 31 |
self.position = [0, 0, 0]
|
| 32 |
|
|
@@ -35,35 +23,34 @@ class Operator:
|
|
| 35 |
dora_event: dict,
|
| 36 |
send_output,
|
| 37 |
) -> DoraStatus:
|
| 38 |
-
global
|
| 39 |
if dora_event["type"] == "INPUT":
|
| 40 |
-
|
|
|
|
| 41 |
self.time = time.time()
|
| 42 |
-
elif
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
direction = np.clip(
|
| 50 |
-
np.array(
|
| 51 |
)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
send_output(
|
| 59 |
-
"control",
|
| 60 |
-
pa.array([x, y, z]),
|
| 61 |
-
dora_event["metadata"],
|
| 62 |
-
)
|
| 63 |
|
| 64 |
send_output(
|
| 65 |
"gimbal_control",
|
| 66 |
-
pa.array(
|
| 67 |
dora_event["metadata"],
|
| 68 |
)
|
| 69 |
|
|
|
|
| 3 |
import pyarrow as pa
|
| 4 |
from dora import DoraStatus
|
| 5 |
|
| 6 |
+
# front-back and left-right movement(float) with min: -1 and max: 1
|
| 7 |
+
POSITION_GOAL = [0, 0]
|
| 8 |
+
# pitch and yaw axis angle in degrees(int) with min: -55 and max: 55
|
| 9 |
+
GIMBAL_GOAL = [0, 0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
CAMERA_WIDTH = 960
|
| 12 |
CAMERA_HEIGHT = 540
|
|
|
|
| 14 |
|
| 15 |
class Operator:
|
| 16 |
def __init__(self):
|
| 17 |
+
self.bboxs = np.array([])
|
| 18 |
self.time = time.time()
|
| 19 |
self.position = [0, 0, 0]
|
| 20 |
|
|
|
|
| 23 |
dora_event: dict,
|
| 24 |
send_output,
|
| 25 |
) -> DoraStatus:
|
| 26 |
+
global POSITION_GOAL, GIMBAL_GOAL
|
| 27 |
if dora_event["type"] == "INPUT":
|
| 28 |
+
id = dora_event["id"]
|
| 29 |
+
if id == "tick":
|
| 30 |
self.time = time.time()
|
| 31 |
+
elif id == "bbox":
|
| 32 |
+
value = dora_event["value"].to_numpy()
|
| 33 |
+
bboxs = value
|
| 34 |
+
self.bboxs = np.reshape(
|
| 35 |
+
bboxs, (-1, 6)
|
| 36 |
+
) # min_x, min_y, max_x, max_y, confidence, label
|
| 37 |
+
elif id == "position":
|
| 38 |
+
value = dora_event["value"].to_numpy()
|
| 39 |
+
[x, y, _pitch, _yaw] = value
|
| 40 |
+
self.position = [x, y]
|
| 41 |
direction = np.clip(
|
| 42 |
+
np.array(POSITION_GOAL) - np.array(self.position), -1, 1
|
| 43 |
)
|
| 44 |
|
| 45 |
+
send_output(
|
| 46 |
+
"control",
|
| 47 |
+
pa.array(direction),
|
| 48 |
+
dora_event["metadata"],
|
| 49 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
send_output(
|
| 52 |
"gimbal_control",
|
| 53 |
+
pa.array(GIMBAL_GOAL),
|
| 54 |
dora_event["metadata"],
|
| 55 |
)
|
| 56 |
|
operators/plot.py
CHANGED
|
@@ -63,17 +63,30 @@ class Operator:
|
|
| 63 |
(0, 255, 0),
|
| 64 |
)
|
| 65 |
|
| 66 |
-
cv2.putText(
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
cv2.putText(
|
| 70 |
image,
|
| 71 |
text["content"],
|
| 72 |
-
(
|
|
|
|
|
|
|
|
|
|
| 73 |
FONT,
|
|
|
|
|
|
|
| 74 |
1,
|
| 75 |
-
(0, 255, 190),
|
| 76 |
)
|
|
|
|
| 77 |
|
| 78 |
for line in self.lines:
|
| 79 |
cv2.line(
|
|
|
|
| 63 |
(0, 255, 0),
|
| 64 |
)
|
| 65 |
|
| 66 |
+
cv2.putText(
|
| 67 |
+
image, self.buffer, (20, 14 + 21 * 14), FONT, 0.5, (190, 250, 0), 1
|
| 68 |
+
)
|
| 69 |
|
| 70 |
+
i = 0
|
| 71 |
+
for text in self.submitted[::-1]:
|
| 72 |
+
color = (
|
| 73 |
+
(0, 255, 190)
|
| 74 |
+
if text["role"] == "user_message"
|
| 75 |
+
else (0, 190, 255)
|
| 76 |
+
)
|
| 77 |
cv2.putText(
|
| 78 |
image,
|
| 79 |
text["content"],
|
| 80 |
+
(
|
| 81 |
+
20,
|
| 82 |
+
14 + (19 - i) * 14,
|
| 83 |
+
),
|
| 84 |
FONT,
|
| 85 |
+
0.5,
|
| 86 |
+
color,
|
| 87 |
1,
|
|
|
|
| 88 |
)
|
| 89 |
+
i += 1
|
| 90 |
|
| 91 |
for line in self.lines:
|
| 92 |
cv2.line(
|
operators/robot.py
CHANGED
|
@@ -1,16 +1,11 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
# -*- coding: utf-8 -*-
|
| 3 |
-
|
| 4 |
from robomaster import robot, blaster, led
|
| 5 |
from typing import Callable, Optional, Union
|
| 6 |
|
| 7 |
-
|
| 8 |
import pyarrow as pa
|
| 9 |
|
| 10 |
from dora import DoraStatus
|
| 11 |
|
| 12 |
-
# Global variables, change it to adapt your needs
|
| 13 |
-
FREQ = 20
|
| 14 |
CONN = "ap"
|
| 15 |
|
| 16 |
|
|
@@ -24,7 +19,7 @@ class Operator:
|
|
| 24 |
), "Could not start video stream"
|
| 25 |
|
| 26 |
self.ep_robot.gimbal.recenter().wait_for_completed()
|
| 27 |
-
self.position = [0, 0
|
| 28 |
self.gimbal_position = [0, 0]
|
| 29 |
self.event = None
|
| 30 |
self.brightness = 0
|
|
@@ -49,13 +44,15 @@ class Operator:
|
|
| 49 |
self.event is not None
|
| 50 |
and not (self.event._event.isSet() and self.event.is_completed)
|
| 51 |
):
|
| 52 |
-
[x, y
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
print("control not completed", flush=True)
|
| 61 |
print("Set: ", self.event._event.isSet(), flush=True)
|
|
@@ -75,8 +72,8 @@ class Operator:
|
|
| 75 |
self.event = self.ep_robot.gimbal.moveto(
|
| 76 |
pitch=gimbal_pitch,
|
| 77 |
yaw=gimbal_yaw,
|
| 78 |
-
pitch_speed=
|
| 79 |
-
yaw_speed=
|
| 80 |
)
|
| 81 |
self.gimbal_position[0] = gimbal_pitch
|
| 82 |
self.gimbal_position[1] = gimbal_yaw
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from robomaster import robot, blaster, led
|
| 2 |
from typing import Callable, Optional, Union
|
| 3 |
|
| 4 |
+
import numpy as np
|
| 5 |
import pyarrow as pa
|
| 6 |
|
| 7 |
from dora import DoraStatus
|
| 8 |
|
|
|
|
|
|
|
| 9 |
CONN = "ap"
|
| 10 |
|
| 11 |
|
|
|
|
| 19 |
), "Could not start video stream"
|
| 20 |
|
| 21 |
self.ep_robot.gimbal.recenter().wait_for_completed()
|
| 22 |
+
self.position = [0, 0]
|
| 23 |
self.gimbal_position = [0, 0]
|
| 24 |
self.event = None
|
| 25 |
self.brightness = 0
|
|
|
|
| 44 |
self.event is not None
|
| 45 |
and not (self.event._event.isSet() and self.event.is_completed)
|
| 46 |
):
|
| 47 |
+
[x, y] = dora_event["value"].to_numpy()
|
| 48 |
+
|
| 49 |
+
if any(abs(np.array([x, y])) > 0.1):
|
| 50 |
+
print("received command: ", x, y, flush=True)
|
| 51 |
+
self.event = self.ep_robot.chassis.move(
|
| 52 |
+
x=x, y=y, z=0.0, xy_speed=0.8, z_speed=0.8
|
| 53 |
+
)
|
| 54 |
+
self.position[0] += x
|
| 55 |
+
self.position[1] += y
|
| 56 |
else:
|
| 57 |
print("control not completed", flush=True)
|
| 58 |
print("Set: ", self.event._event.isSet(), flush=True)
|
|
|
|
| 72 |
self.event = self.ep_robot.gimbal.moveto(
|
| 73 |
pitch=gimbal_pitch,
|
| 74 |
yaw=gimbal_yaw,
|
| 75 |
+
pitch_speed=50,
|
| 76 |
+
yaw_speed=50,
|
| 77 |
)
|
| 78 |
self.gimbal_position[0] = gimbal_pitch
|
| 79 |
self.gimbal_position[1] = gimbal_yaw
|