forked from wemakewaves/PyRow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strokelog.py
executable file
·72 lines (55 loc) · 2.31 KB
/
strokelog.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
#!/usr/bin/env python
#Copyright (c) 2011, Sam Gambrell
#Licensed under the Simplified BSD License.
#This is an example file to show how to make use of pyrow
#Have the rowing machine on and plugged into the computer before starting the program
#The program will record Time, Distance, SPM, Pace, and Force Data for each
#stroke and save it to 'workout.csv'
#NOTE: This code has not been thoroughly tested and may not function as advertised.
#Please report and findings to the author so that they may be addressed in a stable release.
import pyrow
import time
if __name__ == '__main__':
#Connecting to erg
ergs = list(pyrow.find())
if len(ergs) == 0:
exit("No ergs found.")
erg = pyrow.pyrow(ergs[0])
print "Connected to erg."
#Open and prepare file
write_file = open('workout.csv', 'w')
write_file.write('Time, Distance, SPM, Pace, Force Plot\n')
#Loop until workout has begun
workout = erg.get_workout()
print "Waiting for workout to start ..."
while workout['state'] == 0:
time.sleep(1)
workout = erg.get_workout()
print "Workout has begun"
#Loop until workout ends
while workout['state'] == 1:
forceplot = erg.get_force_plot()
#Loop while waiting for drive
while forceplot['strokestate'] != 2 and workout['state'] == 1:
#ToDo: sleep?
forceplot = erg.get_force_plot()
workout = erg.get_workout()
#Record force data during the drive
force = forceplot['forceplot'] #start of pull (when strokestate first changed to 2)
monitor = erg.get_monitor() #get monitor data for start of stroke
#Loop during drive
while forceplot['strokestate'] == 2:
#ToDo: sleep?
forceplot = erg.get_force_plot()
force.extend(forceplot['forceplot'])
forceplot = erg.get_force_plot()
force.extend(forceplot['forceplot'])
#Write data to write_file
workoutdata = str(monitor['time']) + "," + str(monitor['distance']) + "," + \
str(monitor['spm']) + "," + str(monitor['pace']) + ","
forcedata = ",".join([str(f) for f in force])
write_file.write(workoutdata + forcedata + '\n')
#Get workout conditions
workout = erg.get_workout()
write_file.close()
print "Workout has ended"