This repository has been archived by the owner on May 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eyedaq_withgps_v2.py
1028 lines (824 loc) · 37.5 KB
/
eyedaq_withgps_v2.py
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
eyedaq_withgps_v2.py
program to
1) view and capture an image of sediment
2) get site info from the user
3) save image to file with the site and time in the file name
Written by:
Daniel Buscombe, Feb-March 2015, updated June 2015
Grand Canyon Monitoring and Research Center, U.G. Geological Survey, Flagstaff, AZ
please contact:
SYNTAX:
python eyedaq_withgps_v2.py
REQUIREMENTS:
python
kivy (http://kivy.org/#home)
"""
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.accordion import *
from kivy.properties import *
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import WindowBase
from kivy.core.window import Window
from kivy.graphics import Canvas, Translate, Fbo, ClearColor, ClearBuffers
from kivy.clock import Clock
#from kivy.uix.popup import Popup
import time, os
from shutil import move as mv
import sys
import textwrap
## pip install kivy-garden
## garden install graph
#from kivy.garden.graph import Graph, MeshLinePlot
# following are temporary for the map updating
#from math import cos, sin
#import random
from numpy import sqrt as sqrt
from numpy import abs as abs
##import numpy as np
import pyproj, csv, serial
from pynmea import nmea
try:
import fortune
except:
print "fortune not installed"
print "pip install fortune"
#comnum= 'COM8' #'/dev/ttyUSB0'
#lat = 0
#long = 0
#pos_x = 0
#pos_y = 0
#alt = 0
#i = 0 #x units for altitude measurment
BAUDRATE = 9600
BAUDRATE2 = 4800
cs2cs_args = "epsg:26949"
# get the transformation matrix of desired output coordinates
try:
trans = pyproj.Proj(init=cs2cs_args)
except:
trans = pyproj.Proj(cs2cs_args)
#=========================
#=========================
def cowsay(str, length=40):
return build_bubble(str, length) + build_cow()
#=========================
def build_cow():
return """
\ ^__^
\ (oo)\_______
(__)\ )\/\\
||----w |
|| ||
"""
#=========================
def build_bubble(str, length=40):
bubble = []
lines = normalize_text(str, length)
bordersize = len(lines[0])
bubble.append(" " + "_" * bordersize)
for index, line in enumerate(lines):
border = get_border(lines, index)
bubble.append("%s %s %s" % (border[0], line, border[1]))
bubble.append(" " + "-" * bordersize)
return "\n".join(bubble)
#=========================
def normalize_text(str, length):
lines = textwrap.wrap(str, length)
maxlen = len(max(lines, key=len))
return [ line.ljust(maxlen) for line in lines ]
#=========================
def get_border(lines, index):
if len(lines) < 2:
return [ "<", ">" ]
elif index == 0:
return [ "/", "\\" ]
elif index == len(lines) - 1:
return [ "\\", "/" ]
else:
return [ "|", "|" ]
#=========================
#=========================
def export_to_png(self, filename, *args):
'''Saves an image of the widget and its children in png format at the
specified filename. Works by removing the widget canvas from its
parent, rendering to an :class:`~kivy.graphics.fbo.Fbo`, and calling
:meth:`~kivy.graphics.texture.Texture.save`.
'''
if self.parent is not None:
canvas_parent_index = self.parent.canvas.indexof(self.canvas)
self.parent.canvas.remove(self.canvas)
fbo = Fbo(size=self.size)
with fbo:
ClearColor(0, 0, 0, 1)
ClearBuffers()
Translate(-self.x, -self.y, 0)
fbo.add(self.canvas)
fbo.draw()
fbo.texture.save(filename)
fbo.remove(self.canvas)
if self.parent is not None:
self.parent.canvas.insert(canvas_parent_index, self.canvas)
return True
#=========================
def scan():
#scan for available ports. return a list of tuples (num, name)
available = []
for i in range(256):
try:
s = serial.Serial(i)
available.append( (i, s.name))
s.close() # explicit close 'cause of delayed GC in java
except serial.SerialException:
pass
return available
#=========================
def init_serial(self):
if os.name=='nt':
#opens the serial port based on the COM number you choose
print '==========================='
print '==========================='
print '==========================='
print "Found Ports:"
for n,s in scan():
print "%s" % s
print " "
#enter your GPS COM port number
print '==========================='
print '==========================='
print '==========================='
print "GPS COM port # for GPS. Enter # only, then enter"
temp = raw_input() #waits here for keyboard input
if temp == 'e':
sys.exit()
comnum = 'COM' + temp #concatenate COM and the port number to define serial port
else:
comnum='/dev/ttyUSB0'
if os.name=='nt':
print '==========================='
print '==========================='
print '==========================='
print "Do you have an echosounder attached? Enter y or n only, then enter"
temp = raw_input() #waits here for keyboard input
if temp == 'y':
#enter your Echosounder COM port number
print "Echosounder COM port # for echosounder. Enter # only, then enter"
temp = raw_input() #waits here for keyboard input
if temp == 'e':
sys.exit()
comnum2 = 'COM' + temp #concatenate COM and the port number to define serial port
else:
self.ser2 = 0
else:
comnum2 ='/dev/ttyUSB1'
try:
global BAUDRATE
self.ser = serial.Serial()
self.ser.baudrate = BAUDRATE
self.ser.port = comnum
self.ser.timeout = 0.5
self.ser.open()
if self.ser.isOpen():
print '==========================='
print 'GPS is open'
print '==========================='
self.gpsopen = 1
except:
self.ser = 0
print '==========================='
print "GPS failed to open"
print '==========================='
try:
global BAUDRATE2
self.ser2 = serial.Serial()
self.ser2.baudrate = BAUDRATE2
self.ser2.port = comnum2
self.ser2.timeout = 2
self.ser2.open()
if self.ser2.isOpen():
print '==========================='
print 'Echosounder is open'
print '==========================='
self.echosounderopen = 1
except:
self.ser2 = 0
print '==========================='
print "Echosounder failed to open"
print '==========================='
return self.ser, self.ser2
#=========================
def get_nmea(self):
gotpos = 0; counter = 0
while (gotpos==0) &(counter<3):
line = self.ser.read(1000) # read 1000 bytes
parts = line.split('\r\n') # split by line return
gpgga_parts = []; gpgsa_parts = [];
gprmc_parts = []; gpvtg_parts = []; gpgsv_parts = []
newparts = [] # create new variable which contains cleaned strings
for k in range(len(parts)):
if parts[k].startswith('$'): #select if starts with $
if len(parts[k].split('*'))>1: #select if contains *
if parts[k].count('$')==1: # select if only contains 1 $
newparts.append(parts[k])
for k in range(len(newparts)):
if "GPGGA" in newparts[k]:
gpgga_parts.append(newparts[k])
elif "GPGSA" in newparts[k]:
gpgsa_parts.append(newparts[k])
elif "GPRMC" in newparts[k]:
gprmc_parts.append(newparts[k])
elif "GPVTG" in newparts[k]:
gpvtg_parts.append(newparts[k])
elif "GPGSV" in newparts[k]:
gpgsv_parts.append(newparts[k])
if gpgga_parts:
gotpos=1
gpgga_parts = gpgga_parts[-1];
if gprmc_parts:
gprmc_parts = gprmc_parts[-1];
if gpgsa_parts:
gpgsa_parts = gpgsa_parts[-1]
if gpvtg_parts:
gpvtg_parts = gpvtg_parts[-1]
if gpgsv_parts:
gpgsv_parts = gpgsv_parts[-1]
counter += 1
gpgga = nmea.GPGGA(); gpgsa = nmea.GPGSA()
gprmc = nmea.GPRMC(); gpvtg = nmea.GPVTG(); gpgsv = nmea.GPGSV()
dat = {}
try:
dat['depth_ft'] = self.ser2.read(1000).split('DBT')[1].split(',f,')[0].split(',')[1]
dat['depth_m'] = str(float(dat['depth_ft'])*0.3048)
#print 'got depth'
except:
dat['depth_ft'] = 'NaN'
dat['depth_m'] = 'NaN'
# GPGGA
try:
gpgga.parse(gpgga_parts)
lats = gpgga.latitude
longs= gpgga.longitude
#convert degrees,decimal minutes to decimal degrees
lat1 = (float(lats[2]+lats[3]+lats[4]+lats[5]+lats[6]+lats[7]+lats[8]))/60
lat = (float(lats[0]+lats[1])+lat1)
long1 = (float(longs[3]+longs[4]+longs[5]+longs[6]+longs[7]+longs[8]+longs[9]))/60
long = (float(longs[0]+longs[1]+longs[2])+long1)
#calc position
dat['lat_1'] = str(lat);
dat['lon_1'] = str(-long)
#convert to az central state plane east/north
e,n = trans(-long,lat)
dat['e_1'] = str(e); dat['n_1'] = str(n)
dat['alt'] = str(gpgga.antenna_altitude)
dat['t'] = str(gpgga.timestamp);
dat['qual'] = str(gpgga.gps_qual)
dat['num_sats'] = str(gpgga.num_sats)
dat['ref_id'] = str(gpgga.ref_station_id)
dat['geo_sep'] = str(gpgga.geo_sep)
except:
dat['lat_1'] = 'NaN'; dat['lon_1'] = 'NaN'
dat['alt'] = 'NaN'; dat['t'] = 'NaN'
dat['qual'] = 'NaN'; dat['num_sats'] = 'NaN'
dat['ref_id'] = 'NaN'; dat['geo_sep'] = 'NaN'
# GPGSA
try:
gpgsa.parse(gpgsa_parts)
dat['hdop'] = str(gpgsa.hdop); dat['pdop'] = str(gpgsa.pdop); dat['vdop'] = str(gpgsa.vdop)
dat['mode'] = str(gpgsa.mode); dat['mode_type'] = str(gpgsa.mode_fix_type)
dat['sv_id01'] = str(gpgsa.sv_id01); dat['sv_id02'] = str(gpgsa.sv_id02)
dat['sv_id03'] = str(gpgsa.sv_id03); dat['sv_id04'] = str(gpgsa.sv_id04)
dat['sv_id05'] = str(gpgsa.sv_id05); dat['sv_id06'] = str(gpgsa.sv_id06)
dat['sv_id07'] = str(gpgsa.sv_id07); dat['sv_id08'] = str(gpgsa.sv_id08)
dat['sv_id09'] = str(gpgsa.sv_id09); dat['sv_id10'] = str(gpgsa.sv_id10)
dat['sv_id11'] = str(gpgsa.sv_id11); dat['sv_id12'] = str(gpgsa.sv_id12)
except:
dat['hdop'] = 'NaN'; dat['pdop'] = 'NaN'; dat['vdop'] = 'NaN'
dat['mode'] = 'NaN'; dat['mode_type'] = 'NaN'
dat['sv_id01'] = 'NaN'; dat['sv_id02'] = 'NaN'
dat['sv_id03'] = 'NaN'; dat['sv_id04'] = 'NaN'
dat['sv_id05'] = 'NaN'; dat['sv_id06'] = 'NaN'
dat['sv_id07'] = 'NaN'; dat['sv_id08'] = 'NaN'
dat['sv_id09'] = 'NaN'; dat['sv_id10'] = 'NaN'
dat['sv_id11'] = 'NaN'; dat['sv_id12'] = 'NaN'
# GPGSV
try:
gpgsv.parse(gpgsv_parts)
dat['az1'] = str(gpgsv.azimuth_1)
dat['az2'] = str(gpgsv.azimuth_2)
dat['elev_deg1'] = str(gpgsv.elevation_deg_1)
dat['elev_deg2'] = str(gpgsv.elevation_deg_2)
dat['num_sv'] = str(gpgsv.num_sv_in_view)
dat['snr1'] = str(gpgsv.snr_1)
dat['snr2'] = str(gpgsv.snr_2)
dat['sv_prn1'] = str(gpgsv.sv_prn_num_1)
dat['sv_prn2'] = str(gpgsv.sv_prn_num_2)
except:
dat['az1'] = 'NaN'; dat['az2'] = 'NaN'
dat['elev_deg1'] = 'NaN'; dat['elev_deg2'] = 'NaN'
dat['num_sv'] = 'NaN'; dat['snr1'] = 'NaN'
dat['snr2'] = 'NaN'; dat['sv_prn1'] = 'NaN'; dat['sv_prn2'] = 'NaN'
# GPRMC
try:
gprmc.parse(gprmc_parts)
dat['date'] = str(gprmc.datestamp)
dat['time_stamp'] = str(gprmc.timestamp)
dat['spd'] = str(gprmc.spd_over_grnd)
dat['true_course'] = str(gprmc.true_course)
dat['mag_var'] = str(gprmc.mag_variation)
dat['mag_var_dir'] = str(gprmc.mag_var_dir)
lats = gprmc.lat; longs= gprmc.lon
#convert degrees,decimal minutes to decimal degrees
lat1 = (float(lats[2]+lats[3]+lats[4]+lats[5]+lats[6]+lats[7]+lats[8]))/60
lat = (float(lats[0]+lats[1])+lat1)
long1 = (float(longs[3]+longs[4]+longs[5]+longs[6]+longs[7]+longs[8]+longs[9]))/60
long = (float(longs[0]+longs[1]+longs[2])+long1)
#calc position
dat['lat_2'] = str(lat); dat['lon_2'] = str(-long)
#convert to az central state plane east/north
e,n = trans(-long,lat)
dat['e_2'] = str(e); dat['n_2'] = str(n)
except:
dat['date'] = 'NaN'; dat['time_stamp'] = 'NaN'
dat['spd'] = 'NaN'; dat['true_course'] = 'NaN'
dat['mag_var'] = 'NaN'; dat['mag_var_dir'] = 'NaN'
dat['lat_2'] = 'NaN'; dat['lon_2'] = 'NaN'
#GPVTG
try:
gpvtg.parse(gpvtg_parts)
dat['true_track'] = str(gpvtg.true_track)
dat['spd_grnd_kmh'] = str(gpvtg.spd_over_grnd_kmph)
dat['spd_grnd_kts'] = str(gpvtg.spd_over_grnd_kts)
dat['mag_track'] = str(gpvtg.mag_track)
except:
dat['true_track'] = 'NaN'; dat['spd_grnd_kmh'] = 'NaN'
dat['spd_grnd_kts'] = 'NaN'; dat['mag_track'] = 'NaN'
self.textinput.text += time.asctime() + ' ' +gpgga_parts + '\n'
self.textinput.text += time.asctime() + ' ' +gpgsa_parts + '\n'
self.textinput.text += time.asctime() + ' ' +gprmc_parts + '\n'
self.textinput.text += time.asctime() + ' ' +gpvtg_parts + '\n'
self.textinput.text += time.asctime() + ' ' +gpgsv_parts + '\n'
return dat
#=========================
## kv markup for building the app
Builder.load_file('eyedaq.kv')
#=========================
#=========================
class Log(TextInput):
def on_double_tap(self):
# make sure it performs it's original function
super(Log, self).on_double_tap()
def on_word_selection(*l):
selected_word = self.selection_text
print selected_word
# let the word be selected wait for
# next frame and get the selected word
Clock.schedule_once(on_word_selection)
class CameraWidget(BoxLayout):
#=========================
#def Play(self, *args):
# self.ids.camera.play = True
# now = time.asctime() #.replace(' ','_')
# self.textinput.text += 'Video resumed '+now+'\n'
#=========================
#def Pause(self, *args):
# self.ids.camera.play = False
# now = time.asctime() #.replace(' ','_').replace(':','_')
# self.textinput.text += 'Video paused '+now+'\n'
#=========================
def TakePicture(self, *args):
#if hasattr(self, 'laststationchange') & hasattr(self, 'lastimage'):
# #self.textinput.text += 'Elapsed: '+str(abs(self.laststationchange - self.lastimage))+'\n'
# if abs(self.laststationchange - self.lastimage) > 30:
# content1 = Button(text = 'Close')
# popup = Popup(title = 'It has been a while ... consider changing station? ', size_hint = (None, None), size = (400,400), auto_dismiss=True, content = content1)
# content1.bind(on_press = popup.dismiss)
# popup.open()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
z = self.textinput3.text.split(':')[3].split(',')[0]
d = self.textinput3.text.split(':')[4].split(',')[0]
if hasattr(self, 'st_n'):
# distance from station start
dist = sqrt((float(n)-float(self.st_n))**2 + (float(e)-float(self.st_e))**2)
if dist > float(self.textinput4.text): #increment station
self.station_up()
self.export_to_png = export_to_png
now = time.asctime().replace(' ','_').replace(':','_')
self.lastimage = time.clock()
filename = 'st'+self.txt_inpt.text+'_sand_'+now+'_e'+e+'_n'+n+'_z'+z+'_d'+d+'.png'
self.export_to_png(self.ids.camera, filename=filename)
self.textinput.text += 'Eyeball image collected'+'\n' #: '+filename+'\n'
try:
mv(filename,'eyeballimages')
except:
self.textinput.text += 'ERROR: image could not be stored'
#=========================
def TakePictureMud(self, *args):
#if hasattr(self, 'laststationchange') & hasattr(self, 'lastimage'):
# #self.textinput.text += 'Elapsed: '+str(abs(self.laststationchange - self.lastimage))+'\n'
# if abs(self.laststationchange - self.lastimage) > 30:
# content1 = Button(text = 'Close')
# popup = Popup(title = 'It has been a while ... consider changing station? ', size_hint = (None, None), size = (400,400), auto_dismiss=True, content = content1)
# content1.bind(on_press = popup.dismiss)
# popup.open()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
z = self.textinput3.text.split(':')[3].split(',')[0]
d = self.textinput3.text.split(':')[4].split(',')[0]
if hasattr(self, 'st_n'):
# distance from station start
dist = sqrt((float(n)-float(self.st_n))**2 + (float(e)-float(self.st_e))**2)
if dist > float(self.textinput4.text): #increment station
self.station_up()
self.export_to_png = export_to_png
now = time.asctime().replace(' ','_').replace(':','_')
self.lastimage = time.clock()
filename = 'st'+self.txt_inpt.text+'_mud_'+now+'_e'+e+'_n'+n+'_z'+z+'_d'+d+'.png'
self.export_to_png(self.ids.camera, filename=filename)
self.textinput.text += 'Mud image collected'+'\n' #: '+filename+'\n'
try:
mv(filename,'mudimages')
except:
self.textinput.text += 'ERROR: image could not be stored'
#=========================
def TakePictureGravel(self, *args):
#if hasattr(self, 'laststationchange') & hasattr(self, 'lastimage'):
# #self.textinput.text += 'Elapsed: '+str(abs(self.laststationchange - self.lastimage))+'\n'
# if abs(self.laststationchange - self.lastimage) > 30:
# content1 = Button(text = 'Close')
# popup = Popup(title = 'It has been a while ... consider changing station? ', size_hint = (None, None), size = (400,400), auto_dismiss=True, content = content1)
# content1.bind(on_press = popup.dismiss)
# popup.open()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
z = self.textinput3.text.split(':')[3].split(',')[0]
d = self.textinput3.text.split(':')[4].split(',')[0]
if hasattr(self, 'st_n'):
# distance from station start
dist = sqrt((float(n)-float(self.st_n))**2 + (float(e)-float(self.st_e))**2)
if dist > float(self.textinput4.text): #increment station
self.station_up()
self.export_to_png = export_to_png
now = time.asctime().replace(' ','_').replace(':','_')
self.lastimage = time.clock()
filename = 'st'+self.txt_inpt.text+'_gravel_'+now+'_e'+e+'_n'+n+'_z'+z+'_d'+d+'.png'
self.export_to_png(self.ids.camera, filename=filename)
self.textinput.text += 'Gravel image collected'+'\n' #: '+filename+'\n'
try:
mv(filename,'gravelimages')
except:
self.textinput.text += 'ERROR: image could not be stored'
#=========================
def TakePictureRock(self, *args):
#if hasattr(self, 'laststationchange') & hasattr(self, 'lastimage'):
# #self.textinput.text += 'Elapsed: '+str(abs(self.laststationchange - self.lastimage))+'\n'
# if abs(self.laststationchange - self.lastimage) > 30:
# content1 = Button(text = 'Close')
# popup = Popup(title = 'It has been a while ... consider changing station? ', size_hint = (None, None), size = (400,400), auto_dismiss=True, content = content1)
# content1.bind(on_press = popup.dismiss)
# popup.open()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
z = self.textinput3.text.split(':')[3].split(',')[0]
d = self.textinput3.text.split(':')[4].split(',')[0]
if hasattr(self, 'st_n'):
# distance from station start
dist = sqrt((float(n)-float(self.st_n))**2 + (float(e)-float(self.st_e))**2)
if dist > float(self.textinput4.text): #increment station
self.station_up()
self.export_to_png = export_to_png
now = time.asctime().replace(' ','_').replace(':','_')
self.lastimage = time.clock()
filename = 'st'+self.txt_inpt.text+'_rock_'+now+'_e'+e+'_n'+n+'_z'+z+'_d'+d+'.png'
self.export_to_png(self.ids.camera, filename=filename)
self.textinput.text += 'Rock image collected'+'\n' #: '+filename+'\n'
try:
mv(filename,'rockimages')
except:
self.textinput.text += 'ERROR: image could not be stored'
#=========================
def TakePictureSandRock(self, *args):
#if hasattr(self, 'laststationchange') & hasattr(self, 'lastimage'):
# #self.textinput.text += 'Elapsed: '+str(abs(self.laststationchange - self.lastimage))+'\n'
# if abs(self.laststationchange - self.lastimage) > 30:
# content1 = Button(text = 'Close')
# popup = Popup(title = 'It has been a while ... consider changing station? ', size_hint = (None, None), size = (400,400), auto_dismiss=True, content = content1)
# content1.bind(on_press = popup.dismiss)
# popup.open()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
z = self.textinput3.text.split(':')[3].split(',')[0]
d = self.textinput3.text.split(':')[4].split(',')[0]
if hasattr(self, 'st_n'):
# distance from station start
dist = sqrt((float(n)-float(self.st_n))**2 + (float(e)-float(self.st_e))**2)
if dist > float(self.textinput4.text): #increment station
self.station_up()
self.export_to_png = export_to_png
now = time.asctime().replace(' ','_').replace(':','_')
self.lastimage = time.clock()
filename = 'st'+self.txt_inpt.text+'_sand_rock_'+now+'_e'+e+'_n'+n+'_z'+z+'_d'+d+'.png'
self.export_to_png(self.ids.camera, filename=filename)
self.textinput.text += 'Sand/Rock image collected'+'\n' #: '+filename+'\n'
try:
mv(filename,'sandrockimages')
except:
self.textinput.text += 'ERROR: image could not be stored'
#=========================
def TakePictureSandGravel(self, *args):
#if hasattr(self, 'laststationchange') & hasattr(self, 'lastimage'):
# #self.textinput.text += 'Elapsed: '+str(abs(self.laststationchange - self.lastimage))+'\n'
# if abs(self.laststationchange - self.lastimage) > 30:
# content1 = Button(text = 'Close')
# popup = Popup(title = 'It has been a while ... consider changing station? ', size_hint = (None, None), size = (400,400), auto_dismiss=True, content = content1)
# content1.bind(on_press = popup.dismiss)
# popup.open()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
z = self.textinput3.text.split(':')[3].split(',')[0]
d = self.textinput3.text.split(':')[4].split(',')[0]
if hasattr(self, 'st_n'):
# distance from station start
dist = sqrt((float(n)-float(self.st_n))**2 + (float(e)-float(self.st_e))**2)
if dist > float(self.textinput4.text): #increment station
self.station_up()
self.export_to_png = export_to_png
now = time.asctime().replace(' ','_').replace(':','_')
self.lastimage = time.clock()
filename = 'st'+self.txt_inpt.text+'_sand_gravel_'+now+'_e'+e+'_n'+n+'_z'+z+'_d'+d+'.png'
self.export_to_png(self.ids.camera, filename=filename)
self.textinput.text += 'Sand/Gravel image collected'+'\n' #: '+filename+'\n'
try:
mv(filename,'sandgravelimages')
except:
self.textinput.text += 'ERROR: image could not be stored'
#=========================
def TakePictureGravelSand(self, *args):
#if hasattr(self, 'laststationchange') & hasattr(self, 'lastimage'):
# #self.textinput.text += 'Elapsed: '+str(abs(self.laststationchange - self.lastimage))+'\n'
# if abs(self.laststationchange - self.lastimage) > 30:
# content1 = Button(text = 'Close')
# popup = Popup(title = 'It has been a while ... consider changing station? ', size_hint = (None, None), size = (400,400), auto_dismiss=True, content = content1)
# content1.bind(on_press = popup.dismiss)
# popup.open()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
z = self.textinput3.text.split(':')[3].split(',')[0]
d = self.textinput3.text.split(':')[4].split(',')[0]
if hasattr(self, 'st_n'):
# distance from station start
dist = sqrt((float(n)-float(self.st_n))**2 + (float(e)-float(self.st_e))**2)
if dist > float(self.textinput4.text): #increment station
self.station_up()
self.export_to_png = export_to_png
now = time.asctime().replace(' ','_').replace(':','_')
self.lastimage = time.clock()
filename = 'st'+self.txt_inpt.text+'_gravel_sand_'+now+'_e'+e+'_n'+n+'_z'+z+'_d'+d+'.png'
self.export_to_png(self.ids.camera, filename=filename)
self.textinput.text += 'Gravel/Sand image collected'+'\n' #: '+filename+'\n'
try:
mv(filename,'gravelsandimages')
except:
self.textinput.text += 'ERROR: image could not be stored'
#=========================
def change_st(self):
self.textinput.text += 'Station is '+self.txt_inpt.text+'\n'
#self.laststationchange = time.clock()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
# make note of current station
self.st_e = e
self.st_n = n
self.textinput5.text = self.st_e
self.textinput6.text = self.st_n
# get the last site visited and add 1, write to station file
fsite = open('station_start.txt','wb')
fsite.write(str(int(self.txt_inpt.text)+1))
fsite.close()
#=========================
def station_up(self):
self.txt_inpt.text = str(int(self.txt_inpt.text)+1)
self.textinput.text += 'Station is '+self.txt_inpt.text+'\n'
#self.laststationchange = time.clock()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
# make note of current station
self.st_e = e
self.st_n = n
self.textinput5.text = self.st_e
self.textinput6.text = self.st_n
# get the last site visited and add 1, write to station file
fsite = open('station_start.txt','wb')
fsite.write(str(int(self.txt_inpt.text)+1))
fsite.close()
#=========================
def station_down(self):
self.txt_inpt.text = str(int(self.txt_inpt.text)-1)
self.textinput.text += 'Station is '+self.txt_inpt.text+'\n'
#self.laststationchange = time.clock()
e = self.textinput3.text.split(':')[1].split(',')[0]
n = self.textinput3.text.split(':')[2].split(',')[0]
# make note of current station
self.st_e = e
self.st_n = n
self.textinput5.text = self.st_e
self.textinput6.text = self.st_n
# get the last site visited and add 1, write to station file
fsite = open('station_start.txt','wb')
fsite.write(str(int(self.txt_inpt.text)+1))
fsite.close()
#=========================
def TakeTimeStamp(self):
self.textinput.text += 'Time is '+time.asctime()+'\n'
#=========================
def MarkWaypoint(self):
self.textinput.text += 'Mark Waypoint at '+time.asctime()+': '+self.textinput3.text
#=========================
def starwars(self):
try:
self.textinput2.text += cowsay(fortune.get_random_fortune('starwars'))
except:
self.textinput2.text += "install fortune"
#=========================
def fortune(self):
try:
self.textinput2.text += cowsay(fortune.get_random_fortune('fortunes'))
except:
self.textinput2.text += "install fortune"
pass
#=========================
#=========================
class Eyeball_DAQApp(App):
#=========================
def __init__(self, **kwargs):
super(Eyeball_DAQApp, self).__init__(**kwargs)
self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
self._keyboard.bind(on_key_down = self._on_keyboard_down)
self._keyboard.bind(on_key_up = self._on_keyboard_up)
#=========================
def _keyboard_closed(self):
self._keyboard.unbind(on_key_down = self._on_keyboard_down)
self._keyboard = None
#=========================
def _on_keyboard_down(self, *args):
print args[1][1]
#=========================
def _on_keyboard_up(self, *args):
print args[1][1]
#if args[1][1] == 'u':
#=========================
def _update_pos(self, dt):
if self.ser!=0:
try:
dat = get_nmea(self)
e = dat['e_1']
n = dat['n_1']
z = dat['alt']
if self.ser2!=0:
d = dat['depth_m']
if hasattr(self, 'textinput5'):
try:
# distance from station start
dist2 = str(sqrt((float(n)-float(self.textinput6.text))**2 + (float(e)-float(self.textinput5.text))**2))
except:
dist2 = ' '
##self.textinput3.text = 'E: '+str(e)+', N: '+str(n)+', Elevation: '+str(z)+'\n'
self.textinput3.text = 'E: '+str(e)+', N: '+str(n)+', Z: '+str(z)+', D: '+str(d)+', Distance from station: '+dist2+'\n'
except:
self.textinput3.text = 'E: NaN, N: NaN, Z: NaN, D: NaN, Distance from station: NaN\n'
#=========================
def _update_time(self, dt):
self.item.title = 'Current time is '+time.asctime()
#=========================
#def _draw_me(self, dt):
# try:
# e = self.textinput3.text.split(':')[1].split(',')[0]
# n = self.textinput3.text.split(':')[2].split(',')[0]
# self.plot.points.append((float(e),float(n)))
# self.graph.xmax = 10+max(self.plot.points)[0]
# self.graph.xmin = min(self.plot.points)[0]-10
# self.graph.ymax = 10+max(self.plot.points)[1]
# self.graph.ymin = min(self.plot.points)[1]-10
# except:
# pass
# #xmax = random.randint(10, 100)
# #self.plot.points = [(x, sin(x / 10.)) for x in range(0, xmax)]
# #self.graph.xmax = xmax
#=========================
def build(self):
self.ser, self.ser2 = init_serial(self)
root = Accordion(orientation='horizontal')
self.item = AccordionItem(title='Current time is '+time.asctime())
image = CameraWidget(size_hint = (2.0, 1.0))
# log
layout = GridLayout(cols=1)
self.textinput = Log(text='Data Acquisition Log\n', size_hint = (0.25, 1.5), markup=True)
layout.add_widget(self.textinput)
image.textinput = self.textinput
## read nav station positions
#with open('nav_stat_gps.txt') as f:
# dump = f.read()
#f.close()
#dump = dump.split('\n')
#for k in dump:
# if k.startswith('e'):
# ep = float(k.split('=')[1].lstrip())
# elif k.startswith('n'):
# np = float(k.split('=')[1].lstrip())
# elif k.startswith('z'):
# zp = float(k.split('=')[1].lstrip())
print "============================================"
print "============================================"
print "======PROGRAM SETTINGS : INPUT REQUIRED====="
print "============================================"
print "============================================"
self.textinput4 = Log(text=str(input('Distance (m) from present station beyond which station number is updated ')), size_hint = (0, 0), markup=False)
layout.add_widget(self.textinput4)
image.textinput4 = self.textinput4
## for st_e and st_n
self.textinput5 = Log(text='', size_hint = (0, 0), markup=False)
layout.add_widget(self.textinput5)
image.textinput5 = self.textinput5
self.textinput6 = Log(text='', size_hint = (0, 0), markup=False)
layout.add_widget(self.textinput6)
image.textinput6 = self.textinput6
## for map
##layout.add_widget(Button(text='Map', width=100))
#self.graph = Graph(xlabel='E', ylabel='N', x_ticks_minor=1,
#x_ticks_major=25, y_ticks_major=10, y_ticks_minor=1,
#y_grid_label=True, x_grid_label=True, padding=5,
#x_grid=True, y_grid=True, xmin=ep-10, xmax=ep+10, ymin=np-10, ymax=np+10)
#self.plot = MeshLinePlot(color=[1, 0, 0, 1])
#self.plot.points = [(ep,np)]
#self.graph.add_plot(self.plot)
#layout.add_widget(self.graph)
#image.graph1 = self.plot
# for quotes
self.textinput2 = Log(text='', size_hint = (0.25, 0.75), markup=True)
layout.add_widget(self.textinput2)
image.textinput2 = self.textinput2
self.textinput3 = Log(text='\n', size_hint = (0.25, 0.3), markup=True)
layout.add_widget(self.textinput3)
image.textinput3 = self.textinput3
# add image to AccordionItem
self.item.add_widget(image)
#item.add_widget(self.textinput)
self.item.add_widget(layout)
Clock.schedule_interval(self._update_pos, 5)
Clock.schedule_interval(self._update_time, 1)
#Clock.schedule_interval(self._draw_me, 10)
root.add_widget(self.item)
return root
#=========================
def on_stop(self):
# write session log to file
with open(os.path.expanduser("~")+os.sep+'log_'+time.asctime().replace(' ','_').replace(':','_')+'.txt','wb') as f:
f.write(self.textinput.text)
f.close()
with open('station_start.txt','rb') as f:
st=str(f.read()).split('\n')[0]
f.close()
countmax=22; counter=0
with open('eyedaq.kv','rb') as oldfile, open('eyedaq_new.kv','wb') as newfile:
for line in oldfile:
counter += 1
if counter==countmax:
newfile.write(" text: '"+st+"'\n")
else:
newfile.write(line)
mv('eyedaq_new.kv','eyedaq.kv')
## close the csv results files
#bedf_csv.close()
#print "output files closed"
# close the serial port
if self.ser!=0:
self.ser.close()