diff --git a/controls/MATLAB/zeroLoadCurrent/Kd_error.m b/controls/MATLAB/zeroLoadCurrent/Kd_error.m index 9e087f5394d289bce2eba3bc3b920af917d8ef2f..d6589a8c08f806c69e4b8517c0fc7c79b1174fe9 100644 --- a/controls/MATLAB/zeroLoadCurrent/Kd_error.m +++ b/controls/MATLAB/zeroLoadCurrent/Kd_error.m @@ -1,15 +1,16 @@ % 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\School\MicroCART\GitRepo\MicroCART_17-18\controls\dataCollection\Thrust and Drag Constant Data v2.xlsx'); -filePath_noLoadCurrentData = 'C:\Users\Andy\Documents\MATLAB\MicroCART\Zero Load Current\No Load Friction Current.csv'; +filePath_noLoadCurrentData = 'C:\Users\Andy\Documents\School\MicroCART\GitRepo\MicroCART_17-18\controls\dataCollection\noLoadCurrentv2.xlsx'; -[I_0, I_1, I_2, dutyCycle_error, error, residual_error, residual_error_ConstantIf] = zeroLoadCurrent(filePath_noLoadCurrentData); +[I_0, I_1, I_2, motorCommand_error, error, residual_error, residual_error_ConstantIf] = zeroLoadCurrent(filePath_noLoadCurrentData); -Pmin = 0.40; -Pmax = 0.8; +Pmin = 1e5; +Pmax = 2e5; Rm = 0.2308; Kv = 96.3422; Kq = 96.3422; +Kd = 1.0317e-7; % Convert RPM to angular speed of each rotor. rotor_speed_0 = data.(2) * (pi/30); @@ -17,10 +18,10 @@ rotor_speed_1 = data.(3) * (pi/30); rotor_speed_2 = data.(4) * (pi/30); rotor_speed_3 = data.(5) * (pi/30); -duty_cycle_percentage = data.(1); +motorCommand = data.(1); Vb = data.(6); -u = ((data.(1)/100) - Pmin)/(Pmax - Pmin); +u = ((data.(1)) - Pmin)/(Pmax - Pmin); If = I_0 * sign(rotor_speed_0) + I_1 * rotor_speed_0 + I_2 * rotor_speed_0.^2; w_num = -1 + sqrt( 1 - 4*Rm*Kv*Kq*Kd*(Kv*Rm*If - Kv*u.*Vb)); @@ -29,13 +30,10 @@ w = w_num / w_den; 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(motorCommand, w); grid() +plot(motorCommand, rotor_speed_0); -xlabel('Duty Cycle Percentage'); +xlabel('Motor Command'); ylabel('Rotor Speed (rad/s)') residual_error diff --git a/controls/MATLAB/zeroLoadCurrent/zeroLoadCurrent.m b/controls/MATLAB/zeroLoadCurrent/zeroLoadCurrent.m index 5ce2636122b937a2396a507ad8acb374a07d73cd..d8cffe27289fcd65e955a9f3e4f23e61c7d8d9fb 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_constantIf] = zeroLoadCurrent(absoluteFilePath) +function [I_0, I_1, I_2, motorCommand, 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 @@ -9,7 +9,7 @@ function [I_0, I_1, I_2, dutyCycle, error, residual_error, residual_error_consta data = readtable(absoluteFilePath); %Extract the motor speed column and convert it to radians per second - dutyCycle = data.(1); + motorCommand = data.(1); motorSpeed_rpm = data.(2); motorSpeed_radPerSec = motorSpeed_rpm * pi/30;