Example #1
0
 /// <summary>
 /// Reads the line and adds it to the buffer for guessing later.
 /// </summary>
 /// <param name="currline">The Line to read.</param>
 private void ReadLineToBuffer(string currline)
 {
     float[] coords = ReadLine(currline);
     if (coords[3] > 0)
     {
         FeedrateBuffer = coords[3];
     }
     //Console.WriteLine("new feedrate"+feedrateBuffer);
     if (coords[0] > 0 || coords[1] > 0 || coords[2] > 0)
     {
         if (coords[0] < 0)
         {
             coords[0] = BufferPos[0];
         }
         if (coords[1] < 0)
         {
             coords[1] = BufferPos[1];
         }
         if (coords[2] < 0)
         {
             coords[2] = BufferPos[2];
         }
         float[] distances = { Math.Abs(coords[0] - BufferPos[0]), Math.Abs(coords[1] - BufferPos[1]), Math.Abs(coords[2] - BufferPos[2]) };
         float[] speed     = { Math.Min((FeedrateBuffer / 60), MaxFeedRateBuffer[0]), Math.Min((FeedrateBuffer / 60), MaxFeedRateBuffer[1]), Math.Min((FeedrateBuffer / 60), MaxFeedRateBuffer[2]) };
         float[] times     = { (float)distances[0] / (float)speed[0], (float)distances[1] / (float)speed[1], (float)distances[2] / (float)speed[2] };
         float   time      = times.Max();
         MovesBuffer.Add(new float[] { coords[0], coords[1], coords[2], time });
         BufferPos = new float[] { coords[0], coords[1], coords[2] };
     }
 }
Example #2
0
        /// <summary>
        /// Syncronizes the position with a Thread
        /// </summary>
        public void Syncpos()
        {
            OctoprintJobProgress progress = Connection.Jobs.GetProgress();
            OctoprintJobInfo     info     = Connection.Jobs.GetInfo();

            if (GCodeString == null)
            {
                if (info.File.Name != "" && info.File.Origin == "local")
                {
                    GetGCode(info.File.Origin + "/" + info.File.Name);
                }
            }
            if (GCodeString == null)
            {
                return;
            }
            int bitspassed = (progress.Filepos - 1) - LastSyncPos;

            string[] linesPassed = { };
            if (bitspassed > 0 && GCodeString != null && GCodeString.Length > LastSyncPos + bitspassed)
            {
                linesPassed = GCodeString.Substring(LastSyncPos, bitspassed).Split(new[] { '\r', '\n' });
            }
            else
            {
                Debug.WriteLine("Something Wrong in Postrackers Syncpos");
            }
            int   count         = 0;
            float secondspassed = 0;

            foreach (string line in linesPassed)
            {
                if (ReadLine(line)[0] < 0 || ReadLine(line)[1] < 0 || ReadLine(line)[2] < 0)
                {
                    if (MovesBuffer.Count <= count)
                    {
                        Debug.WriteLine("count seems to high");
                    }
                    else
                    {
                        secondspassed += MovesBuffer[count][3];
                    }
                    count++;
                }
            }
            if (count > 1 && MovesBuffer.Count >= count)
            {
                MovesBuffer.RemoveRange(0, count);
                LastSyncPos = progress.Filepos;
                //Console.WriteLine("10 seconds passed in: "+secondspassed+" seconds and the next move is this long: "+movesBuffer[0][3]);
                //movesBuffer.RemoveAt(0);
            }
        }