17-6-16 上午10:16 H:\Matlab Do...\demo.m 第 1 页,共 1 页
%% 初始化
clear,clc
close all
warning off
feature jit off
%% 主程序
% R代表所插补的圆的半径
R=10;
%ThetaAround代表所要插补的角度范围
ThetaAround=[135,90;90,0;0,-45];;
% Use_SN代表所在控制的插补方向
% Use_S表示进行顺向插补 Use_N表示进行逆向插补
Use_SN 'Use_S' ;
% 通过OCT_MControl函数进行插补并返回插补信息
% Data是切削刀头的移动坐标数据
% MovePosition是切削刀头的移动方向信息
[Data,MovePosition]=OCT_MControl(ThetaAround,R,Use_SN);
%% 作图,动态演示插补过程
hold on
grid on
axis equal
ezplot(strcat( 'x^2+y^2=' ,num2str(R^2)),[-R,R]);
mycomet(Data.X,Data.Y)
17-6-16 上午10:19 H:\...\OCT_MControl.m 第 1 页,共 1 页
function [Data,MovePosition]=OCT_MControl(ThetaAround,O_R,Use_SN)
% 插补过程的总控制函数
% 对于跨过几个象限的圆弧,程序可以分段对其每个象限圆弧进行插补
Data.X=[];
Data.Y=[];
Data.Fm=[];
% 确定插补段数
for n=1:size(ThetaAround,1)
% 将半径及角度信息转换为插补的起始与终止点坐标
Position.X_FirstPosition=O_R*cosd(ThetaAround(n,1));
Position.Y_FirstPosition=O_R*sind(ThetaAround(n,1));
Position.X_EndPosition=O_R*cosd(ThetaAround(n,2));
Position.Y_EndPosition=O_R*sind(ThetaAround(n,2));
% 对每一象限的圆弧进行单独插补并返回数据
TmpData{n,1}=OCT_GetData(OCT_Function(Position,Use_SN));
% 记录移动方向信息
MovePosition{n,1}=TmpData{n,1}.MovePosition;
% 记录坐标及误差等数据信息
Data.X=[Data.X;TmpData{n,1}.X];
Data.Y=[Data.Y;TmpData{n,1}.Y];
Data.Fm=[Data.X;TmpData{n,1}.Fm];
end
17-6-16 上午10:17 H:\Matlab...\mycomet.m 第 1 页,共 3 页
function mycomet(varargin)
[ax,args,nargs] = axescheck(varargin{:});
if nargs < 1
error(message( 'MATLAB:narginchk:notEnoughInputs' ));
elseif nargs > 3
error(message( 'MATLAB:narginchk:tooManyInputs' ));
end
if nargs < 2, x = args{1}; y = x; x = 1:length(y); end
if nargs 2, [x,y] = deal(args{:}); end
if nargs < 3, p = 0.10; end
if nargs 3, [x,y,p] = deal(args{:}); end
if ~isscalar(p) || ~isreal(p) || p < 0 || p >= 1
error(message( 'MATLAB:comet:InvalidP' ));
end
ax = newplot(ax);
if ~ishold(ax)
[minx,maxx] = minmax(x);