/
mistyrest.py
executable file
·66 lines (53 loc) · 2.02 KB
/
mistyrest.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
#!/usr/bin/env python
"""Demo of changing face on Misty II via rerobots API
Besides standard Python libraries, this example code requires
`requests` (https://pypi.org/project/requests/).
This is free software, released under the Apache License, Version 2.0.
You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
Copyright (c) 2019 rerobots, Inc.
"""
import time
import requests
# TODO: put here the https URL from the "Misty robot proxy" panel of
# your instance details page under https://rerobots.net/instances
#
# For example,
#
# MPURL = 'https://proxy.rerobots.net/7947941869cbaf5e8bc75d80fd7ea8307ec67f16ee84c1043dcbeae85aaf3d28/mistyproxy/5de82c965c7544e25321b5323e5f72e841c74a7c6f5ae25015ddaaaee26d9fdd'
MPURL = ''
# Change the color of the chest LED to green
# https://docs.mistyrobotics.com/misty-ii/web-api/api-reference/#changeled
res = requests.post(MPURL + '/api/led', json={
'red': 0,
'green': 255,
'blue': 0,
})
assert res.ok, 'response from POST /api/led: {} {}'.format(res.status_code, res.reason)
# Tilt the head forward
# https://docs.mistyrobotics.com/misty-ii/web-api/api-reference/#movehead
res = requests.post(MPURL + '/api/head', json={
'Pitch': 20,
'Roll': 0,
'Yaw': 0,
'Velocity': 3,
})
assert res.ok, 'response from POST /api/head: {} {}'.format(res.status_code, res.reason)
# Sleep for 5 seconds to allow more time for human to observe results
time.sleep(5)
# Tilt the head back
# https://docs.mistyrobotics.com/misty-ii/web-api/api-reference/#movehead
res = requests.post(MPURL + '/api/head', json={
'Pitch': 0,
'Roll': 0,
'Yaw': 0,
'Velocity': 3,
})
assert res.ok, 'response from POST /api/head: {} {}'.format(res.status_code, res.reason)
# Change the color of the chest LED to purple
# https://docs.mistyrobotics.com/misty-ii/web-api/api-reference/#changeled
res = requests.post(MPURL + '/api/led', json={
'red': 255,
'green': 0,
'blue': 255,
})
assert res.ok, 'response from POST /api/led: {} {}'.format(res.status_code, res.reason)