質問編集履歴
2
追記 データフレーム生成段階のコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -136,4 +136,132 @@
|
|
136
136
|
|
137
137
|
29 [0] [0]
|
138
138
|
|
139
|
+
```python
|
140
|
+
|
141
|
+
import pandas as pd
|
142
|
+
|
143
|
+
import time
|
144
|
+
|
145
|
+
import spidev
|
146
|
+
|
147
|
+
import sys
|
148
|
+
|
149
|
+
import numpy as np
|
150
|
+
|
151
|
+
import subprocess
|
152
|
+
|
153
|
+
from threading import Thread
|
154
|
+
|
155
|
+
import csv
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
139
|
-
|
161
|
+
cond = True
|
162
|
+
|
163
|
+
data1 = 0
|
164
|
+
|
165
|
+
data2 = 0
|
166
|
+
|
167
|
+
df1 = pd.DataFrame(columns=['ch0','ch2'])#data2
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
def main():
|
174
|
+
|
175
|
+
spi = spidev.SpiDev()
|
176
|
+
|
177
|
+
spi.open(0,0)
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
def f():
|
182
|
+
|
183
|
+
global cond
|
184
|
+
|
185
|
+
time.sleep(20)
|
186
|
+
|
187
|
+
cond = False
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
thread = Thread(target=f)
|
192
|
+
|
193
|
+
thread.start()
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
while cond:
|
198
|
+
|
199
|
+
resp = spi.xfer2([0x68,0x00])
|
200
|
+
|
201
|
+
data1 = ((resp[0] << 8 ) + resp[1]) & 0x3ff
|
202
|
+
|
203
|
+
resp2 = spi.xfer([0x78,0x00])
|
204
|
+
|
205
|
+
data2 = ((resp2[0] << 8) + resp2[1]) & 0x3ff
|
206
|
+
|
207
|
+
global df1
|
208
|
+
|
209
|
+
df1 = df1.append({'ch0':[data1],'ch2':[data2]},ignore_index=True)
|
210
|
+
|
211
|
+
print (df1)
|
212
|
+
|
213
|
+
df1.to_csv('myakuha.csv')
|
214
|
+
|
215
|
+
#left max
|
216
|
+
|
217
|
+
df10max = df1['ch0'].max()
|
218
|
+
|
219
|
+
#print('left:',df10max)
|
220
|
+
|
221
|
+
#right max
|
222
|
+
|
223
|
+
df12max = df1['ch2'].max()
|
224
|
+
|
225
|
+
#print('right:',df12max)
|
226
|
+
|
227
|
+
df110max = np.array(df10max)
|
228
|
+
|
229
|
+
df112max = np.array(df12max)
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
if df10max > df12max:
|
236
|
+
|
237
|
+
leftmax = df110max - df112max
|
238
|
+
|
239
|
+
print ('overL:',leftmax)
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
if df10max < df12max:
|
244
|
+
|
245
|
+
rightmax = df112max - df110max
|
246
|
+
|
247
|
+
print ('overR:',rightmax)
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
if __name__=='__main__':
|
262
|
+
|
263
|
+
main()
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
```
|
1
エラー内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,15 +6,33 @@
|
|
6
6
|
|
7
7
|
Traceback (most recent call last):
|
8
8
|
|
9
|
-
File "/home/pi/
|
9
|
+
File "/home/pi/5\17.py", line 14, in <module>
|
10
10
|
|
11
11
|
main()
|
12
12
|
|
13
|
-
File "/home/pi/
|
13
|
+
File "/home/pi/5\17.py", line 7, in main
|
14
14
|
|
15
|
-
d
|
15
|
+
data.plot()
|
16
16
|
|
17
|
+
File "/usr/lib/python3/dist-packages/pandas/tools/plotting.py", line
|
18
|
+
|
19
|
+
2165, in plot_frame
|
20
|
+
|
21
|
+
plot_obj.generate()
|
22
|
+
|
23
|
+
File "/usr/lib/python3/dist-packages/pandas/tools/plotting.py", line
|
24
|
+
|
25
|
+
900, in generate
|
26
|
+
|
27
|
+
self._compute_plot_data()
|
28
|
+
|
29
|
+
File "/usr/lib/python3/dist-packages/pandas/tools/plotting.py", line
|
30
|
+
|
31
|
+
970, in _compute_plot_data
|
32
|
+
|
33
|
+
'plot'.format(numeric_data.__class__.__name__))
|
34
|
+
|
17
|
-
|
35
|
+
TypeError: Empty 'DataFrame': no numeric data to plot
|
18
36
|
|
19
37
|
|
20
38
|
|