-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
86 lines (82 loc) · 2.58 KB
/
utils.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
import pygame
from controllers.robot_cbf import RobotCBF
def draw_robot(
screen: pygame.Surface,
robot: RobotCBF,
draw_filtered_command: bool = False,
color1: tuple = (175, 175, 175),
color2: tuple = (255, 0, 0),
arrow_size: int = 10,
):
pygame.draw.circle(screen, robot.color, (robot.x, robot.y), robot.size)
# draw arrows
if robot.ux != 0:
pygame.draw.line(
screen,
color1,
(robot.x, robot.y),
(robot.x + 20 * robot.nominal_ux, robot.y),
width=10,
)
pygame.draw.polygon(
screen,
color1,
[
(robot.x + 20 * robot.nominal_ux, robot.y + arrow_size),
(robot.x + 20 * robot.nominal_ux, robot.y - arrow_size),
(robot.x + (arrow_size + 20) * robot.nominal_ux, robot.y),
],
)
if robot.uy != 0:
pygame.draw.line(
screen,
color1,
(robot.x, robot.y),
(robot.x, robot.y + 20 * robot.nominal_uy),
width=10,
)
pygame.draw.polygon(
screen,
color1,
[
(robot.x + arrow_size, robot.y + 20 * robot.nominal_uy),
(robot.x - arrow_size, robot.y + 20 * robot.nominal_uy),
(robot.x, robot.y + (arrow_size + 20) * robot.nominal_uy),
],
)
# draw output of safety filter
if draw_filtered_command:
if robot.ux != 0:
pygame.draw.line(
screen,
color2,
(robot.x, robot.y),
(robot.x + 20 * robot.ux, robot.y),
width=10,
)
pygame.draw.polygon(
screen,
color2,
[
(robot.x + 20 * robot.ux, robot.y + arrow_size),
(robot.x + 20 * robot.ux, robot.y - arrow_size),
(robot.x + (arrow_size + 20) * robot.ux, robot.y),
],
)
if robot.uy != 0:
pygame.draw.line(
screen,
color2,
(robot.x, robot.y),
(robot.x, robot.y + 20 * robot.uy),
width=10,
)
pygame.draw.polygon(
screen,
color2,
[
(robot.x + arrow_size, robot.y + 20 * robot.uy),
(robot.x - arrow_size, robot.y + 20 * robot.uy),
(robot.x, robot.y + (arrow_size + 20) * robot.uy),
],
)