机械臂-五次多项式与三次多项式对比

##1、三次多项式算法
代码如下:

L(1) = Link(  'd',     0.081,  'a' ,-0.01 , 'alpha',   pi/2 ,'offset',0);
L(2) = Link(  'd',     0 ,  'a' , 0.099 , 'alpha',   0 ,'offset',pi/2);
L(3) = Link(  'd',  0 ,  'a' , -0.01 , 'alpha',pi/2,'offset',pi/2);
L(4) = Link( 'd',  0.117+0.123,  'a' , 0 , 'alpha', pi/2 ,'offset',0);
L(5) = Link( 'd',0 ,  'a' , 0.057 , 'alpha',pi/2,'offset',-pi);
robot = SerialLink(L,'name','五自由度机械臂'); %建立连杆机器
robot.display;
robot.teach;       %画出模型并进行调控
robot.plot([0 0 0 0 0]) %输入一定参数后机器人图形
%%
Theta=[40,-30,-30,30,-15;
       0,15,0,10,20;
       -40,30,30,-20,30];
Velocity=[0,0,0,0,0,0;40,40,20,30,20,10;0,0,0,0,0,0];
Accle=[0,0,0,0,0,0;0,0,0,0,0,0;0,0,0,0,0,0];
[m,n]=size(Theta);
% 三次多项式轨迹规划,定义插补次数n,根据驱动器支持的最大插补次数设定
Time=[0,0,0,0,0,0;5,5,5,5,5,5;10,10,10,10,10,10];
StopTime=Time(3,1);
FixedStep=0.2;
SimpleNum=0:FixedStep:StopTime;Cunt=length(SimpleNum);
for i=1:n
    %% 求每个关节角的五次多项式插补轨迹点
    [q(:,i),qd(:,i),qdd(:,i)] = threejtraj_Function(Theta(:,i),Time(:,i), ...
                                Velocity(:,i),Accle(:,i)); 
end
qT=q';vT=qd';aT=qdd';t=2000;
%% 求正解
T=robot.fkine(deg2rad(q));        %求正解,得到每次对应的空间位姿矩阵
JTA=transl(T);                  %空间位姿矩阵转化为位置矩阵
%% 绘制末端位置
W=[-700,+700,-700,+700,0,+1000]*0.001;
% 求约束角度的正解,获取末端位姿
T1=robot.fkine(deg2rad(Theta(1,:))); 
T2=robot.fkine(deg2rad(Theta(2,:))); 
T3=robot.fkine(deg2rad(Theta(3,:))); 
% 动态仿真
% figure('Color',[1,1,1],'Position',[485,180,386,310],'Visible','on');
hold on
plot3(JTA(1:end,1), JTA(1:end,2), JTA(1:end,3),'b','LineWidth',1.5);
axis equal;   %设置坐标轴范围
hold on;grid on;
plot3(T1(1,4),T1(2,4),T1(3,4),'o','color','r','LineWidth',2);%#7E2F8E
plot3(T2(1,4),T2(2,4),T2(3,4),'o','color','r','LineWidth',2);
plot3(T3(1,4),T3(2,4),T3(3,4),'o','color','r','LineWidth',2);
robot.plot(q*(pi/180)); 

%%
figure(3)
i=1:5;
subplot(3,1,1);
plot(q(:,i));
legend('theta1','theta2','theta3','theta4','theta5')
title('位置');
grid on;
subplot(3,1,2);

plot(qd(:,i));
legend('theta1','theta2','theta3','theta4','theta5')
title('速度');
grid on;
subplot(3,1,3);

plot(qdd(:,i));
legend('theta1','theta2','theta3','theta4','theta5')
title('加速度');
grid on;

结果如下:
在这里插入图片描述
在这里插入图片描述
##2、五次多项式
代码如下:

clear
clc
close all

%标准DH
%Link(DH,option):
L(1) = Link(  'd',     0.081,  'a' ,-0.01 , 'alpha',   pi/2 ,'offset',0);
L(2) = Link(  'd',     0 ,  'a' , 0.099 , 'alpha',   0 ,'offset',pi/2);
L(3) = Link(  'd',  0 ,  'a' , -0.01 , 'alpha',pi/2,'offset',pi/2);
L(4) = Link( 'd',  0.117+0.123,  'a' , 0 , 'alpha', pi/2 ,'offset',0);
L(5) = Link( 'd',0 ,  'a' , 0.057 , 'alpha',pi/2,'offset',-pi);
% L(6) = Link( 'd',  0.225 ,  'a' , 0 , 'alpha',0,'offset',0);
robot = SerialLink(L,'name','五自由度机械臂'); %建立连杆机器
robot.display;
robot.teach;       %画出模型并进行调控
% robot.plot([0]) %输入一定参数后机器人图形
%%
%轨迹规划
Theta=[40,-30,-30,30,-15;
       0,15,0,10,20;
       -40,30,30,-20,30];
Velocity=[0,0,0,0,0,0;40,40,20,30,20,10;0,0,0,0,0,0];
Accle=[0,0,0,0,0,0;0,0,0,0,0,0;0,0,0,0,0,0];
[m,n]=size(Theta);
% 三次多项式轨迹规划,定义插补次数n,根据驱动器支持的最大插补次数设定
Time=[0,0,0,0,0,0;5,5,5,5,5,5;10,10,10,10,10,10];
StopTime=Time(3,1);
FixedStep=0.2;
SimpleNum=0:FixedStep:StopTime;Cunt=length(SimpleNum);
for i=1:n
    %% 求每个关节角的五次多项式插补轨迹点
    [q(:,i),qd(:,i),qdd(:,i)] = Fivejtraj_Function(Theta(:,i),Time(:,i), ...
                                Velocity(:,i),Accle(:,i),FixedStep); 
end
qT=q';vT=qd';aT=qdd';t=2000;
robot.plot(q*(pi/180)) 
Tc=robot.fkine(q*(pi/180))
Tjtraj=transl(Tc);
hold on
plot2(Tjtraj,'r');grid on;

figure(3)
i=1:5;
subplot(3,1,1);
plot(q(:,i));
legend('theta1','theta2','theta3','theta4','theta5')
title('位置');
grid on;
subplot(3,1,2);

plot(qd(:,i));
legend('theta1','theta2','theta3','theta4','theta5')
title('速度');
grid on;
subplot(3,1,3);

plot(qdd(:,i));
legend('theta1','theta2','theta3','theta4','theta5')
title('加速度');
grid on;

结果如下:
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CAE工作者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值