예제 #1
0
        public GCodeData Clone()
        {
            var r = new GCodeData();

            foreach (var coordinate in Coordinates)
            {
                r.Coordinates[coordinate.Key] = coordinate.Value;
            }

            return(r);
        }
예제 #2
0
        private static void CalculateMovement(GCodeData prev, GCodeData gdata)
        {
            InitializeAxes();
            var stpsDict = new Dictionary <PrinterAxis, Movement>();
            var stepsX   =
                _xAxisCalculator.CalculateSteps(prev.Coordinates[PrinterAxis.X], gdata.Coordinates[PrinterAxis.X], 200);

            var stepsY =
                _yAxisCalculator.CalculateSteps(prev.Coordinates[PrinterAxis.Y], gdata.Coordinates[PrinterAxis.Y], 200);

            var stepsZ =
                _yAxisCalculator.CalculateSteps(prev.Coordinates[PrinterAxis.Z], gdata.Coordinates[PrinterAxis.Z], 200);

            var stepsE =
                _eAxisCalculator.CalculateSteps(prev.Coordinates[PrinterAxis.E], gdata.Coordinates[PrinterAxis.E], 200);


            var times   = new[] { stepsE.TotalTime, stepsX.TotalTime, stepsY.TotalTime, stepsZ.TotalTime };
            var maxTime = times.Max();

            stepsE.SpeedFactor = (stepsE.TotalTime != 0) ? maxTime / stepsE.TotalTime : 1;
            stepsZ.SpeedFactor = (stepsZ.TotalTime != 0) ? maxTime / stepsZ.TotalTime : 1;
            stepsX.SpeedFactor = 1; // (stepsX.TotalTime != 0) ? maxTime / stepsX.TotalTime : 1;
            stepsY.SpeedFactor = 1; // (stepsY.TotalTime != 0) ? maxTime / stepsY.TotalTime : 1;

            if (stepsX.TotalTime != 0)
            {
                CalculateTimeStamps(stepsX);
                stpsDict.Add(PrinterAxis.X, stepsX);
            }

            if (stepsY.TotalTime != 0)
            {
                CalculateTimeStamps(stepsY);
                stpsDict.Add(PrinterAxis.Y, stepsY);
            }

            if (stepsZ.TotalTime != 0)
            {
                CalculateTimeStamps(stepsZ);
                stpsDict.Add(PrinterAxis.Z, stepsZ);
            }

            if (stepsE.TotalTime != 0)
            {
                CalculateTimeStamps(stepsE);
                stpsDict.Add(PrinterAxis.E, stepsE);
            }

            _commandsList.Add(new MoveCommand(stpsDict));
        }
예제 #3
0
        static void Main(string[] args)
        {
            InitializeAxes(); //inputing initial configurations
            var reader = new FileReader();
            // var lines = reader.Readfile(); // Calling the Read file methold which returns all the gcode commands

            List <string> lines;

            if (args.Length > 0)
            {
                // a cheat here, as we have our test file then change stps values.
                if (args[0].ToLower() == "syncsample.gcode")
                {
                    ChangeSteps();
                }

                lines = reader.Readfile(args[0]);
            }
            else
            {
                lines = reader.Readfile();
            }


            var noHomeSkip  = true;
            var gdata       = new GCodeData();
            var lineCounter = 1;

            foreach (var line in lines)
            {
                Console.WriteLine($"line {lineCounter++} from {lines.Count}"); // keeping track of current line
                Console.WriteLine("-------------");

                /*     M109 S240 ; wait for temperature to be reached
                 *     ---------- > yhis will be taken as first element
                 *     after second split
                 * [0]M109                  [1]s240           [2]""           * */
                var commands = line.Split(';')[0].Split(' ');
                if (commands[0].StartsWith("M"))
                {
                    ProcesMachineRelatedCommand(commands); // Writing the Machine (M) commands on screenrinter commands starting with M
                }
                if (commands[0] == "G28")                  // Reference Point
                {
                    Console.WriteLine("executing homing....");
                    gdata.Coordinates[PrinterAxis.X] = 0;
                    gdata.Coordinates[PrinterAxis.Y] = 0;
                    gdata.Coordinates[PrinterAxis.Z] = 0;
                    gdata.Coordinates[PrinterAxis.E] = 0;
                    noHomeSkip = false;
                }
                if (noHomeSkip)
                {
                    // cannot move printer before home executed;
                    Console.WriteLine("no home executed");
                    continue;
                }

                var prev = gdata.Clone();

                if (commands[0] == "G01" || commands[0] == "G1")
                {
                    Console.WriteLine(line);
                    foreach (var c in commands)// looing through the commands
                    {
                        /*G1 X61.832 Y83.245  E22.14390          X=61.832       Y=83.245     E=22.14390      */
                        if (c.Trim().StartsWith("X"))
                        {
                            gdata.Coordinates[PrinterAxis.X] = decimal.Parse(c.Replace("X", string.Empty));
                        }
                        if (c.Trim().StartsWith("Y"))
                        {
                            gdata.Coordinates[PrinterAxis.Y] = decimal.Parse(c.Replace("Y", string.Empty));
                        }
                        if (c.Trim().StartsWith("Z"))
                        {
                            gdata.Coordinates[PrinterAxis.Z] = decimal.Parse(c.Replace("Z", string.Empty));
                        }

                        if (c.Trim().StartsWith("E"))
                        {
                            gdata.Coordinates[PrinterAxis.E] = decimal.Parse(c.Replace("E", string.Empty));
                        }
                    }

                    CalculateMovement(prev, gdata);
                }
            }

            Console.WriteLine($"move recorded: {_commandsList.Count}");

            System.IO.File.WriteAllLines("output.json", new List <string>());

            foreach (var printerCommand in _commandsList)
            {
                var data = JsonConvert.SerializeObject(printerCommand);
                System.IO.File.AppendAllText("output.json", data);
                System.IO.File.AppendAllText("output.json", "\n\r");
                Console.Write(".");
            }
        }