-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharm_viz.py
80 lines (60 loc) · 2.18 KB
/
arm_viz.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
import pygame
from math import sin, cos, radians
import process_wpilib_logs
BASE_ARM_LENGTH = 200
WIDTH = 800
HEIGHT = 800
# state variables
arm_length_ = 0
arm_tilt_ = 0
intake_tilt_ = 0
pygame.init()
# R, G, B
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)
LIGHT_BLUE = (100, 100, 255)
# create our hardware surface object
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# set the title for the window
pygame.display.set_caption("ArmViz v 0.2")
# go ahead and clear window
screen.fill(WHITE)
# make ourselves a font for displaying text
font = pygame.font.Font(None, 48)
# make ourselves a clock as well
clock = pygame.time.Clock()
print(len(process_wpilib_logs.liftEncLog[1]))
index = 0
frame = 0
# search for where the setpoint changes (where things actually start to happen)
for idx, setpoint in enumerate(process_wpilib_logs.liftSetpointLog[1]):
if setpoint != 0:
index = idx
break
# main loop
while True:
screen.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
#TODO
length_setpoint_ = BASE_ARM_LENGTH + process_wpilib_logs.extendSetpointLog[1][index]
arm_length_ = BASE_ARM_LENGTH + process_wpilib_logs.extendEncLog[1][index]
# draw the setpoint
setpoint_x = sin(radians(process_wpilib_logs.liftSetpointLog[1][index])) * length_setpoint_ + WIDTH//2
setpoint_y = cos(radians(process_wpilib_logs.liftSetpointLog[1][index])) * length_setpoint_ + HEIGHT//2
pygame.draw.line(screen, LIGHT_BLUE, (WIDTH//2, HEIGHT//2), (setpoint_x, setpoint_y), 20)
# draw the current arm tilt from the middle of the window with a length of BASE_ARM_LENGTH, and a width of 10
x = sin(radians(process_wpilib_logs.liftEncLog[1][index])) * arm_length_ + WIDTH//2
y = cos(radians(process_wpilib_logs.liftEncLog[1][index])) * arm_length_ + HEIGHT//2
pygame.draw.line(screen, BLUE, (WIDTH//2, HEIGHT//2), (x, y), 15)
# advance the time once every 2 frames
frame += 1
if frame % 1 == 0:
index += 1
pygame.display.flip()
clock.tick(60)
# if process_wpilib_logs.liftEncLog[0][index] > 200:
# raise SystemExit