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

Added comments and updated function calls

parent bf7656da
No related branches found
No related tags found
No related merge requests found
% Add path to zeroLoadCurrent() function
addpath('C:\Users\Andy\Documents\School\MicroCART\GitRepo\MicroCART_17-18\controls\MATLAB\zeroLoadCurrent')
% Import data as a table. % Import data as a table.
data = readtable('C:\Users\Andy\Documents\MATLAB\MicroCART\Thrust and Drag Constant\Thrust and Drag Constant Data.xlsx'); 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'; 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_0 = data.(2) * (pi/30);
rotor_speed_1 = data.(3) * (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; ...@@ -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]; If = [If0; If1; If2; If3];
% Call the calc_thrust_constant() function. % Call the calc_thrust_constant() function.
Kt = calc_thrust_constant(data); Kt = calcThrustConstant(data);
% Call the calc_drift_constant() function. % 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 );
% Read in data
data = readtable('C:\Users\Andy\Documents\MATLAB\MicroCART\Thrust and Drag Constant\Thrust and Drag Constant Data.xlsx'); 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'; 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; Pmin = 0.40;
Pmax = 0.8; Pmax = 0.8;
Rm = 0.2308; Rm = 0.2308;
Kv = 96.3422; Kv = 96.3422;
Kq = 96.3422; Kq = 96.3422;
If = 0.44;
% Convert RPM to angular speed of each rotor. % Convert RPM to angular speed of each rotor.
rotor_speed_0 = data.(2) * (pi/30); rotor_speed_0 = data.(2) * (pi/30);
...@@ -31,18 +31,13 @@ figure() ...@@ -31,18 +31,13 @@ figure()
hold on hold on
plot(duty_cycle_percentage, w); grid() plot(duty_cycle_percentage, w); grid()
plot(duty_cycle_percentage, rotor_speed_0); plot(duty_cycle_percentage, rotor_speed_0);
plot(duty_cycle_percentage, rotor_speed_1); %plot(duty_cycle_percentage, rotor_speed_1);
plot(duty_cycle_percentage, rotor_speed_2); %plot(duty_cycle_percentage, rotor_speed_2);
plot(duty_cycle_percentage, rotor_speed_3); %plot(duty_cycle_percentage, rotor_speed_3);
xlabel('Duty Cycle Percentage'); xlabel('Duty Cycle Percentage');
ylabel('Rotor Speed (rad/s)') ylabel('Rotor Speed (rad/s)')
figure()
plot(dutyCycle_error, error); grid()
xlabel('Duty Cycle Percentage');
ylabel('Error');
residual_error residual_error
residual_error_withIfConstant residual_error_ConstantIf
\ No newline at end of file \ No newline at end of file
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 %This function takes in an absolute file path to a .csv or Excel file with
%the following format: %the following format:
% Second column should be the motor speed in revolutions per minute % 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 ...@@ -48,10 +48,10 @@ function [I_0, I_1, I_2, dutyCycle, error, residual_error, residual_error_withIf
If_constant = 0.511; If_constant = 0.511;
error_withIfConstant = A*[If_constant; 0; 0] - b; error_withIfConstant = A*[If_constant; 0; 0] - b;
%Get the residual (?) %Get the residual error
residual_error = sum(error.^2); 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 %Extract the components of the vector
I_0 = I_vector(1); I_0 = I_vector(1);
......
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