integrate the hardware to the software, change the UI and truncate

This commit is contained in:
Ryan Xu 2023-02-05 17:51:38 -08:00
parent ecd19e582e
commit 81d1b12079
3 changed files with 28 additions and 14 deletions

View File

@ -44,9 +44,19 @@ def read():
writer.writerow(header) writer.writerow(header)
f.close() f.close()
while True: while True:
dat_list = np.random.randint(0, v_in * 1000, SENSORS_MAX) # create a randomized voltage data #dat_list = np.random.randint(0, v_in * 1000, SENSORS_MAX) # create a randomized voltage data
# take only the nonzero indices, and truncated to two decimal places to "filter" out some hardware errors # take only the nonzero indices, and truncated to two decimal places to "filter" out some hardware errors
dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2 #dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2
'''ser = serial.Serial(port)
ser.flushInput()
while True:
try:
ser_bytes = ser.readline()
decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
except:
print("Keyboard Interrupt")
break'''
#dat_sel = np.trunc((np.take(decoded_bytes, sensor_ports) / 1000) * 10**2) / 10**2
r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1) # *2 <-- change with actual formula for ammonia concentration r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1) # *2 <-- change with actual formula for ammonia concentration
# created a new array to convert resistance values to sci notation # created a new array to convert resistance values to sci notation
r_arr2 = np.empty(len(r_arr), dtype=object) r_arr2 = np.empty(len(r_arr), dtype=object)
@ -81,15 +91,19 @@ def read():
f.close() f.close()
while controller.isOpen(): while controller.isOpen():
try: try:
#controller.flushInput()
read_data = controller.readline().decode("utf-8") read_data = controller.readline().decode("utf-8")
# use numpy so it can make list calculations easier (and possibly faster) # use numpy so it can make list calculations easier (and possibly faster)
dat_list = np.asarray(json.loads(read_data), dtype=np.uint32)[:SENSORS_MAX] dat_list = np.asarray(json.loads(read_data), dtype=np.float32)[:SENSORS_MAX]
#ser_bytes = controller.readline()
#decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
#dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2
dat_sel = np.take(dat_list, sensor_ports)
# if we decided to switch back to analogRead(), replace this line of comment to the algorithm to something like the commented line below # if we decided to switch back to analogRead(), replace this line of comment to the algorithm to something like the commented line below
# dat_sel = np.take(dat_list, sensor_ports) * v_in / resolution # dat_sel = np.take(dat_list, sensor_ports) * v_in / resolution
# take only the nonzero indices, and truncated to two decimal places to "filter" out some hardware errors # take only the nonzero indices, and truncated to two decimal places to "filter" out some hardware errors
dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2 #dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2
r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1) # *2 <-- change with actual formula for ammonia concentration r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1) # *2 <-- change with actual formula for ammonia concentration
# created a new array to convert resistance values to sci notation # created a new array to convert resistance values to sci notation
r_arr2 = np.empty(len(r_arr), dtype=object) r_arr2 = np.empty(len(r_arr), dtype=object)

View File

@ -232,7 +232,7 @@
<property name="gripper">0</property> <property name="gripper">0</property>
<property name="hidden">0</property> <property name="hidden">0</property>
<property name="id">wxID_ANY</property> <property name="id">wxID_ANY</property>
<property name="label">Resistor 3</property> <property name="label">Resistor 2</property>
<property name="max_size"></property> <property name="max_size"></property>
<property name="maximize_button">0</property> <property name="maximize_button">0</property>
<property name="maximum_size"></property> <property name="maximum_size"></property>
@ -240,7 +240,7 @@
<property name="minimize_button">0</property> <property name="minimize_button">0</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="moveable">1</property> <property name="moveable">1</property>
<property name="name">r3_prompt</property> <property name="name">r2_prompt</property>
<property name="pane_border">1</property> <property name="pane_border">1</property>
<property name="pane_position"></property> <property name="pane_position"></property>
<property name="pane_size"></property> <property name="pane_size"></property>
@ -315,7 +315,7 @@
<property name="gripper">0</property> <property name="gripper">0</property>
<property name="hidden">0</property> <property name="hidden">0</property>
<property name="id">wxID_ANY</property> <property name="id">wxID_ANY</property>
<property name="label">Resistor 2</property> <property name="label">Resistor 3</property>
<property name="max_size"></property> <property name="max_size"></property>
<property name="maximize_button">0</property> <property name="maximize_button">0</property>
<property name="maximum_size"></property> <property name="maximum_size"></property>
@ -323,7 +323,7 @@
<property name="minimize_button">0</property> <property name="minimize_button">0</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="moveable">1</property> <property name="moveable">1</property>
<property name="name">r2_prompt</property> <property name="name">r3_prompt</property>
<property name="pane_border">1</property> <property name="pane_border">1</property>
<property name="pane_position"></property> <property name="pane_position"></property>
<property name="pane_size"></property> <property name="pane_size"></property>

8
ui.py
View File

@ -33,14 +33,14 @@ class Frame ( wx.Frame ):
self.r1_prompt.Wrap( -1 ) self.r1_prompt.Wrap( -1 )
res_grid.Add( self.r1_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 ) res_grid.Add( self.r1_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.r3_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 3", wx.DefaultPosition, wx.DefaultSize, 0 )
self.r3_prompt.Wrap( -1 )
res_grid.Add( self.r3_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.r2_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 2", wx.DefaultPosition, wx.DefaultSize, 0 ) self.r2_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 2", wx.DefaultPosition, wx.DefaultSize, 0 )
self.r2_prompt.Wrap( -1 ) self.r2_prompt.Wrap( -1 )
res_grid.Add( self.r2_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 ) res_grid.Add( self.r2_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.r3_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 3", wx.DefaultPosition, wx.DefaultSize, 0 )
self.r3_prompt.Wrap( -1 )
res_grid.Add( self.r3_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.r4_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 4", wx.DefaultPosition, wx.DefaultSize, 0 ) self.r4_prompt = wx.StaticText( ref_entre.GetStaticBox(), wx.ID_ANY, u"Resistor 4", wx.DefaultPosition, wx.DefaultSize, 0 )
self.r4_prompt.Wrap( -1 ) self.r4_prompt.Wrap( -1 )
res_grid.Add( self.r4_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 ) res_grid.Add( self.r4_prompt, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 5 )