@@ -22,43 +22,116 @@ function gait_gui_optimize(hAx,hObject,eventdata,handles)
2222g2 = fullfile(datapath ,strcat(current_system ,' __' ,current_shch ,' .mat' ));
2323if exist(g1 ,' file' ) == 2
2424 load(g1 );
25+ if exist(' alpha4' )==1
26+ n_dim= 4 ;
27+ elseif exist(' alpha3' )==1
28+ n_dim= 3 ;
29+ else
30+ n_dim= 2 ;
31+ end
2532elseif exist(g2 ,' file' ) == 2
2633 load(g2 );
34+ n_dim= length(s .vecfield .eval .content .Avec_optimized(1 ,: ));
2735 if numel(p .phi_fun_full ) == 1
2836 t = p.time_full{1 ,1 };
2937 a12 = p.phi_fun_full{1 ,1 }(t );
30- alpha1 = a12(: ,1 );
31- alpha2 = a12(: ,2 );
38+ if n_dim >= 2
39+ alpha1 = a12(: ,1 );
40+ alpha2 = a12(: ,2 );
41+ end
42+ if n_dim >= 3
43+ alpha3 = a12(: ,3 );
44+ end
45+ if n_dim >= 4
46+ alpha4 = a12(: ,4 );
47+ end
3248 else
3349 error(' Selected gait file has more than one cycle. Optimizer only works on single cycles.' )
3450 end
3551end
3652
37- % Interpolating to increase number of points forming the gait
38- endslope1 = (alpha1(2 )-alpha1(end - 1 ))/(t(end )-t(end - 2 ));
39- endslope2 = (alpha2(2 )-alpha2(end - 1 ))/(t(end )-t(end - 2 ));
40- spline_alpha1 = spline(t ,[endslope1 ;alpha1(: );endslope1 ]);
41- spline_alpha2 = spline(t ,[endslope2 ;alpha2(: );endslope2 ]);
42- period = 2 * pi ;
43- n_plot = 100 ;
44- t_plot = linspace(0 ,period ,n_plot + 1 );
45- alpha1_plot = ppval(spline_alpha1 ,t_plot );
46- alpha2_plot = ppval(spline_alpha2 ,t_plot );
47-
53+ if n_dim == 2
54+ % Interpolating to increase number of points forming the gait
55+ endslope1 = (alpha1(2 )-alpha1(end - 1 ))/(t(end )-t(end - 2 ));
56+ endslope2 = (alpha2(2 )-alpha2(end - 1 ))/(t(end )-t(end - 2 ));
57+ spline_alpha1 = spline(t ,[endslope1 ;alpha1(: );endslope1 ]);
58+ spline_alpha2 = spline(t ,[endslope2 ;alpha2(: );endslope2 ]);
59+ period = 2 * pi ;
60+ n_plot = 100 ;
61+ t_plot = linspace(0 ,period ,n_plot + 1 );
62+ alpha1_plot = ppval(spline_alpha1 ,t_plot );
63+ alpha2_plot = ppval(spline_alpha2 ,t_plot );
64+ elseif n_dim == 3
65+ endslope1 = (alpha1(2 )-alpha1(end - 1 ))/(t(end )-t(end - 2 ));
66+ endslope2 = (alpha2(2 )-alpha2(end - 1 ))/(t(end )-t(end - 2 ));
67+ endslope3 = (alpha3(2 )-alpha3(end - 1 ))/(t(end )-t(end - 2 ));
68+ spline_alpha1 = spline(t ,[endslope1 ;alpha1(: );endslope1 ]);
69+ spline_alpha2 = spline(t ,[endslope2 ;alpha2(: );endslope2 ]);
70+ spline_alpha3 = spline(t ,[endslope3 ;alpha3(: );endslope3 ]);
71+ period = 2 * pi ;
72+ n_plot = 100 ;
73+ t_plot = linspace(0 ,period ,n_plot + 1 );
74+ alpha1_plot = ppval(spline_alpha1 ,t_plot );
75+ alpha2_plot = ppval(spline_alpha2 ,t_plot );
76+ alpha3_plot = ppval(spline_alpha3 ,t_plot );
77+ elseif n_dim == 4
78+ endslope1 = (alpha1(2 )-alpha1(end - 1 ))/(t(end )-t(end - 2 ));
79+ endslope2 = (alpha2(2 )-alpha2(end - 1 ))/(t(end )-t(end - 2 ));
80+ endslope3 = (alpha3(2 )-alpha3(end - 1 ))/(t(end )-t(end - 2 ));
81+ endslope4 = (alpha4(2 )-alpha4(end - 1 ))/(t(end )-t(end - 2 ));
82+ spline_alpha1 = spline(t ,[endslope1 ;alpha1(: );endslope1 ]);
83+ spline_alpha2 = spline(t ,[endslope2 ;alpha2(: );endslope2 ]);
84+ spline_alpha3 = spline(t ,[endslope3 ;alpha3(: );endslope3 ]);
85+ spline_alpha4 = spline(t ,[endslope4 ;alpha4(: );endslope3 ]);
86+ period = 2 * pi ;
87+ n_plot = 100 ;
88+ t_plot = linspace(0 ,period ,n_plot + 1 );
89+ alpha1_plot = ppval(spline_alpha1 ,t_plot );
90+ alpha2_plot = ppval(spline_alpha2 ,t_plot );
91+ alpha3_plot = ppval(spline_alpha3 ,t_plot );
92+ alpha4_plot = ppval(spline_alpha4 ,t_plot );
93+ end
4894% loading sysf file
4995f= fullfile(datapath ,strcat(current_system ,' _calc.mat' ));
5096load(f );
5197
52- % Calling the optimizer
53- lb= 0.95 *[s .grid_range(1 )*ones(n_plot + 1 ,1 );s .grid_range(3 )*ones(n_plot + 1 ,1 )];% 0.9 was points value
54- ub= 0.95 *[s .grid_range(2 )*ones(n_plot + 1 ,1 );s .grid_range(4 )*ones(n_plot + 1 ,1 )];
55- y= optimalgaitgenerator(s ,2 ,n_plot ,alpha1_plot ,alpha2_plot ,lb ,ub ,hAx ,hObject ,eventdata ,handles );
56- alpha1 = [y(1 : 100 )' ,y(1 )]' ;
57- alpha2 = [y(101 : 200 )' ,y(101 )]' ;
58- t= t_plot ;
59- tnew= t(1 ): (t(2 )-t(1 ))/4 : t(end );
60- alpha12= interp1(t ,alpha1 ,tnew ,' spline' );
61- alpha22= interp1(t ,alpha2 ,tnew ,' spline' );
98+ if n_dim == 2
99+ % Calling the optimizer
100+ lb= 0.95 *[s .grid_range(1 )*ones(n_plot + 1 ,1 );s .grid_range(3 )*ones(n_plot + 1 ,1 )];% 0.9 was points value
101+ ub= 0.95 *[s .grid_range(2 )*ones(n_plot + 1 ,1 );s .grid_range(4 )*ones(n_plot + 1 ,1 )];
102+ y= optimalgaitgenerator(s ,2 ,n_plot ,alpha1_plot ,alpha2_plot ,lb ,ub );
103+ alpha1 = [y(1 : 100 )' ,y(1 )]' ;
104+ alpha2 = [y(101 : 200 )' ,y(101 )]' ;
105+ t= t_plot ;
106+ tnew= t(1 ): (t(2 )-t(1 ))/4 : t(end );
107+ alpha12= interp1(t ,alpha1 ,tnew ,' spline' );
108+ alpha22= interp1(t ,alpha2 ,tnew ,' spline' );
109+ elseif n_dim == 3
110+ % Calling the optimizer
111+ lb= 0.95 *[s .grid_range(1 )*ones(n_plot + 1 ,1 );s .grid_range(3 )*ones(n_plot + 1 ,1 );s .grid_range(5 )*ones(n_plot + 1 ,1 )];% 0.9 was points value
112+ ub= 0.95 *[s .grid_range(2 )*ones(n_plot + 1 ,1 );s .grid_range(4 )*ones(n_plot + 1 ,1 );s .grid_range(6 )*ones(n_plot + 1 ,1 )];
113+ y= optimalgaitgenerator3(s ,3 ,n_plot ,alpha1_plot ,alpha2_plot ,alpha3_plot ,lb ,ub );
114+ alpha1 = [y(1 : 100 )' ,y(1 )]' ;
115+ alpha2 = [y(101 : 200 )' ,y(101 )]' ;
116+ alpha3 = [y(201 : 300 )' ,y(201 )]' ;
117+ t= t_plot ;
118+ tnew= t(1 ): (t(2 )-t(1 ))/4 : t(end );
119+ alpha12= interp1(t ,alpha1 ,tnew ,' spline' );
120+ alpha22= interp1(t ,alpha2 ,tnew ,' spline' );
121+ elseif n_dim == 4
122+ % Calling the optimizer
123+ lb= 0.95 *[s .grid_range(1 )*ones(n_plot + 1 ,1 );s .grid_range(3 )*ones(n_plot + 1 ,1 );s .grid_range(5 )*ones(n_plot + 1 ,1 );s .grid_range(7 )*ones(n_plot + 1 ,1 )];% 0.9 was points value
124+ ub= 0.95 *[s .grid_range(2 )*ones(n_plot + 1 ,1 );s .grid_range(4 )*ones(n_plot + 1 ,1 );s .grid_range(6 )*ones(n_plot + 1 ,1 );s .grid_range(8 )*ones(n_plot + 1 ,1 )];
125+ y= optimalgaitgenerator4(s ,4 ,n_plot ,alpha1_plot ,alpha2_plot ,alpha3_plot ,alpha4_plot ,lb ,ub );
126+ alpha1 = [y(1 : 100 )' ,y(1 )]' ;
127+ alpha2 = [y(101 : 200 )' ,y(101 )]' ;
128+ alpha3 = [y(201 : 300 )' ,y(201 )]' ;
129+ alpha4 = [y(301 : 400 )' ,y(301 )]' ;
130+ t= t_plot ;
131+ tnew= t(1 ): (t(2 )-t(1 ))/4 : t(end );
132+ alpha12= interp1(t ,alpha1 ,tnew ,' spline' );
133+ alpha22= interp1(t ,alpha2 ,tnew ,' spline' );
134+ end
62135
63136
64137% Provide zdata to line if necessary
@@ -97,7 +170,13 @@ function gait_gui_optimize(hAx,hObject,eventdata,handles)
97170 % Save the data to a parameters file
98171% save(fullfile(shchpath,paramfilename),'alpha1','alpha2','t')
99172% save(fullfile(shchpath,strcat(paramfilenamebare,'_optimal.mat')),'alpha1','alpha2','t')
173+ if n_dim == 2
100174 save(fullfile(shchpath ,strcat(paramfiletext ,' .mat' )),' alpha1' ,' alpha2' ,' t' )
175+ elseif n_dim == 3
176+ save(fullfile(shchpath ,strcat(paramfiletext ,' .mat' )),' alpha1' ,' alpha2' ,' alpha3' ,' t' )
177+ elseif n_dim == 4
178+ save(fullfile(shchpath ,strcat(paramfiletext ,' .mat' )),' alpha1' ,' alpha2' ,' alpha3' ,' alpha4' ,' t' )
179+ end
101180
102181 % Create the file if it doesn't already exist; future work could be
103182 % more fine-grained about this (making sure that any patches are
@@ -107,7 +186,7 @@ function gait_gui_optimize(hAx,hObject,eventdata,handles)
107186 % ['shchf_' paramfilenamebare '.m']
108187 if ~exist(fullfile(shchpath ,[' shchf_' paramfiletext ' .m' ]),' file' )
109188 % [paramfilenamebare '_optimal'], [paramfilenamebare '_optimal']
110- gait_gui_draw_make_shchf(paramfiletext ,paramfiledisplaytext )
189+ gait_gui_draw_make_shchf(paramfiletext ,paramfiledisplaytext , n_dim )
111190
112191 end
113192
@@ -134,7 +213,7 @@ function gait_gui_optimize(hAx,hObject,eventdata,handles)
134213 lastpushbutton = ' plotpushbutton1' ;
135214end
136215
137- plot_info = plotpushbutton_Callback(findall(0 ,' tag' ,lastpushbutton ), eventdata , handles );
216+ plot_info = plotpushbutton_Callback(findall(0 ,' tag' ,lastpushbutton ), eventdata , handles );
138217
139218
140219end
0 commit comments