简体   繁体   English

计算n维圆弧路径

[英]Calculate n-dimensional arc path

I'm implementing a driver for a CNC mill, and I'm having trouble implementing the G-code arc commands.我正在为 CNC 铣床实施驱动程序,但在实施 G 代码圆弧命令时遇到问题。

I have found several implementations of the midpoint circle algorithm, but it is not really usable as-is.我发现了中点圆算法的几种实现,但它并不是真正可用的。

The problem with the midpoint circle algo as I found it, is that it is 2D and draws all the octants at the same time, while I need sequential steps through a 3D path, given by the start, end and center points.我发现中点圆算法的问题在于它是 2D 并同时绘制所有八分圆,而我需要通过 3D 路径的顺序步骤,由起点、终点和中心点给出。

I found a nice multidimensional equivalent of Bresenham's line drawing algo using floating point operations.我使用浮点运算找到了Bresenham 的线条绘制算法的一个很好的多维等价物 Maybe a similar thing exists for drawing an arc?也许存在类似的东西来绘制弧线?

I might be able to bend this algo to my will using a lot of thinking and experimenting, but since drawing an arc is not an unsolved problem, and CNC machines have been made before, I wonder if an elegant solution already exists?我也许可以通过大量的思考和实验来使这个算法随心所欲,但是由于绘制圆弧并不是一个未解决的问题,而且之前已经制造了 CNC 机器,我想知道是否已经存在一个优雅的解决方案?

My dxftools python package used for processing DXF files for a not very smart 2D cutter has a function to split an arc into line segments in 2D.我的dxftools python 包用于处理不太智能的 2D 刀具的 DXF 文件,它具有将圆弧分割为 2D 线段的功能。 You could use this code and then use 3D coordinate tranformations to arbitrarily place this in 3D space.您可以使用此代码,然后使用 3D 坐标变换将其任意放置在 3D 空间中。 Examples of coordinate transforms can be found in my py-stl package.坐标变换的例子可以在我的py-stl包中找到。

In LinuxCNC , position generation is separated from step generation.LinuxCNC 中,位置生成与步骤生成是分开的。 In the position generating loop, the system tracks the distance it has already moved along the current primitive (line or helix) and uses a simple formula to get the location that is distance D along that primitive.在位置生成循环中,系统跟踪它已经沿当前基元(直线或螺旋线)移动的距离,并使用一个简单的公式来获得沿该基元距离 D 的位置。 (Typically, this is done once per millisecond). (通常,每毫秒执行一次)。 This position can be used in different ways depending on whether you have servos, hardware step generation, or software step generation.该位置可以以不同的方式使用,具体取决于您是使用伺服系统、硬件步进生成还是软件步进生成。

In a software step generation system, the difference between the old commanded position and the new commanded position is determined along each axis, and this is used to update the rates of a digital waveform generator using the direct digital synthesis method (DDS).在软件步骤生成系统中,旧指令位置和新指令位置之间的差异沿每个轴确定,这用于使用直接数字合成方法 (DDS) 更新数字波形发生器的速率。 Then, at a higher rate (typically every 20-50µs), the DDS determines for each axis whether a step should be generated at that time.然后,以更高的速率(通常每 20-50 微秒),DDS 为每个轴确定此时是否应生成一个阶跃。

This is a different design than you are describing, but it is a more flexible one.这是一种与您所描述的不同的设计,但它更灵活。 For instance, by separating position generation from step generation, you can revise the blending algorithm in your position generation code without revising step generation;例如,通过将位置生成与步骤生成分离,您可以修改位置生成代码中的混合算法,而无需修改步骤生成; and you can replace software step generation with hardware step generation or servo control with algorithms like PID.您可以用硬件步骤生成或伺服控制代替软件步骤生成,例如 PID 算法。

In your design, you can approximate the method I describe above by simply dicing your helical arc into line segments as described by Roland, and using those as inputs into your step generation code which understands only lines.在您的设计中,您可以通过简单地将您的螺旋弧切割成 Roland 描述的线段,并将这些线段用作仅理解线的步骤生成代码的输入来近似我上面描述的方法。 In a sense, this is not too different from what LinuxCNC does, except that the curve primitive becomes sampled according to distance instead of according to time.从某种意义上说,这与 LinuxCNC 所做的没有太大区别,只是曲线基元根据距离而不是根据时间进行采样。

Well on CNC there is usually more than just 2D as there are also speeds, tool angles more than one actuator per axis kinematics etc... For this purpose I usually use parametric cubics with parameter t=<0.0,1.0> .好吧,在CNC上,通常不仅仅是 2D,因为还有速度、刀具角度,每个轴运动学上有一个以上的致动器等等......为此,我通常使用参数为t=<0.0,1.0>参数t=<0.0,1.0> So I convert the path into set of cubic curves which are easily evaluable in any dimensionality.所以我将路径转换为一组三次曲线,这些曲线在任何维度上都很容易评估。 After this step you got 3 usual ways of rasterization:在这一步之后,你得到了 3 种常用的光栅化方法:

  1. constant dt step恒定dt步长

    parametric cubics are usually nonlinear so in order to move to another pixel (or whatever) you need to increase parameter t with smaller step than your resolution is something like:参数三次通常是非线性的,因此为了移动到另一个像素(或其他像素),您需要以比分辨率更小的步长增加参数t类似于:

     dt < 1.0 / curve_length

    the less dt is the better chances are you will not miss a pixel but of coarse will have many more duplicate positions. dt越少,您就越有可能不会错过一个像素,但粗略的将有更多的重复位置。

  2. search next dt step搜索下一个dt

    using binary search you can find what is the next t so the distance to current position is single pixel.使用二分搜索,您可以找到下一个t是什么,因此到当前位置的距离是单个像素。 This is much more precise but also slower up to a point...这更精确,但在某种程度上也更慢......

  3. convert to lines转换为行

    you can sample your cubic curve into set of lines (how many depends on size of the curve) and rasterize lines as usuall using DDA or Bresenham.您可以将三次曲线采样为一组线(多少取决于曲线的大小)并像往常一样使用 DDA 或 Bresenham 栅格化线。 This is simplest but the result will not be exactly a curve.这是最简单的,但结果不会完全是一条曲线。

Cubics are like this:立方体是这样的:

P(t) = a0 + a1*t + a2*t^2 + a3*t^3
t = <0.0,1.0>

where P(t) is position and a0,a1,a2,a3 are coefficients in for m of vectors where each axis has own scalar coefficient.其中P(t)是位置, a0,a1,a2,a3是 m 个向量的系数,其中每个轴都有自己的标量系数。

See How can i produce multi point linear interpolation?请参阅如何生成多点线性插值? and the sublinks on how to use/compute them.以及有关如何使用/计算它们的子链接。

Anyway if you insist on arc interpolation assuming circular arc:无论如何,如果您坚持假设圆弧的圆弧插补:

P(t) = ( Rotation_matrix(t) * (P0 - Pcenter) ) + Pcenter
t = <0.0,2*PI>

Where Rotation_matrix rotates your point around (0,0,0,...,0) by t [rad] in the curve direction and P0 is start point and Pcenter is center of the arc.其中Rotation_matrix将您的点绕(0,0,0,...,0)沿曲线方向旋转t [rad]P0是起点, Pcenter是圆弧的中心。

In case of non axis aligned rotation you can use Rodrigues_rotation_formula instead.在非轴对齐旋转的情况下,您可以使用Rodrigues_rotation_formula代替。

However using homogenous transform matrices is your best option in ND you just scale up the matrix size:然而,在 ND 中使用同构变换矩阵是您的最佳选择,您只需扩大矩阵大小:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM