Issue with continuous JOG. Not sure which methods to use.

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

Issue with continuous JOG. Not sure which methods to use.

Postby zerodivide » Sat Apr 24, 2021 8:31 pm

I have developed a plugin for my custom hardware pendant but having issue with continuous jog where you press a button and the axis moves until you release it.

I have a buttonDown and buttonUp event handlers that receive events from the pendant.

Inside buttonDown, the only UC method to jog axis I found is JogOnAxis
Inside buttonUp I use stop() method.

But something is weird here.
First of all JogOnAxis does not work if called in the same direction. It just ignores the call until you jog in reverse.
Second I can't get the stopwithdeccel() method to work. It just ignores it and axis continue moving.

Which methods I should use for this usecase?
zerodivide
 
Posts: 27
Joined: Thu Oct 01, 2020 9:10 pm

Re: Issue with continuous JOG. Not sure which methods to use

Postby eabrust » Sun Apr 25, 2021 3:30 pm

Hi Zerodivide,

I think the API has a few/several methods to send jogs. The method(s) I like to use in my plugins (Xbox controller w/ proportional speed) is to call JogOnSpeed from the API for continuous jog. I use it to both start jog at a velocity, and to stop. For step jog, I use AddLinearMoveRel.


Here is the code I use on a jog button press (or a xbox stick movement) to make Y axis 'go' + movement, there is a check for if to make a continuous or step jog, then send the command:

Code: Select all
  'Y Up
    Private Sub btnJogUp_Click_1(sender As Object, e As EventArgs) Handles btnJogUp.MouseDown
        If rbJogCont.Checked Then
            UC100.JogOnSpeed(1, False, yvelPCT(nudJogVel.Value)) ' Start axis in + direction and speed commanded by nudJogVel.value.....
        End If
        If rbJogStep.Checked Then
            UC100.AddLinearMoveRel(1, nudJogStep.Value, 1, yvelPCT(nudJogVel.Value), False)  'start axis in + direction for step distance in nudJogStep.value, and move at speed per nudJogVel.value.....  you don't need to stop the axis from this
        End If
    End Sub






And for the 'STOP' action on button release, all I do is send velocity =0 to that axis :

Code: Select all

    Private Sub btnJogUp_Click_1a(sender As Object, e As EventArgs) Handles btnJogUp.MouseUp
        If rbJogCont.Checked Then
            UC100.JogOnSpeed(1, False, 0)   ' stop the axis, just set velocity to 0......
        End If
    End Sub



The last bit of info is that the jog speed command to set in the JogOnSpeed call is a percentage of the axis maximum feedrate the user has set in their settings, so you have to back out the percentage by what speed you want to command. I put that as function call (separate function for each axis in my code, so only y axis is here):

Code: Select all

    Private Function yvelPCT(ByVal yvel As Double) As Double

        'Convert speed in 'unit/min' to 'Jog %'
        If xmaxVel = 0 And ymaxVel = 0 Then
            xmaxVel = UC.Getfielddouble(True, 9)
            ymaxVel = UC.Getfielddouble(True, 24)
            zmaxVel = UC.Getfielddouble(True, 39)

        End If

        yvelPCT = yvel / ymaxVel * 100 ' Define velocity as a % of max axis velocity, as input to JogOnSpeed command.
        Return yvelPCT
    End Function




Note that button press code is repeated for opposite direction (change the 'false' to 'true' in above calls), and then each axis gets the same blocks of code.



Hope this helps, I'm a vb hack user, so you'll have to clean it up to C#.

Note: if you use VB, I put a vb version of the API here for ref: http://www.forum.cncdrive.com/viewtopic.php?f=4&t=2229&p=18012#p18012. It isn't 100% complete, but it is mostly there.

regards
Eric
CraftyCNC: Plugins for UCCNC (and other neat stuff): http://www.craftycnc.com/plugins-for-uccnc/
eabrust
 
Posts: 354
Joined: Fri Sep 16, 2016 2:32 am
Location: Near Shirland IL, USA

Re: Issue with continuous JOG. Not sure which methods to use

Postby zerodivide » Sun Apr 25, 2021 4:25 pm

Thanks Eric!
Yes I use the same method to start the movement.
Didn't realize I simply have to call it again with speed 0!
Tried everything except that.

Another question. I notice my Shutdown event handler is not getting called when UCCNC is closed. Have you seen this issue? If so how did you resolve it?

I need it to reset the Arduino and close connection properly.

Thank you very much.
zerodivide
 
Posts: 27
Joined: Thu Oct 01, 2020 9:10 pm

Re: Issue with continuous JOG. Not sure which methods to use

Postby eabrust » Sun Apr 25, 2021 9:02 pm

Hi Zerodivide,

Not sure what the best place for the actions to do on shutdown. When you refer to the shutdown handler, are you referring to the 'shutdown_event' sub in the UCCNCplugin class, or to a form event? The only thing I have in the 'shutdown_event' is to close my open forms, then I tend to put things like saving settings, cleanup of variable, closing files, etc on the formclosing event of my main form, before the start of the thread to check when to fully close the form is called:

Code: Select all

    Private Sub PluginForm_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        ' Do not close the form when the red X button is pressed
        ' But start a Thread which will stop the Loop call from the UCCNC
        ' to prevent the form closing while there is a GUI update in the Loop event
        If Not MustClose Then
            e.Cancel = True

            'Cleanup work and save settings on shutdown:
            If cbAutoSaveSettings.Checked Then
                Try
                    formsave()
                Catch ex As Exception
                    MsgBox("error saving settings")
                End Try
            End If


            Dim thrClose As New Thread(Sub() Closeform())
            thrClose.CurrentCulture = Thread.CurrentThread.CurrentCulture ' Preserve regional settings
            thrClose.Start()

        Else


            ' Form is closing here...
        End If
    End Sub




Things generally work good this way, but I've found that occasionally the routines I run on shutdown may not always fully run before UCCNC goes away (sometimes, my saving of my plugin's settings may wind up incomplete, etc)... I still need to figure that out fully.

regards
Eric
CraftyCNC: Plugins for UCCNC (and other neat stuff): http://www.craftycnc.com/plugins-for-uccnc/
eabrust
 
Posts: 354
Joined: Fri Sep 16, 2016 2:32 am
Location: Near Shirland IL, USA

Re: Issue with continuous JOG. Not sure which methods to use

Postby zerodivide » Mon Apr 26, 2021 12:34 am

Hi Eric,

Yes I am using shutdown_event method.
But I don't think UCCNC actually calls it.

It more looks like your WinForms forms actually fire the FormClosing event on their own when the parent process tries to shut down....

Perhaps I could do the same with an invisible form...

It would be nice if we could hear from the developers on this.
zerodivide
 
Posts: 27
Joined: Thu Oct 01, 2020 9:10 pm

Re: Issue with continuous JOG. Not sure which methods to use

Postby eabrust » Mon Apr 26, 2021 3:03 am

I do a lot of trial/error and popping up msgbox's to verify what fires, etc as I try to figure out how the plugins behave on start and shutdowns relative to the UCCNC start and close process. Have you tried popping up a message box or something similar from the shutdown_event method, just to verify it is getting called on the shutdown and make sure you there isn't glitch in your arduino reset routine?

I'm pretty sure the shutdown_event does indeed run and is what triggers plugin forms to close when UCCNC is closing. I just put all my plugin terminating items in the forms close event because I'm doing form cleanup tasks. Like I said, don't know if there is a right/wrong way, I just fumble about until I get something that works :lol:



regards
Eric
CraftyCNC: Plugins for UCCNC (and other neat stuff): http://www.craftycnc.com/plugins-for-uccnc/
eabrust
 
Posts: 354
Joined: Fri Sep 16, 2016 2:32 am
Location: Near Shirland IL, USA


Return to Plugins

Who is online

Users browsing this forum: No registered users and 12 guests