MPG for positioning and FRO control

Moderators: TomKerekes, dynomotion

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

MPG for positioning and FRO control

Post by gui_marchioro » Fri Sep 23, 2022 10:51 am

Hello everyone,

I am configuring the interface of KFLOP and an MPG controller (wiring scheme attached) and I would like to know if there is any example of C program where:
- when the Control switch is pressed the encoder control axis position.
- when the Control switch is released the encoder control FRO.

Thanks,

Guilherme
Attachments
mpgWiring.png

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

Re: MPG for positioning and FRO control

Post by TomKerekes » Fri Sep 23, 2022 6:20 pm

Hi Guilherme,

No I'm not aware of such a C program.

When the Control Switch is released you might accumulate the Position changes in a variable and then periodically use that to change the FRO. You might see the SetFROwithPot.c example for something similar.

It can be tricky how to handle when on-screen controls can change things as well as external things. So you need to decide how to handle two things setting the same thing. Do you want both to be active? Maybe use PC_COMM_SET_FRO_INC to just increment and decrement the On-Screen FRO instead of setting it.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

cemoa9
Posts: 82
Joined: Mon Jun 01, 2020 11:01 am

Re: MPG for positioning and FRO control

Post by cemoa9 » Mon Sep 26, 2022 7:08 pm

Hello Guilherme,

You can check the init file of my Mazak or Stama, they have similar function. (available on the forum in the machines presentation)

Cordially,

Francois

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Re: MPG for positioning and FRO control

Post by gui_marchioro » Thu Aug 10, 2023 11:18 pm

Hello,

Thanks for the responses Francois and Tom.

Francois I've looked in your files and also in the example SetFROwithHWEncoderLog.c to base my MPG program.

The problem is that when I call DoPCFloat(PC_COMM_SET_FRO, FRO) or DoPCFloat(PC_COMM_SET_FRO_INC, FRO) nothing seems to happen.

There is another command required to make it work?

Here is a sample of my code to control both FRO and RRO at the same time:

Code: Select all

void ChangeFROAndRRO()
{
    static double T;
    static int FirstTime=TRUE;
    static double LastFRO=1, LastTime=0, LastRRO=1, LastEncoder=0, 
                    LastUpdateEncoder=1e30, Encoder=0, FRO=1, incrementFactorFRO=1, increment=0,
                    RRO=1, incrementFactorRRO=1;
    
    // Initializes the position of the MPG encoder in the first execution.
	if (FirstTime)
	{
	    LastEncoder = chan[MPG_INPUT_AXIS].Position;
	}

    T = WaitNextTimeSlice();
    Encoder += (chan[MPG_INPUT_AXIS].Position - LastEncoder);   // accumulate changes
    LastEncoder = chan[MPG_INPUT_AXIS].Position;

    if ((Encoder > CHANGE_TOL || Encoder < -CHANGE_TOL) && T > LastTime+CHANGE_TIME)
    {
        increment = (Encoder > 0) ? 0.1 : -0.1;

        FRO = LastFRO + increment;
        if (FRO > FRO_MAX) FRO=FRO_MAX;
        if (FRO < FRO_MIN) FRO=FRO_MIN;
        incrementFactorFRO = 1 + ((FRO - LastFRO)/LastFRO);
        LastFRO = FRO;
        printf("FRO: %f, incrementFactor: %f, increment: %f. MPGWatch.c.\n", FRO, incrementFactorFRO, increment);
        DoPCFloat(PC_COMM_SET_FRO, FRO);
        
        RRO = LastRRO + increment;
        if (RRO > RRO_MAX || FRO >= RRO_MAX) RRO=RRO_MAX;
        if (RRO < RRO_MIN) RRO=RRO_MIN;
        incrementFactorRRO = 1 + ((RRO - LastRRO)/LastRRO);
        LastRRO = RRO;
        printf("RRO: %f, incrementFactor: %f, increment: %f. MPGWatch.c.\n", RRO, incrementFactorRRO, increment);
        DoPCFloat(PC_COMM_SET_RRO, RRO);    
        
        LastTime=T;
        Encoder = 0;
    }
}
Sincerely,
Guilherme

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

Re: MPG for positioning and FRO control

Post by TomKerekes » Fri Aug 11, 2023 2:01 am

Hi Guilherme,

FirstTime is not being set FALSE so it reinitializes every time
Regards,

Tom Kerekes
Dynomotion, Inc.

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Re: MPG for positioning and FRO control

Post by gui_marchioro » Sun Aug 13, 2023 2:27 pm

Hi,

Sharp eyes Tom! Thanks for the review.

I added the variable's reset, but still FRO and RRO are not being changed.

Here is a video showing how it is working:



It is just a test program containing G0 and G1 statements to assess if speed changes. While I spin the MPG's encoder notice that FRO and RRO variables change as expected (the values are being printed in the console), but the speed in the machine didn't.

Is there something else that I could be missing?

Sincerely,
Guilherme

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

Re: MPG for positioning and FRO control

Post by TomKerekes » Sun Aug 13, 2023 8:08 pm

Hi Guilherme,

Sorry I can't duplicate the problem.

Note the video shows a G0 move while the screen is displaying Feed Override. But the FRO slider should still move regardless.

Please post your entire program(s). Also post your Tool Setup - Trajectory Planner settings.

Maybe it has to do with your custom Screen. Temporarily switch to Resizable 3 Axis to check if the problem exists.

What Version are you running?
Regards,

Tom Kerekes
Dynomotion, Inc.

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Re: MPG for positioning and FRO control

Post by gui_marchioro » Mon Aug 14, 2023 2:34 am

Hello Tom,

I am running on version 4.35h.

Here is the MPG program, my custom screen, and my configurations. I call BasicServiceMPG() method in the infinite loop from initialization program.

I will check if the problem persists when using the default screen you mentioned.

Sincerely,
Guilherme
Attachments
3AxisEdit_004_traduzido.scr
(61.88 KiB) Downloaded 232 times
MPGWatch.c
(7.28 KiB) Downloaded 234 times
GCodeConfigCNC.txt
(23.14 KiB) Downloaded 232 times

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

Re: MPG for positioning and FRO control

Post by TomKerekes » Mon Aug 14, 2023 7:28 pm

Still not setting FirstTime to FALSE.
Regards,

Tom Kerekes
Dynomotion, Inc.

gui_marchioro
Posts: 59
Joined: Sun Aug 21, 2022 11:22 pm

Re: MPG for positioning and FRO control

Post by gui_marchioro » Tue Aug 15, 2023 1:07 am

Hello,

You are right. I posted an out of date version of the file, sorry.

In the video I tested with the right one. File is attached.

Sincerely,
Guilherme
Attachments
MPGWatch.c
(7.3 KiB) Downloaded 234 times

Post Reply