diff --git a/controls/model/loggingAnalysis/logAnalysis.m b/controls/model/loggingAnalysis/logAnalysis.m index 3728014f1f63101b17e4025cdcaf17bdcb284273..e427bf141ec9003dd7d5dc1e896dd1f1d1fe0411 100644 --- a/controls/model/loggingAnalysis/logAnalysis.m +++ b/controls/model/loggingAnalysis/logAnalysis.m @@ -5,20 +5,20 @@ sim('test_model.slx'); % Determine model time for various sampling times and scale it according to % logged data timescale -indices_40ms = find(pitch_setpoint_model.time > time(1)); -indices_5ms = find(x_command_model.time > time(1)); +indices_40ms = find(pitch_setpoint_model.time >= time(1)); +indices_5ms = find(x_command_model.time >= time(1)); time_model_40ms = pitch_setpoint_model.time(indices_40ms); time_model_5ms = x_command_model.time(indices_5ms); % Pull x control structure data pitch_setpoint_model_data = pitch_setpoint_model.signals.values(indices_40ms); -pitchrate_setpoint_model_data = pitchrate_setpoint_model.signals.values(indices_40ms); +pitchrate_setpoint_model_data = pitchrate_setpoint_model.signals.values(indices_5ms); x_command_model_data = x_command_model.signals.values(indices_5ms); x_position_model_data = x_position_model.signals.values(indices_40ms); % Pull y control structure data roll_setpoint_model_data = roll_setpoint_model.signals.values(indices_40ms); -rollrate_setpoint_model_data = rollrate_setpoint_model.signals.values(indices_40ms); +rollrate_setpoint_model_data = rollrate_setpoint_model.signals.values(indices_5ms); y_command_model_data = y_command_model.signals.values(indices_5ms); y_position_model_data = y_position_model.signals.values(indices_40ms); @@ -28,7 +28,7 @@ z_position_model_data = z_position_model.signals.values(indices_40ms); % Pull yaw control structure data yawrate_setpoint_model_data = yawrate_setpoint_model.signals.values(indices_40ms); -yaw_command_model_data = yaw_command_model.signals.values(indices_40ms); +yaw_command_model_data = yaw_command_model.signals.values(indices_5ms); yaw_value_model_data = yaw_value_model.signals.values(indices_40ms); % Pull duty cycle commands from model @@ -59,7 +59,7 @@ legend('Log', 'Model', 'location', 'northwest'); % Plot pitch controller output subplot(2, 2, 2); stairs(time, pitchrate_setpoint,'.-'); hold on; grid minor; -stairs(time_model_40ms, pitchrate_setpoint_model_data, '.-'); hold off; +stairs(time_model_5ms, pitchrate_setpoint_model_data, '.-'); hold off; title('Pitch Controller Output'); xlabel('Time (s)'); ylabel('d\theta/dt (rad/s)'); @@ -97,7 +97,7 @@ legend('Log', 'Model', 'location', 'northwest'); % Plot roll controller output subplot(2, 2, 2); stairs(time, rollrate_setpoint,'.-'); hold on; grid minor; -stairs(time_model_40ms, rollrate_setpoint_model_data, '.-'); hold off; +stairs(time_model_5ms, rollrate_setpoint_model_data, '.-'); hold off; title('Roll Controller Output'); xlabel('Time (s)'); ylabel('d\phi/dt (rad/s)'); @@ -143,7 +143,7 @@ legend('Log', 'Model', 'location', 'northwest'); %% Plot yaw control structure -% Plot roll controller output +% Plot yaw controller output figure(4); subplot(2, 2, 1); stairs(time, yawrate_setpoint,'.-'); hold on; grid minor; stairs(time_model_40ms, yawrate_setpoint_model_data, '.-'); hold off; @@ -155,7 +155,7 @@ legend('Log', 'Model', 'location', 'northwest'); % Plot yaw controller command subplot(2, 2, 2); stairs(time, yaw_command, '.-'); hold on; grid minor; -stairs(time_model_40ms, yaw_command_model_data, '.-'); hold off; +stairs(time_model_5ms, yaw_command_model_data, '.-'); hold off; title('Yaw Command'); xlabel('Time (s)'); ylabel('Command'); diff --git a/controls/model/modelParameters.m b/controls/model/modelParameters.m index 1015b5e7283ae9dadb24bc9ddbbf142e7e0e0b09..4ff541ead94489dbfb5d7da83ae62d4adf8fcdd4 100644 --- a/controls/model/modelParameters.m +++ b/controls/model/modelParameters.m @@ -216,7 +216,8 @@ elseif logAnalysisToggle == 1 && temp == 1 [dataStruct, headers] = parse_log_model(params.file.pathName); time = dataStruct.Time.data; - %time = dataStruct.time.data; + time = time - time(1); + runtime = max(time); % Determine x position error @@ -236,12 +237,12 @@ elseif logAnalysisToggle == 1 && temp == 1 % Determine pitch error pitch_setpoint = dataStruct.X_pos_PID_Correction.data; - pitch_value = dataStruct.VRPN_Pitch_Constant.data; + pitch_value = dataStruct.Pitch_Constant.data; pitch_error = timeseries(pitch_setpoint - pitch_value, time); % Determine roll error roll_setpoint = dataStruct.Y_pos_PID_Correction.data; - roll_value = dataStruct.VRPN_Roll_Constant.data; + roll_value = dataStruct.Roll_Constant.data; roll_error = timeseries(roll_setpoint - roll_value, time); % Determine yaw error @@ -293,7 +294,7 @@ elseif logAnalysisToggle == 1 && temp == 1 raw_gyro_data = timeseries( raw_gyro_data_arr , time ); %Create time series object for z command - throttle_command = timeseries(z_command, time); + throttle_command = timeseries(dataStruct.RC_Throttle_Constant.data, time); %Pull the measurements from the complimentary filter pitch_measured_IMU = dataStruct.Pitch_Constant.data; diff --git a/controls/model/test_model.slx b/controls/model/test_model.slx index 0b455c4d9bf456d70c78019764a204410ee556ce..714e5c977f6c505ea95c96d4cb0ac6325d7dd456 100644 Binary files a/controls/model/test_model.slx and b/controls/model/test_model.slx differ