插补速度控制平滑处理控制小总结

插补概念

在CNC数控车床中需要控制刀具沿着任意的曲线或者给定系列点走刀,而刀具很难沿着曲线行走,通常的做法是没把曲线量化分割为直线线段圆弧线段两种,这就涉及到直线插补,圆弧插补。所谓“插补”就是指在一条已知的起点O和终点A的曲线上进行数据点的密集化,插补的任务就是跟句给进速度要求,在起点O和终点A之间,计算曲线上的具体坐标值。

 

clc;
clear;

pStart = [0,0];
pEnd = [8,14];
targetEnd = pEnd - pStart;
step = 0.2;
nDir = 0;
StepCount = 0;

xCurVal=0;
yCurVal=0;


StepMount = (abs(targetEnd(1)) + abs(targetEnd(2)))/step
Output = zeros(StepMount,2);
lDevVal=yCurVal*targetEnd(1)-xCurVal*targetEnd(2);
% 象限判断  
if targetEnd(1) > 0
    if targetEnd(2) > 0
        nDir = 1;
    else
        nDir = 4;
    end
else
    if targetEnd(2) > 0
        nDir = 2;
    else
        nDir = 3;
    end
end
nDir
% for i = 1:SetpMount
% end
while StepCount < StepMount
    
 		if lDevVal>=0 
			% 偏差〉=0   
			switch nDir 
                case 1
                    
                    xCurVal = xCurVal + step;    
                    % InsertPoint(xCurVal,yCurVal);  
                    Output(StepCount+1,:) = [xCurVal,yCurVal];
                     
                case 2  
                    xCurVal = xCurVal - step;  
    % 				InsertPoint(xCurVal,yCurVal);   
                    Output(StepCount+1,:) = [xCurVal,yCurVal];
                  
                case 3
                    xCurVal = xCurVal - step;   
    % 				InsertPoint(xCurVal,yCurVal);    
                    Output(StepCount+1,:) = [xCurVal,yCurVal];
                case 4
                    xCurVal = xCurVal + step;  
    % 				InsertPoint(xCurVal,yCurVal);  
                    Output(StepCount+1,:) = [xCurVal,yCurVal];
                otherwise
                    ;
             end
			lDevVal = lDevVal - targetEnd(2);  
        else
			% 偏差<0  
			switch nDir
			   
                case 1
                    yCurVal = yCurVal + step;   
    % 				InsertPoint(xCurVal,yCurVal);  
                    Output(StepCount+1,:) = [xCurVal,yCurVal];
                case 2  
                    yCurVal = yCurVal + step;  
    % 				InsertPoint(xCurVal,yCurVal);   
                    Output(StepCount+1,:) = [xCurVal,yCurVal];
                case 3
                    yCurVal= yCurVal - step;   
    % 				InsertPoint(xCurVal,yCurVal);    
                    Output(StepCount+1,:) = [xCurVal,yCurVal];
                case 4
                    yCurVal= yCurVal - step;    
    % 				InsertPoint(xCurVal,yCurVal);  
                    Output(StepCount+1,:) = [xCurVal,yCurVal];
                 otherwise
                    ;
                end
			lDevVal= lDevVal + targetEnd(1); 
            end
		StepCount = StepCount + 1
end
plot([0;targetEnd(1)],[0;targetEnd(2)])
hold on
plot(Output(:,1),Output(:,2))


执行效果,蓝线为理想直线,红线为刀具实际走过的线 

猜你喜欢

转载自blog.csdn.net/qq_29796781/article/details/81434497