forked from Smehnov/hackathon-spot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
90 lines (67 loc) · 2.71 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import wave
import sys
import pyaudio
file_name = "file_example_WAV_1MG.wav"
CHUNK = 1024
with wave.open(file_name, 'rb') as wf:
# Instantiate PyAudio and initialize PortAudio system resources (1)
p = pyaudio.PyAudio()
print(p.get_host_api_count())
print()
# Open stream (2)
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
# Play samples from the wave file (3)
while len(data := wf.readframes(CHUNK)): # Requires Python 3.8+ for :=
stream.write(data)
# Close stream (4)
stream.close()
# Release PortAudio system resources (5)
p.terminate()
# 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()