| 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 |
|
|