forked from merklebot/hackathon-arm-image
-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.py
57 lines (45 loc) · 1.88 KB
/
main.py
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
import os
import time
from spot_controller import SpotController
import cv2
ROBOT_IP = "10.0.0.3"#os.environ['ROBOT_IP']
SPOT_USERNAME = "admin"#os.environ['SPOT_USERNAME']
SPOT_PASSWORD = "2zqa8dgw7lor"#os.environ['SPOT_PASSWORD']
def capture_image():
camera_capture = cv2.VideoCapture(0)
rv, image = camera_capture.read()
print(f"Image Dimensions: {image.shape}")
camera_capture.release()
cv2.imwrite(f'/merklebot/job_data/camera_{time.time()}.jpg', image)
def main():
#example of using micro and speakers
print("Start recording audio")
sample_name = "aaaa.wav"
cmd = f'arecord -vv --format=cd --device={os.environ["AUDIO_INPUT_DEVICE"]} -r 48000 --duration=10 -c 1 {sample_name}'
print(cmd)
os.system(cmd)
print("Playing sound")
os.system(f"ffplay -nodisp -autoexit -loglevel quiet {sample_name}")
# # Capture image
# Use wrapper in context manager to lease control, turn on E-Stop, power on the robot and stand up at start
# and to return lease + sit down at the end
with SpotController(username=SPOT_USERNAME, password=SPOT_PASSWORD, robot_ip=ROBOT_IP) as spot:
time.sleep(2)
capture_image()
# Move head to specified positions with intermediate time.sleep
spot.move_head_in_points(yaws=[0.2, 0],
pitches=[0.3, 0],
rolls=[0.4, 0],
sleep_after_point_reached=1)
capture_image()
time.sleep(3)
# Make Spot to move by goal_x meters forward and goal_y meters left
spot.move_to_goal(goal_x=0.5, goal_y=0)
time.sleep(3)
capture_image()
# Control Spot by velocity in m/s (or in rad/s for rotation)
spot.move_by_velocity_control(v_x=-0.3, v_y=0, v_rot=0, cmd_duration=2)
capture_image()
time.sleep(3)
if __name__ == '__main__':
main()