Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: linuxfan on February 23, 2019, 05:09:22 PM

Title: Mach4 MPG axis stop after inc steps overflow
Post by: linuxfan on February 23, 2019, 05:09:22 PM
I am using pokeys57E to drive lathe on m4, and it works great. However I can't figure out how to achieve that axis stops after one would stop rotating MPG.
When inc steps are small, it is ok, but when 1mm per step is choosed, inc overlow happens if you turn mpg too fast. So machine wants to execute all commanded steps, and it runs even when mpg is not turned anymore. What I would like is, that when mpg encoder is not turned, motion of axis stops not matter if all steps were not executed.
I assign mpg to axes with mcMpgSetAxis on startup script, and I use fast enc. 1 and fast enc 2 on pokeys, as this is cyclic lathe.
I have looked at function mcJogIncStop and it seems it has something to do with what I want to achive, but if I put it in PLC loop script, it will stop axis right away, but steps aren't working properly, so 0.01mm inc won't actually make machine step 0.01mm etc.. Could someone advise what would be the correct approach to this?
Thanks
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: joeaverage on February 23, 2019, 08:56:50 PM
Hi,
there are two jogging modes, Step and Continuous.

What you have described is the behavior of Mach when jogging in Step mode.

Each click of the MPG causes a move instruction to be appended to the motion buffer. Each click will move the current
axis one 'jog increment' whatever the current jog increment is at the current time. If the succession of move instructions
exceeds the jog rate the instructions stack up in the buffer. Even when the MPG is stopped movement will continue until
the buffer is empty. This is normal behavior.

The only way you can stop the motion controller from completing its task is to EStop.

There may be another alternative, I haven't tried it, this API is really meant for probing routines but may none the less offer
you away to 'cheat' Mach4:

Quote
LUA Syntax:
rc = mc.mcMotionClearPlanner(
      number mInst)

Description:
Clears the motion planner of all previously planned moves.

What I am suggesting is that if you had some timer arrangement that detected that the MPG had ceased producing pulses
for say half a second then you could issue a mc.mcMotionClearPlanner instruction.

That may offer a way to prevent overrun in Step jog mode but perhaps you should experiment more with Continuous jog
mode.

This is from "Mill Operations Guide" in your Docs folder, page 23:

Quote
There are 2 basic jog modes which are selectable by pressing the “Jog Mode” button. The current selection will be indicated by an LED. Figure 3-5 shows the continuous mode selected. In continuous mode the machine will move at the specified jog rate as long as a jog button is held down. The jog rate can be changed by moving the slider at the bottom of the jogging tab or by directly typing the desired rate into the DRO in the bottom right corner. The number shown in the DRO is a percentage of the max velocity, or rapid rate, of the machine. Continuous mode is useful for moving the machine relatively large distances and rough positioning. When finding the edge of a work piece, locating a hole, or other precision position is required, step jog is much more accurate. In step jog, the machine moves only by the specified increment amount, regardless of how long the jog button is held down. The jog increment can be changed by pressing the “Cycle Jog Inc” button. This button will change the DRO to the right of it to show the current increment amount. The increment values can be changed on the General tab in the Mach configuration.

Thus in Continuous mode if you release the jog button the axis stops immediately. What happens when supplied by an MPG signal
however? My pendant (VistaCNC P1A) when in Velocity mode (same as Continuous mode) if you turn the MPG wheel fast enough
the axis moves at the current jog rate. If you slow down or stop the axis also stops. I recall when I set it up there was a setting
somewhere that allowed me to program how fast that threshold was.....can't remember where just at the moment.

I believe the same thing happens with an ordinary MPG attached to your motion controller.

Try it out.

Craig
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: joeaverage on February 23, 2019, 09:01:29 PM
Hi,
just had the thought if you used the mcMotionClearPlanner() it may be that the DRO would no longer be accurate.

The DRO advances 1mm at each click (assuming the current jog increment is 1mm) and if an extra 20 clicks were in the
buffer when the mcMotionClearPlanner() instruction came along the axis would cease to move but I suspect the DRO would
still show where it was supposed to be....not ideal.

Craig
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: SwiftyJ on February 24, 2019, 04:20:44 AM
Would using mc.mcJogIsJogging to check that the axis is not jogging before issuing additional jog moves help?

Thanks
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: MN300 on February 24, 2019, 06:38:09 AM
Two solutions to the problem of the MPG logic storing pulses come to mind.
1) Turn the MPG slowly
2) Change the size of the steps, instead of 0.01, 0.1, 1.0 do something like 0.01, 0.05, 0.25.
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: linuxfan on February 25, 2019, 11:14:48 AM
joeaverage and everybody else, thanks for quick reply. MN300 about your first solution, I have to say I admire your simplistic approach :D. Sadly I need something more robust. I touht there is a simple solution to this, as this is how industrial grade controllers work. No matter pulses left in buffer, motion will stop as mpg stops. Otherwise its a crash waiting to happen. About solution to check if mpg is still turning and stopping motion with loop script after some time span, this would work, but it would result in slugish response. What I want is almost instant response.
One solution came to my mind. One could create two registers and feed them with encoder pulses, than map registers to mpgs with MpgSetEncoderReg. This way I could constantly monitor pulserate from mpg, and as soon as it approaches maximum machine speed, I could take over and feed registers with maximum machine speed, ignoring actual encoder pulserate. As soon as encoder pulserate would drop, I could then instantly map it back. This would solve problem with overflow of steps. But I am a bit worried of overall response of mpg. I would like to have less than 60ms response, I use 25ms buffer time on pokeys, and I am worried how much of a delay plc loop would make. For now, I have other things to solve, so I will just go with ugly solution of allowing max step of  0.1mm, and as safety turn it to 0.01mm in startup script.   

Anyway, I have to say I am impressed with M4 compared to M3. I have sucesfully create acceleration ramps for pwm depending on gear lathe is, automatic gear changing with hydraulic solenoid.. The ease of adopting your screen, creating script and screen for carousel type tool changer on machinning centre.. it is absolutly great and a huge step forward compared to M3..
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: joeaverage on February 25, 2019, 12:09:07 PM
Hi,
try Continuous mode, that's what its for.

Craig
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: MN300 on February 25, 2019, 02:38:49 PM
The Lua script for the MPG defines the connection of the encoder to an axis that is used by the core program.
For example:  mc.mcMpgSetInc(inst, 0, .001)

Encoder steps add distance to the destination register. The whole point of using an encoder rather than a button is so rotating a certain number of steps adds a matching distance to the destination. The problem is that in some cases the stored distance is too much.

A solution would be for NFS were to add an additional parameter to  mc.mcMpgSetInc that limits the maximum number of steps beyond the current position. The MPG script could change it for each increment choice, as the user prefers.
A similar limit could be added to jog commands.
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: linuxfan on February 26, 2019, 12:12:42 PM
Craig, Continuous mode has effect only on how jog button behaves, and whether it excecutes one increment or drives machine as long as you hold it. It won't affect behavior of mpg.
MN300 yes, this would be nice addition. Lua function to prevent stacking up increments faster than machine can execute them is what we need.
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: joeaverage on February 26, 2019, 12:25:21 PM
Hi,
have you tried it?

On my machine in Velocity mode the axis stops the moment the MPG stops.

Craig
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: linuxfan on February 26, 2019, 12:49:21 PM
Yes I've tried. The thing is, I saw you are using vista pendant, which has plugin doing the communication with m3/m4. And the way velocity mode works is, like you would be holding jog button down and constantly adjust jog rate % up to 100% depending on how fast you turn the wheel. This is why step overflow doesn't happen. Sadly this is not what I am trying to achieve, I would still like to have precise one encoder pulse equals set inc distance, I just want to prevent steps overflow, or steps building up.
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: joeaverage on February 26, 2019, 01:00:01 PM
Hi,
but that contradicts the idea of each click advancing the axis one increment.

If you spin the  MPG two revolutions at 100 clicks per rev then the axis should advance 200 mm (1mm increment).
If you however determine that no more than five clicks should be 'stored up' then the axis may move 25mm before
the limit is reached and thereafter the remaining clicks get ignored. Thus you have turned the MPG two turns but
the axis will not move 200mm.

Craig
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: joeaverage on February 26, 2019, 01:04:09 PM
Hi,

Quote
And the way velocity mode works is, like you would be holding jog button down and constantly adjust jog rate % up to 100% depending on how fast you turn the wheel

That is not how it works in practice. In reality if you turn the MPG at moderate speed the axis accelerates to it current
maximum speed, a programmable percentage of G0 speed. Once the MPG stops pulsing the axis stops immediately.

Craig
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: linuxfan on February 26, 2019, 01:19:19 PM
One could argue it contradicts idea of mpg step mode, and yes, steps would get ingored. But it makes sense to me to stop axis when mpg is not turning, and it is the way industrial controllers work. It will follow step inc, as long as it won't violate max machine speed, if you spin it too fast, it will just let go those extra pulses. I've checked video of how vista pendant works, and how it is presented there, faster you turn the mpg, the faster axis moves, if you move it as fast as G0or faster, it will run at G0. As soon as you stop, motion stops. If you turn mpg one click, it makes almost random move every time. I am 99% sure plugin uses JOG function, so when you start rotating your mpg, it triggers jog, and it constantly calculates percentage of jog depending on how fast you turn the mpg. As you stop turning it, it releases jog, and motion stops. But correct me if I am wrong.
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: jevs on August 29, 2019, 10:04:24 PM
Hi,
try Continuous mode, that's what its for.

Craig

I have been trying to figure out how to get the MPG to work in continuous mode for two days.....nowhere can I find how to do this or anything in the API that sets the MPG to continuous....
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: Ya-Nvr-No on August 30, 2019, 03:28:36 PM
I look at the view screen script under Operator.
I copy everything and past in a text editor and then search for examples
shows me the line numbers and some coding possibilities of how I might use it.
Hopefully I can set break points and then test by single stepping through my code.
You still have to put that code it in the MPG script your using, or i'm sure you could use a module and a shared function. called by any mpg device code.
Title: Re: Mach4 MPG axis stop after inc steps overflow
Post by: jevs on August 30, 2019, 04:16:48 PM
But that is button jogging. I cannot find a way to relate that to the MPG??? I tried a couple things and had no luck.
Are those actually the functions that can be made to work for Velocity jogging with the MPG?