Limit Feedrate in GCode G1

Moderators: TomKerekes, dynomotion

dominfo
Posts: 26
Joined: Tue Sep 12, 2023 8:39 am

Re: Limit Feedrate in GCode G1

Post by dominfo » Sat Dec 14, 2024 2:10 pm

Hello Tom

Thanks for the patch. Unfortunately still some issues are there.
TomKerekes wrote:
Wed Dec 11, 2024 10:29 pm

Fix bug with KM_IO.SetAnalogValue(int value)
Ok
Expose Interpreter.SaveVars to save the GCode Interpreter Variables to disk which include fixture and global offsets.
Bug, the property Interpreter.SaveVars is private, not exposed publicly
Expose CoordMotion.RapidParamsDirty to force refresh of Rapid axis parameters from KFLOP/Kogna
Ok

Expose DoRapidsAsFeeds which breaks down Rapids into small segments which is necessary for non-linear kinematics so that Rapids follow a straight line in CAD Space (which is curved in actuator space).
Bug, the property DoRapidsAsFeeds is private, not exposed publicly
Fix Issues with KM_Axis and KM_AxisGroup:
1. Velocity and Acceleration will be in 'Units' (inches or mm) and represent the values for Independent motions, Jogging, and G0 Rapids.
KM_Axis Velocity and Acceleration seems to be in inches only (see point 3)
2. Jerk will be added to be complete and will be in 'Units' as well.
KM_Axis Jerk seems to be in inches only (see point 3)
3. When set these values will be written to KFLOP/Kogna multiplied by the CPU (Counts/per unit)
OK, the boolean CPU_is_mm is not used as I mentioned in point 1 and 2
4. 2 new Parameters CoordVelocity and CoordAccel will be added for Coordinated Motion and be in 'Units'
Ok
5. Changed KM_AxisGroup property name from Velocity to FeedRate
Ok
6. A new Boolean, CPU_is_mm will be added to indicate if Units are mm, otherwise Units are Inches, which will be used within EnableGroup to set the MotionParameters in inches appropriately
This new boolean CPU_is_mm gives me problems when set to true.
It seems that the positions (individual moves or Gcode) are multiplied by 25.4 and feedrates in Gcode interpreter are divided by 25.4
Not easy for me to identify the relationship but some mm<>inches conversions seems confused..

My actual working solution:
1/ set everything to units (not think about mm or inches, even if those values are more relevant to mm)
CountsPerUnit10000
Velocity 150
Acceleration 1400
Jerk 1400
CPU_is_mm = False
2/ force KM_Controller.CoordMotion.Interpreter.SetupParams.LengthUnits = KMotion_dotNet.CANON_UNITS.CANON_UNITS_INCHES
it can work but a G21 (mm mode) in program would give big troubles.

Regards
Frederic

dominfo
Posts: 26
Joined: Tue Sep 12, 2023 8:39 am

Re: Limit Feedrate in GCode G1

Post by dominfo » Tue Dec 17, 2024 3:47 pm

Hello Tom,

I finally managed a good working solution (with G20 and/or G21) with your last patch related to the KM_AxisGroup.

The Kogna is now setup always relative to inches units.
My .Net interface is managing itself the mm (display in mm of UI) <-> inch (setup for Kogna)

Please can you adjust the following for the next Release:
  • Remove the boolean CPU_is_mm introduced in the patch. It gives more confusion that benefit.
  • Set Interpreter.SaveVars as Public Method
  • Set DoRapidsAsFeeds as a Public Property
Regards
Frederic

User avatar
TomKerekes
Posts: 2711
Joined: Mon Dec 04, 2017 1:49 am

Re: Limit Feedrate in GCode G1

Post by TomKerekes » Tue Dec 17, 2024 6:16 pm

Hi Fredric,

Sorry for the delay and yet another bug.

Please re-download KMotion_dotNet.dll to the \KMotion\Release folder.

The two properties should now be public.

There was a bug in EnableGroup regarding converting the CPU to inches. To convert CPU from mm to inches it is necessary to multiply by 25.4 not divide as with velocity etc.

I think the CPU_is_mm is necessary.

I tested both Inches and mm with the code below. Both modes set the same rapid velocity to 5.9 inches/sec (5900 counts/sec) and feed velocity to 3 inches/sec (3000 counts/sec).

I also tested GCode with G20 and G21. Feed rates F120 and F3048 respectively. Both result in feeds of 2 inches/sec (2000 counts/sec).

Please let me know of any issues.

Thank you for your patience.

Code: Select all

            KMotion_dotNet.KM_Axis XAxis = KM.GetAxis(0, "X");
            KMotion_dotNet.KM_Axis YAxis = KM.GetAxis(1, "Y");
            KMotion_dotNet.KM_Axis[] AxisList = { XAxis, YAxis };

            KMotion_dotNet.KM_AxisGroup AxisGroup = KM.GetAxisGroup(123, "TK", AxisList);

#if false
            XAxis.CPU = 1000; // counts/inch (must set first)
            XAxis.CPU_is_mm = false; // (actually not necessary as default is inches)
            YAxis.CPU = 1000;
            YAxis.CPU_is_mm = false;

            // set rapid 3rd order parameters
            XAxis.Jerk = 280;         // inches/sec3
            YAxis.Jerk = 280;
            XAxis.Acceleration = 28;  // inches/sec2
            YAxis.Acceleration = 28;
            XAxis.Velocity = 5.9;     // inches/sec
            YAxis.Velocity = 5.9;

            // set Coordinated motion 2nd order parameters
            XAxis.CoordVelocity = 3; // inches/sec
            XAxis.CoordAccel = 30;   // inches/sec2
            YAxis.CoordVelocity = 3; // inches/sec
            YAxis.CoordAccel = 30;   // inches/sec2
#else
            XAxis.CPU = 1000 / 25.4; // counts/mm (must set first)
            XAxis.CPU_is_mm = true; // (set units as mm)
            YAxis.CPU = 1000 / 25.4;
            YAxis.CPU_is_mm = true;

            // set rapid 3rd order parameters
            XAxis.Jerk = 280 * 25.4;        // mm/sec3
            YAxis.Jerk = 280 * 25.4;
            XAxis.Acceleration = 28 * 25.4; // mm/sec2
            YAxis.Acceleration = 28 * 25.4;
            XAxis.Velocity = 5.9 * 25.4;    // mm/sec
            YAxis.Velocity = 5.9 * 25.4;

            // set Coordinated motion 2nd order parameters
            XAxis.CoordVelocity = 3 * 25.4; // mm/sec
            XAxis.CoordAccel = 30 * 25.4;   // mm/sec2
            YAxis.CoordVelocity = 3 * 25.4; // mm/sec
            YAxis.CoordAccel = 30 * 25.4;   // mm/sec2
#endif
            AxisGroup.EnableGroup();
Attachments
box.ngc
(76 Bytes) Downloaded 15 times
boxmm.ngc
(97 Bytes) Downloaded 15 times
Regards,

Tom Kerekes
Dynomotion, Inc.

dominfo
Posts: 26
Joined: Tue Sep 12, 2023 8:39 am

Re: Limit Feedrate in GCode G1

Post by dominfo » Wed Dec 18, 2024 11:56 am

Hello Tom

It works now as expected with boolean CPU_is_mm !
The two properties are now public !
Thanks for your work.

Unfortunately, I identified an issue with the new SaveVars :(
FYI, I created in my previous tests my own implementation of the SaveVars command.

Using now your SaveVars, an error message is triggered when trying to execute a Gcode:
[Interpreter Complete] Line = 1 Status = 68 Sequence = 0 Error = Coordinate system index parameter 5220 out of range
I verified the var file and effectively the 5220 parameter is always set to 0.

I used the following code but without success.

Code: Select all

KM_6AxisGroup.SetOffsetData(1, 55.0, 55.0, -55.0, 0.0, 0.0, 0.0); // Set values on Offset #1 (G54)
CoordMotion.Interpreter.SaveVars(); // 5220=0.000000 in var file
CoordMotion.Interpreter.ChangeFixtureNumber(1); // should execute a G54 command and change 5220 parameter
CoordMotion.Interpreter.SaveVars(); // 5220=0.000000   no change on var file
CoordMotion.Interpreter.SetupParams.OriginIndex = 1; // the previous G54 command changed it to 0, forced back to 1
CoordMotion.Interpreter.SaveVars(); // 5220=0.000000   no change on var file
emc_temp.var.txt
(1.08 KiB) Downloaded 15 times
...
5213 0.000000
5214 0.000000
5215 0.000000
5216 0.000000
5220 0.000000
5221 55.000000
5222 55.000000
5223 -55.000000
5224 0.000000
5225 0.000000
5226 0.000000
...
Regards
Frederic

User avatar
TomKerekes
Posts: 2711
Joined: Mon Dec 04, 2017 1:49 am

Re: Limit Feedrate in GCode G1

Post by TomKerekes » Wed Dec 18, 2024 6:26 pm

Hi Fredric,
Unfortunately, I identified an issue with the new SaveVars :(
FYI, I created in my previous tests my own implementation of the SaveVars command.

Using now your SaveVars, an error message is triggered when trying to execute a Gcode:
Its a bit complicated as Variable 5220 saves the Interpreter's last selected Fixture number. SetOffsetData only sets the associated GCode Offset Variables without selecting a fixture.

Furthermore executing SaveVars before all the Variables have been set basically writes indeterminate data to the file.

ChangeFixtureNumber(1) fails because first use of the Interpreter initializes, which reads in the invalid Variable File creating an error.

You might call InitializeInterpreter to initialize the Variables.

Code: Select all

            KM.CoordMotion.Interpreter.InitializeInterpreter();  // initialize Interpreter and read GCode Vars
            AxisGroup.SetOffsetData(1, 55.0, 55.0, -55.0, 0.0, 0.0, 0.0); // Set values on Offset #1 (G54)
            KM.CoordMotion.Interpreter.SaveVars();

To set the Interpreter to a different fixture, and force a re-load of values from the Variables if already selected use:

Code: Select all

            KM.CoordMotion.Interpreter.SetupParams.OriginIndex = -1;  // force update from GCode Vars
            KM.CoordMotion.Interpreter.ChangeFixtureNumber(1);  // Load offsets for fixture
Regards,

Tom Kerekes
Dynomotion, Inc.

dominfo
Posts: 26
Joined: Tue Sep 12, 2023 8:39 am

Re: Limit Feedrate in GCode G1

Post by dominfo » Thu Dec 19, 2024 1:23 pm

Hello Tom,

I tried this code

Code: Select all

        KMinterpreter.InitializeInterpreter(); // initialize Interpreter and read GCode Vars
        KMinterpreter.SetOrigin(1, 54.0, 54.0, -54.0, 0.0, 0.0, 0.0); // Set XYZABC values on Offset #1 (G54))
        KMinterpreter.SaveVars(); // G54 values are correctly saved (5221 to 5226) but 5220=0.000000 is saved in the file
        KMinterpreter.SetupParams.OriginIndex = -1; // force update from GCode Vars
        KMinterpreter.ChangeFixtureNumber(1);
        KMinterpreter.SaveVars(); // 5220=0.000000 => no change, the ChangeFixtureNumber(1) command had no action on it !
I don't understand while the value 5220 is still at 0.000000, it should be at 1.000000 according to your explanations.

Regards
Frederic

User avatar
TomKerekes
Posts: 2711
Joined: Mon Dec 04, 2017 1:49 am

Re: Limit Feedrate in GCode G1

Post by TomKerekes » Fri Dec 20, 2024 12:17 am

Hi Frederic,

We should probably handle things better, but if the file has an invalid value of 5220=0 then the code creates an error message and does nothing. Try setting 5220 to a valid number in the file first.
Regards,

Tom Kerekes
Dynomotion, Inc.

dominfo
Posts: 26
Joined: Tue Sep 12, 2023 8:39 am

Re: Limit Feedrate in GCode G1

Post by dominfo » Fri Dec 20, 2024 12:00 pm

Hi Tom
TomKerekes wrote:
Fri Dec 20, 2024 12:17 am
Try setting 5220 to a valid number in the file first.

My test was:
  • create an empty emc.var
  • run following code

    Code: Select all

    KMcontroller.CoordMotion.Interpreter.VarsFile = "emc.var"
    KMinterpreter.InitializeInterpreter(); // initialize Interpreter and read GCode Vars
    KMinterpreter.SetOrigin(1, 54.0, 54.0, -54.0, 0.0, 0.0, 0.0); // Set XYZABC values on Offset #1 (G54))
    KMinterpreter.SetupParams.OriginIndex = -1; // force update from GCode Vars
    KMinterpreter.ChangeFixtureNumber(1);
    KMinterpreter.SaveVars(); // 5220=0.000000 => no change, the ChangeFixtureNumber(1) command had no action on it !
    At this level the emc.var contains all datas as expected except 5220 (at 0.00000)
  • Running several times the same code doesn't change the 5220.
  • modify 5220 to 1.00000 in the emc.var
  • run again the same code, keeps 5220 to 1.00000
  • run

    Code: Select all

    KMinterpreter.ChangeFixtureNumber(4);
    KMinterpreter.SaveVars(); 
    5220 is set to 4.00000 as expected !!!!
Conclusion
I suggest to force the value of 5220 to 1.0 if needed in GCodeInterpreter/rs274ngc.cpp/rs274ngc_restore_parameters

Code: Select all

int rs274ngc_restore_parameters(
....
    fclose(infile);
    CHK((required != RS274NGC_MAX_PARAMETERS),
	NCE_REQUIRED_PARAMETER_MISSING);
    for (; k < RS274NGC_MAX_PARAMETERS; k++) {
	pars[k] = 0;
    }
    // ********************************
    if (pars[5220] < 1.0)
    	pars[5220] = 1.0; // force 5220 to a value allowed if needed
    // ********************************
    return RS274NGC_OK;
}
Regards
Frederic

User avatar
TomKerekes
Posts: 2711
Joined: Mon Dec 04, 2017 1:49 am

Re: Limit Feedrate in GCode G1

Post by TomKerekes » Fri Dec 20, 2024 11:17 pm

Hi Frederic,

Will do. Also changing ChangeFixtureNumber to return any error code.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply