ProbeIt for UCCNC

This is where you talk about Plugins. How they are made and how they work, show examples.

ProbeIt for UCCNC

Postby eabrust » Sat Feb 08, 2020 6:46 pm

I've been back working on a few touch probing related plugins since getting UCCAM copy working. I figured that with some of the questions Keith was asking relative to digitizing ( ) made this a good opportunity to show what I'm working on despite it being no where near ready for anyone to use...

I had been wanting to port the 'ProbeIt' wizard from Mach3 code into UCCNC for some time, however almost every single probe routine in it is dependent on doing a combined X/Y G31 probe, which still isn't supported (insert sad face here :( ). But I was playing around a few weekends ago and came up with a way to create a simulated multi-axis G31 command using the 'Jog Safe Probing' feature that UCCNC has. After a little testing, came up with something to try and make it work....

Below video shows the first stages of porting ProbeIt code into UCCNC as a plugin, and running a probe calibration table for angles between 0 - 360 in increments of 10 degrees.

It has a long way to go, but it's a start! :)

In the end, I want to replicate all the features ProbeIt for Mach3 had and add a bunch more since programing in .Net is so much more powerfull than Mach3 wizard code allowed. Some things on the to-do list:
profile tracing-save direct to DXF
manual jog against part - save direct to DXF
Include DXF recording of all basic probe routines (edge, center points, sides, etc)
Incorporate 3d surface scanning (I'm pulling in the 'probecloud' plugin I started a while ago, and will build upon it)

thanks for looking,

Posts: 113
Joined: Fri Sep 16, 2016 2:32 am

Re: ProbeIt for UCCNC

Postby eabrust » Mon Feb 10, 2020 12:57 am

Howdy all,

Well, today we got a bunch of snow throughout the day here, so I spent a lot of time working on the ProbeIt re-write for UCCNC (when not shoveling...). Was finally able to get the 2D profile tracing working satisfactorily after losing much hair... but this was the part I was hoping to get working so I'm happy :)

The below video and some pics show a test tracing of a knife scale that I originally made by doing a profile trace by the UCamCopy plugin, so it was a good opportunity to compare by measuring a copy of a copy.

Pardon the poor video and audio, I really don't know how to take decent videos in my shop ....

And here is a comparison of the geometry after import into VCarve (no edits, just raw imported DXF)
UCamCopy vs Probeit.JPG

Compare by overlaying (red is UCamCopy trace, black is test of ProbeIt code)
Overlay-UCamCopy vs ProbeIt.JPG

All things considered, to probe around a piece of wood on a rack and pinion driven CNC router, and get within ~ .010" on 3.6" dimension using a hack of a G31 probe command and with very little tweaking or calibrating shows promise. Now that the basic routines work, the rest is just a lot of cleanup of code and making a usable interface.

I really do enjoy programming in .Net for UCCNC, way better than Mach3/4.... Thanks CNCDrive!

Thanks for looking, and I hope this is of interest for what you were asking about Keith. I'll be working on it as time permits over the next few weeks.

Posts: 113
Joined: Fri Sep 16, 2016 2:32 am

Re: ProbeIt for UCCNC

Postby beefy » Mon Feb 10, 2020 9:42 pm

That's looking fantastic Eric, you're a legend.

The accuracy looks fine for my initial needs. Personally I'm not after super high accuracy, more just reproducing profiles for plasma cutting, and see if I can make a buck here and there in my back yard.

Happy to pay for your plugin when you release it.


Posts: 366
Joined: Mon Sep 05, 2016 10:34 am

Re: ProbeIt for UCCNC

Postby cncdrive » Mon Feb 10, 2020 10:17 pm

Hi Eric,

Nice work!
Site Admin
Posts: 3206
Joined: Tue Aug 12, 2014 11:17 pm

Re: ProbeIt for UCCNC

Postby eabrust » Tue Feb 11, 2020 2:04 am

Thanks Balzas,

Thought it might be fun to share a little bit of the coding side of plugins, maybe it will help others, maybe someone will point out dumb things I've done and I can learn some more too. And Hopefully no real programmers reading this will puke at the sight of VB and poor coding... :lol: joking of course.

So this is what I came up with to emulate a G31 in the X/Y plane at some angle:
Code: Select all

    ''' <summary>
    ''' This routine emulates a 'G31' command by using JSP mode, but only works in X/Y currently
    ''' </summary>
    ''' <param name="x"></param>
    ''' <param name="y"></param>
    ''' <param name="frate"></param>

    Function XYJSPG31(ByVal x As Double, ByVal y As Double, ByVal frate As Double) As Int16
        ' Returns 0 for no error, 1 for error

        Dim dx, dy As Double
        Dim XSpd, YSpd As Double
        Dim angle As Double

        XYJSPG31 = 1 ' Default to 'fail' flag

        If UC.GetLED(37) Then
            MsgBox("Probe Active, aborting!")
            UC.AddStatusmessage("Probe is active!")

            abortflag = True
            thrMyProc = Nothing
            XYJSPG31 = 1 'Fault

            Exit Function
        End If

        UC.Callbutton(552) ' Enable JSP Mode

        XHit = 0 ' Clear all prior hit data!
        YHit = 0
        ZHit = 0

        jspg31Xstart = UC.GetXpos ' Note start location before move
        jspg31Ystart = UC.GetYpos

        dx = x - UC.GetXpos ' Delta X, Delta Y
        dy = y - UC.GetYpos

        jspg31distance = Math.Sqrt(dx ^ 2 + dy ^ 2) ' Total move distance

        angle = Math.Atan2(dy, dx)  ' Angle of move in X/Y coordinate system

        XSpd = frate * Math.Cos(angle) ' Calculate the X and Y feedrates to move at desired angle
        YSpd = frate * Math.Sin(angle)

        If UC.GetLED(246) = False Then ' Extra redundant check, make sure JSP is on
            MsgBox("Error, JogSafeProbe Not Enabled")

            XYJSPG31 = 1
            thrMyProc = Nothing ' Abort

            Exit Function


            sendVelocity(XSpd, YSpd, frate) 'Start jogging at desired feedrate, this routine uses JogOnSpeed from the API, converts frate to % spd for each axis.

        End If

        While Not IsMoving() ' Delay so the UCCNC 'is moving' LED lights up before watching 'ismoving'
        End While

        While ProbeIsMoving() ' This custom 'IsMoving' routine causes a stop if target missed!
        End While

        UC100.JogOnSpeed(0, True, 0) ' Stop
        UC100.JogOnSpeed(1, True, 0) ' Stop
        UC100.JogOnSpeed(2, True, 0) ' Stop

        GetHitData() 'Routine to fill current location into hit positions

        XYJSPG31 = 0 ' Set OK flag

        UC.Callbutton(553) ' Turn off JSP to move off item

        While UC.GetLED(246) ' Wait for JSP led to turn off
        End While

    End Function

    ''' <summary>
    ''' This provides similar funcitonality to 'ISMOVING', except will also flag if distance moved exceeds set probe distance to stop
    ''' </summary>
    ''' <returns></returns>
    Private Function ProbeIsMoving() As Boolean
        ProbeCheckFlag = True ' default the flags to TRUE, as false is the triggering condition...
        DistanceFlag = True
        Dim thrIsMoving As New Thread(Sub() CheckProbeIsMoving())
        thrIsMoving.CurrentCulture = Thread.CurrentThread.CurrentCulture
        While thrIsMoving.IsAlive
        End While
        Return ProbecheckFlag
    End Function

    Private Sub CheckProbeIsMoving()
        IsMovingFlag = UC.IsMoving ' Standard check of 'IsMoving' from internal to UCCNC
        DistanceCheck() ' Custom check to see if the specified distance is met
        If IsMovingFlag = False Or DistanceFlag = False Then
            ProbecheckFlag = False
        End If
    End Sub

    Private Sub DistanceCheck()
        Dim distance As Double
        DistanceFlag = True
        distance = ((UC.GetXpos - jspg31Xstart) ^ 2 + (UC.GetYpos - jspg31Ystart) ^ 2) ^ 0.5  'Just comparing current position to desired end position
        If distance >= jspg31distance Then  ' If current position > or = desired, stop if not already stopped by JSP hit...
            DistanceFlag = False
        End If

    End Sub

It's not real pretty, but it seems to get the job done. In my testing with jogging against parts with JSP mode on, I found that if I stayed under ~10 in/min, there was a negligible difference between where the axis stopped while jogging, and where it stopped using a true G31 move (most likely driven by my axis accel rates, so may be different for others...). Going faster obviously resulted in a greater deviation, but I figure that could potentially be calibrated out too, but on the other hand probing should not be happening at crazy speeds.

So in a nutshell, that is what the plugin is currently built upon at the lowest level. Of course there are many layers of code above that to make the actual routines, and figure out touch location by offsetting ball diameter at the traveling vector angle, etc.

As a side note, if multi-axis G31 becomes built into UCCNC and is available, I'll be able to go back through the plugin and just replace all of the calls of my 'fake' G31 routine with calls to the real version, and hopefully accuracy could be improved a little more.

Posts: 113
Joined: Fri Sep 16, 2016 2:32 am

Return to Plugins

Who is online

Users browsing this forum: No registered users and 4 guests