forked from NiryoRobotics/niryo_one_matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matlab_Gui.m
669 lines (591 loc) · 29.6 KB
/
Matlab_Gui.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
%/////////////////////////////////////%
% @project MATLAB-ROS Interface %
% @Niryo One %
% @filename Matlab_Gui %
%/////////////////////////////////////%
% Matlab_Gui.m
% Copyright (C) 2018 Niryo
% All rights reserved.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% this fucntion is created by guide matlab %
function varargout = Matlab_Gui(varargin)
% MATLAB_GUI MATLAB code for Matlab_Gui.fig
% MATLAB_GUI, by itself, creates a new MATLAB_GUI or raises the existing
% singleton*.
%
% H = MATLAB_GUI returns the handle to a new MATLAB_GUI or the handle to
% the existing singleton*.
%
% MATLAB_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MATLAB_GUI.M with the given input arguments.
%
% MATLAB_GUI('Property','Value',...) creates a new MATLAB_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Matlab_Gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Matlab_Gui_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
% Edit the above text to modify the response to help Matlab_Gui
% Last Modified by GUIDE v2.5 06-Apr-2018 16:02:23
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Matlab_Gui_OpeningFcn, ...
'gui_OutputFcn', @Matlab_Gui_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 Matlab_Gui is made visible.
function Matlab_Gui_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 Matlab_Gui (see VARARGIN)
% Choose default command line output for Matlab_Gui
global new_data_trajectory_received;
new_data_trajectory_received=0;
rosshutdown; % shutdown any ros node
connexion_state =0; % indicate if the robot si connected
handles.connexion_state=connexion_state;
guidata(hObject,handles);
handles.output = hObject;
handles.output = hObject;
axes(handles.axes1);
imshow('images/logo.png');
axes(handles.axes2);
imshow('images/Matlab_Logo.png');
% Update handles structure
guidata(hObject, handles);
set(handles.connect,'string','Connect to Niryo One')
set(handles.connectionButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white')
set(handles.plotButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles. logsButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles.hwButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles.commandButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles.connectionPanel,'visible','on')
set(handles.commandPanel,'visible','off')
set(handles.hwPanel,'visible','off')
set(handles.logsPanel,'visible','off')
set(handles.plotPanel,'visible','off')
% UIWAIT makes Matlab_Gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Matlab_Gui_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;
% --- Executes on button press in connectionButton.
function connectionButton_Callback(~, ~, handles)
set(handles.connectionPanel,'visible','on')
set(handles.commandPanel,'visible','off')
set(handles.hwPanel,'visible','off')
set(handles.logsPanel,'visible','off')
set(handles.plotPanel,'visible','off')
set(handles.connectionButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white')
set(handles.commandButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles.plotButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles. logsButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles.hwButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
% --- Executes on button press in commandButton.
function commandButton_Callback(hObject, ~, handles)
% hObject handle to commandButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.connectionPanel,'visible','off');
set(handles.commandPanel,'visible','on');
set(handles.hwPanel,'visible','off');
set(handles.logsPanel,'visible','off');
set(handles.plotPanel,'visible','off');
set(handles.edit56,'visible','off');
set(handles.commandButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
set(handles.connectionButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.plotButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles. logsButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.hwButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
if handles.connexion_state ==0
return;
end
hw_status_msg=receive(handles.hw_status,10);% receiv ehardware status msg
if (hw_status_msg.CalibrationNeeded==0) && (hw_status_msg.CalibrationInProgress==false) % get calibrationNeeded flag
set(handles.motorbutton,'visible','off');
set(handles.newCalibrationButton,'visible','on');
elseif (hw_status_msg.CalibrationInProgress==true)
set(handles.motorbutton,'visible','off');
set(handles.newCalibrationButton,'visible','off');
elseif (hw_status_msg.CalibrationNeeded==1)&& (hw_status_msg.CalibrationInProgress==false)
set(handles.motorbutton,'visible','on');
set(handles.newCalibrationButton,'visible','off');
end
% --- Executes on button press in plotButton.
function plotButton_Callback(~, eventdata, handles)
% hObject handle to plotButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.connectionPanel,'visible','off');
set(handles.commandPanel,'visible','off');
set(handles.hwPanel,'visible','on');
set(handles.logsPanel,'visible','off');
set(handles.plotPanel,'visible','on');
set(handles.edit55,'visible','off');
set(handles.plotButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
set(handles.connectionButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.commandButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles. logsButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.hwButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
% --- Executes on button press in logsButton.
function logsButton_Callback(hObject, ~, handles)
% hObject handle to logsButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global logs
set(handles.connectionPanel,'visible','off')
set(handles.commandPanel,'visible','off')
set(handles.hwPanel,'visible','off')
set(handles.logsPanel,'visible','on')
set(handles.plotPanel,'visible','off')
set(handles.logsButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white')
set(handles.connectionButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles.commandButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles.plotButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles.hwButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89])
set(handles.editlogs,'string',logs)% dispay application logs
% --- Executes on button press in hwButton.
function hwButton_Callback(hObject, eventdata, handles)
%global hw_status;
global logs;
% test if the robot is connected
if handles.connexion_state==0
logs=logs+newline+"you should connect to you robot first";
guidata(hObject,handles);
return;
end
% hObject handle to hwButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.connectionPanel,'visible','off');
set(handles.commandPanel,'visible','off');
set(handles.hwPanel,'visible','on');
set(handles.logsPanel,'visible','off');
set(handles.plotPanel,'visible','off');
set(handles.hwButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
set(handles.connectionButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.commandButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.plotButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.logsButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
hw_status_msg=receive(handles.hw_status,10);
logs=logs+ newline+ "Get hardware status";
set(handles.edit21,'string', hw_status_msg.RpiTemperature);
set(handles.edit22,'string', hw_status_msg.CalibrationNeeded);
% set(handles.edit20,'string', hw_status_msg.CalibrationInProgress);
get_hardware_status_motors(handles,hw_status_msg);
guidata(hObject,handles);
% button connect to niryo one %
% this function callback set matlab environemment , start a matlab node and
% connect to master ( robot)%
% create subscribers, publishers and services for the application %
% --- Executes on button press in connect
function connect_Callback(hObject, eventdata, handles)
global logs;
global new_data_trajectory_received;
new_data_trajectory_received=0;
set(handles.moveButton,'string','2.Move Joints','BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.disconnect,'string','Disconnect from Niryo One');
logs='';
set(handles.connect,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
if (handles.connexion_state == 0)
Robot_ip_adress = get(handles.edit1,'String'); % get robot ip adress
Robot_ip_adress = strcat('http://',Robot_ip_adress,':11311');
Computer_ip_adress = get(handles.edit2,'String');% get computer ip adress
setenv('ROS_MASTER_URI',Robot_ip_adress); % set ros matser URI to specifie the ros master location
setenv('ROS_IP',Computer_ip_adress); % set environment variables ROS_IP( network address of a ROS Node ), It's must be ip adress of the pc where matlab is installed
try
rosinit; % initialize ROS
catch e
logs= e.message;
set(handles.connect,'BackgroundColor','red','ForegroundColor','white');
pause(0.75);
set(handles.connect,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
return;
end
set(handles.connect,'string','Connecting....... ','BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
%pause(2);
logs="connected to niryo one";
% hardware status
try
hw_status=rossubscriber('/niryo_one/hardware_status'); %create a subscriber for hardware statuts topic
handles.hw_status=hw_status;
catch e
logs= e.message;
rosshutdown;
return;
end
% learning mode
handles.learning_mode_client=rossvcclient('/niryo_one/activate_learning_mode');% create a ros service client for activate learning mode
handles.learning_mode_req = rosmessage(handles.learning_mode_client); % create message for learning_mode_client
disp('..............learning mode .......');
handles.Learning_mode_state=rossubscriber('/niryo_one/learning_mode');
logs=logs+ newline+ " Connect to Learning Mode service ";
% request new calibartion
handles.new_calibration=rossvcclient('/niryo_one/request_new_calibration');
handles.new_calibration_msg= rosmessage(handles.new_calibration);
disp('..............create request new calibration message .......');
logs=logs +newline +"create request new calibration message .";
% calibrate motors%
handles.calibrate_motors_client=rossvcclient('/niryo_one/calibrate_motors');
handles.calibrate_motors_msg=rosmessage(handles.calibrate_motors_client);
disp('create calibrate maoters message');
logs=logs +newline +'create calibrate motors message ';
% get trajectory
handles.theor_trajectory_sub=rossubscriber('/niryo_one_follow_joint_trajectory_controller/follow_joint_trajectory/goal') ;
handles.jointState=rossubscriber('/joint_states','BufferSize',40);
% Matlab node subscirbers and publisher
handles.move_joint_sub=rossubscriber('/niryo_one_matlab/result') ;
handles.move_joint_pub=rospublisher('/niryo_one_matlab/command');
handles.move_joint_msg=rosmessage(handles.move_joint_pub);
% button set
set(handles.connect,'string','connected ','BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
handles.connexion_state=1;
guidata(hObject, handles);
else
logs=logs+ newline+ "you are already connected to your robot.";
disp('.............you are already connected to your robot ...................');
end
% --- Executes on button press in disconnect.
function disconnect_Callback(hObject,~, handles)
global logs;
set(handles.disconnect,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
if (handles.connexion_state==1)
rosshutdown;
handles.connexion_state =0;
logs=logs+ newline + "disconnect form niryo one";
set(handles.connect,'string','Connect to Niryo One ');
set(handles.disconnect,'string','disconnected','BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
else
logs=logs+ newline + "you are already disconnect form niryo one";
set(handles.disconnect,'string','disconnected','BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.connect,'string','Connect to Niryo One ');
end
guidata(hObject, handles);
% --- Executes on button press in moveButton.
function moveButton_Callback(hObject, eventdata, handles)
global logs;
if (handles.connexion_state==0)
logs=logs+newline+"you should connect to you robot first";
return;
end
set(handles.moveButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
[validation,joint]=validate_joints(handles,handles.Learning_mode_state,logs) ;
if validation==0
return ;
end
handles.move_joint_msg.CmdType=1;
handles.move_joint_msg.Joints=joint;
send(handles.move_joint_pub,handles.move_joint_msg);
set(handles.moveButton,'string','Moving.....','BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
logs=logs+newline+"move jonit";
set(handles.moveButton,'string','2.Move Joints','BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
% --- Executes on button press in learningModeButton.
function learningModeButton_Callback(hObject, eventdata, handles)
global logs;
if (handles.connexion_state==0)
logs=logs+newline+"you should connect to you robot first" ;
return;
end
Learning_mode_state_msg=receive(handles.Learning_mode_state);
set(handles.learningModeButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
if (Learning_mode_state_msg.Data==1)
set_learning_mode_msg(handles.learning_mode_client,handles.learning_mode_req,0,logs,handles) ;
else
set_learning_mode_msg(handles.learning_mode_client,handles.learning_mode_req,1,logs,handles) ;
end
set(handles.learningModeButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.edit56,'visible','off');
% --- Executes on button press in motorbutton.
function motorbutton_Callback(~, ~, handles)
global logs;
if handles.connexion_state==0
logs=logs+newline+"you should connect to you robot first" ;
return;
end
set(handles.motorbutton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
% testif the calibrationNeeded is on or off
motor_calibration_resp = call(handles.calibrate_motors_client,handles.calibrate_motors_msg);
disp( motor_calibration_resp.Message);
logs=logs+ newline + motor_calibration_resp.Message;
set(handles.edit56,'string',motor_calibration_resp.Message,'visible','on');
pause(1)
set(handles.edit56,'visible','off');
set(handles.motorbutton,'visible','off');
set(handles.newCalibrationButton,'visible','off');
set(handles.motorbutton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
hw_status_msg=receive(handles.hw_status) ;
while(hw_status_msg.CalibrationInProgress==true)
hw_status_msg=receive(handles.hw_status);
end
set(handles.motorbutton,'visible','off');
set(handles.newCalibrationButton,'visible','on');
% --- Executes on button press in newCalibrationButton.
function newCalibrationButton_Callback(hObject, eventdata,handles)
global logs;
if handles.connexion_state==0
logs=logs+newline+"you should connect to you robot first" ;
return;
end
set(handles.newCalibrationButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
new_calibration_resp = call(handles.new_calibration,handles.new_calibration_msg);
disp('.......new calibration requested.........');
set(handles.edit56,'string',new_calibration_resp.Message,'visible','on');
pause(0.5);
set(handles.edit56,'visible','off');
logs=logs+ newline+new_calibration_resp.Message;
set(handles.newCalibrationButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
set(handles.motorbutton,'visible','on');
set(handles.newCalibrationButton,'visible','off');
% choose joint graph %%%%%%
function jointGroup_SelectionChangedFcn(hObject, eventdata, handles)
global thero_trajectory;
global real_trajectory;
global diff_trajectory;
global imported_data;
global time;
global jointStateMsg; % joint State Message : real trajectory
global thero_trajectory_data ; %follow joint trajectory Goal message : thero trajectory
global logs;
if handles.connexion_state==0
logs=logs+newline+"you should connect to you robot first";
return;
end
[theor_time,thero_y,real_time,real_y,diff_y,imported_data]=get_trajectories(thero_trajectory,real_trajectory,diff_trajectory,imported_data,time,jointStateMsg,thero_trajectory_data);
handles.theor_time=theor_time;
handles.thero_y=thero_y;
handles.real_time=real_time;
handles.real_y=real_y;
handles.diff_y=diff_y;
switch get(get(handles.jointGroup,'SelectedObject'),'Tag') % Get Tag of selected object
case 'radiobutton7'
%execute this code when fontsize08_radiobutton is selected
plot_graphs(handles,handles.real_time,handles.theor_time, handles.diff_y,handles.thero_y,handles.real_y,1,-3.1,3.1);
case 'radiobutton8'
%joint2
plot_graphs(handles,real_time,theor_time,diff_y,thero_y,real_y,2,-1.7,1.7);
case 'radiobutton9'
%joint3
plot_graphs(handles,handles.real_time,handles.theor_time,handles.diff_y,handles.thero_y,handles.real_y,3,-1.6,1.1);
case 'radiobutton10'
%joint4
plot_graphs(handles,handles.real_time,handles.theor_time,handles.diff_y,handles.thero_y,handles.real_y,4,-2.8,2.8);
case 'radiobutton11'
% joint5
plot_graphs(handles,handles.real_time,handles.theor_time,handles.diff_y,handles.thero_y,handles.real_y,5,-2.5,2.5);
case 'radiobutton12'
%joint6
plot_graphs(handles,handles.real_time,handles.theor_time,handles.diff_y,handles.thero_y,handles.real_y,6,-2.8,2.8);
otherwise
end
guidata(hObject, handles);
% --- Executes on button press in trajectoryButton.
% on plot Panel
function trajectoryButton_Callback(hObject, eventdata, handles)
global new_data_trajectory_received;
global thero_trajectory_data ;
global logs;
global jointStateMsg;
global time;
if handles.connexion_state==0
logs=logs+newline+"you should connect to you robot first" ;
return;
end
set(handles.trajectoryButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
thero_trajectory_data=receive(handles.theor_trajectory_sub);
logs= logs+newline+"get a new trajectory";
[jointStateMsg,time]=get_joint_state(handles,thero_trajectory_data,handles.jointState);
logs= logs+newline+"get real trajectory";
set(handles.trajectoryButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
new_data_trajectory_received=1;
jointGroup_SelectionChangedFcn(hObject, eventdata, handles);
% --- Executes get trajectory
% On command Panel
function getTrajectoryButton_Callback(hObject, eventdata, handles)
global new_data_trajectory_received;
global thero_trajectory_data ;
global logs;
global jointStateMsg;
global time;
if handles.connexion_state==0
logs=logs+newline+"you should connect to you robot first" ;
return;
end
set(handles.getTrajectoryButton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
thero_trajectory_data=receive(handles.theor_trajectory_sub);
logs= logs+newline+"get theoretical trajectory ";
[jointStateMsg,time]=get_joint_state(handles,thero_trajectory_data,handles.jointState);
logs= logs+newline+" get real trajectory ";
set(handles.getTrajectoryButton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
new_data_trajectory_received=1;
plotButton_Callback(hObject, eventdata, handles);
jointGroup_SelectionChangedFcn(hObject, eventdata, handles);
% --- Executes export data to a file %%%%%%%%%%%%%%%%
function exportbutton_Callback(hObject, eventdata, handles)
% hObject handle to exportbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global new_data_trajectory_received;
global joint_position;
global thero_trajectory_data;
global logs ;
global time;
global jointStateMsg;
set(handles.exportbutton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
if(new_data_trajectory_received==0)||(handles.connexion_state==0)
set(handles.edit55,'string','try to get a new trajectory command ','visible','on');
pause(1);
set(handles.edit55,'visible','off') ;
set(handles.exportbutton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
return;
end
try
joint_position=[thero_trajectory_data.Goal.Trajectory.Points(:,1).Positions];
export_trajectory(time,jointStateMsg,thero_trajectory_data,joint_position);
catch e
logs= logs+ newline + "you should specify file name , try again";
set(handles.exportbutton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
return;
end
logs= logs + newline +"export trajectory " ;
set(handles.edit55,'string','data exported successfully','visible','on');
pause(1);
set(handles.edit55,'visible','off');
new_data_trajectory_received=0;
set(handles.exportbutton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
% --- Executes on button press in importButton.
function importButton_Callback(hObject, eventdata, handles)
% hObject handle to importButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global thero_trajectory;
global real_trajectory;
global diff_trajectory;
global imported_data;
try
set(handles.exportbutton,'BackgroundColor',[0.1,0.67,0.89],'ForegroundColor','white');
[thero_trajectory,real_trajectory,diff_trajectory]=import_trajectory();
imported_data=1;
set(handles.exportbutton,'BackgroundColor','white','ForegroundColor',[0.1,0.67,0.89]);
jointGroup_SelectionChangedFcn(hObject, eventdata, handles);
catch e
return;
end
% --- Executes on button press in set_current_button.
function set_current_button_Callback(hObject, eventdata, handles)
try
jointStateMessage=receive(handles.jointState);
current_position=[jointStateMessage.Position];
set(handles.joint1,'string',current_position(1,:));
set(handles.joint2,'string',current_position(2,:));
set(handles.joint3,'string',current_position(3,:));
set(handles.joint4,'string',current_position(4,:));
set(handles.joint5,'string',current_position(5,:));
set(handles.joint6,'string',current_position(6,:));
catch e
disp("you need to connect to niryo one first ") ;
return;
end
function figurebutton_Callback(~, eventdata, handles)
% hObject handle to figurebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%jointGroup_SelectionChangedFcn(hObject, eventdata, handles)
try
switch get(get(handles.jointGroup,'SelectedObject'),'Tag') % Get Tag of selected object
%joint1
case 'radiobutton7'
i=1;
figure('Name','Joint 1 ');
plot(handles.real_time,handles.real_y(i,:),'b',handles.theor_time,handles.thero_y(i,:),'--r');
xlabel('time');
ylabel('trajectory');
legend('theorical','real');
grid on ;
title('joint1 trajectory');
%joint2
case 'radiobutton8'
i=2;
figure('Name','Joint 2 ');
plot(handles.real_time,handles.real_y(i,:),'b',handles.theor_time,handles.thero_y(i,:),'--r');
xlabel('time');
ylabel('trajectory');
legend('theorical','real');
grid on
title('joint 2 trajectory')
%joint3
case 'radiobutton9'
i=3;
figure('Name','Joint 3 ');
plot(handles.real_time,handles.real_y(i,:),'b',handles.theor_time,handles.thero_y(i,:),'--r');
xlabel('time');
ylabel('trajectory');
legend('theorical','real');
grid on ;
title('joint 4 trajectory');
%joint4
case 'radiobutton10'
i=4;
figure('Name','Joint 4 ');
plot(handles.real_time,handles.real_y(i,:),'b',handles.theor_time,handles.thero_y(i,:),'--r');
xlabel('time');
ylabel('trajectory');
legend('theorical','real');
grid on ;
title('joint 4 trajectory');
case 'radiobutton11'
% joint5
i=5;
figure('Name','Joint 5');
plot(handles.real_time,handles.real_y(i,:),'b',handles.theor_time,handles.thero_y(i,:),'--r');
xlabel('time');
ylabel('trajectory');
legend('theorical','real');
grid on ;
title('joint 5 trajectory');
%joint6
case 'radiobutton12'
i=6;
figure('Name','Joint 6 ');
plot(handles.real_time,handles.real_y(i,:),'b',handles.theor_time,handles.thero_y(i,:),'--r');
xlabel('time');
ylabel('trajectory');
legend('theorical','real');
grid on ;
title('joint 6 trajectory');
otherwise
end
catch e
disp("there is no data to plot");
end
% % --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
jointGroup_SelectionChangedFcn(hObject, eventdata, handles);