588,138 active members*
5,342 visitors online*
Register for free
Login
Page 1 of 2 12
Results 1 to 20 of 34
  1. #1
    Join Date
    Jan 2013
    Posts
    73

    Cool KFLOP - MACH3 Touch plate

    Can someone help with modifying the code that I was using with Mach3 paralell port, to use with KFLOP.
    It doesnt work with Kflop.

    I tested the Touchplate, with the Mach3 probe light.
    When I start the script, the Z axis starts to move down, but when I touch the plate it keeps moving down.

    "CODE"
    Option Explicit 'VBScript To probe In the z axis 'NOTE: This script is for metric as Native Units alterd by hemsworthlad

    Dim fastdown
    Dim slowdown
    Dim searchamount
    Dim retractamount
    Dim plateoffset
    Dim currentfeed
    Dim Znew


    fastdown = 150
    slowdown = 50
    searchamount = 100
    retractamount = 20

    If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty
    Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if aplicable
    Else
    Code "G4 P1" 'Pause 1 seconds to give time to position probe plate
    PlateOffset = GetUserDRO(1151) 'Get plate offset DRO
    CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
    Code "F" &fastdown 'slow down feedrate to what ever is set in fastdown var

    Rem Probe In the z direction
    ZNew = GetDro(2) - searchamount 'probe move to current z - what ever is set in searchamount var
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew +2.5 'move back + 2.5mm to hit point incase there was overshoot +.1
    While IsMoving ()
    Wend

    Rem End add lines

    Code "F" &slowdown 'slow down feedrate to what ever is set in slowdown var
    ZNew = GetDro(2) - 6 'probe move to current z - 6mm
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew 'move back to hit point incase there was overshoot
    While IsMoving ()
    Wend

    If PlateOffset <> 0 Then
    Call SetDro (2, PlateOffset) 'set the Z axis DRO to plate thickness
    Code "G4 P0.25" 'Pause for Dro to update.
    ZNew = PlateOffset + retractamount 'calc retract
    Code "G0 Z" &ZNew 'put the Z retract height you want here
    While IsMoving ()
    Wend
    Code "(Z axis is now zeroed)" 'puts this message in the status bar

    End If

    Code "F" &CurrentFeed 'Returns to prior feed rate
    End If

  2. #2
    Join Date
    May 2006
    Posts
    4053
    Hi mlinkadelsol,

    Have you read through this?

    Regards
    TK
    http://dynomotion.com

  3. #3
    Join Date
    Jan 2013
    Posts
    73
    I have read the manuals, but dont understand,
    Should that code work if I include: Notify User Program?
    Thnx.

  4. #4
    Join Date
    May 2006
    Posts
    4053
    Hi mlinkadelsol,

    It would be helpful if you explained what parts of the step by step process you understand and what parts you don't. That would help us help you.

    You must configure the following two lines in the C Program based on what type of probe sensor you have and where it is wired into KFLOP

    #define PROBE_BIT 0
    #define PROBE_ACTIVE_STATE 1

    Then save the C Program with a new file name and assign the file name as the Notify Program to be used by the Dynomotion Plugin.

    At that point the G31 probe command in Mach3 should then work. I would test it with the simple command provided in the probe setup explanation we provided before trying your more complex macro. Namely:

    G31 Z-4 F40

    HTH Regards
    TK
    http://dynomotion.com

  5. #5
    Join Date
    Jan 2013
    Posts
    73
    Hello, Tom, thanx for your reply.
    I connected the probe to IO 24 as low active, and set the Probe pin to 24 in Mach3 INPUT settings.
    When I touched the Endmill on my router (which is grounded) with my touchprobe (piece of PCB board that is connected to the pin 24 on KFLOP) the LED on Mach 3 Blue screen came on, so I thought that the probe should work. I didnt understand that I have to include NotifyProbeMach3.c

    Next, i have a Gantry CNC, so my Axis are:
    Ch0 - X1
    Ch1 - X2 slaved to Ch0
    Ch2 - Y
    Ch3 - Z

    So i would have to modify NotifyProbeMach3.c as follows?
    #define X 0 --> #define X 0
    #define Y 1 --> #define Y 2
    #define Z 2 --> #define Z 3

    #define PROBE_BIT 0 --> #define PROBE_BIT 24
    #define PROBE_ACTIVE_STATE 1 --> #define PROBE_ACTIVE_STATE 0
    ???

    I noticed some code for glass scales, I use steppers in open loop, if that makes any difference.
    Thanks.

    ***
    #include "KMotionDef.h"

    //Plugin calls for Mach3 NotifyPlugins Commands

    #define X 0
    #define Y 1
    #define Z 2

    float DecelTimeForAxis(int axis);

    main()
    {
    int msg = persist.UserData[6]; // Mach3 notify Message 10000-10999

    printf("Mach3 Notify Call, Message = %d\n",msg);

    if (msg==10100)
    {
    // adjust the commanded position to match the glass scale encoder
    DisableAxis(X);
    EnableAxisDest(X,chan[X].Position);
    }
    if (msg==10101)
    {
    // adjust the commanded position to match the glass scale encoder
    DisableAxis(Y);
    EnableAxisDest(Y,chan[Y].Position);
    }
    if (msg==10102)
    {
    // adjust the commanded position to match the glass scale encoder
    DisableAxis(Z);
    EnableAxisDest(Z,chan[Z].Position);
    }
    if (msg==10500)
    {
    if (CS0_StoppingState == 0)
    StopCoordinatedMotion();
    else
    ResumeCoordinatedMotion();
    }
    if (msg==10300)
    {
    // User wants to disable Z (switch to OL)

    DisableAxis(Z);
    chan[Z].OutputMode = STEP_DIR_MODE;

    EnableAxisDest(Z,chan[Z].Position);
    }
    if (msg==10301)
    {
    // User wants to enable Z (switch to CL)
    DisableAxis(Z);
    chan[Z].OutputMode = CL_STEP_DIR_MODE;

    EnableAxisDest(Z,chan[Z].Position);
    }

    // handles probing
    //
    // flag is 0 - while watching for probe hit
    // flag is 1 - if probe was already set from start
    // flag is 2 - after successful probe hit
    // flag is 3 - Tells Plugin to upload status (3) to
    // DRO 1100 and let User handle the error
    //
    // returns the captured results in User Variables
    // X - 50+51
    // Y - 52+53
    // Z - 54+55
    // A - 56+57
    // B - 58+59
    // C - 60+61
    // status result 62

    #define PROBE_BIT 0
    #define PROBE_ACTIVE_STATE 1
    #define PROBE_ERROR_HANDLING 0 // 0 Stops Mach3 on probe error
    // #define PROBE_ERROR_HANDLING 3 // 3 User must query DRO 1100 and handle error

    if (msg==20000)
    {
    double *d = (double *)&persist.UserData[MACH3_PROBE_RESULTS_VAR];
    int flag=1;

    persist.UserData[MACH3_PROBE_STATUS_VAR]=PROBE_ERROR_HANDLING;

    while (ReadBit(PROBE_BIT)!=PROBE_ACTIVE_STATE)
    {
    flag=2;
    WaitNextTimeSlice();
    }

    if (CS0_axis_x>=0) d[0]=chan[CS0_axis_x].Dest;
    if (CS0_axis_y>=0) d[1]=chan[CS0_axis_y].Dest;
    if (CS0_axis_z>=0) d[2]=chan[CS0_axis_z].Dest;
    if (CS0_axis_a>=0) d[3]=chan[CS0_axis_a].Dest;
    if (CS0_axis_b>=0) d[4]=chan[CS0_axis_b].Dest;
    if (CS0_axis_c>=0) d[5]=chan[CS0_axis_c].Dest;

    persist.UserData[MACH3_PROBE_STATUS_VAR]=flag;
    StopCoordinatedMotion();
    }
    }

  6. #6
    Join Date
    May 2006
    Posts
    4053
    Hi mlinkadelsol,

    The Notify C Program can be used for may different things. The message number passed in tells the program what function it is supposed to handle. That example included some other stuff for a closed loop system with encoders and with a special mode for switching the Z axis to manual mode and a hardware feed hold screen button. Those are NotifyPlugins messages 10300 through 10500

    In your case all you care about is when msg=20000 which is for probing. All those other message checks can be deleted if you wish but they can be left in and won't hurt anything as those messages will never be sent in your system.

    The axis definitions are correct as you described, but unnecessary.

    The proposed change of:

    #define PROBE_BIT 0 --> #define PROBE_BIT 24
    #define PROBE_ACTIVE_STATE 1 --> #define PROBE_ACTIVE_STATE 0

    is correct.

    I'm not sure wiring a KFLOP IO pin directly out to the machine is a good idea. That is a high impedance 3.3V LVTTL input. Touching it to Machine Earth Ground could damage KFLOP if there happens to be say a 7V noise spike on earth ground due to VFD noise or whatever. Adding a 100ohm resistor in series and a 0.1uF ceramic capacitor from the KFLOP input to KFLOP ground might offer some protection.

    Also the input is floating so when un-grounded it is indeterminate what it might do. It might float high or it might stay low. There should be a pull up resistor (~1K ohm) to 3.3V to make sure it goes high when not grounded.

    HTH
    Regards
    TK
    TK
    http://dynomotion.com

  7. #7
    Join Date
    Jan 2013
    Posts
    73

    Smile

    Thnx. again for your reply Tom.

    I connected a 1K resistor from IO pin 24 to +3.3V, but i didnt add a 100ohm resistor in series and a 0.1uF ceramic capacitor from the KFLOP input to KFLOP ground for protection, i will do that.

    Thanks again.
    I will try the code.

  8. #8
    Join Date
    Jan 2013
    Posts
    73
    Hello, Tom.
    I got problems with touch plate.
    Now, when I press the Z- button in Mach3 to set the tool zero, the Endmill goes down to the touch plate, make a contact with feed 300, then retract 3mm and touch the touchplate with slower feed speed. After it touches the touchplate for 2nd time it doesnt retract in Z+, but goes further down in Z-.
    Here is the code if you can check it out:

    Rem VBScript To probe In the z axis

    If GetOemLED(801) Then 'check if English Units
    If GetOemLED(16)<>0 Then 'Checks for machine coordinates
    code "(Please change to working coordinates)"
    Else


    If GetOemLed (825) <> 0 Then 'check to see if the probe is already grounded or faulty
    Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if aplicable
    Else
    Code "G4 P1" 'pause 1 seconds to give time to position probe plate
    PlateOffset = GetUserDRO(1151) 'get plate offset DRO
    CurrentFeed = GetOemDRO(818) 'get the current feedrate to return to later
    Code "F10" 'slow down feedrate to 10 ipm

    Rem Probe In the z direction
    ZNew = GetDro(2) - 6 'probe move to current z - 6 inches
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew +.1 'move back +.1 to hit point incase there was overshoot +.1
    While IsMoving ()
    Wend

    Rem End add lines

    Code "F2" 'slow down feedrate to 2 ipm
    ZNew = GetDro(2) - .25 'probe move to current z - .25 inches
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew 'move back to hit point incase there was overshoot
    While IsMoving ()
    Wend

    If PlateOffset <> 0 Then
    Call SetDro (2, PlateOffset) 'set the Z axis DRO to plate thickness
    Code "G4 P0.25" 'pause for Dro to update.
    'ZNew = PlateOffset + 3.6315 'calc retract
    'Code "G0 Z" &ZNew 'put the Z retract height you want here
    Code("G53G0Z-0.5") 'Z retract

    While IsMoving ()
    Wend
    Code "(Z axis is now zeroed in English Units)" 'puts this message in the status bar

    End If

    Code "F" &CurrentFeed 'returns to prior feed rate
    End If
    End If
    Else 'This portion of script is for Metric Native Units

    If GetOemLed (825) <> 0 Then 'check to see if the probe is already grounded or faulty
    Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if aplicable
    Else
    Code "G4 P1" 'pause 1 seconds to give time to position probe plate
    PlateOffset = GetUserDRO(1151) 'get plate offset DRO
    CurrentFeed = GetOemDRO(818) 'get the current feedrate to return to later
    Code "F300" 'slow down feedrate to 300 mmpm

    Rem Probe In the z direction
    ZNew = GetDro(2) - 150 'probe move to current z - 150 mm
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew + 3 'move back + 3 mm to hit point incase there was overshoot + 3 mm
    While IsMoving ()
    Wend

    Rem End add lines

    Code "F50" 'slow down feedrate to 50 mmpm
    ZNew = GetDro(2) - 6 'probe move to current z - 6 mm
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew 'move back to hit point incase there was overshoot
    While IsMoving ()
    Wend

    If PlateOffset <> 0 Then
    Call SetDro (2, PlateOffset) 'set the Z axis DRO to plate thickness
    Code "G4 P0.25" 'pause for Dro to update.
    'ZNew = PlateOffset + 50 'calc retract
    Code("G53G0Z-12")
    'Code "G0 Z" &ZNew 'put the Z retract height you want here
    While IsMoving ()
    Wend
    Code "(Z axis is now zeroed in Metric units)" 'puts this message in the status bar

    End If

    Code "F" &CurrentFeed 'returns to prior feed rate
    Code "F200"
    Sleep 100
    End If
    End If

    One more question:
    Im running Mach3 on windows 7 home premium, can that be a problem?
    And a funny thing is when I calibrate an axis with Mach3 (set steps per unit) I get 161 steps per unit.
    My steppers are 1.8degree/step (200/turn), im running them at half step.
    The Ballscrew has a lead 5mm/turn.

  9. #9
    Join Date
    May 2006
    Posts
    4053
    Hi mlinkadelsol,

    It looks like in the macro after the second probe at low speed it does a:

    G53G0Z-12

    which would be a move to an absolute position of -12mm in raw Machine coordinates regardless of any probe results. Do you now where -12mm in raw machine coordinates would be on your machine?

    Regards
    TK
    http://dynomotion.com

  10. #10
    Join Date
    Jan 2013
    Posts
    73
    That seems to be fine cause my Z0 is on top.

    Here is the code I tryed today:


    Rem VBScript To probe In the z axis

    If GetOemLED(801) Then 'check if English Units
    If GetOemLED(16)<>0 Then 'Checks for machine coordinates
    code "(Please change to working coordinates)"
    Else


    If GetOemLed (825) <> 0 Then 'check to see if the probe is already grounded or faulty
    Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if aplicable
    Else
    Code "G4 P1" 'pause 1 seconds to give time to position probe plate
    PlateOffset = GetUserDRO(1151) 'get plate offset DRO
    CurrentFeed = GetOemDRO(818) 'get the current feedrate to return to later
    Code "F10" 'slow down feedrate to 10 ipm

    Rem Probe In the z direction
    ZNew = GetDro(2) - 6 'probe move to current z - 6 inches
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew +.1 'move back +.1 to hit point incase there was overshoot +.1
    While IsMoving ()
    Wend

    Rem End add lines

    Code "F2" 'slow down feedrate to 2 ipm
    ZNew = GetDro(2) - .25 'probe move to current z - .25 inches
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew 'move back to hit point incase there was overshoot
    While IsMoving ()
    Wend

    If PlateOffset <> 0 Then
    Call SetDro (2, PlateOffset) 'set the Z axis DRO to plate thickness
    Code "G4 P0.25" 'pause for Dro to update.
    'ZNew = PlateOffset + 3.6315 'calc retract
    'Code "G0 Z" &ZNew 'put the Z retract height you want here
    Code("G53G0Z-0.5") 'Z retract

    While IsMoving ()
    Wend
    Code "(Z axis is now zeroed in English Units)" 'puts this message in the status bar

    End If

    Code "F" &CurrentFeed 'returns to prior feed rate
    End If
    End If
    Else 'This portion of script is for Metric Native Units

    If GetOemLed (825) <> 0 Then 'check to see if the probe is already grounded or faulty
    Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if aplicable
    Else
    Code "G4 P1" 'pause 1 seconds to give time to position probe plate
    PlateOffset = GetUserDRO(1151) 'get plate offset DRO
    CurrentFeed = GetOemDRO(818) 'get the current feedrate to return to later
    Code "F300" 'slow down feedrate to 300 mmpm

    Rem Probe In the z direction
    ZNew = GetDro(2) - 150 'probe move to current z - 150 mm
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew + 3 'move back + 3 mm to hit point incase there was overshoot + 3 mm
    While IsMoving ()
    Wend

    Rem End add lines

    Code "F50" 'slow down feedrate to 50 mmpm
    ZNew = GetDro(2) - 6 'probe move to current z - 6 mm
    Code "G31Z" &ZNew
    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point
    Code "G0 Z" &ZNew 'move back to hit point incase there was overshoot
    While IsMoving ()
    Wend

    If PlateOffset <> 0 Then
    Call SetDro (2, PlateOffset) 'set the Z axis DRO to plate thickness
    Code "G4 P0.25" 'pause for Dro to update.
    'ZNew = PlateOffset + 50 'calc retract
    Code("G53G0Z-12")
    'Code "G0 Z" &ZNew 'put the Z retract height you want here
    While IsMoving ()
    Wend
    Code "(Z axis is now zeroed in Metric units)" 'puts this message in the status bar

    End If

    Code "F" &CurrentFeed 'returns to prior feed rate
    Code "F200"
    Sleep 100
    End If
    End If

    I figured that when i have machine coordinates and work coordinates it works fine.
    But if one of the coordinates is not exactly 0, after first touch on the probe it start moving down instead retracting and doing a second hit with slower feed rate.

    ***

    Can that be the wrong settings on KFLOP?
    Here is my NotifyProbeMach.c -

    #include "KMotionDef.h"

    //Plugin calls for Mach3 NotifyPlugins Commands

    #define X 0
    #define Y 1
    #define Z 2

    float DecelTimeForAxis(int axis);

    main()
    {
    int msg = persist.UserData[6]; // Mach3 notify Message 10000-10999

    printf("Mach3 Notify Call, Message = %d\n",msg);

    if (msg==10100)
    {
    // adjust the commanded position to match the glass scale encoder
    DisableAxis(X);
    EnableAxisDest(X,chan[X].Position);
    }
    if (msg==10101)
    {
    // adjust the commanded position to match the glass scale encoder
    DisableAxis(Y);
    EnableAxisDest(Y,chan[Y].Position);
    }
    if (msg==10102)
    {
    // adjust the commanded position to match the glass scale encoder
    DisableAxis(Z);
    EnableAxisDest(Z,chan[Z].Position);
    }
    if (msg==10500)
    {
    if (CS0_StoppingState == 0)
    StopCoordinatedMotion();
    else
    ResumeCoordinatedMotion();
    }
    if (msg==10300)
    {
    // User wants to disable Z (switch to OL)

    DisableAxis(Z);
    chan[Z].OutputMode = STEP_DIR_MODE;

    EnableAxisDest(Z,chan[Z].Position);
    }
    if (msg==10301)
    {
    // User wants to enable Z (switch to CL)
    DisableAxis(Z);
    chan[Z].OutputMode = CL_STEP_DIR_MODE;

    EnableAxisDest(Z,chan[Z].Position);
    }

    // handles probing
    //
    // flag is 0 - while watching for probe hit
    // flag is 1 - if probe was already set from start
    // flag is 2 - after successful probe hit
    // flag is 3 - Tells Plugin to upload status (3) to
    // DRO 1100 and let User handle the error
    //
    // returns the captured results in User Variables
    // X - 50+51
    // Y - 52+53
    // Z - 54+55
    // A - 56+57
    // B - 58+59
    // C - 60+61
    // status result 62

    #define PROBE_BIT 24
    #define PROBE_ACTIVE_STATE 0
    #define PROBE_ERROR_HANDLING 0 // 0 Stops Mach3 on probe error
    // #define PROBE_ERROR_HANDLING 3 // 3 User must query DRO 1100 and handle error

    if (msg==20000)
    {
    double *d = (double *)&persist.UserData[MACH3_PROBE_RESULTS_VAR];
    int flag=1;

    persist.UserData[MACH3_PROBE_STATUS_VAR]=PROBE_ERROR_HANDLING;

    while (ReadBit(PROBE_BIT)!=PROBE_ACTIVE_STATE)
    {
    flag=2;
    WaitNextTimeSlice();
    }

    if (CS0_axis_x>=0) d[0]=chan[CS0_axis_x].Dest;
    if (CS0_axis_y>=0) d[1]=chan[CS0_axis_y].Dest;
    if (CS0_axis_z>=0) d[2]=chan[CS0_axis_z].Dest;
    if (CS0_axis_a>=0) d[3]=chan[CS0_axis_a].Dest;
    if (CS0_axis_b>=0) d[4]=chan[CS0_axis_b].Dest;
    if (CS0_axis_c>=0) d[5]=chan[CS0_axis_c].Dest;

    persist.UserData[MACH3_PROBE_STATUS_VAR]=flag;
    StopCoordinatedMotion();
    }
    }

    And about the stepper question, I write it wrong Im running them Quarter step not Half step, so 160 steps per unit is OK!

    Please help me with this touch probe problem.
    Thanks Tom.

  11. #11
    Join Date
    Mar 2003
    Posts
    35538
    Personally, I'd remove the
    Code("G53G0Z-12")
    and use the following line instead:

    ZNew = PlateOffset + 50 'calc retract

    Code "G0 Z" &ZNew 'put the Z retract height you want here

    This way it will always retract, whereas the G53 method may be inconsistent, depending on your machine z zero location.
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  12. #12
    Join Date
    Jan 2013
    Posts
    73
    Plate thickness:1.57mm
    Lets say the endmill is 20mm from the plate at the beginning, and I Zero the DRO.
    When I press the Z- button, the endmill searches for the plate in Z-, when it makes a contacts it retracts to +3mm to make a second hit at the slower feed rate.
    But instead of retracting 3mm from the plate it retracts to +3mm on DRO (so its actually 23mm from the plate) and it never make a second contact (cause it searches the plate for 6mm in Z-)
    In my opinion it should zero the DRO when it first make a contact and retract 3mm from the plate, and then make a second contact but it never zeroes at first hit.
    I tried to put the endmill approximately 4mm from the plate and zero the DRO, start the program then it makes a second hit but the result is not accurate.
    When i check it manualy, jog the Z down to the plate it doesnt read 1.57mm at the contact but somewhere around: -0.36mm instead +1.57
    I dont konw where lies the problem, before KFLOP everything worked like a charm.

    Is there any KFLOP user who got touch probe sucessfully setup in Mach3 by Bigtex.set file?

  13. #13
    Join Date
    May 2006
    Posts
    4053
    I wonder if we have a race condition between the time Mach3 detects the probe and when we upload the results. As a test try adding a big delay:

    Code "G4 P1" 'pause 1 seconds

    between waiting for finished and reading the result.

    While IsMoving() 'wait for probe move to finish
    Wend

    ZNew = GetVar(2002) 'read the touch point


    Do this all 4 places


    Regards
    TK
    http://dynomotion.com

  14. #14
    Join Date
    May 2006
    Posts
    4053
    Hi mlinkadelsol,

    Sorry I missed your last post.

    We had an issue with our Plugin returning Probe results in machine coordinates instead of work coordinates. This was changed in Version 4.30e

    If you are running an older Version please try our latest test release to see if it solves the problem.

    http://dynomotion.com/Software/KMotion430j.exe

    Regards
    TK
    http://dynomotion.com

  15. #15
    Join Date
    Jan 2013
    Posts
    73
    Pause didnt help.
    Its acting strange.
    The code worked with paralell port.

    My Kflop GANTRY setup:
    Ch0 = X1
    Ch1 = X2
    Ch2 = Y
    Ch3 = Z

    Please check my NotifyMach code.

    #include "KMotionDef.h"

    //Plugin calls for Mach3 NotifyPlugins Commands

    #define X 0
    #define Y 2
    #define Z 3

    float DecelTimeForAxis(int axis);

    main()
    {
    int msg = persist.UserData[6]; // Mach3 notify Message 10000-10999

    printf("Mach3 Notify Call, Message = %d\n",msg);

    if (msg==10100)
    {
    // adjust the commanded position to match the glass scale encoder
    DisableAxis(X);
    EnableAxisDest(X,chan[X].Position);
    }
    if (msg==10101)
    {
    // adjust the commanded position to match the glass scale encoder
    DisableAxis(Y);
    EnableAxisDest(Y,chan[Y].Position);
    }
    if (msg==10102)
    {
    // adjust the commanded position to match the glass scale encoder
    DisableAxis(Z);
    EnableAxisDest(Z,chan[Z].Position);
    }
    if (msg==10500)
    {
    if (CS0_StoppingState == 0)
    StopCoordinatedMotion();
    else
    ResumeCoordinatedMotion();
    }
    if (msg==10300)
    {
    // User wants to disable Z (switch to OL)

    DisableAxis(Z);
    chan[Z].OutputMode = STEP_DIR_MODE;

    EnableAxisDest(Z,chan[Z].Position);
    }
    if (msg==10301)
    {
    // User wants to enable Z (switch to CL)
    DisableAxis(Z);
    chan[Z].OutputMode = CL_STEP_DIR_MODE;

    EnableAxisDest(Z,chan[Z].Position);
    }

    // handles probing
    //
    // flag is 0 - while watching for probe hit
    // flag is 1 - if probe was already set from start
    // flag is 2 - after successful probe hit
    // flag is 3 - Tells Plugin to upload status (3) to
    // DRO 1100 and let User handle the error
    //
    // returns the captured results in User Variables
    // X - 50+51
    // Y - 52+53
    // Z - 54+55
    // A - 56+57
    // B - 58+59
    // C - 60+61
    // status result 62

    #define PROBE_BIT 24
    #define PROBE_ACTIVE_STATE 0
    #define PROBE_ERROR_HANDLING 0 // 0 Stops Mach3 on probe error
    // #define PROBE_ERROR_HANDLING 3 // 3 User must query DRO 1100 and handle error

    if (msg==20000)
    {
    double *d = (double *)&persist.UserData[MACH3_PROBE_RESULTS_VAR];
    int flag=1;

    persist.UserData[MACH3_PROBE_STATUS_VAR]=PROBE_ERROR_HANDLING;

    while (ReadBit(PROBE_BIT)!=PROBE_ACTIVE_STATE)
    {
    flag=2;
    WaitNextTimeSlice();
    }

    if (CS0_axis_x>=0) d[0]=chan[CS0_axis_x].Dest;
    if (CS0_axis_y>=0) d[2]=chan[CS0_axis_y].Dest;
    if (CS0_axis_z>=0) d[3]=chan[CS0_axis_z].Dest;
    if (CS0_axis_a>=0) d[1]=chan[CS0_axis_a].Dest;
    if (CS0_axis_b>=0) d[4]=chan[CS0_axis_b].Dest;
    if (CS0_axis_c>=0) d[5]=chan[CS0_axis_c].Dest;

    persist.UserData[MACH3_PROBE_STATUS_VAR]=flag;
    StopCoordinatedMotion();
    }
    }

  16. #16
    Join Date
    Jan 2013
    Posts
    73
    Ok, Ill try KFLOP 4.30.
    Im using 4.29.
    Thnx.

  17. #17
    Join Date
    Jan 2013
    Posts
    73
    Tom, probing seems to be working now.
    But the Homing isnt working anymore.
    Please help.

    The homing works when I start the C program in KFLOP but not in MACH 3, when I press REF ALL HOME button.

    Thnx.

  18. #18
    Join Date
    Jan 2013
    Posts
    73
    Code for Homing:

    #include "KMotionDef.h"

    // Configuration and Homing program for a 3 axis System
    // Limit switches are disabled and used as a home switch
    // then they are re-enabled



    main()
    {
    DefineCoordSystem(0,2,3,-1); //Define XYZ coordinated motion axes

    //place to save limit switch settings
    int SaveX1Limits;
    int SaveX2Limits;
    int SaveYLimits;
    int SaveZLimits;

    DisableAxis(0); //X1
    DisableAxis(1); //X2
    DisableAxis(2); //Y
    DisableAxis(3); //Z

    // Set the axis parameters here
    // after everything is configured in the KMotion Screens
    // use copy C Code to clipboard on the configuration screen
    // then paste here. Repeat for each axis


    //X1 - desno
    ch0->InputMode=NO_INPUT_MODE;
    ch0->OutputMode=STEP_DIR_MODE;
    ch0->Vel=4000;
    ch0->Accel=40000;
    ch0->Jerk=400000;
    ch0->P=0;
    ch0->I=0.01;
    ch0->D=0;
    ch0->FFAccel=0;
    ch0->FFVel=0;
    ch0->MaxI=200;
    ch0->MaxErr=1e+006;
    ch0->MaxOutput=200;
    ch0->DeadBandGain=1;
    ch0->DeadBandRange=0;
    ch0->InputChan0=0;
    ch0->InputChan1=0;
    ch0->OutputChan0=0;
    ch0->OutputChan1=0;
    ch0->MasterAxis=-1;
    ch0->LimitSwitchOptions=0x140015;
    ch0->InputGain0=1;
    ch0->InputGain1=1;
    ch0->InputOffset0=0;
    ch0->InputOffset1=0;
    ch0->OutputGain=1;
    ch0->OutputOffset=0;
    ch0->SlaveGain=1;
    ch0->BacklashMode=BACKLASH_OFF;
    ch0->BacklashAmount=0;
    ch0->BacklashRate=0;
    ch0->invDistPerCycle=1;
    ch0->Lead=0;
    ch0->MaxFollowingError=1000000000;
    ch0->StepperAmplitude=20;

    ch0->iir[0].B0=1;
    ch0->iir[0].B1=0;
    ch0->iir[0].B2=0;
    ch0->iir[0].A1=0;
    ch0->iir[0].A2=0;

    ch0->iir[1].B0=1;
    ch0->iir[1].B1=0;
    ch0->iir[1].B2=0;
    ch0->iir[1].A1=0;
    ch0->iir[1].A2=0;

    ch0->iir[2].B0=0.000768788;
    ch0->iir[2].B1=0.00153758;
    ch0->iir[2].B2=0.000768788;
    ch0->iir[2].A1=1.92076;
    ch0->iir[2].A2=-0.923833;
    //EnableAxisDest(0,0);

    //X2 - lijevo
    ch1->InputMode=NO_INPUT_MODE;
    ch1->OutputMode=STEP_DIR_MODE;
    ch1->Vel=4000;
    ch1->Accel=40000;
    ch1->Jerk=400000;
    ch1->P=0;
    ch1->I=0;
    ch1->D=0;
    ch1->FFAccel=0;
    ch1->FFVel=0;
    ch1->MaxI=200;
    ch1->MaxErr=1e+006;
    ch1->MaxOutput=200;
    ch1->DeadBandGain=1;
    ch1->DeadBandRange=0;
    ch1->InputChan0=1;
    ch1->InputChan1=1;
    ch1->OutputChan0=1;
    ch1->OutputChan1=3;
    ch1->MasterAxis=0;
    ch1->LimitSwitchOptions=0x150015;
    ch1->InputGain0=1;
    ch1->InputGain1=1;
    ch1->InputOffset0=0;
    ch1->InputOffset1=0;
    ch1->OutputGain=1;
    ch1->OutputOffset=0;
    ch1->SlaveGain=1;
    ch1->BacklashMode=BACKLASH_OFF;
    ch1->BacklashAmount=0;
    ch1->BacklashRate=0;
    ch1->invDistPerCycle=1;
    ch1->Lead=0;
    ch1->MaxFollowingError=1000000000;
    ch1->StepperAmplitude=20;

    ch1->iir[0].B0=1;
    ch1->iir[0].B1=0;
    ch1->iir[0].B2=0;
    ch1->iir[0].A1=0;
    ch1->iir[0].A2=0;

    ch1->iir[1].B0=1;
    ch1->iir[1].B1=0;
    ch1->iir[1].B2=0;
    ch1->iir[1].A1=0;
    ch1->iir[1].A2=0;

    ch1->iir[2].B0=1;
    ch1->iir[2].B1=0;
    ch1->iir[2].B2=0;
    ch1->iir[2].A1=0;
    ch1->iir[2].A2=0;
    //EnableAxisDest(1,0);

    //Y
    ch2->InputMode=NO_INPUT_MODE;
    ch2->OutputMode=STEP_DIR_MODE;
    ch2->Vel=4000;
    ch2->Accel=40000;
    ch2->Jerk=400000;
    ch2->P=0;
    ch2->I=0.01;
    ch2->D=0;
    ch2->FFAccel=0;
    ch2->FFVel=0;
    ch2->MaxI=200;
    ch2->MaxErr=1e+006;
    ch2->MaxOutput=200;
    ch2->DeadBandGain=1;
    ch2->DeadBandRange=0;
    ch2->InputChan0=2;
    ch2->InputChan1=0;
    ch2->OutputChan0=2;
    ch2->OutputChan1=0;
    ch2->MasterAxis=-1;
    ch2->LimitSwitchOptions=0x160015;
    ch2->InputGain0=1;
    ch2->InputGain1=1;
    ch2->InputOffset0=0;
    ch2->InputOffset1=0;
    ch2->OutputGain=1;
    ch2->OutputOffset=0;
    ch2->SlaveGain=1;
    ch2->BacklashMode=BACKLASH_OFF;
    ch2->BacklashAmount=0;
    ch2->BacklashRate=0;
    ch2->invDistPerCycle=1;
    ch2->Lead=0;
    ch2->MaxFollowingError=1000000000;
    ch2->StepperAmplitude=20;

    ch2->iir[0].B0=1;
    ch2->iir[0].B1=0;
    ch2->iir[0].B2=0;
    ch2->iir[0].A1=0;
    ch2->iir[0].A2=0;

    ch2->iir[1].B0=1;
    ch2->iir[1].B1=0;
    ch2->iir[1].B2=0;
    ch2->iir[1].A1=0;
    ch2->iir[1].A2=0;

    ch2->iir[2].B0=0.000769;
    ch2->iir[2].B1=0.001538;
    ch2->iir[2].B2=0.000769;
    ch2->iir[2].A1=1.92081;
    ch2->iir[2].A2=-0.923885;
    //EnableAxisDest(2,0);

    //Z
    ch3->InputMode=NO_INPUT_MODE;
    ch3->OutputMode=STEP_DIR_MODE;
    ch3->Vel=4000;
    ch3->Accel=40000;
    ch3->Jerk=400000;
    ch3->P=0;
    ch3->I=0.01;
    ch3->D=0;
    ch3->FFAccel=0;
    ch3->FFVel=0;
    ch3->MaxI=200;
    ch3->MaxErr=1e+006;
    ch3->MaxOutput=200;
    ch3->DeadBandGain=1;
    ch3->DeadBandRange=0;
    ch3->InputChan0=3;
    ch3->InputChan1=0;
    ch3->OutputChan0=3;
    ch3->OutputChan1=0;
    ch3->MasterAxis=-1;
    ch3->LimitSwitchOptions=0x1700001a;
    ch3->InputGain0=1;
    ch3->InputGain1=1;
    ch3->InputOffset0=0;
    ch3->InputOffset1=0;
    ch3->OutputGain=1;
    ch3->OutputOffset=0;
    ch3->SlaveGain=1;
    ch3->BacklashMode=BACKLASH_OFF;
    ch3->BacklashAmount=0;
    ch3->BacklashRate=0;
    ch3->invDistPerCycle=1;
    ch3->Lead=0;
    ch3->MaxFollowingError=1000000000;
    ch3->StepperAmplitude=20;

    ch3->iir[0].B0=1;
    ch3->iir[0].B1=0;
    ch3->iir[0].B2=0;
    ch3->iir[0].A1=0;
    ch3->iir[0].A2=0;

    ch3->iir[1].B0=1;
    ch3->iir[1].B1=0;
    ch3->iir[1].B2=0;
    ch3->iir[1].A1=0;
    ch3->iir[1].A2=0;

    ch3->iir[2].B0=0.000769;
    ch3->iir[2].B1=0.001538;
    ch3->iir[2].B2=0.000769;
    ch3->iir[2].A1=1.92081;
    ch3->iir[2].A2=-0.923885;
    //EnableAxis(3,0);


    // disable the limits (first save how they were set)
    SaveX1Limits = ch0->LimitSwitchOptions;
    SaveX2Limits = ch1->LimitSwitchOptions;
    SaveYLimits = ch2->LimitSwitchOptions;
    SaveZLimits = ch3->LimitSwitchOptions;

    ch0->LimitSwitchOptions = 0; //X1
    ch1->LimitSwitchOptions = 0; //X2
    ch2->LimitSwitchOptions = 0; //Y
    ch3->LimitSwitchOptions = 0; //Z

    // enable all 3 axes and begin servoing where we are


    EnableAxis(0);
    EnableAxis(1);
    EnableAxis(2);
    EnableAxis(3);

    //Z-AXIS
    //HOME Z-AXIS FAST
    Jog(3,+2000); // jog FAST NEGATIVE
    while (ReadBit(23)) ; // loop until IO bit goes high
    Jog(3,0); // stop
    while (!CheckDone(3)) ; // loop until motion completes
    DisableAxis(3); // disable the axis
    Zero(3); // Zero the position
    EnableAxis(3); // re-enable the ServoTick
    Move(3,-400.0); // move some amount inside the limits
    while (!CheckDone(3)) ; // loop until motion completes
    //ch2->LimitSwitchOptions = SaveYLimits;

    //HOME Z-AXIS 2nd TIME SLOWER
    Jog(3,300); // jog slowly NEGATIVE
    while (ReadBit(23)) ; // loop until IO bit goes high
    Jog(3,0); // stop
    while (!CheckDone(3)) ; // loop until motion completes
    DisableAxis(3); // disable the axis
    Zero(3); // Zero the position
    EnableAxis(3); // re-enable the ServoTick
    Move(3,-807.839402); // move some amount inside the limits
    while (!CheckDone(3)) ; // loop until motion completes

    ch3->LimitSwitchOptions = SaveZLimits; // restore limit settings
    //Z-AXIS END

    //HOME Y-AXIS FAST
    Jog(2,-2000); // jog FAST NEGATIVE
    while (ReadBit(22)) ; // loop until IO bit goes high
    Jog(2,0); // stop
    while (!CheckDone(2)) ; // loop until motion completes
    DisableAxis(2); // disable the axis
    Zero(2); // Zero the position
    EnableAxis(2); // re-enable the ServoTick
    Move(2,400.0); // move some amount inside the limits
    while (!CheckDone(2)) ; // loop until motion completes
    //ch2->LimitSwitchOptions = SaveYLimits;

    //HOME Y-AXIS 2nd TIME SLOWER
    Jog(2,-300); // jog slowly NEGATIVE
    while (ReadBit(22)) ; // loop until IO bit goes high
    Jog(2,0); // stop
    while (!CheckDone(2)) ; // loop until motion completes
    DisableAxis(2); // disable the axis
    Zero(2); // Zero the position
    EnableAxis(2); // re-enable the ServoTick
    Move(2,807.839402); // move some amount inside the limits
    while (!CheckDone(2)) ; // loop until motion completes

    ch2->LimitSwitchOptions = SaveYLimits; // restore limit settings
    //Y-AXIS END

    //X-SQUARE START
    //HOME X-AXIS FAST
    Jog(0,-2000); // jog FAST NEGATIVE X1
    while (ReadBit(20) && ReadBit(21)) ; // loop until IO bit goes high
    Jog(0,0); // stop
    while (!CheckDone(0)) ; // loop until motion completes
    DisableAxis(0); // disable the axis
    Zero(0); // Zero the position
    EnableAxis(0); // re-enable the ServoTick
    Move(0,300.0); // move some amount inside the limits
    while (!CheckDone(0)) ; // loop until motion completes
    ch0->LimitSwitchOptions = SaveX1Limits;

    //HOME X-AXIS 2nd TIME SLOWER
    ch1->MasterAxis=-1; //DESLAVE AXIS

    //SQUARING X1
    Jog(0,-300); // jog X1 slow NEGATIVE
    while (ReadBit(20)) ; // loop until IO bit goes high
    Jog(0,0); // stop
    while (!CheckDone(0)) ; // loop until motion completes
    DisableAxis(0); // disable the axis

    //SQUARING X2
    Jog(1,-300); // jog X1 slow NEGATIVE
    while (ReadBit(21)) ; // loop until IO bit goes high
    Jog(1,0); // stop
    while (!CheckDone(1)) ; // loop until motion completes
    DisableAxis(1); // disable the axis
    //
    ch1->MasterAxis=0; //SLAVE AXIS
    Zero(0); // Zero the position
    EnableAxis(0); // re-enable the ServoTick
    EnableAxis(1); // re-enable the ServoTick
    Move(0,807.473885); // move some amount inside the limits
    while (!CheckDone(0)) ; // loop until motion completes

    ch0->LimitSwitchOptions = SaveX1Limits; // restore limit settings
    //X-SQUARE END

    DefineCoordSystem(0,2,3,-1); //Define XYZ coordinated motion axes
    }
    Attached Thumbnails Attached Thumbnails 1.jpg   2.jpg  

  19. #19
    Join Date
    May 2006
    Posts
    4053
    Hi mlinkadelsol,

    I'm not sure why it doesn't work. What happens?

    But Mach3 expects to be able to home each axis separately. So it makes separate calls to our Plugin with a "flags" variable informing which axis it wants homed. We pass that variable to the Home C Program so your program will know which axis it is supposed to home. See the HomeMach3.c example for how to check the "flags" variable.

    Your program is configuring and homing all the axis at once. You should merge your code that homes each individual axes into the HomeMach3.c example at the appropriate place.

    But that doesn't explain why it "doesn't work". I would expect all the axes to be all homed multiple times.

    To test if the Mach3->Screen Button->Plugin->KFLOP communication is all working try configuring our plugin to our HomeMach3.c example which simply prints the "flags" variable. Run KMotion.exe at the same time as Mach3 and watch the Console Screen when you push REF ALL HOME.

    If that works try your program. Maybe add a printf("Homing..\n"); at the beginning to see if it ever starts.

    Also on the C Programs Screen a green bar indicates if each thread is running. You are using Thread #3 for you home program. Check if Thread #3 is "stuck" running forever.

    HTH
    Regards
    TK
    TK
    http://dynomotion.com

  20. #20
    Join Date
    Jan 2013
    Posts
    73
    Hello, I still got 2 Problems unsolved.

    1st is that the Homing still isnt working in Mach3, so I need to start Kmotion first and Run C-program for homing. After my machine is Homed then I start the Mach 3, so I have the machine in Zero position (Its very frustrating that I cant home my machine from Mach3)

    Before I upgraded Kmotion to 4.30j from 4.29 It worked just fine
    Could that be a problem in Kflop Mach3 plugin?
    After I upgraded Kmotion Probing was solved, but I loosed the Homing function.

    2nd problem is when I press the button ''Initial Zero Setup'' on Mach3 blue screen from BigTex, my ''Fixed probe location (machine coords)'' X-axis gets zeroed. That is not happening if Im using paralell port.
    So again could that be another problem in Kflop Mach3 plugin?

    --Can U give me an example how should I write my code to Home my axis sepparately?--

    Thank you.

    Quote Originally Posted by TomKerekes View Post
    Hi mlinkadelsol,

    I'm not sure why it doesn't work. What happens?

    But Mach3 expects to be able to home each axis separately. So it makes separate calls to our Plugin with a "flags" variable informing which axis it wants homed. We pass that variable to the Home C Program so your program will know which axis it is supposed to home. See the HomeMach3.c example for how to check the "flags" variable.


    Your program is configuring and homing all the axis at once. You should merge your code that homes each individual axes into the HomeMach3.c example at the appropriate place.

    But that doesn't explain why it "doesn't work". I would expect all the axes to be all homed multiple times.

    To test if the Mach3->Screen Button->Plugin->KFLOP communication is all working try configuring our plugin to our HomeMach3.c example which simply prints the "flags" variable. Run KMotion.exe at the same time as Mach3 and watch the Console Screen when you push REF ALL HOME.

    If that works try your program. Maybe add a printf("Homing..\n"); at the beginning to see if it ever starts.

    Also on the C Programs Screen a green bar indicates if each thread is running. You are using Thread #3 for you home program. Check if Thread #3 is "stuck" running forever.

    HTH
    Regards
    TK

Page 1 of 2 12

Similar Threads

  1. KFlop with touch probe
    By RichChant in forum Dynomotion/Kflop/Kanalog
    Replies: 12
    Last Post: 06-27-2014, 12:37 AM
  2. Touch Plate
    By gishere in forum LinuxCNC (formerly EMC2)
    Replies: 7
    Last Post: 03-01-2014, 01:50 PM
  3. z touch off plate
    By Alwaysintheknow in forum Chinese Machines
    Replies: 1
    Last Post: 06-10-2013, 03:20 AM
  4. Replies: 12
    Last Post: 06-05-2013, 06:05 PM
  5. Touch plate, Probotix PBX-RF board, and Mach3 software?
    By jeffmorris in forum DIY CNC Router Table Machines
    Replies: 6
    Last Post: 07-28-2012, 03:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •