forked from phospho-app/phosphobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquare_relative.py
More file actions
56 lines (46 loc) · 1.6 KB
/
Copy pathsquare_relative.py
File metadata and controls
56 lines (46 loc) · 1.6 KB
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
import time
import requests
# Configurations
PI_IP: str = "127.0.0.1"
PI_PORT: int = 80
NUMBER_OF_SQUARES: int = 100
# Function to call the API
def call_to_api(endpoint: str, data: dict = {}):
response = requests.post(f"http://{PI_IP}:{PI_PORT}/move/{endpoint}", json=data)
return response.json()
# Example code to move the robot in a square of 4 cm x 4 cm
# 1 - Initialize the robot
call_to_api("init")
print("Initializing robot")
time.sleep(2)
# We move it to the top left corner of the square
call_to_api("relative", {"x": 0, "y": -3, "z": 3, "rx": 0, "ry": 0, "rz": 0, "open": 0})
print("Moving to top left corner")
time.sleep(0.2)
# With the move relative endpoint, we can move relative to its current position
# 2 - We make the robot follow a 3 cm x 3 cm square
for _ in range(NUMBER_OF_SQUARES):
# Move to the top right corner
call_to_api(
"relative", {"x": 0, "y": 3, "z": 0, "rx": 0, "ry": 0, "rz": 0, "open": 0}
)
print("Moving to top right corner")
time.sleep(0.2)
# Move to the bottom right corner
call_to_api(
"relative", {"x": 0, "y": 0, "z": -3, "rx": 0, "ry": 0, "rz": 0, "open": 0}
)
print("Moving to bottom right corner")
time.sleep(0.2)
# Move to the bottom left corner
call_to_api(
"relative", {"x": 0, "y": -3, "z": 0, "rx": 0, "ry": 0, "rz": 0, "open": 0}
)
print("Moving to bottom left corner")
time.sleep(0.2)
# Move to the top left corner
call_to_api(
"relative", {"x": 0, "y": 0, "z": 3, "rx": 0, "ry": 0, "rz": 0, "open": 0}
)
print("Moving to top left corner")
time.sleep(0.2)