示例#1
0
        void emit_linear(GCodeLine line)
        {
            Debug.Assert(line.code == 1);

            double dx = 0, dy = 0;
            bool   brelx = GCodeUtil.TryFindParamNum(line.parameters, "XI", ref dx);
            bool   brely = GCodeUtil.TryFindParamNum(line.parameters, "YI", ref dy);

            LinearMoveData move = new LinearMoveData(new Vector2d(dx, dy));

            if (brelx || brely)
            {
                listener.LinearMoveToRelative2d(move);
                return;
            }

            double x = 0, y = 0;
            bool   absx = GCodeUtil.TryFindParamNum(line.parameters, "X", ref x);
            bool   absy = GCodeUtil.TryFindParamNum(line.parameters, "Y", ref y);

            if (absx && absy)
            {
                listener.LinearMoveToAbsolute2d(move);
                return;
            }

            // [RMS] can we have this??
            if (absx || absy)
            {
                System.Diagnostics.Debug.Assert(false);
            }
        }
        // G92 - Position register: Set the specified axes positions to the given position
        // Sets the position of the state machine and the bot. NB: There are two methods of forming the G92 command:
        void set_position(GCodeLine line)
        {
            double x = 0, y = 0, z = 0;

            if (GCodeUtil.TryFindParamNum(line.parameters, "X", ref x))
            {
                CurPosition.x = x;
            }
            if (GCodeUtil.TryFindParamNum(line.parameters, "Y", ref y))
            {
                CurPosition.y = y;
            }
            if (GCodeUtil.TryFindParamNum(line.parameters, "Z", ref z))
            {
                CurPosition.z = z;
            }
        }
示例#3
0
        void emit_arc(GCodeLine line, bool clockwise)
        {
            double dx = 0, dy = 0;

            // either of these might be missing...
            bool brelx = GCodeUtil.TryFindParamNum(line.parameters, "XI", ref dx);
            bool brely = GCodeUtil.TryFindParamNum(line.parameters, "YI", ref dy);

            Debug.Assert(brelx == true && brely == true);

            double r  = 0;
            bool   br = GCodeUtil.TryFindParamNum(line.parameters, "R", ref r);

            Debug.Assert(br == true);

            // [RMS] seems like G5 always has negative radius and G4 positive ??
            //   (this will tell us)
            Debug.Assert((clockwise && r < 0) || (clockwise == false && r > 0));
            r = Math.Abs(r);

            listener.ArcToRelative2d(new Vector2d(dx, dy), r, clockwise);
        }
示例#4
0
        // G92 - Position register: Set the specified axes positions to the given position
        // Sets the position of the state machine and the bot. NB: There are two methods of forming the G92 command:
        private void set_position(GCodeLine line)
        {
            double x = 0, y = 0, z = 0, a = 0;

            if (GCodeUtil.TryFindParamNum(line.Parameters, "X", ref x))
            {
                CurPosition.x = x;
            }
            if (GCodeUtil.TryFindParamNum(line.Parameters, "Y", ref y))
            {
                CurPosition.y = y;
            }
            if (GCodeUtil.TryFindParamNum(line.Parameters, "Z", ref z))
            {
                CurPosition.z = z;
            }
            if (GCodeUtil.TryFindParamNum(line.Parameters, "A", ref a))
            {
                ExtrusionA = a;
                listener.CustomCommand(
                    (int)CustomListenerCommands.ResetExtruder, GCodeUtil.Extrude(a));
                // reset our state
                in_travel = in_extrude = in_retract = false;
            }

            // E is "current" stepper (A for single extruder)
            double e = 0;

            if (GCodeUtil.TryFindParamNum(line.Parameters, "E", ref e))
            {
                ExtrusionA = e;
                listener.CustomCommand(
                    (int)CustomListenerCommands.ResetExtruder, GCodeUtil.Extrude(e));
                // reset our state
                in_travel = in_extrude = in_retract = false;
            }
        }
        void emit_linear(GCodeLine line)
        {
            Debug.Assert(line.code == 0 || line.code == 1);

            double x         = GCodeUtil.UnspecifiedValue,
                   y         = GCodeUtil.UnspecifiedValue,
                   z         = GCodeUtil.UnspecifiedValue;
            bool     found_x = GCodeUtil.TryFindParamNum(line.parameters, "X", ref x);
            bool     found_y = GCodeUtil.TryFindParamNum(line.parameters, "Y", ref y);
            bool     found_z = GCodeUtil.TryFindParamNum(line.parameters, "Z", ref z);
            Vector3d newPos  = (UseRelativePosition) ? Vector3d.Zero : CurPosition;

            if (found_x)
            {
                newPos.x = x;
            }
            if (found_y)
            {
                newPos.y = y;
            }
            if (found_z)
            {
                newPos.z = z;
            }
            if (UseRelativePosition)
            {
                CurPosition += newPos;
            }
            else
            {
                CurPosition = newPos;
            }

            // F is feed rate (this changes?)
            double f     = 0;
            bool   haveF = GCodeUtil.TryFindParamNum(line.parameters, "F", ref f);

            LinearMoveData move = new LinearMoveData(
                newPos,
                (haveF) ? f : GCodeUtil.UnspecifiedValue);

            bool is_travel = (line.code == 0);

            if (is_travel)
            {
                if (in_travel == false)
                {
                    listener.BeginTravel();
                    in_travel = true;
                    in_cut    = false;
                }
            }
            else
            {
                if (in_cut == false)
                {
                    listener.BeginCut();
                    in_travel = false;
                    in_cut    = true;
                }
            }

            move.source = line;
            Debug.Assert(in_travel || in_cut);
            listener.LinearMoveToAbsolute3d(move);
        }
示例#6
0
        protected virtual void EmitLinear(GCodeLine line)
        {
            Debug.Assert(line.Code == 0 || line.Code == 1);

            double x         = GCodeUtil.UnspecifiedValue,
                   y         = GCodeUtil.UnspecifiedValue,
                   z         = GCodeUtil.UnspecifiedValue;
            bool     found_x = GCodeUtil.TryFindParamNum(line.Parameters, "X", ref x);
            bool     found_y = GCodeUtil.TryFindParamNum(line.Parameters, "Y", ref y);
            bool     found_z = GCodeUtil.TryFindParamNum(line.Parameters, "Z", ref z);
            Vector3d newPos  = (UseRelativePosition) ? Vector3d.Zero : CurPosition;

            if (found_x)
            {
                newPos.x = x;
            }
            if (found_y)
            {
                newPos.y = y;
            }
            if (found_z)
            {
                newPos.z = z;
            }
            if (UseRelativePosition)
            {
                CurPosition += newPos;
            }
            else
            {
                CurPosition = newPos;
            }

            // F is feed rate (this changes?)
            double f     = 0;
            bool   haveF = GCodeUtil.TryFindParamNum(line.Parameters, "F", ref f);

            // A is extrusion stepper. E is also "current" stepper.
            double a     = 0;
            bool   haveA = GCodeUtil.TryFindParamNum(line.Parameters, "A", ref a);

            if (haveA == false)
            {
                haveA = GCodeUtil.TryFindParamNum(line.Parameters, "E", ref a);
            }
            if (UseRelativeExtruder)
            {
                a = ExtrusionA + a;
            }

            LinearMoveData move = new LinearMoveData(
                newPos,
                (haveF) ? f : GCodeUtil.UnspecifiedValue,
                (haveA) ? GCodeUtil.Extrude(a) : GCodeUtil.UnspecifiedPosition);

            if (haveA == false)
            {
                // if we do not have extrusion, this is a travel move
                if (in_travel == false)
                {
                    listener.BeginTravel();
                    in_travel  = true;
                    in_extrude = false;
                }
            }
            else if (in_retract)
            {
                // if we are in retract, we stay in until we see forward movement

                Debug.Assert(in_travel);
                Debug.Assert(a <= LastRetractA + 0.001);
                if (MathUtil.EpsilonEqual(a, LastRetractA, 0.00001))
                {
                    in_retract = false;
                    listener.BeginDeposition();
                    in_extrude = true;
                    in_travel  = false;
                    ExtrusionA = a;
                }
            }
            else if (a < ExtrusionA)
            {
                // if extrusion moved backwards, we need to enter travel

                in_retract   = true;
                LastRetractA = ExtrusionA;
                ExtrusionA   = a;
                if (in_travel == false)
                {
                    listener.BeginTravel();
                    in_travel  = true;
                    in_extrude = false;
                }
            }
            else
            {
                // if we are in travel, we need to begin extruding
                if (in_travel)
                {
                    listener.BeginDeposition();
                    in_travel  = false;
                    in_extrude = true;
                }
                if (in_extrude == false)
                {       // handle initialization cases
                    listener.BeginDeposition();
                    in_extrude = true;
                }
                ExtrusionA = a;
            }

            move.source = line;
            Debug.Assert(in_travel || in_extrude);
            listener.LinearMoveToAbsolute3d(move);
        }