0

实际上,我设计了一个控制 CNC 机床的 C# 程序,例如,我们可以使用 UGS,那里有很多软件,但我需要用 C# 创建。我在这里唯一受苦的是3D坐标系。如何在 3D 中创建轴图。示例:Planet Cnc 的“Cnc USB 控制器”我想用 C# 创建这个软件。

4

1 回答 1

0

我会尽我所能回答,但你应该考虑定义你想要实现的范围,即如果你只想要一个坐标系或一个 UI 来配合它,比如 UGS。

仅制作坐标系的最佳方法是定义您需要的所有数据,例如位置、旋转、进给、快速、偏移等。然后将所有这些数据包装在一个类中以用于机器状态,并使用方法来帮助您操作数据.

例子

public struct Vector3 
{
    public float x,y,z
}

public struct Rotation 
{
    public float x,y,z //Or whatever your machine uses, the 5 axis at my work is v,w for rotation. 
                       //I recommend leaving it as x,y,z though cause it will make it more robust as you 
                       //can use the same code on different machines by interpreting the values differently later on.
                       //Alternatively you could use a Quaternion if need but most machines interprat eular angles just fine without gimble lock.
}

//only if you need scale. stay away from this if you can help it, it will make zeroing harder because you will have to use matrix math to make the position and rotation work properly with it(I could be wrong about that though).
public struct Scale 
{
    public float x,y,z
}

public struct Transform 
{
    public Vector3 position;
    public Rotation rotation;
}

//then create a class to define the state of the machine.
public class MachineState 
{
    public bool rapid = false;
    public bool feed = false;
    public bool flood = false;
    public bool mist = false;
    public Transform transform;
    
    //An example of a method to manipulate the data.
    public Vector3 CalculateOffset (Vector3 offsetPosition, Vector3 offset) 
    {
        //Add your offset logic here.
    } 
}

如果您还需要 UI,那么我推荐 .net MUAI 或 Windows Forms,它们中的任何一个都应该可以直接创建一个 UI 来使用这些数据,以及添加 3D 视图和您能想到的任何其他内容。

.Net MAUI: https ://docs.microsoft.com/en-us/dotnet/maui/what-is-maui

Windows 窗体: https ://docs.microsoft.com/en-us/dotnet/desktop/winforms/?view=netdesktop-5.0

我希望这能帮助你走上正确的道路,但也对我所说的一切持保留态度,因为我以前从未制作过操纵数控机床的程序。

我只是对它们进行操作和数据分析。不过,我确实对坐标系有很多了解,因为我曾经是一名游戏开发人员。

于 2021-10-20T04:45:01.410 回答