|
from robomaster import robot, led |
|
|
|
from dora import Node |
|
from time import sleep |
|
import numpy as np |
|
import pyarrow as pa |
|
|
|
|
|
CONN = "ap" |
|
|
|
|
|
ep_robot = robot.Robot() |
|
print("Initializing robot...", flush=True) |
|
assert ep_robot.initialize(conn_type=CONN), "Could not initialize ep_robot" |
|
assert ep_robot.camera.start_video_stream(display=False), "Could not start video stream" |
|
|
|
node = Node() |
|
ep_robot.gimbal.recenter().wait_for_completed() |
|
backlog = [] |
|
last_control = "" |
|
position = np.array([0.0, 0.0, 0.0]) |
|
count = -1 |
|
event = None |
|
rgb = [0, 0, 0] |
|
|
|
|
|
def wait(event): |
|
if event is not None and not (event._event.isSet() and event.is_completed): |
|
sleep(1) |
|
|
|
|
|
for dora_event in node: |
|
event_type = dora_event["type"] |
|
if event_type == "INPUT": |
|
if dora_event["id"] == "tick": |
|
node.send_output("position", pa.array(position)) |
|
node.send_output("control_reply", pa.array([count])) |
|
|
|
elif dora_event["id"] == "planning_control": |
|
[x, y, z, xy_speed, z_speed, pitch, yaw, count] = dora_event[ |
|
"value" |
|
].to_numpy() |
|
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 |
|
) |
|
position = position + np.array([x, y, z]) |
|
wait(event) |
|
sleep(6) |
|
|
|
elif dora_event["id"] == "led": |
|
[r, g, b] = dora_event["value"].to_numpy() |
|
rgb = [r, g, b] |
|
if rgb != rgb: |
|
ep_robot.led.set_led( |
|
comp=led.COMP_ALL, r=r, g=g, b=b, effect=led.EFFECT_ON |
|
) |
|
rgb = rgb |
|
|