Skip to content
Snippets Groups Projects
Commit a1ac6855 authored by Andy Snawerdt's avatar Andy Snawerdt
Browse files

Updated logging tools for model verification

parent 3ec52a49
No related branches found
No related tags found
No related merge requests found
......@@ -208,7 +208,7 @@ legend('Log', 'Model', 'location', 'northwest');
figure(6); subplot(2, 1, 1);
stairs(time, pitch_measured_IMU, '.-'); hold on; grid minor;
stairs(time_model_5ms, pitch_accel, '.-'); hold off;
title('Pitch Complimentary Filter Output');
title('Pitch Complementary Filter Output');
xlabel('Time (s)');
ylabel('Pitch Angle (rad)');
legend('Log', 'Model', 'location', 'northwest');
......@@ -216,9 +216,7 @@ legend('Log', 'Model', 'location', 'northwest');
subplot(2, 1, 2);
stairs(time, roll_measured_IMU, '.-'); hold on; grid minor;
stairs(time_model_5ms, roll_accel, '.-'); hold off;
title('Roll Complimentary Filter Output');
title('Roll Complementary Filter Output');
xlabel('Time (s)');
ylabel('Roll Angle (rad)');
legend('Log', 'Model', 'location', 'northwest');
temp = 1;
% Log Analysis Toggle
logAnalysisToggle = 1; % 1 for log analysis, 0 for normal operation
......@@ -43,9 +42,9 @@ temp = 1;
% Equilibrium height controller output
height_controlled_o = (((Rm*If + ...
+ (((omega0_o * 2 * Rm * Kv * Kq ...
+ (((omega0_o * 2 * Rm * Kv * Kq ...
* Kd + 1)^2) - 1)/(4* Rm*Kv^2*Kq ...
*Kd))/Vb)*(Pmax- Pmin)+Pmin);
* Kd))/Vb)*(Pmax- Pmin) + Pmin);
% Equilibrium positions
x_o = 0;
......@@ -67,133 +66,7 @@ temp = 1;
pitchrate_o = 0;
yawrate_o = 0;
% Import Data and determine errors
if logAnalysisToggle == 1 && temp == 0
% Import Data to Workspace
%data = importdata('loggingAnalysis/logFiles/logData.csv');
data = importdata('loggingAnalysis/logFiles/test.csv');
% Set up time vector
time = data.data(:, 1);
runtime = max(time);
% Determine x position error
x_setpoint = data.data(:, 25);
x_position = data.data(:, 20);
x_error = timeseries(x_setpoint - x_position, time);
% Determine y position error
y_setpoint = data.data(:, 26);
y_position = data.data(:, 21);
y_error = timeseries(y_setpoint - y_position, time);
% Determine z position error
z_setpoint = data.data(:, 27);
z_position = data.data(:, 22);
z_error = timeseries(z_setpoint - z_position, time);
% Determine pitch error
pitch_setpoint = data.data(:, 9);
pitch_value = data.data(:, 23);
pitch_error = timeseries(pitch_setpoint - pitch_value, time);
% Determine roll error
roll_setpoint = data.data(:, 10);
roll_value = data.data(:, 24);
roll_error = timeseries(roll_setpoint - roll_value, time);
% Determine yaw error
yaw_setpoint = zeros(length(time), 1); % NEEDS UPDATED WHEN LOG FILE INCLUDES YAW SETPOINT
yaw_value = data.data(:,10);%(length(time), 1); % NEEDS UPDATED WHEN LOG FILE INCLUDES YAW VALUE
yaw_error = timeseries(yaw_setpoint - yaw_value, time);
% Determine pitch rate error
pitchrate_setpoint = data.data(:, 11);
pitchrate_value = data.data(:, 6);
pitchrate_error = timeseries(pitchrate_setpoint - pitchrate_value, time);
% Determine roll rate error
rollrate_setpoint = data.data(:, 12);
rollrate_value = data.data(:, 5);
rollrate_error = timeseries(rollrate_setpoint - rollrate_value, time);
% Determine yaw rate error
yawrate_setpoint = data.data(:, 13);
yawrate_value = data.data(:, 7);
yawrate_error = timeseries(yawrate_setpoint - yawrate_value, time);
% Pull motor commands from log
x_command = data.data(:, 14);
y_command = data.data(:, 15);
z_command = data.data(:, 8);
yaw_command = data.data(:, 16);
%Create time series object for z command
throttle_command = timeseries(z_command, time);
% Determine signal mix PWM values
PWM0 = data.data(:, 28);
PWM1 = data.data(:, 29);
PWM2 = data.data(:, 30);
PWM3 = data.data(:, 31);
%Pull the measurements from the acceleratometer
raw_accel_data_x = data.data(:, 2);
raw_accel_data_y = data.data(:, 3);
raw_accel_data_z = data.data(:, 4);
raw_accel_data_arr = ...
[ raw_accel_data_x , raw_accel_data_y , raw_accel_data_z ];
raw_accel_data = timeseries( raw_accel_data_arr , time );
%Pull the measurements from the gyroscope
raw_gyro_data_x = data.data(:, 5);
raw_gyro_data_y = data.data(:, 6);
raw_gyro_data_z = data.data(:, 7);
raw_gyro_data_arr = ...
[ raw_gyro_data_x , raw_gyro_data_y , raw_gyro_data_z ];
raw_gyro_data = timeseries( raw_gyro_data_arr , time );
% Determine the initial height controller command
% height_controlled_o = 1; % NEEDS UPDATED WHEN LOG FILES INCLUDE THROTTLE COMMAND
% Determine the initial rotor speeds based on PWM inputs
u_P0 = (PWM0(1) - Pmin) / (Pmax - Pmin);
u_P1 = (PWM1(1) - Pmin) / (Pmax - Pmin);
u_P2 = (PWM2(1) - Pmin) / (Pmax - Pmin);
u_P3 = (PWM3(1) - Pmin) / (Pmax - Pmin);
Vb_eff_0 = u_P0 * Vb;
Vb_eff_1 = u_P1 * Vb;
Vb_eff_2 = u_P2 * Vb;
Vb_eff_3 = u_P3 * Vb;
omega0_o = (-1 + sqrt(1 - 4*Rm*Kv*Kq*Kd*( Kv*Rm*If - Kv*Vb_eff_0))) / (2*Rm*Kv*Kq*Kd);
omega1_o = (-1 + sqrt(1 - 4*Rm*Kv*Kq*Kd*( Kv*Rm*If - Kv*Vb_eff_1))) / (2*Rm*Kv*Kq*Kd);
omega2_o = (-1 + sqrt(1 - 4*Rm*Kv*Kq*Kd*( Kv*Rm*If - Kv*Vb_eff_2))) / (2*Rm*Kv*Kq*Kd);
omega3_o = (-1 + sqrt(1 - 4*Rm*Kv*Kq*Kd*( Kv*Rm*If - Kv*Vb_eff_3))) / (2*Rm*Kv*Kq*Kd);
% Determine initial positions for x, y, and z
x_o = x_position(1);
y_o = y_position(1);
z_o = z_position(1);
% Determine initial velocity for x, y, and z
x_vel_o = (x_position(2) - x_position(1)) / (time(2) - time(1));
y_vel_o = (y_position(2) - y_position(1)) / (time(2) - time(1));
z_vel_o = (z_position(2) - z_position(1)) / (time(2) - time(1));
% Determine initial angles
roll_o = roll_value(1);
pitch_o = pitch_value(1);
yaw_o = yaw_value(1);
% Determine initial angular rates
rollrate_o = rollrate_value(1);
pitchrate_o = pitchrate_value(1);
yawrate_o = yawrate_value(1);
elseif logAnalysisToggle == 1 && temp == 1
if logAnalysisToggle == 1
%%%%%% Commented out section until logging is .txt file based %%%%%%
% FNAME
% if you know the name of the log file that you want to parse, set the it
......@@ -218,6 +91,9 @@ elseif logAnalysisToggle == 1 && temp == 1
time = dataStruct.Time.data;
time = time - time(1);
time = time(1):0.005:time(length(time)-7);
time = time';
runtime = max(time);
% Determine x position error
......
function [loggedData, headers] = parse_log_model(filename, params, expData)
function [loggedData, headers] = parse_log_model(filename)
%parse_log This independent function parses the data stored in the file and
%returns a structure containing the data
% filename - this is the complete path of the file with the filename
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment