コード例 #1
0
        public void RoutPath(LineStrip line, bool backwards, Vector3 offset)
        {
            bool first = true;

            foreach (Vector3 point in line.Vertices)
            {
                // TODO: Pick some unit and stick with it!  Inches would be fine.
                Vector3 pointOffset = point + offset;

                MoveTool m = new MoveTool(pointOffset, MoveTool.SpeedType.Cutting);
                if (first)
                {
                    first = false;

                    if ((finalPosition.Xy - pointOffset.Xy).Length > .0001)
                    {
                        // Need to move the router up, over to new position, then down again.
                        MoveTool m1 = new MoveTool(new Vector3(finalPosition.X, finalPosition.Y, move_height), MoveTool.SpeedType.Rapid);
                        MoveTool m2 = new MoveTool(new Vector3(m.Target.X, m.Target.Y, move_height), MoveTool.SpeedType.Rapid);
                        AddCommand(m1);
                        AddCommand(m2);
                    }
                }
                AddCommand(m);
            }
        }
コード例 #2
0
        public void RoutPath(Rout r, bool backwards)
        {
            List <Vector2> mine = new List <Vector2>();

            foreach (Vector2 p in (r.Points))
            {
                mine.Add(new Vector2(p.X, p.Y));
            }

            if (backwards)
            {
                mine.Reverse();
            }

            for (int i = 0; i < mine.Count; i++)
            {
                float x = mine[i].X / 1000.0f;
                float y = mine[i].Y / 1000.0f;
                float z = r.Depth / 1000.0f;

                MoveTool m = new MoveTool(new Vector3(x, y, z), rout_speed);
                if (i == 0)
                {
                    if ((finalPosition.Xy - m.Location.Xy).Length > .0001)
                    {
                        // Need to move the router up, over to new position, then down again.
                        MoveTool m1 = new MoveTool(new Vector3(finalPosition.X, finalPosition.Y, move_height), move_speed);
                        MoveTool m2 = new MoveTool(new Vector3(m.Location.X, m.Location.Y, move_height), move_speed);
                        AddCommand(m1);
                        AddCommand(m2);
                    }
                }
                AddCommand(m);
            }
        }
コード例 #3
0
        public void Draw()
        {
            GL.PushMatrix();

            GL.Translate(0, 0, -0.1);
            Vector3 p = device.GetPosition();

            CoolDrawing.DrawCircle(12.5f, new OpenTK.Vector2(p.X * 1000, p.Y * 1000), Color.DarkGreen);

            for (int i = 0; i < commands.Count(); i++)
            {
                if (commands[i] is MoveTool)
                {
                    MoveTool m             = commands[i] as MoveTool;
                    Vector3  finalPosition = m.FinalPosition();
                    CoolDrawing.DrawCircle(5.0f, new Vector2(finalPosition.X * 1000, finalPosition.Y * 1000), Color.Blue);
                }
            }

            for (int i = 0; i < previousPoints.Count(); i++)
            {
                double age = DateTime.Now.Subtract(previousPoints[i].createTime).TotalMilliseconds;
                if (age > 5000)
                {
                    previousPoints.RemoveAt(i);
                    i--;
                }
                else
                {
                    int alpha = (int)(255 - 255 * age / 5000.0f);
                    CoolDrawing.DrawCircle(5.0f, new Vector2(previousPoints[i].location.X * 1000, previousPoints[i].location.Y * 1000), Color.FromArgb(alpha, Color.DarkGreen));
                }
            }

            float w = 0;

            // Assume full bit penetrates at 20 mills depth
            if (p.Z < 0)
            {
                w = -p.Z / .020f * 12.5f;
                if (w > 12.5f)
                {
                    w = 12.5f;
                }
                CoolDrawing.DrawFilledCircle(w, new OpenTK.Vector2(p.X * 1000, p.Y * 1000), Color.FromArgb(100, Color.OrangeRed));
                if (p.Z < -.020)
                {
                    float t = (p.Z + .020f) / .040f * 12.5f;
                    CoolDrawing.DrawFilledCircle(t, new OpenTK.Vector2(p.X * 1000, p.Y * 1000), Color.FromArgb(100, Color.DarkRed));
                }
            }
            else
            {
                w = p.Z / move_height * 12.5f;
                CoolDrawing.DrawFilledCircle(w, new OpenTK.Vector2(p.X * 1000, p.Y * 1000), Color.FromArgb(100, Color.LightGreen));
            }

            GL.PopMatrix();
        }
コード例 #4
0
ファイル: GCodeLoader.cs プロジェクト: zhangzheng1205/PathCAM
        public static void ExportGCode(List <ICommand> commands, string filename)
        {
            using (var file = File.CreateText(filename))
            {
                file.WriteLine("G20 (Units are Inches)");
                file.WriteLine("G90 (Absolute Positioning)");
                file.WriteLine("G94 (Units per Minute feed rate)");

                // TODO: paramaterize these
                float rapidSpeed   = 50.0f;
                float cuttingSpeed = 25.0f;
                float plungeSpeed  = 10.0f;

                float lastSpeed  = -1;
                float lastHeight = 0;
                float scale      = 1.0f;
                foreach (ICommand command in commands)
                {
                    if (command is MoveTool)
                    {
                        MoveTool m        = command as MoveTool;
                        float    speed    = m.Speed == MoveTool.SpeedType.Cutting ? cuttingSpeed * scale : rapidSpeed * scale;
                        var      gCommand = m.Speed == MoveTool.SpeedType.Cutting ? "G1" : "G0";

                        Vector3 target = m.Target * scale;
                        float   height = target.Z;
                        if ((height + 0.001f) < lastHeight)
                        {
                            speed = Math.Min(plungeSpeed, speed);
                        }
                        lastHeight = height;
                        if (lastSpeed != speed)
                        {
                            lastSpeed = speed;
                            file.WriteLine("{0} F{1:F4}", gCommand, speed);
                        }

                        file.WriteLine("{0} X{1:F4} Y{2:F4} Z{3:F4}", gCommand, target.X, target.Y, target.Z);
                    }
                }
            }
        }
コード例 #5
0
ファイル: Router.cs プロジェクト: glocklueng/cnc_machine
        public void RoutPath(Rout r, bool backwards)
        {
            List<Vector2> mine = new List<Vector2>();
            foreach (Vector2 p in (r.Points))
            {
                mine.Add(new Vector2(p.X, p.Y));
            }

            if (backwards)
            {
                mine.Reverse();
            }

            for (int i = 0; i < mine.Count; i++)
            {
                float x = mine[i].X / 1000.0f;
                float y = mine[i].Y / 1000.0f;
                float z = r.Depth / 1000.0f;

                MoveTool m = new MoveTool(new Vector3(x, y, z), rout_speed);
                if (i == 0)
                {
                    if ((finalPosition.Xy - m.Location.Xy).Length > .0001)
                    {
                        // Need to move the router up, over to new position, then down again.
                        MoveTool m1 = new MoveTool(new Vector3(finalPosition.X, finalPosition.Y, move_height), move_speed);
                        MoveTool m2 = new MoveTool(new Vector3(m.Location.X, m.Location.Y, move_height), move_speed);
                        AddCommand(m1);
                        AddCommand(m2);
                    }
                }
                AddCommand(m);
            }
        }