Skip to content

Commit 9017ea2

Browse files
committing to switch branches
1 parent 8440828 commit 9017ea2

File tree

4 files changed

+132
-14
lines changed

4 files changed

+132
-14
lines changed

SAMA_sampling.py

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# NAME: serial_write.py
2+
# AUTHOR: Matthew Miller
3+
# PURPOSE: Records data from iMet sensor into a file called IMETDATAXX.CSV.
4+
# If the program detects that an ADC has been attached, the program
5+
# will send ADC data, immediately followed by iMet data through the
6+
# serial port. This is intended to be used with an xBee in coordination
7+
# with a ground station computer. The ground station computer will be
8+
# set up to display a live graph of the data.
9+
10+
#NOTE: all xbee communication lines have been commented out for the time being (serial initialization and a single write inside the while loop
11+
# This was done on 6/7/21 for testing purposes)
12+
13+
import os
14+
import time
15+
import serial
16+
import sys
17+
from gpiozero import LED, Button
18+
19+
#check if Arduino ADC is connected via USB
20+
#if not used, program continues with only iMET recording
21+
try:
22+
ser_ADC = serial.Serial(
23+
port='/dev/ARD',
24+
baudrate = 9600,
25+
parity=serial.PARITY_NONE,
26+
stopbits=serial.STOPBITS_ONE,
27+
bytesize=serial.EIGHTBITS,
28+
timeout=2
29+
)
30+
use_ADC = 1
31+
except: #error if no adc attached.
32+
print("No ADC attached. Not using.\n")
33+
use_ADC = 0
34+
35+
36+
#ser_xBee = serial.Serial(
37+
# port='/dev/ttyS0',
38+
# baudrate = 9600,
39+
# parity=serial.PARITY_NONE,
40+
# stopbits=serial.STOPBITS_ONE,
41+
# bytesize=serial.EIGHTBITS,
42+
# timeout=1
43+
#)
44+
45+
#check if iMet attached
46+
try:
47+
ser_SAMA = serial.Serial(
48+
port='/dev/ttyUSB1',
49+
baudrate = 9600,
50+
parity=serial.PARITY_NONE,
51+
stopbits=serial.STOPBITS_ONE,
52+
bytesize=serial.EIGHTBITS,
53+
timeout=1
54+
)
55+
except:
56+
print("no iMET attached, cannot continue. \n")
57+
exit()
58+
59+
try:
60+
collect_ADC = LED(27)
61+
stop_button = Button(25, pull_up=False)
62+
63+
counter=0#potentially unneccessary
64+
65+
#open iMET file
66+
#first get filename
67+
config = "/home/pi/BC6B/CONFIG"
68+
location = sys.argv[1]
69+
init_SAMA_filename = "SAMADATA"
70+
for i in range(100):
71+
j = i-1
72+
to_append = str(j)+".CSV" #TODO was i
73+
config_to_append = str(i) + ".YML"
74+
true_config = config + config_to_append
75+
SAMA_appended = location + init_SAMA_filename + to_append
76+
file_exists = os.path.isfile(true_config)
77+
if file_exists == 0: #if file doesn't exist exit loop and create it
78+
#file is created in the following while loop
79+
print("file created")
80+
break
81+
82+
print("launching while loop \n")
83+
84+
temp = 1
85+
while(True):
86+
if use_ADC == 1:
87+
SAMA_file = open(SAMA_appended, "a+") #open new iMET file appending
88+
data_SAMA = ser_SAMA.readline().decode()
89+
collect_ADC.on() #tell arduino to grab data
90+
collect_ADC.off()
91+
data_ADC = ser_ADC.readline().decode()
92+
#data_all = data_ADC + data_iMET
93+
#ser_xBee.write(data_all)
94+
SAMA_file.write(data_SAMA)
95+
SAMA_file.write("\n")
96+
SAMA_file.close()
97+
98+
else:
99+
SAMA_file = open(SAMA_appended, "a+") #open new iMET file appending
100+
data_SAMA = ser_SAMA.readline().decode()
101+
SAMA_file.write(data_SAMA)
102+
SAMA_file.write("\n")
103+
SAMA_file.close()
104+
time.sleep(1)
105+
106+
#stop_button.wait_for_press()
107+
#print("aye bro the button was pressed")
108+
"""
109+
time.sleep(1)
110+
for x in range (10):
111+
iMET_file = open(iMET_appended, "a+") #open new iMET file appending
112+
data_iMET = ser_iMET.readline().decode()
113+
print(data_iMET)
114+
iMET_file.write(data_iMET)
115+
iMET_file.write("\n")
116+
iMET_file.close()
117+
118+
119+
print("done\n")
120+
"""
121+
except:
122+
print("exception thrown")
123+
if not SAMA_file.closed:
124+
SAMA_file.close()
125+
126+

get_data.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ while [ $RUN_N -lt 100 ]; do
6565
sleep 1
6666
sudo cp /home/pi/BC6B/DAQDATA$RUN_N.RAW /media/sda1/DAQDATA$RUN_N.RAW
6767
sleep 1
68-
sudo cp /home/pi/BC6B/IMETDATA$RUN_N.CSV /media/sda1/IMETDATA$RUN_N.CSV
68+
sudo cp /home/pi/BC6B/SAMADATA$RUN_N.CSV /media/sda1/SAMADATA$RUN_N.CSV #TODO: change SAMA to iMET
6969
sleep 5
7070
sudo cp /home/pi/BC6B/CONFIG$RUN_N.YML /media/sda1/CONFIG$RUN_N.YML
7171
sudo ./extract_all.sh $USB_PTH $RUN_N

iMET_sampling.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
try:
4747
ser_iMET = serial.Serial(
4848
port='/dev/ttyUSB1',
49-
baudrate = 57600,
49+
baudrate = 57600,
5050
parity=serial.PARITY_NONE,
5151
stopbits=serial.STOPBITS_ONE,
5252
bytesize=serial.EIGHTBITS,
@@ -76,6 +76,7 @@
7676
file_exists = os.path.isfile(true_config)
7777
if file_exists == 0: #if file doesn't exist exit loop and create it
7878
#file is created in the following while loop
79+
print("file created")
7980
break
8081

8182
print("launching while loop \n")
@@ -99,8 +100,10 @@
99100
iMET_file = open(iMET_appended, "a+") #open new iMET file appending
100101
data_iMET = ser_iMET.readline().decode()
101102
iMET_file.write(data_iMET)
103+
print(data_iMET) #TODO
102104
iMET_file.write("\n")
103105
iMET_file.close()
106+
time.sleep(1)
104107

105108
#stop_button.wait_for_press()
106109
#print("aye bro the button was pressed")

src/main.cpp

+1-12
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,7 @@ int main(int argc, const char *argv[]) {
302302
fifo.open(FIFOFILE, ios::out);
303303
fifo << "GPS Acquired." << endl;
304304
fifo.close();
305-
<<<<<<< HEAD
306305

307-
308-
=======
309-
310-
>>>>>>> 81498be71a3b1e96acd061e52768a61fcec12fe1
311306
pthread_t vn_write_thread;
312307
pthread_create(&vn_write_thread, NULL, vec_write, NULL);
313308
vs.registerAsyncPacketReceivedHandler(NULL, vecnavBinaryEventHandle);
@@ -428,13 +423,7 @@ int main(int argc, const char *argv[]) {
428423
pthread_cancel(timer_thread);
429424
cout << "enter pressed, should be wrapping up" << endl;
430425
stop_sampling = true; // this kills transmission and file writing threads.
431-
<<<<<<< HEAD
432-
433-
=======
434-
// fifo.open(FIFOFILE, ios::out);
435-
// fifo << "ending VN thread" << endl;
436-
// fifo.close(); //TODO TODO
437-
>>>>>>> 81498be71a3b1e96acd061e52768a61fcec12fe1
426+
438427
pthread_join(transmit_thread, NULL);
439428
pthread_join(vn_write_thread, NULL);
440429

0 commit comments

Comments
 (0)