From d1929714a02c2c02cb744607ec485c33a0aa3e1f Mon Sep 17 00:00:00 2001 From: Andy Snawerdt <Andy Snawerdt> Date: Fri, 28 Oct 2016 22:36:09 -0500 Subject: [PATCH] Added comments and updated function calls --- .../thrustDragConstantCalculations.m | 9 ++++++--- controls/MATLAB/zeroLoadCurrent/Kd_error.m | 17 ++++++----------- .../MATLAB/zeroLoadCurrent/zeroLoadCurrent.m | 6 +++--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/controls/MATLAB/thrustAndDragConstant/thrustDragConstantCalculations.m b/controls/MATLAB/thrustAndDragConstant/thrustDragConstantCalculations.m index 1f8caf84b..1ef354792 100644 --- a/controls/MATLAB/thrustAndDragConstant/thrustDragConstantCalculations.m +++ b/controls/MATLAB/thrustAndDragConstant/thrustDragConstantCalculations.m @@ -1,9 +1,12 @@ +% Add path to zeroLoadCurrent() function +addpath('C:\Users\Andy\Documents\School\MicroCART\GitRepo\MicroCART_17-18\controls\MATLAB\zeroLoadCurrent') + % Import data as a table. data = readtable('C:\Users\Andy\Documents\MATLAB\MicroCART\Thrust and Drag Constant\Thrust and Drag Constant Data.xlsx'); filePath_noLoadCurrentData = 'C:\Users\Andy\Documents\MATLAB\MicroCART\Zero Load Current\No Load Friction Current.csv'; -[I_0, I_1, I_2] = zero_load_current(filePath_noLoadCurrentData); +[I_0, I_1, I_2] = zeroLoadCurrent(filePath_noLoadCurrentData); rotor_speed_0 = data.(2) * (pi/30); rotor_speed_1 = data.(3) * (pi/30); @@ -23,8 +26,8 @@ If3 = I_0 * sign(rotor_speed_3) + I_1 * rotor_speed_3 + I_2 * rotor_speed_3.^2; If = [If0; If1; If2; If3]; % Call the calc_thrust_constant() function. -Kt = calc_thrust_constant(data); +Kt = calcThrustConstant(data); % Call the calc_drift_constant() function. -Kd = calc_drag_constant(data, Pmin, Pmax, Rm, Kv, Kq, If ); +Kd = calcDragConstant(data, Pmin, Pmax, Rm, Kv, Kq, If ); diff --git a/controls/MATLAB/zeroLoadCurrent/Kd_error.m b/controls/MATLAB/zeroLoadCurrent/Kd_error.m index 8ecec2bdc..9e087f539 100644 --- a/controls/MATLAB/zeroLoadCurrent/Kd_error.m +++ b/controls/MATLAB/zeroLoadCurrent/Kd_error.m @@ -1,15 +1,15 @@ +% Read in data data = readtable('C:\Users\Andy\Documents\MATLAB\MicroCART\Thrust and Drag Constant\Thrust and Drag Constant Data.xlsx'); filePath_noLoadCurrentData = 'C:\Users\Andy\Documents\MATLAB\MicroCART\Zero Load Current\No Load Friction Current.csv'; -[I_0, I_1, I_2, dutyCycle_error, error, residual_error, residual_error_withIfConstant] = zero_load_current(filePath_noLoadCurrentData); +[I_0, I_1, I_2, dutyCycle_error, error, residual_error, residual_error_ConstantIf] = zeroLoadCurrent(filePath_noLoadCurrentData); Pmin = 0.40; Pmax = 0.8; Rm = 0.2308; Kv = 96.3422; Kq = 96.3422; -If = 0.44; % Convert RPM to angular speed of each rotor. rotor_speed_0 = data.(2) * (pi/30); @@ -31,18 +31,13 @@ figure() hold on plot(duty_cycle_percentage, w); grid() plot(duty_cycle_percentage, rotor_speed_0); -plot(duty_cycle_percentage, rotor_speed_1); -plot(duty_cycle_percentage, rotor_speed_2); -plot(duty_cycle_percentage, rotor_speed_3); +%plot(duty_cycle_percentage, rotor_speed_1); +%plot(duty_cycle_percentage, rotor_speed_2); +%plot(duty_cycle_percentage, rotor_speed_3); xlabel('Duty Cycle Percentage'); ylabel('Rotor Speed (rad/s)') -figure() -plot(dutyCycle_error, error); grid() -xlabel('Duty Cycle Percentage'); -ylabel('Error'); - residual_error -residual_error_withIfConstant \ No newline at end of file +residual_error_ConstantIf \ No newline at end of file diff --git a/controls/MATLAB/zeroLoadCurrent/zeroLoadCurrent.m b/controls/MATLAB/zeroLoadCurrent/zeroLoadCurrent.m index 330f295c5..5ce263612 100644 --- a/controls/MATLAB/zeroLoadCurrent/zeroLoadCurrent.m +++ b/controls/MATLAB/zeroLoadCurrent/zeroLoadCurrent.m @@ -1,4 +1,4 @@ -function [I_0, I_1, I_2, dutyCycle, error, residual_error, residual_error_withIfConstant] = zeroLoadCurrent(absoluteFilePath) +function [I_0, I_1, I_2, dutyCycle, error, residual_error, residual_error_constantIf] = zeroLoadCurrent(absoluteFilePath) %This function takes in an absolute file path to a .csv or Excel file with %the following format: % Second column should be the motor speed in revolutions per minute @@ -48,10 +48,10 @@ function [I_0, I_1, I_2, dutyCycle, error, residual_error, residual_error_withIf If_constant = 0.511; error_withIfConstant = A*[If_constant; 0; 0] - b; - %Get the residual (?) + %Get the residual error residual_error = sum(error.^2); - residual_error_withIfConstant = sum(error_withIfConstant.^2); + residual_error_constantIf = sum(error_withIfConstant.^2); %Extract the components of the vector I_0 = I_vector(1); -- GitLab