www.gusucode.com > rtwdemos 工具箱matlab源码程序 > rtwdemos/rtwdemo_pmsmfoc_plotsignals.m
function rtwdemo_pmsmfoc_plotsignals(logsout) % Plot results of PMSM Controller System Test Bench % Copyright 2010-2012 The MathWorks, Inc. figureName = 'PMSM FOC Signals'; hFig = findobj('Name',figureName); if isempty(hFig) hFig = figure; set(hFig,'Name',figureName); else figure(hFig); clf(hFig); end speed_command_rpm = logsout.getElement('speed_command_rpm').Values; rotor_velocity_rpm = logsout.getElement('rotor_velocity_rpm').Values; controller_mode = logsout.getElement('controller_mode').Values; %% Plot full run of data subplot(2,1,1) line(speed_command_rpm.Time, speed_command_rpm.Data,... 'LineWidth',2,'Color','b',... 'DisplayName','Commanded Speed'); line(rotor_velocity_rpm.Time, rotor_velocity_rpm.Data(:),... 'LineWidth',2,'Color','r',... 'DisplayName','Measured Speed'); legend('Speed Command','Measured Speed','Location','SouthEast'); tMax = max([rotor_velocity_rpm.Time;speed_command_rpm.Time]); yMin = min([rotor_velocity_rpm.Data(:);speed_command_rpm.Data]) - 100; yMax = max([rotor_velocity_rpm.Data(:);speed_command_rpm.Data]) + 100; xlim([0 tMax]); ylim([yMin yMax]); set(gca, 'YGrid','on',... 'XMinorTick','on',... 'XGrid','on'); box('on'); title('Commanded and Measured Rotor Speeds','FontWeight','bold','FontSize',12); xlabel('Time (sec)'); ylabel('Speed (RPM)'); %% Zoom in on transition subplot(2,1,2) nIndex = find( controller_mode.Data == EnumControllerMode.VelocityControl, 1, 'first'); tIndex = controller_mode.Time(nIndex); tEnd = tIndex + 0.04; rotor_velocity_rpm_data = rotor_velocity_rpm.Data(:); nEnd = find((rotor_velocity_rpm.Time > tEnd), 1, 'first'); line(rotor_velocity_rpm.Time(1:nEnd), rotor_velocity_rpm_data(1:nEnd),... 'DisplayName','Motor Speed',... 'LineWidth',2,'Color','r'); yMin = min(rotor_velocity_rpm_data(1:nEnd))-100; yMax = max(rotor_velocity_rpm_data(1:nEnd))+100; yUpperText = 0.75*(yMin+yMax) + yMin; yLowerText = 0.25*(yMin+yMax) + yMin; nOn = find( controller_mode.Data == EnumControllerMode.Startup, 1, 'first'); tOn = controller_mode.Time(nOn); line([tOn tOn],[yMin, yMax], 'LineWidth',2,'LineStyle','--','Color','k'); text(tOn, yUpperText,'\leftarrow Motor On',... 'FontWeight','bold','FontSize',10); nIndex = find( controller_mode.Data == EnumControllerMode.VelocityControl, 1, 'first'); tIndex = controller_mode.Time(nIndex); line([tIndex tIndex],[yMin, yMax], 'LineWidth',2,'LineStyle','--','Color','k'); text(tIndex, yLowerText,{'\leftarrow Closed Loop Velocity Control'},... 'FontWeight','bold','FontSize',10); xlim([0 tEnd]); ylim([yMin yMax]); set(gca, 'YGrid','off',... 'XMinorTick','off',... 'XGrid','off'); box('on'); title('Measured Rotor Speed During Startup','FontWeight','bold','FontSize',12); xlabel('Time (sec)'); ylabel('Speed (RPM)');