diff --git a/controls/DataAnalysisTool/Tool/DataAnalysis.m b/controls/DataAnalysisTool/Tool/DataAnalysis.m index 34834d0460e095c21808b0cc26c5d084546a9319..5cd77413d324f07efd498f48265e068b096ef1b3 100644 --- a/controls/DataAnalysisTool/Tool/DataAnalysis.m +++ b/controls/DataAnalysisTool/Tool/DataAnalysis.m @@ -8,14 +8,14 @@ % window. % %fname = 'sampleLogFileWithMarker.txt'; -fname = 'testies_v2.txt'; +fname = ''; % PLOTTING SWITCHES - set them to 0 or 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % plot = 1; % to choose plotting separatePlot = 1; % to generate separatePlots multiPlot = 1; % to generate multiPlot -subPlot = 0; % to generate subPlots +subPlot = 1; % to generate subPlots clearFigs = 0; % to close all the plots (needed only by the GUI) % DATA TO PLOT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -25,27 +25,28 @@ clearFigs = 0; % to close all the plots (needed only by the GUI) % seperatePlots. If this is empty but "plot" switch is 1, all the columns % will be plotted using seperatePlots. % -separateData = {'PID_roll_vel'}; +separateData = {'X pos PID_Correction', 'Altitude PID_Correction'}; % MULTIDATA % write names of the data headers that you want to plot using multiPlots. % If this is empty but "plot" switch is 1, the data headers in separateData % will be plotted using multiPlots. % -multiData = {}; +multiData = {'X pos PID_Correction', 'Altitude PID_Correction'}; % SUBDATA % write names of the data headers that you want to plot using subPlots. % If this is empty but "plot" switch is 1, the data headers in multiData % will be plotted using subPlots. % -subData = {}; +subData = {'X pos PID_Correction', 'Altitude PID_Correction'}; + % COLOR FOR PLOTTING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % color = 'r'; % one character for color of the plotting line marker = ''; % one character for the marker of the plotting line -style = ':'; % one character for the style of the plotting line +style = '-'; % one character for the style of the plotting line backgnd = [1 1 1]; % rgb array for background color of the plot @@ -94,10 +95,9 @@ expData = parse_log(params.file.pathName, params); % plot the data accoriding to the plotting parameters set % plot_data(expData, params.plotting); - %% creating the main structure to be stored in the workspace %%%%%%%%%%%%% % -main.params = params; -main.expData = expData; -clearvars -except main; -save main main; \ No newline at end of file +% main.params = params; +% main.expData = expData; +% clearvars -except main; +% save main main; \ No newline at end of file diff --git a/controls/DataAnalysisTool/Tool/main.mat b/controls/DataAnalysisTool/Tool/main.mat deleted file mode 100644 index 2385f3363d899a77037979f39fda9055a9a94454..0000000000000000000000000000000000000000 Binary files a/controls/DataAnalysisTool/Tool/main.mat and /dev/null differ diff --git a/controls/DataAnalysisTool/Tool/parse_log.m b/controls/DataAnalysisTool/Tool/parse_log.m index f265c9c849b881ba8452362518bed7b4106f994d..acdf40e77d7f1294c58d8c2a26c39a741cf382a9 100644 --- a/controls/DataAnalysisTool/Tool/parse_log.m +++ b/controls/DataAnalysisTool/Tool/parse_log.m @@ -43,6 +43,7 @@ identifier = string(1); if (regexp(identifier,'%')) foundHeaders = 1; % this is a line of headers; extract headers: + string = strrep(string,' ', '_'); headers = strsplit(string); headers{1} = strrep(headers{1},'%', ''); numOfHeaders = length(headers); @@ -126,17 +127,20 @@ if exist('params', 'var') end else for i = 1:length(params.plotting.separateData) + params.plotting.separateData{i} = strrep(params.plotting.separateData{i},' ', '_'); eval(['loggedData.' params.plotting.separateData{i} '.params.plot = 1;']); end end else for i = 1:length(params.plotting.multiData) + params.plotting.multiData{i} = strrep(params.plotting.multiData{i},' ', '_'); eval(['loggedData.' params.plotting.multiData{i} '.params.plot = 1;']); end end else for i = 1:length(params.plotting.subData) + params.plotting.subData{i} = strrep(params.plotting.subData{i},' ', '_'); eval(['loggedData.' params.plotting.subData{i} '.params.plot = 1;']); end end @@ -150,11 +154,13 @@ if exist('params', 'var') end else for i = 1:length(params.plotting.separateData) + params.plotting.separateData{i} = strrep(params.plotting.separateData{i},' ', '_'); eval(['loggedData.' params.plotting.separateData{i} '.params.plot = 1;']); end end else for i = 1:length(params.plotting.multiData) + params.plotting.multiData{i} = strrep(params.plotting.multiData{i},' ', '_'); eval(['loggedData.' params.plotting.multiData{i} '.params.plot = 1;']); end end @@ -167,6 +173,7 @@ if exist('params', 'var') end else for i = 1:length(params.plotting.separateData) + params.plotting.separateData{i} = strrep(params.plotting.separateData{i},' ', '_'); eval(['loggedData.' params.plotting.separateData{i} '.params.plot = 1;']); end end diff --git a/controls/DataAnalysisTool/Tool/plot_data.m b/controls/DataAnalysisTool/Tool/plot_data.m index ea7fd3410c23971dde2515f85c6fb0e0821de0c7..31119a99856a6d0732138d7d2b6b8a1b3943dd8c 100644 --- a/controls/DataAnalysisTool/Tool/plot_data.m +++ b/controls/DataAnalysisTool/Tool/plot_data.m @@ -6,6 +6,8 @@ function plot_data(expData, plotParams) % check plotting switch if (~plotParams.plot) disp('No plotting'); +elseif(~plotParams.multiPlot && ~plotParams.subPlot && ~plotParams.separatePlot) + disp('No plotting, select a plotting style'); else %% check separate plotting switch if(plotParams.separatePlot) @@ -74,7 +76,7 @@ else if(isempty(plotParams.subData)) % if none mentioned, use headers mentioned for multi plotting if(isempty(plotParams.multiData)) % if no headers mentioned for multi plotting, use headers mentioned for separate plotting if(isempty(plotParams.separateData)) % if no headers mentioned for separate plotting, use all of the headers - headers = fieldNames(expData); + headers = fieldnames(expData); else headers = plotParams.separateData; end diff --git a/controls/DataAnalysisTool/Tool/plot_multi.m b/controls/DataAnalysisTool/Tool/plot_multi.m index d63c9df36fddf81cefcee997e480e8ade2c3a38f..15bdcab7a569ffbd1849803bab754c20f73e9dc7 100644 --- a/controls/DataAnalysisTool/Tool/plot_multi.m +++ b/controls/DataAnalysisTool/Tool/plot_multi.m @@ -13,6 +13,7 @@ function plot_multi(expData, useMarker, varargin) numOfHeaders = 0; headers = {}; for i = 1:length(varargin) + varargin{i} = strrep(varargin{i},' ', '_'); if(~isPlotCharString(varargin{i})) numOfHeaders = numOfHeaders + 1; headers{numOfHeaders} = varargin{i}; @@ -144,13 +145,15 @@ for i = 1:numOfHeaders end end -ylabel(yAxisLabel); +ylabel(yAxisLabel,'Interpreter', 'none'); % constructing statement for inserting the legend -legendString = ['legend(''']; +legendString = ['legend(']; for i = 1:numOfHeaders if(i == numOfHeaders) - legendString = strcat(legendString,headers{i},''',''Location'',''NorthWest'');'); + legendString = strcat(legendString,headers{i},'''}',',''Interpreter'',''none'',''Location'',''NorthWest'');'); + elseif(i == 1) + legendString = strcat(legendString,'{''',headers{i},''','''); else legendString = strcat(legendString,headers{i},''','''); end diff --git a/controls/DataAnalysisTool/Tool/plot_separate.m b/controls/DataAnalysisTool/Tool/plot_separate.m index 21258d6dacefad42184b8a649f738b7d9a5ee11a..c429b4ff17362bc559876c67cfb79bf3e2e27ab0 100644 --- a/controls/DataAnalysisTool/Tool/plot_separate.m +++ b/controls/DataAnalysisTool/Tool/plot_separate.m @@ -25,6 +25,7 @@ end % bulding the plot statement that will be executed for i = 1:length(varargin) + varargin{i} = strrep(varargin{i},' ', '_'); dataHeader = varargin{i}; % continue to next iteration if current argument is a plotting character string @@ -49,19 +50,19 @@ for i = 1:length(varargin) plotCharString = buildPlotCharString(eval(['expData.' dataHeader '.params'])); plotString = strcat(plotString,',''', plotCharString, ''');'); end - + % plotting data and making it look good figure; whitebg(gcf,eval(['expData.' dataHeader '.params.backgnd'])); % setting background eval(plotString); % plotting - title(dataHeader); % setting title + title(dataHeader, 'Interpreter', 'none'); % setting title xlabel(['Time (' time.unit ')']); % setting the x-axis label if(eval(['isempty(expData.' dataHeader '.unit)'])) yAxisLabel = dataHeader; else yAxisLabel = [dataHeader ' (' eval(['expData.' dataHeader '.unit']) ')']; end - ylabel(yAxisLabel); % setting y-axis label + ylabel(yAxisLabel,'Interpreter', 'none'); % setting y-axis label xlim([0, time.data(end)]); % setting x-axis limits grid ON; % setting grid lines on the graph % adding markers diff --git a/controls/DataAnalysisTool/Tool/plot_sub.m b/controls/DataAnalysisTool/Tool/plot_sub.m index f91b59e2ff472dc38a39ed3575176a7a6c291f00..e088eb2c4724994f7369281e749a62710c894b76 100644 --- a/controls/DataAnalysisTool/Tool/plot_sub.m +++ b/controls/DataAnalysisTool/Tool/plot_sub.m @@ -41,6 +41,8 @@ for i = 1:length(varargin) continue; end + varargin{i} = strrep(varargin{i},' ', '_'); + % keeping track of the number of headers currHeaderIndex = currHeaderIndex + 1; @@ -75,14 +77,14 @@ for i = 1:length(varargin) %% plotting data and making it look pretty eval(plotString); - title(varargin{i}); + title(varargin{i},'Interpreter','none'); xlabel(['Time (' time.unit ')']); if(eval(['isempty(expData.' varargin{i} '.unit)'])) yAxisLabel = varargin{i}; else yAxisLabel = [varargin{i} ' (' eval(['expData.' varargin{i} '.unit']) ')']; end - ylabel(yAxisLabel); + ylabel(yAxisLabel,'Interpreter','none'); xlim([0,time.data(end)]); grid ON; set(gca,'Color',eval(['expData.' varargin{i} '.params.backgnd'])); diff --git a/controls/model/c_controller.c b/controls/model/c_controller.c index 6bcee0997d9c72199d6983b738bac881478fdbe6..aff3ffbc6aad17c2751048c88c508d7834d74399 100644 --- a/controls/model/c_controller.c +++ b/controls/model/c_controller.c @@ -1,6 +1,6 @@ #include "c_controller.h" -#include "quad_files/control_algorithm.c" -#include "quad_files/computation_graph.c" +#include "control_algorithm.c" +#include "computation_graph.c" double c_controller(int vrpn_id, double vrpn_ts, double set_x, double set_y, double set_z, double set_yaw, double cur_x, double cur_y, double cur_z, double cur_phi, double cur_theta, double cur_psi, diff --git a/controls/model/c_controller.h b/controls/model/c_controller.h index e53b1a508409d70211a99fe6ba6de76e092ae7a5..4cf3a88f751129dd1777898ae599358964d012e5 100644 --- a/controls/model/c_controller.h +++ b/controls/model/c_controller.h @@ -1,12 +1,12 @@ #ifndef C_CONTROLLER_H #define C_CONTROLLER_H -#include "quad_files/computation_graph.h" -#include "quad_files/graph_blocks/node_pid.h" -#include "quad_files/graph_blocks/node_bounds.h" -#include "quad_files/graph_blocks/node_constant.h" -#include "quad_files/graph_blocks/node_mixer.h" -#include "quad_files/PID.h" -#include "quad_files/control_algorithm.h" +#include "computation_graph.h" +#include "node_pid.h" +#include "node_bounds.h" +#include "node_constant.h" +#include "node_mixer.h" +#include "PID.h" +#include "control_algorithm.h" double c_controller(int vrpn_id, double vrpn_ts, double set_x, double set_y, double set_z, double set_yaw, double cur_x, double cur_y, double cur_z, diff --git a/controls/model/loggingAnalysis/logAnalysis.m b/controls/model/loggingAnalysis/logAnalysis.m index ae48f90734c220bf920b8367ca5fca88411d84c7..e1ba18ae230e9a3641771d0879861cb59a09f734 100644 --- a/controls/model/loggingAnalysis/logAnalysis.m +++ b/controls/model/loggingAnalysis/logAnalysis.m @@ -32,10 +32,10 @@ yaw_command_model_data = yaw_command_model.signals.values(indices_40ms); yaw_value_model_data = yaw_value_model.signals.values(indices_40ms); % Pull duty cycle commands from model -PWM0_model = motorCommands.signals.values(indices_40ms, 1); -PWM1_model = motorCommands.signals.values(indices_40ms, 2); -PWM2_model = motorCommands.signals.values(indices_40ms, 3); -PWM3_model = motorCommands.signals.values(indices_40ms, 4); +PWM0_model = motorCommands.signals.values(indices_5ms, 1); +PWM1_model = motorCommands.signals.values(indices_5ms, 2); +PWM2_model = motorCommands.signals.values(indices_5ms, 3); +PWM3_model = motorCommands.signals.values(indices_5ms, 4); %% Plot x control structure @@ -165,7 +165,7 @@ legend('Log', 'Model', 'location', 'northwest'); %% Plot PWM Commands figure(5); subplot(2, 2, 1); stairs(time, PWM0,'.-'); hold on; grid minor; -stairs(time_model_40ms, PWM0_model, '.-'); hold off; +stairs(time_model_5ms, PWM0_model, '.-'); hold off; title('PWM0 Value'); xlabel('Time (s)'); ylabel('PWM0 Command'); @@ -173,7 +173,7 @@ legend('Log', 'Model', 'location', 'northwest'); subplot(2, 2, 2); stairs(time, PWM1,'.-'); hold on; grid minor; -stairs(time_model_40ms, PWM1_model, '.-'); hold off; +stairs(time_model_5ms, PWM1_model, '.-'); hold off; title('PWM1 Value'); xlabel('Time (s)'); ylabel('PWM1 Command'); @@ -181,7 +181,7 @@ legend('Log', 'Model', 'location', 'northwest'); subplot(2, 2, 3); stairs(time, PWM2,'.-'); hold on; grid minor; -stairs(time_model_40ms, PWM2_model, '.-'); hold off; +stairs(time_model_5ms, PWM2_model, '.-'); hold off; title('PWM2 Value'); xlabel('Time (s)'); ylabel('PWM2 Command'); @@ -189,7 +189,7 @@ legend('Log', 'Model', 'location', 'northwest'); subplot(2, 2, 4); stairs(time, PWM3,'.-'); hold on; grid minor; -stairs(time_model_40ms, PWM3_model, '.-'); hold off; +stairs(time_model_5ms, PWM3_model, '.-'); hold off; title('PWM3 Value'); xlabel('Time (s)'); ylabel('PWM3 Command'); diff --git a/controls/model/modelParameters.m b/controls/model/modelParameters.m index 97115a7c498158b6e5d7765cb3de075772fee193..bda6e93514a28d95838ee3a62e6ded80d694facf 100644 --- a/controls/model/modelParameters.m +++ b/controls/model/modelParameters.m @@ -1,4 +1,4 @@ -temp = 0; +temp = 1; % Log Analysis Toggle logAnalysisToggle = 1; % 1 for log analysis, 0 for normal operation @@ -181,7 +181,7 @@ elseif logAnalysisToggle == 1 && temp == 1 % window. % %fname = 'sampleLogFile.txt'; - fname = 'sampleLogFile.txt'; + fname = ''; fpath = ''; if(isempty(fname)) @@ -208,8 +208,8 @@ elseif logAnalysisToggle == 1 && temp == 1 y_error = timeseries(y_setpoint - y_position, time); % Determine z position error - z_setpoint = dataStruct.Z_Setpoint_Constant.data; - z_position = dataStruct.VRPN_Z_Constant.data; + z_setpoint = dataStruct.Alt_Setpoint_Constant.data; + z_position = dataStruct.VRPN_Alt_Constant.data; z_error = timeseries(z_setpoint - z_position, time); % Determine pitch error @@ -243,10 +243,10 @@ elseif logAnalysisToggle == 1 && temp == 1 yawrate_error = timeseries(yawrate_setpoint - yawrate_value, time); % Pull motor commands from log - x_command = dataStruct.Pitch_Rate_PID_Correction; - y_command = dataStruct.Roll_Rate_PID_Correction; - z_command = dataStruct.Altitude_PID_Correction; - yaw_command = dataStruct.Yaw_Rate_PID_Correction; + x_command = dataStruct.Pitch_Rate_PID_Correction.data; + y_command = dataStruct.Roll_Rate_PID_Correction.data; + z_command = dataStruct.Altitude_PID_Correction.data; + yaw_command = dataStruct.Yaw_Rate_PID_Correction.data; % Determine signal mix PWM values PWM0 = dataStruct.Signal_Mixer_PWM_0.data; diff --git a/controls/model/parse_log_model.m b/controls/model/parse_log_model.m index 9fba92fa6d0d3d670370b06a035fd9ee802698d2..59aef835bd0d5077e9619b7c02880a8390d95643 100644 --- a/controls/model/parse_log_model.m +++ b/controls/model/parse_log_model.m @@ -43,6 +43,7 @@ identifier = string(1); if (regexp(identifier,'%')) foundHeaders = 1; % this is a line of headers; extract headers: + string = strrep(string,' ', '_'); headers = strsplit(string); headers{1} = strrep(headers{1},'%', ''); numOfHeaders = length(headers); @@ -106,6 +107,5 @@ for i = 1:numOfHeaders end - end diff --git a/controls/model/quad_files/.gitignore b/controls/model/quad_files/.gitignore deleted file mode 100644 index 1c4bc674e912af84e9c6bed639cd5780a68b7846..0000000000000000000000000000000000000000 --- a/controls/model/quad_files/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Don't track the copied files here -*.h -*.c \ No newline at end of file diff --git a/controls/model/quad_files/copy_files.bat b/controls/model/quad_files/copy_files.bat deleted file mode 100644 index bd5f65861b103ddaf3b761a47c9bc584bb35b50b..0000000000000000000000000000000000000000 --- a/controls/model/quad_files/copy_files.bat +++ /dev/null @@ -1,27 +0,0 @@ -copy ..\..\..\quad\computation_graph\src\computation_graph.c computation_graph.c -copy ..\..\..\quad\computation_graph\src\computation_graph.h computation_graph.h - -copy ..\..\..\quad\sw\modular_quad_pid\src\control_algorithm.h control_algorithm.h -copy ..\..\..\quad\sw\modular_quad_pid\src\control_algorithm.c control_algorithm.c - -copy ..\..\..\quad\sw\modular_quad_pid\src\PID.h PID.h -copy ..\..\..\quad\sw\modular_quad_pid\src\type_def.h type_def.h -copy ..\..\..\quad\sw\modular_quad_pid\src\sensor_processing.h sensor_processing.h -copy ..\..\..\quad\sw\modular_quad_pid\src\log_data.h log_data.h -copy ..\..\..\quad\sw\modular_quad_pid\src\quadposition.h quadposition.h -copy ..\..\..\quad\sw\modular_quad_pid\src\util.h util.h -copy ..\..\..\quad\sw\modular_quad_pid\src\timer.h timer.h -copy ..\..\..\groundStation\src\backend\commands.h commands.h -copy ..\..\..\groundStation\src\backend\callbacks.h callbacks.h - -mkdir graph_blocks -copy ..\..\..\quad\computation_graph\src\graph_blocks\node_constant.h graph_blocks\node_constant.h -copy ..\..\..\quad\computation_graph\src\graph_blocks\node_constant.c graph_blocks\node_constant.c -copy ..\..\..\quad\computation_graph\src\graph_blocks\node_add.h graph_blocks\node_add.h -copy ..\..\..\quad\computation_graph\src\graph_blocks\node_add.c graph_blocks\node_add.c -copy ..\..\..\quad\sw\modular_quad_pid\src\graph_blocks\node_mixer.c graph_blocks\node_mixer.c -copy ..\..\..\quad\sw\modular_quad_pid\src\graph_blocks\node_mixer.h graph_blocks\node_mixer.h -copy ..\..\..\quad\sw\modular_quad_pid\src\graph_blocks\node_pid.c graph_blocks\node_pid.c -copy ..\..\..\quad\sw\modular_quad_pid\src\graph_blocks\node_pid.h graph_blocks\node_pid.h -copy ..\..\..\quad\sw\modular_quad_pid\src\graph_blocks\node_bounds.c graph_blocks\node_bounds.c -copy ..\..\..\quad\sw\modular_quad_pid\src\graph_blocks\node_bounds.h graph_blocks\node_bounds.h \ No newline at end of file diff --git a/controls/model/test_model.slx b/controls/model/test_model.slx index 56975e7eba373b73a005d9451ddcb553bd36f882..93229cbac59b18930c7e4a1158b9e2f6c53bb53c 100644 Binary files a/controls/model/test_model.slx and b/controls/model/test_model.slx differ