Question
BSDM Kinematic Analysis 코드를 이용해 제 모델을 직접 분석하려고 합니다.
링크의 Position Vector 표현에 어려움이 있어 질문 드립니다.
Answer
아까 같이 이야기 했던 코드 원본 답변에 적어둠
정상 작동함을 확인했으니 잘 수정해보길
Position Analysis Code
%% Kinematic Analysis
% Initialization
clear all; close all; clc;
%% Design Parameters
% Basic Parameters
fileName = 'Test';
link_num = 4;
ang_num = 150;
% Input Angle: Theta
theta_init = deg2rad(60); % [rad]
theta_final = deg2rad(30); % [rad]
theta = linspace(theta_init, theta_final, ang_num); % [rad]
% Link Length
L_ref = 15.12; % [in]
Ld = L_ref/sin(theta_init); % [in]
L2 = 0.5*Ld; % [in]
L3 = Ld - L2; % [in]
L1 = 19; % [in]
L4 = L_ref; % [in]
%% Position Analysis
% Angle History
theta1 = 0.5*pi - asin(L2/L1.*sin(theta)); % [rad]
theta2 = 0.5*pi + theta; % [rad]
theta3 = -(1.5*pi - asin(Ld/L4.*sin(theta))); % [rad]
% Posicion Vector
r{1} = L1.*[cos(theta1); sin(theta1)]; % [in]
r{2} = L2.*[cos(theta2); sin(theta2)]; % [in]
r{3} = L3.*[cos(theta2); sin(theta2)]; % [in]
r{4} = L4.*[cos(theta3); sin(theta3)]; % [in]
% Position of the Links
link{1}.x = [zeros(1, ang_num); r{1}(1,:)];
link{1}.y = [zeros(1, ang_num); r{1}(2,:)];
link{2}.x = [link{1}.x(2,:); link{1}.x(2,:) + r{2}(1,:)];
link{2}.y = [link{1}.y(2,:); link{1}.y(2,:) + r{2}(2,:)];
link{3}.x = [link{2}.x(1,:) - r{3}(1,:); link{2}.x(1,:)];
link{3}.y = [link{2}.y(1,:) - r{3}(2,:); link{2}.y(1,:)];
link{4}.x = [link{3}.x(1,:); link{3}.x(1,:) + r{4}(1,:)];
link{4}.y = [link{3}.y(1,:); link{3}.y(1,:) + r{4}(2,:)];
%% Post Process
% Plot Setting
[Fig, Axes] = PlotSetting(1000, 800);
axis off;
axis equal;
axis([-20, 20, -5, 30]);
xlabel('X [ mm ]', 'FontWeight', 'bold');
ylabel('Y [ mm ]', 'FontWeight', 'bold');
linkColor = {[0.20 0.20 0.20], [0.20 0.20 0.92], [0.90 0.55 0.35], [0.20 0.92 0.20], ...
[0.20 0.20 0.92], [0.92 0.20 0.20], [0.90 0.84 0.40], [0.92 0.20 0.20]}; % RGB
% Plot Initial State
link_geo = cell(2, link_num);
ang_idx = 1;
for idx = 1:link_num
link_geo{1, idx} = line(link{idx}.x(:,ang_idx)', link{idx}.y(:,ang_idx)', ...
'LineWidth', 5, 'Color', linkColor{idx}, 'LineStyle', '-');
link_geo{2, idx} = line(-link{idx}.x(:,ang_idx)', link{idx}.y(:,ang_idx)', ...
'LineWidth', 5, 'Color', linkColor{idx}, 'LineStyle', '-');
end
%% Plot Animation
% Animation Setting
video = VideoWriter([fileName, '_Kinematic_Animation.mp4'], 'MPEG-4');
video.FrameRate = 30;
video.Quality = 100;
open(video);
for ang_idx = 1:ang_num
% Plot Links
for idx = 1:link_num
link_geo{1, idx}.XData = real(link{idx}.x(:,ang_idx)');
link_geo{1, idx}.YData = real(link{idx}.y(:,ang_idx)');
link_geo{2, idx}.XData = real(-link{idx}.x(:,ang_idx)');
link_geo{2, idx}.YData = real(link{idx}.y(:,ang_idx)');
end
% Write Video
drawnow;
frame = getframe(Fig);
writeVideo(video, frame);
end
close(video);
MATLAB
복사
Mention for reply completion notification: @전현준