资源简介

之前智能控制课程作业,主要针对倒立摆进行了建模与模糊控制仿真,其中实验1-1是仅针对角度的模糊PID控制,实验1-2是针对位置与角度的分段模糊控制。

资源截图

代码片段和文件信息

video_flag = 0; % choose 1 if you want to save a video file of plot animation
l=0.25;Ts=0.01;
T_final = 10;
%% Make video
if video_flag == 1
    % Video file open
    makeVideo = VideoWriter(‘仿真‘);
    % frame Rate - frames per second
    makeVideo.frameRate = 100;
    % Quality -  (0 ~ 100)
    makeVideo.Quality = 80;
    open(makeVideo);
end

%% Plot
Time = [0:Ts:T_final]‘;
X_result = zeros(size(Time1)4);
F_save = zeros(size(Time1)1);
u_save = zeros(size(Time1)2);
j=1;
for i=1:size(x1)
    if x(i1)==Time(j) || x(i1)Time(j) || x(i1)>Time(j) 
        X_result(j1)=x(i2);
        X_result(j2)=x(i3);
        X_result(j3)=q(i2);
        X_result(j4)=q(i3);
        F_save(j)=u(i2);
        u_save(j1:2)=u(i3:4);
        j=j+1;
        if (x(i1)-Time(j-1))>Ts
            X_result(j:)=X_result(j-1:);
            F_save(j)=F_save(j-1);
            u_save(j:)=u_save(j-1:);
            j=j+1;
        end
    end
end

figure(1)
axis_limit = 1;
for i=1:size(X_result1)    
    cart_position_x = X_result(i1);
    pend_position_x = X_result(i1) - l*sin(X_result(i3));
    pend_position_y = l*cos(X_result(i3));
    
    hold off
    plot(pend_position_x pend_position_y ‘ok‘ ‘MarkerSize‘ 25 ‘MarkerFaceColor‘[0.2 0.9 0.2])   % pendulum
    hold on
    plot(cart_position_x 0 ‘sk‘ ‘MarkerSize‘ 50 ‘MarkerFaceColor‘[0.8 0.8 0.8])    % cart
    hold on    
    if cart_position_x > pend_position_x
        plot(linspace(cart_position_xpend_position_x2) linspace(0pend_position_y2) ‘k‘ ‘LineWidth‘ 3)   % rod
    else
        plot(linspace(cart_position_xpend_position_x2) linspace(0pend_position_y2) ‘r‘ ‘LineWidth‘ 3)   % rod
    end
    grid on
    xlabel(‘[m]‘)
    ylabel(‘[m]‘)
    axis([-axis_limit axis_limit -0.5 0.5])
    sim_status = sprintf(‘Simulation time: %5.2f s‘Time(i));
    title(sim_status‘FontSize‘13)
    
    if video_flag == 1 && rem(Time(i)0.01) == 0
        frame = getframe(gcf);
        writeVideo(makeVideoframe);
    end
    
    pause(Ts);
end

if video_flag == 1
    close(makeVideo);
end

figure(2)
subplot(311)
plot(Time X_result(:1:2))
grid on
xlabel(‘Time [s]‘)
legend(‘cart position [m]‘ ‘cart velocity [m/s]‘)

subplot(312)
plot(Time X_result(:3:4)*180/pi)
grid on
xlabel(‘Time [s]‘)
legend(‘pendulum angle [deg]‘ ‘pendulum velocity [deg/s]‘)

subplot(313)
plot(Time F_save)
hold on
plot(Time u_save(:1)‘r‘)
plot(Time u_save(:2)‘c‘)
grid on
xlabel(‘Time [s]‘)
ylabel(‘Force [N]‘)
legend(‘Input force‘ ‘u_x‘ ‘u_q‘)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      64468  2020-05-16 09:25  pendulum_new.mdl

     文件      64460  2020-05-16 09:24  pendulum_pre.mdl

     文件       1005  2020-05-13 23:00  PID_fuzzy.fis

     文件      58823  2020-05-13 22:54  PID_pendulum.mdl

     文件       1612  2020-04-20 00:25  position_fuzzy.fis

     文件    1391330  2020-05-16 10:16  改进仿真.avi

     文件    1367497  2020-08-28 09:06  模糊控制实验报告.docx

     文件    1405318  2020-05-16 09:17  原始仿真.avi

     文件        392  2020-05-12 17:03  slprj\sim\varcache\pendulum\checksumOfCache.mat

     文件        312  2020-05-12 17:03  slprj\sim\varcache\pendulum\tmwinternal\simulink_cache.xml

     文件        320  2020-05-12 17:03  slprj\sim\varcache\pendulum\varInfo.mat

     文件        392  2020-05-16 16:16  slprj\sim\varcache\pendulum_2new\checksumOfCache.mat

     文件        312  2020-05-16 16:16  slprj\sim\varcache\pendulum_2new\tmwinternal\simulink_cache.xml

     文件        664  2020-05-16 16:16  slprj\sim\varcache\pendulum_2new\varInfo.mat

     文件        392  2020-05-16 21:59  slprj\sim\varcache\pendulum_2new2\checksumOfCache.mat

     文件        312  2020-05-16 21:59  slprj\sim\varcache\pendulum_2new2\tmwinternal\simulink_cache.xml

     文件       2040  2020-05-16 21:59  slprj\sim\varcache\pendulum_2new2\varInfo.mat

     文件       2363  2020-05-16 20:41  slprj\_sfprj\EMLReport\emlReportAccessInfo.mat

     文件      14583  2020-05-16 10:12  slprj\_sfprj\EMLReport\s2cS8aOCnfFkWWBtyflfeVC.mat

     文件      14573  2020-05-16 11:56  slprj\_sfprj\EMLReport\s2JP2xM81RXNbnBJZiDImbB.mat

     文件      14574  2020-05-16 11:46  slprj\_sfprj\EMLReport\s2Zd5Y6kpxZNJM8M6fBm9PH.mat

     文件       6449  2020-05-16 11:16  slprj\_sfprj\EMLReport\s5NjuhFR8roNxtZGaWTUBFD.mat

     文件       6448  2020-05-16 19:32  slprj\_sfprj\EMLReport\s5QwqOylGP1Gsno409od8tE.mat

     文件       6448  2020-05-16 11:46  slprj\_sfprj\EMLReport\s7euX1V622nJNySW8lXnBcH.mat

     文件       6444  2020-05-16 11:56  slprj\_sfprj\EMLReport\s7Fa2ZKmu4ndF1EWaaabbcF.mat

     文件       6445  2020-05-16 21:59  slprj\_sfprj\EMLReport\s7qRqmqTNNHaB4gwGZ1KcM.mat

     文件       6963  2020-05-16 19:04  slprj\_sfprj\EMLReport\sAR473TyTGvkEIWvZWHnjQH.mat

     文件       6396  2020-05-12 19:51  slprj\_sfprj\EMLReport\sArpARZMncimKInzIkHmFEH.mat

     文件      14564  2020-05-12 19:51  slprj\_sfprj\EMLReport\sciq4AmpmyeAJEqt7EVstPH.mat

     文件      14583  2020-05-16 19:35  slprj\_sfprj\EMLReport\sCRhMaj9Jw23XNYPAiUfbiC.mat

............此处省略215个文件信息

评论

共有 条评论