-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDTPCF.lua
More file actions
163 lines (138 loc) · 5.29 KB
/
DTPCF.lua
File metadata and controls
163 lines (138 loc) · 5.29 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
print("Program to collect voltage measurements from strain gauges. Using LJLogM instead is recommended")
print("Logs voltages from AIN0-AIN13 to file.")
print("Updating to write to new file every 24 hrs")
--Requires SD Card installed inside the T7 or T7-Pro.
--Requires FW 1.0150 or newer. On older firmware the file must exist already on the SD card
--Older firmware uses "assert" command: file=assert(io.open(Filename, "w"))
local hardware = MB.R(60010, 1)
if(bit.band(hardware, 8) ~= 8) then
print("uSD card not detected")
MB.W(6000, 1, 0)--stop script
end
local mbRead=MB.R --local functions for faster processing
local mbReadArray=MB.RA
--local Filename = "/log21.csv" --set name of file to create on SD card
-- local fileInterval = 20000 --hour in ms
local timeCount = 0
local maxTime = 720 --num 5 sec intervals in one hour
local dataInterval = 5000 --sampeling freq -- every 5 sec
local countX = 0
local count = 991
local voltage0 = 0
local voltage1 = 0
local voltage2 = 0
local voltage3 = 0
local voltage4 = 0
local voltage5 = 0
local voltage6 = 0
local voltage7 = 0
local voltage8 = 0
local voltage9 = 0
local voltage10 = 0
local voltage11 = 0
local voltage12 = 0
local voltage13 = 0
local voltageStr0 = ""
local voltageStr1 = ""
local voltageStr2 = ""
local voltageStr3 = ""
local voltageStr4 = ""
local voltageStr5 = ""
local voltageStr6 = ""
local voltageStr7 = ""
local voltageStr8 = ""
local voltageStr9 = ""
local voltageStr10 = ""
local voltageStr11 = ""
local voltageStr12 = ""
local voltageStr13 = ""
local delimiter = ","
local timeStamp = ""
local Filepre = "/testLog"
local Filesuf = ".csv"
local Filename = "/testLog00.csv"
local file = io.open(Filename, "w") --create and open file for write access
-- Make sure that the file was opened properly.
if file then
print("Opened File on uSD Card")
else
-- If the file was not opened properly we probably have a bad SD card.
print("!! Failed to open file on uSD Card !!")
end
MB.W(48005, 0, 1) --ensure analog is on
LJ.IntervalConfig(0, dataInterval) --set interval
local checkInterval=LJ.CheckInterval
while true do
if (timeCount == maxTime) then
--make a new file
print("new file")
fg = LJ.CheckFileFlag()
countX = countX + 1 --increment filename
Filename = Filepre..string.format("%02d", countX)..Filesuf
file:close()
LJ.ClearFileFlag() --inform host that previous file is available.
file = io.open(Filename, "w") --create or replace a new file
timeCount = 0
end
if checkInterval(0) then --if its time for data
timeCount = timeCount + 1
fg = LJ.CheckFileFlag()
if fg == 1 then --increment filename
count = count +1
Filename = Filepre..string.format("%02d", countX)..string.format("%02d", count)..Filesuf
file:close()
LJ.ClearFileFlag() --inform host that previous file is available.
file = io.open(Filename, "w") --create or replace a new file
print ("Command issued by host to create new file")
end
--interval completed
voltage0 = mbRead(0,3) --voltage on AIN0, address is 0, type is 3
voltage1 = mbRead(2,3)
voltage2 = mbRead(4,3)
voltage3 = mbRead(6,3)
voltage4 = mbRead(8,3)
voltage5 = mbRead(10,3)
voltage6 = mbRead(12,3)
voltage7 = mbRead(14,3)
voltage8 = mbRead(16,3)
voltage9 = mbRead(18,3)
voltage10 = mbRead(20,3)
voltage11 = mbRead(22,3)
voltage12 = mbRead(24,3)
voltage13 = mbRead(26,3)
print("AIN0: ", voltage0, "V", "AIN1: ", voltage1, "V", "AIN2: ", voltage2, "V", "AIN3: ", voltage3, "V", "AIN4: ", voltage4, "V", "AIN5: ", voltage5, "V", "AIN6: ", voltage6, "V", "AIN7: ", voltage7, "V", "AIN8: ", voltage8, "V", "AIN9: ", voltage9, "V", "AIN10: ", voltage10, "V", "AIN11: ", voltage11, "V", "AIN12: ", voltage12, "V", "AIN13: ", voltage13, "V") --print values to console
voltageStr0 = string.format("%.6f", voltage0)
voltageStr1 = string.format("%.6f", voltage1)
voltageStr2 = string.format("%.6f", voltage2)
voltageStr3 = string.format("%.6f", voltage3)
voltageStr4 = string.format("%.6f", voltage4)
voltageStr5 = string.format("%.6f", voltage5)
voltageStr6 = string.format("%.6f", voltage6)
voltageStr7 = string.format("%.6f", voltage7)
voltageStr8 = string.format("%.6f", voltage8)
voltageStr9 = string.format("%.6f", voltage9)
voltageStr10 = string.format("%.6f", voltage10)
voltageStr11 = string.format("%.6f", voltage11)
voltageStr12 = string.format("%.6f", voltage12)
voltageStr13 = string.format("%.6f", voltage13)
timeStamp = string.format("%02d", timeCount*5)
file:write(timeStamp, delimiter,
voltageStr0, delimiter,
voltageStr1, delimiter,
voltageStr2, delimiter,
voltageStr3, delimiter,
voltageStr4, delimiter,
voltageStr5, delimiter,
voltageStr6, delimiter,
voltageStr7, delimiter,
voltageStr8, delimiter,
voltageStr9, delimiter,
voltageStr10, delimiter,
voltageStr11, delimiter,
voltageStr12, delimiter,
voltageStr13, "\n") --write values to file
end
end
file:close()
print("Done acquiring data. Finished script")
MB.W(6000, 1, 0);