File size: 2,350 Bytes
1646f18 533dd7a 1646f18 533dd7a 1646f18 533dd7a 1646f18 533dd7a |
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 |
from robomaster import robot
from time import sleep
from dora import Node
import numpy as np
import pyarrow as pa
def wait(event):
if event is not None and not (event._event.isSet() and event.is_completed):
sleep(1)
ep_robot = robot.Robot()
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"
ep_robot.gimbal.recenter().wait_for_completed()
node = Node()
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
|