-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdce_testing.py
More file actions
99 lines (76 loc) · 2.72 KB
/
dce_testing.py
File metadata and controls
99 lines (76 loc) · 2.72 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
#TODO: Update docustring
"""
A module written to to test custom BCT DCE control code
"""
"""
STUFF TO DO (FOR SIMON)
-Fix errors (see screenshot from 3/13)
-Formatting experiment timestep files and making more than one
-figure out how to clean up logging in general to have less events
"""
from datetime import date
from Logs.log import log
from dce_control import *
from time import sleep
from imu_control import *
__author__="Simon Kowerski"
__credits__=["Simon Kowerski"]
__creation_date__="8/8/2024"
spin = True # If true, the wheel will spin
spinning = False # Keeps track of if the wheel is currently spinninng. Should be false at compile time
kill = False # If set to true, will simply connect to the wheel and set its speed to zero and then end
imu_data_points = 80 # Number of times to read and print imu data for each direction
time_each_dir = 20 # Time delay (in seconds) before switching wheel torque
__gExpLogPath="Logs/ExpLogs/"
try:
log(0)
dce_startup()
filename = f"{str(date.today())}_{str(time.localtime().tm_hour)}-{str(time.localtime().tm_min)}.explog"
file = open(f"{__gExpLogPath}{filename}", "w")
file.write("DCE Testing IMU Outputs\n")
if kill:
set_wheel_speed(1,0)
else:
global yaw0, imu, yawOld
yaw0,imu=init_imu()
yawOld=0
if spin:
set_wheel_torque(1,1)
spinning = True
print("Full Positive Torque")
for i in range(imu_data_points):
yaw,pitch,roll=imu_data(imu,yaw0,yawOld)
file.write(f"{i} yaw: {yaw}\tpitch: {pitch}\troll: {roll}\n")
sleep(time_each_dir/imu_data_points)
file.write(f"\n\n SWITCHING DIRECTIONS \n\n");
set_wheel_torque(1,-1)
print("\nFull Negative Torque")
for x in range(imu_data_points):
yaw,pitch,roll=imu_data(imu,yaw0,yawOld)
file.write(f"{x} yaw: {yaw}\tpitch: {pitch}\troll: {roll}\n")
sleep(time_each_dir/imu_data_points)
output=read_data("Torque")
print("torque")
print(output[0])
print(output[1])
print(output[2])
print()
output=read_data("SPEED")
print("speed")
print(output[0])
print(output[1])
print(output[2])
print()
if spin:
set_wheel_speed(1, 0)
spinning = False
log(1)
except ERROR:
if spin and spinning:
set_wheel_speed(1, 0)
log(2)
except Exception:
if spin and spinning:
set_wheel_speed(1, 0)
raise ERROR(1000)