-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
2478 lines (1861 loc) · 88.3 KB
/
main.m
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
function varargout = main(varargin)
% MAIN M-file for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help main
% Last Modified by GUIDE v2.5 13-Nov-2008 11:29:53
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before main is made visible.
function main_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global ePic; % Creating ePic global object
ePic = ePicKernel();
global ControllerState; % controller is off be default
ControllerState = 0;
global pathDatas; % path graph
pathDatas = zeros(10000,2);
global pathDatai;
pathDatai = 1;
global timer1_period; % update timer
timer1_period=0.1;
global timer1;
global p_buffer; % pointer for value save circular buffer
p_buffer = 0;
global buff_size;
buff_size = 1;
global valuesSensors;
valuesSensors = zeros(1,3);
axes(handles.axes_path);
scatter(0,0); % clear plot
set(handles.axes_path,'XTick',[]);
set(handles.axes_path,'XTickLabel',[]);
set(handles.axes_path,'YTick',[]);
set(handles.axes_path,'YTickLabel',[]);
img = imread('epuck.tif');
axes(handles.axes_epuck);
image(img);
set(handles.axes_epuck,'XTick',[]);
set(handles.axes_epuck,'XTickLabel',[]);
set(handles.axes_epuck,'YTick',[]);
set(handles.axes_epuck,'YTickLabel',[]);
% timer 1 settings
timer1 = timer('TimerFcn',@btm_timer1_Callback,'period',timer1_period);
set(timer1,'ExecutionMode','fixedDelay');
set(timer1,'BusyMode','drop');
% Autodetect serial ports
serialTmp = instrhwinfo('serial');
if (size(serialTmp.SerialPorts,1) > 0)
set(handles.str_port,'String',serialTmp.SerialPorts);
else
set(handles.str_port,'String','no port detected');
end
drawnow;
% if epic is connected, disconnect ePic
if (get(ePic,'connectionState') == 1)
ePic = disconnect(ePic);
end
% --- Outputs from this function are returned to the command line.
function varargout = main_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% Initialse controls
function ResetControls(handles)
set(handles.ck_LED_1,'Value',0);
set(handles.ck_LED_2,'Value',0);
set(handles.ck_LED_3,'Value',0);
set(handles.ck_LED_4,'Value',0);
set(handles.ck_LED_5,'Value',0);
set(handles.ck_LED_6,'Value',0);
set(handles.ck_LED_7,'Value',0);
set(handles.ck_LED_8,'Value',0);
set(handles.ck_LED_B,'Value',0);
set(handles.ck_LED_F,'Value',0);
% --- Executes on button press in btmConnect.
function btmConnect_Callback(hObject, eventdata, handles)
% hObject handle to btmConnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global ePic;
global timer1; % global variable for the timer
global timer1_period; % global variable for the period of timer1
global handles_save;
Sel_Sensor_Callback(hObject, eventdata, handles); % Initialise Sensor Selection
set(handles.txt_err_timer,'Visible','off');
set(handles.txt_timer_stop,'Visible','off');
port = get(handles.str_port,'String');
if length(port) > 1
port = port{get(handles.str_port,'Value')};
end
if (get(ePic,'connectionState') == 0)
set(handles.btmConnect,'String','Connecting...');
set(handles.btmConnect,'Enable','off');
guidata(hObject, handles);
drawnow();
% Open serial connection and init timer
[ePic result] = connect(ePic, port);
if (result == 1)
set(handles.str_port,'Enable','off');
set(handles.btmConnect,'String','Disconnect');
ResetControls(handles);
% create and start timer. Save handles for timer callback function
handles_save = handles;
timer1_period = str2num(get(handles.str_time,'String'));
set(timer1,'period',timer1_period);
start(timer1);
else
% Connection error
msgbox('Connection error. Try an other port or switch the e-puck on');
set(handles.btmConnect,'String','Connect');
end
set(handles.btmConnect,'Enable','on');
else
set(handles.btmConnect,'String','Disconnecting...');
set(handles.btmConnect,'Enable','off');
guidata(hObject, handles);
drawnow();
% Close serial connection and kill timer
stop(timer1);
[ePic result] = disconnect(ePic);
if (result == 1)
set(handles.str_port,'Enable','on');
set(handles.btmConnect,'String','Connect');
set(handles.btmConnect,'Enable','on');
end
end
set(handles.txt_err_timer,'Visible','off');
% --- Executes on button press in ck_LED_0.
function ck_LED_0_Callback(hObject, eventdata, handles)
% hObject handle to ck_LED_0 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_LED_0
global ePic;
if ( get(handles.ck_LED_0,'Value'))
ePic = set(ePic,'ledON', 0);
else
ePic = set(ePic,'ledOFF',0);
end
% --- Executes on button press in ck_LED_1.
function ck_LED_1_Callback(hObject, eventdata, handles)
% hObject handle to ck_LED_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_LED_1
global ePic;
if ( get(handles.ck_LED_1,'Value'))
ePic = set(ePic,'ledON', 1);
else
ePic = set(ePic,'ledOFF',1);
end
% --- Executes on button press in ck_LED_2.
function ck_LED_2_Callback(hObject, eventdata, handles)
% hObject handle to ck_LED_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_LED_2
global ePic;
if ( get(handles.ck_LED_2,'Value'))
ePic = set(ePic,'ledON', 2);
else
ePic = set(ePic,'ledOFF',2);
end
% --- Executes on button press in ck_LED_3.
function ck_LED_3_Callback(hObject, eventdata, handles)
% hObject handle to ck_LED_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_LED_3
global ePic;
if ( get(handles.ck_LED_3,'Value'))
ePic = set(ePic,'ledON', 3);
else
ePic = set(ePic,'ledOFF',3);
end
% --- Executes on button press in ck_LED_4.
function ck_LED_4_Callback(hObject, eventdata, handles)
% hObject handle to ck_LED_4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_LED_4
global ePic;
if ( get(handles.ck_LED_4,'Value'))
ePic = set(ePic,'ledON', 4);
else
ePic = set(ePic,'ledOFF',4);
end
% --- Executes on button press in checkbox5.
function ck_LED_5_Callback(hObject, eventdata, handles)
% hObject handle to checkbox5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox5
global ePic;
if ( get(handles.ck_LED_5,'Value'))
ePic = set(ePic,'ledON', 5);
else
ePic = set(ePic,'ledOFF',5);
end
% --- Executes on button press in checkbox6.
function ck_LED_6_Callback(hObject, eventdata, handles)
% hObject handle to checkbox6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox6
global ePic;
if ( get(handles.ck_LED_6,'Value'))
ePic = set(ePic,'ledON', 6);
else
ePic = set(ePic,'ledOFF',6);
end
% --- Executes on button press in checkbox7.
function ck_LED_7_Callback(hObject, eventdata, handles)
% hObject handle to checkbox7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox7
global ePic;
if ( get(handles.ck_LED_7,'Value'))
ePic = set(ePic,'ledON', 7);
else
ePic = set(ePic,'ledOFF',7);
end
% --- Executes on button press in checkbox8.
function ck_LED_8_Callback(hObject, eventdata, handles)
% hObject handle to checkbox8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox8
global ePic;
if ( get(handles.ck_LED_8,'Value'))
ePic = set(ePic,'ledON', 10);
set(handles.ck_LED_1,'Value',1);
set(handles.ck_LED_2,'Value',1);
set(handles.ck_LED_3,'Value',1);
set(handles.ck_LED_4,'Value',1);
set(handles.ck_LED_5,'Value',1);
set(handles.ck_LED_6,'Value',1);
set(handles.ck_LED_7,'Value',1);
set(handles.ck_LED_B,'Value',1);
set(handles.ck_LED_F,'Value',1);
else
ePic = set(ePic,'ledOFF',10);
set(handles.ck_LED_1,'Value',0);
set(handles.ck_LED_2,'Value',0);
set(handles.ck_LED_3,'Value',0);
set(handles.ck_LED_4,'Value',0);
set(handles.ck_LED_5,'Value',0);
set(handles.ck_LED_6,'Value',0);
set(handles.ck_LED_7,'Value',0);
set(handles.ck_LED_B,'Value',0);
set(handles.ck_LED_F,'Value',0);
end
% --- Executes on button press in ck_LED_B.
function ck_LED_B_Callback(hObject, eventdata, handles)
% hObject handle to ck_LED_B (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_LED_B
global ePic;
if ( get(handles.ck_LED_B,'Value'))
ePic = set(ePic,'ledON', 8);
else
ePic = set(ePic,'ledOFF',8);
end
% --- Executes on button press in checkbox10.
function ck_LED_F_Callback(hObject, eventdata, handles)
% hObject handle to checkbox10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox10
global ePic;
if ( get(handles.ck_LED_F,'Value'))
ePic = set(ePic,'ledON', 9);
else
ePic = set(ePic,'ledOFF',9);
end
% --- Executes on selection change in Sel_Sensor.
function Sel_Sensor_Callback(hObject, eventdata, handles)
% hObject handle to Sel_Sensor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns Sel_Sensor contents as cell array
% contents{get(hObject,'Value')} returns selected item from Sel_Sensor
global ePic;
% disable update
ePic = updateDef(ePic, 'external',0);
set (handles.ck_autoAcc,'Value',0);
% for sensor data saving
buff_size_Callback(hObject, eventdata, handles);
sel_value = get(handles.Sel_Sensor,'Value');
% show/hide led selection
if (sel_value == 10)
set(handles.uipanel_LEDSelect,'Visible','on');
else
set(handles.uipanel_LEDSelect,'Visible','off');
end
if (sel_value <=5)
set (handles.ck_autoAcc,'Visible','off');
else
set (handles.ck_autoAcc,'Visible','on');
end
ePic = set(ePic, 'external', sel_value);
% --- Executes during object creation, after setting all properties.
function Sel_Sensor_CreateFcn(hObject, eventdata, handles)
% hObject handle to Sel_Sensor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function str_value1_Callback(hObject, eventdata, handles)
% hObject handle to str_value1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of str_value1 as text
% str2double(get(hObject,'String')) returns contents of str_value1 as a double
% --- Executes during object creation, after setting all properties.
function str_value1_CreateFcn(hObject, eventdata, handles)
% hObject handle to str_value1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function str_value2_Callback(hObject, eventdata, handles)
% hObject handle to str_value2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of str_value2 as text
% str2double(get(hObject,'String')) returns contents of str_value2 as a double
% --- Executes during object creation, after setting all properties.
function str_value2_CreateFcn(hObject, eventdata, handles)
% hObject handle to str_value2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function str_value3_Callback(hObject, eventdata, handles)
% hObject handle to str_value3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of str_value3 as text
% str2double(get(hObject,'String')) returns contents of str_value3 as a double
% --- Executes during object creation, after setting all properties.
function str_value3_CreateFcn(hObject, eventdata, handles)
% hObject handle to str_value3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in ck_sensorLED_4.
function ck_sensorLED_4_Callback(hObject, eventdata, handles)
% hObject handle to ck_sensorLED_4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_sensorLED_4
% --- Executes on button press in ck_sensorLED_3.
function ck_sensorLED_3_Callback(hObject, eventdata, handles)
% hObject handle to ck_sensorLED_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_sensorLED_3
% --- Executes on button press in ck_sensorLED_1.
function ck_sensorLED_1_Callback(hObject, eventdata, handles)
% hObject handle to ck_sensorLED_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_sensorLED_1
% --- Executes on button press in ck_sensorLED_2.
function ck_sensorLED_2_Callback(hObject, eventdata, handles)
% hObject handle to ck_sensorLED_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_sensorLED_2
% --- Executes on button press in ck_sensorLED_5.
function ck_sensorLED_5_Callback(hObject, eventdata, handles)
% hObject handle to ck_sensorLED_5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_sensorLED_5
% --- Executes on button press in btm_timer1.
function btm_timer1_Callback(hObject, eventdata, handles)
% hObject handle to btm_timer1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tstart = tic;
global ePic;
global handles_save;
global valuesSensors; % used for saving value to MATLAB workspace
global p_buffer;
global buff_size;
global pathDatas; % used to plot path
global pathDatai;
global ControllerState;
global timer1_period;
ePic = update(ePic); % time step : read the requested values
% Selected sensor
selectedSensor = get(handles_save.Sel_Sensor,'Value');
selectedSensorValue = 0;
[val, up] = get(ePic, 'accel'); % Accelerometers
if (up >= 1)
if (selectedSensor == 1)
selectedSensorValue = val;
end
end
[val, up] = get(ePic, 'proxi'); % Proximity sensors
if (up >= 1)
set(handles_save.str_prox1,'String',val(1));
set(handles_save.str_prox2,'String',val(2));
set(handles_save.str_prox3,'String',val(3));
set(handles_save.str_prox4,'String',val(4));
set(handles_save.str_prox5,'String',val(5));
set(handles_save.str_prox6,'String',val(6));
set(handles_save.str_prox7,'String',val(7));
set(handles_save.str_prox8,'String',val(8));
if (selectedSensor == 2)
selectedSensorValue = val;
end
end
[val, up] = get(ePic, 'micro'); % Microphones
if (up >= 1)
if (selectedSensor == 3)
selectedSensorValue = val;
end
end
[val, up] = get(ePic, 'light'); % Light sensors
if (up >= 1)
if (selectedSensor == 4)
selectedSensorValue = val;
end
end
[val, up] = get(ePic, 'speed'); % Motors speed
if (up >= 1)
set(handles_save.str_getLSpeed,'String',val(1));
set(handles_save.str_getRSpeed,'String',val(2));
end
[val, up] = get(ePic, 'pos'); % Motors position
if (up >= 1)
set(handles_save.str_getLPos,'String',val(1));
set(handles_save.str_getRPos,'String',val(2));
end
[val, up] = get(ePic, 'floor'); % Floor sensors
if (up >= 1)
if (selectedSensor == 5)
selectedSensorValue = val;
end
end
% External sensors --------------------------------
% Depend of the current selected sensor
if (selectedSensor == 10) % five led IR sensor
ledIR(1) = get(handles_save.ck_sensorLED_1,'Value');
ledIR(2) = get(handles_save.ck_sensorLED_2,'Value');
ledIR(3) = get(handles_save.ck_sensorLED_3,'Value');
ledIR(4) = get(handles_save.ck_sensorLED_4,'Value');
ledIR(5) = get(handles_save.ck_sensorLED_5,'Value');
ePic = set(ePic,'ledIR',ledIR);
end
if (selectedSensor > 6) % External sensor
[val, up] = get(ePic, 'external');
if (up >= 1)
if (selectedSensor == 13)
selectedSensorValue = val(1);
else
selectedSensorValue = val;
end
end
end
% Display selected sensor value in the global field
tmp_text = '';
for i=1:size(selectedSensorValue,2)
tmp_text{i} = num2str(selectedSensorValue(i));
end
set(handles_save.txt_sensor,'String',tmp_text);
% Save values in global variable
p_buffer = p_buffer + 1;
if (buff_size>-1 && p_buffer>buff_size)
set(handles_save.btm_SaveSensors,'BackgroundColor','g');
p_buffer = 1;
end
if (size(selectedSensorValue,2) ~= size(valuesSensors,2))
valuesSensors = zeros(buff_size,size(selectedSensorValue,2));
end
valuesSensors(p_buffer,:) = selectedSensorValue;
% Update odometry -----------------------------------------
ePic = updateOdometry(ePic);
[val, up] = get(ePic,'odom');
if (up > 0)
set(handles_save.txt_odoX,'String',num2str(100 * val(1)));
set(handles_save.txt_odoY,'String',num2str(100 * val(2)));
set(handles_save.txt_odoT,'String',num2str(val(3)));
end
% Graph e-puck path ---------------------------------------
if (get(handles_save.ck_drawPath,'Value')==1)
[val, up] = get(ePic,'odom');
if (up > 0)
% Refresh path graph
pathDatas(pathDatai,:) = val(1:2);
pathDatai = pathDatai+1;
if (pathDatai==10001)
pathDatai = 1;
end
end
end
% Controller execution ------------------------------------
% (ControllerState==-1 means that switching off is in progress)
if (((get(handles_save.ck_controller,'Value')==1) || (ControllerState==-1)) && (get(ePic,'connectionState') == 1))
tmp = get(handles_save.str_controller,'String');
tmp = tmp{get(handles_save.str_controller,'Value')};
try
eval(strtok(tmp,'.'));
catch
set(handles_save.txt_timer_stop,'Visible','on');
set(handles_save.ck_controller,'Value',0);
err =lasterror;
assignin('base', 'ERROR_msg_controller',err);
error_file = '';
for i=1:size(err.stack,1)
error_file = sprintf('%sFile : %s \n Name : %s, Line : %d \n\n',error_file ,err.stack(i,1).file, err.stack(i,1).name, err.stack(i,1).line);
end
error_msg = sprintf('Error identifier : \n %s \n \n Error message : \n %s \n \n %s', err.identifier,err.message,error_file);
msgbox(error_msg, 'Controller error','error');
end
end
% Check if timer is not too slow
if (timer1_period<toc(tstart))
set(handles_save.txt_err_timer,'Visible','on');
end
% --- Executes on button press in ck_autoAcc.
function ck_autoAcc_Callback(hObject, eventdata, handles)
% hObject handle to ck_autoAcc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_autoAcc
% Refresh the sensor selection
global ePic;
if (status(ePic,'external') ~= 0)
if get(handles.ck_autoAcc,'Value') == 0
ePic=updateDef(ePic,'external',-1);
else
ePic=updateDef(ePic,'external',1);
end
end
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in btm_stop.
function btm_stop_Callback(hObject, eventdata, handles)
% hObject handle to btm_stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global ePic;
ePic=set(ePic,'speed', [0 0]);
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit7 as text
% str2double(get(hObject,'String')) returns contents of edit7 as a double
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit9_Callback(hObject, eventdata, handles)
% hObject handle to edit9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit9 as text
% str2double(get(hObject,'String')) returns contents of edit9 as a double
% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function str_getLSpeed_Callback(hObject, eventdata, handles)
% hObject handle to str_getLSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of str_getLSpeed as text
% str2double(get(hObject,'String')) returns contents of str_getLSpeed as a double
% --- Executes during object creation, after setting all properties.
function str_getLSpeed_CreateFcn(hObject, eventdata, handles)
% hObject handle to str_getLSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function str_getRSpeed_Callback(hObject, eventdata, handles)
% hObject handle to str_getRSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of str_getRSpeed as text
% str2double(get(hObject,'String')) returns contents of str_getRSpeed as a double
% --- Executes during object creation, after setting all properties.
function str_getRSpeed_CreateFcn(hObject, eventdata, handles)
% hObject handle to str_getRSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function str_getLPos_Callback(hObject, eventdata, handles)
% hObject handle to str_getLPos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of str_getLPos as text
% str2double(get(hObject,'String')) returns contents of str_getLPos as a double
% --- Executes during object creation, after setting all properties.
function str_getLPos_CreateFcn(hObject, eventdata, handles)
% hObject handle to str_getLPos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function str_getRPos_Callback(hObject, eventdata, handles)
% hObject handle to str_getRPos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of str_getRPos as text
% str2double(get(hObject,'String')) returns contents of str_getRPos as a double
% --- Executes during object creation, after setting all properties.
function str_getRPos_CreateFcn(hObject, eventdata, handles)
% hObject handle to str_getRPos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in ck_updateMotorS.
function ck_updateMotorS_Callback(hObject, eventdata, handles)
% hObject handle to ck_updateMotorS (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_updateMotorS
% --- Executes on button press in ck_updateMotorP.
function ck_updateMotorP_Callback(hObject, eventdata, handles)
% hObject handle to ck_updateMotorP (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ck_updateMotorP
function str_setLSpeed_Callback(hObject, eventdata, handles)
% hObject handle to str_setLSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of str_setLSpeed as text
% str2double(get(hObject,'String')) returns contents of str_setLSpeed as a double
% --- Executes during object creation, after setting all properties.
function str_setLSpeed_CreateFcn(hObject, eventdata, handles)
% hObject handle to str_setLSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function str_setRSpeed_Callback(hObject, eventdata, handles)
% hObject handle to str_setRSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of str_setRSpeed as text
% str2double(get(hObject,'String')) returns contents of str_setRSpeed as a double
% --- Executes during object creation, after setting all properties.
function str_setRSpeed_CreateFcn(hObject, eventdata, handles)
% hObject handle to str_setRSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.