-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
52 lines (41 loc) · 1.75 KB
/
utils.py
File metadata and controls
52 lines (41 loc) · 1.75 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
import json
class ApiResponse:
def __init__(self, status, body):
self.__status = status
self.__body = body
def to_json(self):
return json.dumps(self.__body), self.__status
def parse_movel_instruction(coordinates_and_angles, acceleration, velocity, pose_object, relative):
if pose_object:
instruction = f"movel(p{str(coordinates_and_angles)}, {acceleration}, {velocity}"
else:
instruction = f"movel({str(coordinates_and_angles)}, {acceleration}, {velocity}"
if relative:
instruction = instruction + ", relative=True)\n"
else:
instruction = instruction + ")\n"
encoded_instruction = instruction.encode("utf-8")
return encoded_instruction
def parse_movej_instruction(joint_positions, acceleration, velocity, position, relative):
if position:
instruction = f"movej(p{str(joint_positions)}, {acceleration}, {velocity})\n"
else:
instruction = f"movej({str(joint_positions)}, {acceleration}, {velocity})\n"
if relative:
instruction = instruction + ", relative=True)\n"
else:
instruction = instruction + ")\n"
encoded_instruction = instruction.encode("utf-8")
return encoded_instruction
def get_acceleration_and_velocity_to_use(acceleration, velocity, default_acceleration, default_velocity):
acceleration = default_acceleration if acceleration is None else acceleration
velocity = default_velocity if velocity is None else velocity
return acceleration, velocity
def validate_json_structure(request):
if not request.is_json:
raise AttributeError("Invalid body, must be a JSON")
else:
try:
request.json
except Exception:
raise AttributeError("Invalid body, must be a JSON")