Skip to content

Commit 68cdba1

Browse files
committed
validseq,plot=3,bangbang=True,clearall
1 parent b152bae commit 68cdba1

2 files changed

Lines changed: 47 additions & 20 deletions

File tree

nintan/cstim.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import concore
22
from ast import literal_eval
33
import time
4+
5+
try:
6+
bangbang = concore.params['bang']
7+
except:
8+
bangbang = False
9+
410
concore.delay = 0.01
511
init_simtime_u = "[0.0, 0.0, 0.0]"
612
init_simtime_ym = "[0.0, 0.0, 0.0]"
@@ -12,11 +18,17 @@
1218
while(concore.simtime<concore.maxtime):
1319
while concore.unchanged():
1420
ym = concore.read(1,"ym",init_simtime_ym)
15-
try:
16-
u[0] = float(literal_eval(input()))
17-
except:
18-
print("bad input, using .5 instead")
19-
u[0] = 0.5
21+
if bangbang:
22+
if ym[0] > 0:
23+
u[0] = 0.9
24+
else:
25+
u[0] = 0.1
26+
else:
27+
try:
28+
u[0] = float(literal_eval(input()))
29+
except:
30+
print("bad input, using .5 instead")
31+
u[0] = 0.5
2032
print("ym="+str(ym[0])+" u="+str(u[0]));
2133
concore.write(1,"u",u);
2234
wallclock2 = time.perf_counter()

nintan/pacq.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
try:
1818
showPlot = concore.params['plot']
1919
except:
20-
showPlot = False
20+
showPlot = 0
2121

2222
try:
2323
tsamp = concore.params['tsamp']
@@ -26,6 +26,11 @@
2626
except:
2727
tsamp = 1
2828

29+
def validseq(t):
30+
for i in range(0,len(t)-1):
31+
if t[i] >= t[i+1]:
32+
print('i='+str(i)+': '+str(t[i])+'>='+str(t[i+1]))
33+
2934
def extract(amplifierData):
3035
s = 0.0
3136
for data in amplifierData:
@@ -51,6 +56,16 @@ def readUint16(array, arrayIndex):
5156
arrayIndex = arrayIndex + 2
5257
return variable, arrayIndex
5358

59+
def clearall():
60+
# Clear TCP data output to ensure no TCP channels are enabled
61+
scommand.sendall(b'execute clearalldataoutputs')
62+
time.sleep(0.1)
63+
# Send TCP commands to set up TCP Data Output Enabled for wide
64+
# band of channel A-010
65+
scommand.sendall(b'set a-010.tcpdataoutputenabled true')
66+
time.sleep(0.1)
67+
68+
5469
def acq():
5570
# Run controller for tsamp second
5671
scommand.sendall(b'set runmode run')
@@ -127,14 +142,6 @@ def acq():
127142
# Calculate timestep from sample rate
128143
timestep = 1 / sampleRate
129144

130-
# Clear TCP data output to ensure no TCP channels are enabled
131-
scommand.sendall(b'execute clearalldataoutputs')
132-
time.sleep(0.1)
133-
134-
# Send TCP commands to set up TCP Data Output Enabled for wide
135-
# band of channel A-010
136-
scommand.sendall(b'set a-010.tcpdataoutputenabled true')
137-
time.sleep(0.1)
138145

139146
# Calculations for accurate parsing
140147
# At 30 kHz with 1 channel, 1 second of wideband waveform data (including magic number, timestamps, and amplifier data) is 181,420 bytes
@@ -148,6 +155,7 @@ def acq():
148155
waveformBytesPerFrame = 4 + 2
149156
waveformBytesPerBlock = framesPerBlock * waveformBytesPerFrame + 4
150157

158+
clearall()
151159

152160
concore.delay = 0.01
153161
init_simtime_u = "[0.0, 0.0, 0.0]"
@@ -169,16 +177,23 @@ def acq():
169177
oldAmpD = amplifierData
170178
amplifierTimestamps = []
171179
amplifierData = []
172-
acq_thread.start()
173-
nxtacq_thread = threading.Thread(target=acq, daemon=True)
174-
ym[0] = extract(oldAmpD)
175-
print("ym="+str(ym[0]))
176-
if showPlot:
180+
if showPlot&1==1:
177181
plt.plot(oldAmpT,oldAmpD)
178-
plt.title("ym="+str(ym[0]))
182+
plt.title("ym="+str(extract(oldAmpD))
179183
plt.xlabel('Time (s)')
180184
plt.ylabel('Voltage (uV)')
181185
plt.show()
186+
if showPlot&2==2:
187+
plt.plot(range(0,len(oldAmpD)),oldAmpD)
188+
plt.title("ym="+str(extract(oldAmpD))
189+
plt.xlabel('index')
190+
plt.ylabel('Voltage (uV)')
191+
plt.show()
192+
acq_thread.start()
193+
nxtacq_thread = threading.Thread(target=acq, daemon=True)
194+
ym[0] = extract(oldAmpD)
195+
validseq(oldAmpT)
196+
print("ym="+str(ym[0]))
182197
concore.write(1,"ym",ym)
183198
acq_thread.join()
184199
print("retry="+str(concore.retrycount))

0 commit comments

Comments
 (0)