%This program is an attempt to implement a PID control for a 2 link robot
%arm
th_init=[-pi/3 pi/3];
ths=[pi/2 -pi/4];
x0=[0 0 th_init 0 0 0 0];
Ts=[0 20];
%Specifications
L1=1;
L2=1;
M1=1;
M2=1;
spec=[L1 L2 M1 M2];
%PID PARAMETERS
Kp1=15;
Kd1=7;
Ki1=10;
Kp2=15;
Kd2=10;
Ki2=10;
Kpid=[Kp1 Kd1 Ki1 Kp2 Kd2 Ki2];
%SOLVER
[T,X]=ode45(@(t,x) r2dof(t,x,ths,spec,Kpid),Ts,x0);
%O/P
th1=X(:,3);
th2=X(:,4);
%Torque Cmp
F1=diff(X(:,7))./diff(T);
F2=diff(X(:,8))./diff(T);
tt=0:(T(end)/(length(F1)-1)):T(end);
%X and Y positions
X1=L1.*sin(th1);
y1=L1.*cos(th1);
x2=L1.*sin(th1)+L2.*sin(th1+th2);
y2=L1.*cos(th1)+L2.*cos(th1+th2);
plot(T,ths(1)-th1)
grid
title('Theta-1 error')
ylabel('theta1 error (rad)')
xlabel('time (sec)')
%theta2 error plot
figure
plot(T,ths(2)-th2)
grid
title('Theta-2 error')
ylabel('theta2 error (rad)')
xlabel('time (sec)')
%torque1 plot
figure
plot(tt,F1)
grid
title('Torque of theta 1')
ylabel('theta1 torque')
xlabel('time (sec)')
%torque2 plot
figure
plot(tt,F2)
grid
title('Torque of theta 2')
ylabel('theta2 torque')
xlabel('time (sec)')
d=2;
j=1:d:length(T);
for i=1:length(j)-1
hold off
plot([X1(j(i)) x2(j(i))],[y1(j(i)) y2(j(i))],'o',[0 X1(j(i))],[0
y1(j(i))],'k',[X1(j(i)) x2(j(i))],[y1(j(i)) y2(j(i))],'k')
title('Motion of 2DOF Robotic Arm')
xlabel('x')
ylabel('y')
axis([-3 3 -3 3]);
grid
hold on
MM(i)=getframe(gcf);
end
drawnow;


海神之光
- 粉丝: 6w+
最新资源
- maven下载安装与配置.md
- 使用memory-profiler定位内存泄漏的具体步骤?
- 基于PyQt5与UNet系列模型的医学图像分割系统设计与实现【unet、unet++、unet3+模型】
- 泛型注解TypeVar与Generic如何协作实现容器类型安全?
- 如何用-call-实现无装饰器的单例模式?
- Vim编辑器基础操作命令全攻略
- 集成MobileUnet和EfficientUnet两种轻量级网络的完整医学图像分割项目、包含训练、验证和推理
- 模块加载时sys.meta-path的拦截机制如何实现?
- 基于EASYOCR的图像文字识别系统
- 二阶Stokes波浪UDF模拟与CFD案例分析
- 2023年中国地级市人工智能水平数据-最新出炉
- 基于SwinTransformer图像分类完整项目
- GB/T 34590-2022 道路车辆 功能安全 12个部分完整版
- 手写字体识别 matlab 手写识别 手写体识别
- 基于SpringBoot+Vue的大学生就业招聘系统设计与实现
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


