机电控制DDA插补
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
基于MATLAB的GUI的DDA脉冲当量样条曲线插补完成三次样条曲线的运动控制与仿真程序和界面如下:
利用MATLAB软件制作GUI界面如下:
插补程序:
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
a0=str2double(get(handles.edit1,'string'));%读入样条参数方程
a1=str2double(get(handles.edit2,'string'));
a2=str2double(get(handles.edit3,'string'));
a3=str2double(get(handles.edit4,'string'));
b0=str2double(get(handles.edit5,'string'));
b1=str2double(get(handles.edit6,'string'));
b2=str2double(get(handles.edit7,'string'));
b3=str2double(get(handles.edit8,'string'));
u=0:0.01:1;
X=a0+a1*u+a2*u.^2+a3*u.^3;
Y=b0+b1*u+b2*u.^2+b3*u.^3;
plot(X,Y);%绘制原参数曲线
hold on;
grid on;
pos1=0;neg1=0;pos2=0;neg2=0;
if a1>=0
pos1=pos1+a1;
else
neg1=neg1+abs(a1);
end
if a2>=0
pos1=pos1+2*a2;
else
neg1=neg1+2*abs(a2);
end
if a3>=0
pos1=pos1+3*a3;
else
neg1=neg1+3*abs(a3);
end
if b1>=0 pos2=pos2+b1;
else
neg2=neg2+abs(b1);
end
if b2>=0
pos2=pos2+2*b2;
else
neg2=neg2+2*abs(b2);
end
if b3>=0
pos2=pos2+3*b3;
else
neg2=neg2+3*abs(b3);
end
K1=max(neg1,pos1);K2=max(neg2,pos2);
K=max(K1,K2);%确定累加次数K
x0=fix(a0);%给定插补初值
x1=a1/K-a2/(K^2)+a3/(K^3);
x2=2*a2/(K^2)-6*a3/(K^3);
x3=6*a3/(K^3);
y0=fix(b0);
y1=b1/K-b2/(K^2)+b3/(K^3);
y2=2*b2/(K^2)-6*b3/(K^3);
y3=6*b3/(K^3);
for i=1:1:K%递推过程
x2=x2+x3;
x1=x1+x2;
x=x0+x1;
y2=y2+y3;
y1=y1+y2;
y=y0+y1;
if (x1==0) && (y1==0)
break;
else
X1=[x0,x];
Y1=[y0,y];
h=line(X1,Y1);
set(h,'color','r');%用红色画出插补曲线 pause(0.2)
hold on;
x0=x;y0=y;
end
end
程序运行结果如下:
给定参数方程
插补轨迹为:
其中蓝色曲线是参数曲线,红色折线段是插补轨迹。
可见,轨迹插补的很好。