MPG with Mach3 using mach3 controls

Moderators: TomKerekes, dynomotion

macona
Posts: 39
Joined: Tue Sep 15, 2020 4:44 am

Re: MPG with Mach3 using mach3 controls

Post by macona » Sun Sep 27, 2020 3:42 am

I noticed that all three axis were moving backwards so I just swapped A&B on the encoder. Whoops.

The enable thing is fixed.

The runaway issue I cant figure out. From a fresh power on of the kflop and go into mach it is fine. MPG move around with a single axis and reboot and it still seems to be fine. MPG around with a few axis and reboot mach and whatever axis is selected on the MPG at mach launch will send that axis to some specific position, every time I relaunch mach it sends it to the exact same dro position. But not every time of messaging with the MPG will the problem manifest. Sometimes I will have to launch, mess around, relaunch several time until it starts doing it, once it happens every time I launch it runs away to the same DRO location.

If I quit mach and pull power to the kflop and relaunch mach it is fine. I tried setting AxisSteps = 0 and it made no difference.

I changed your add-in to print NewPos, Pos, and Change1, they show what you would expect, the encoder position. And nothing changes between before it starts acting up and after other than the position.

Is there a kflop command that will hard reset the kflop? I can put that in the routine that runs when I quit mach and flush the memory. Otherwise I can put a NC relay on an output and trigger it on quit and make it power cycle itself.

Im not sure what to do about the the prototype issue. How do I fix it?

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

Re: MPG with Mach3 using mach3 controls

Post by TomKerekes » Sun Sep 27, 2020 5:16 pm

Hi Jerry,

ok progress :)
The runaway issue I cant figure out. From a fresh power on of the kflop and go into mach it is fine. MPG move around with a single axis and reboot and it still seems to be fine. MPG around with a few axis and reboot mach and whatever axis is selected on the MPG at mach launch will send that axis to some specific position, every time I relaunch mach it sends it to the exact same dro position. But not every time of messaging with the MPG will the problem manifest. Sometimes I will have to launch, mess around, relaunch several time until it starts doing it, once it happens every time I launch it runs away to the same DRO location.

If I quit mach and pull power to the kflop and relaunch mach it is fine. I tried setting AxisSteps = 0 and it made no difference.

I changed your add-in to print NewPos, Pos, and Change1, they show what you would expect, the encoder position. And nothing changes between before it starts acting up and after other than the position.
The way the smoothing works is that the axis converges on the MPG Target position getting closer and closer but never quite getting there. So there is code that checks for an axis change and if still converging then it commands the last axis to move exactly to the last/final target position before switching axes. I suspect the problem might be related to that but don't see how.

The last move occurs when there is no MPG movement for 1 second also. So you might take note if waiting more than 1 second makes any difference before exiting Mach3 or before moving the MPG.

Its also not clear exactly what you are doing. What exactly is "reboot mach". When Mach3 starts does it re-initialize?

Also the code monitors Mach3 running and disables 5 seconds after Mach3 exits. Are you waiting 5 seconds? You should also be able to use the MPG during the 5 seconds after exiting Mach3. Can you?

Please post your latest code and I will try to add some printouts to help figure out what is going on.

Is there a kflop command that will hard reset the kflop? I can put that in the routine that runs when I quit mach and flush the memory. Otherwise I can put a NC relay on an output and trigger it on quit and make it power cycle itself.
Before doing that let's try to figure out what is going on.


Im not sure what to do about the the prototype issue. How do I fix it?
Add this before main()

void ServiceMPG(void);
Regards,

Tom Kerekes
Dynomotion, Inc.

macona
Posts: 39
Joined: Tue Sep 15, 2020 4:44 am

Re: MPG with Mach3 using mach3 controls

Post by macona » Sun Sep 27, 2020 6:53 pm

Rebooting, mach. Quit and relaunch. I have waited for the full time out and not waited before relaunching mach and the issue crops up either way. Yes, Mach reinitializes, you can hear the servos enable when it does.

I think I may have found what triggers it. If I switch axis before that 1 second is up it will do it on the next relaunch. When it is going wherever it is going if I hit escape it stops the move.

Like I mentioned before, every time I relaunch Mach after it starts exhibiting this behavior. Lets say I made a move on Z and then switched to A. After quitting mach and relaunching it A or whichever axis is selected will start making a move, usually negative.If I make a MPG move on any other axis than Z and quit and relaunch it will take off at startup as usual. But if I make a MPG move in Z and let it settle before switching axis or just quitting mach when I relaunch it acts as it should. Nothing moves.

Its like some value is getting stuck in a register and whenever mach launches it sends it to that location. If I make another move on that axis it clears it and everything is happy again.
InitStepDir3AxisSupermax2 tk.c
(13 KiB) Downloaded 81 times

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

Re: MPG with Mach3 using mach3 controls

Post by TomKerekes » Mon Sep 28, 2020 2:57 am

Hi Jeremy,

I think I see it. Try changing:

Code: Select all

	NewPos = (chan[MPG_INPUT_AXIS].Position / 4);
	Change1 = NewPos - Pos;
to

Code: Select all

	NewPos = chan[MPG_INPUT_AXIS].Position;
	Change1 = (NewPos - Pos)/4;
Otherwise we initialize the MPG position to the full encoder position then difference it with a quarter of the encoder position which is likely a large change which invokes a big move.
Regards,

Tom Kerekes
Dynomotion, Inc.

macona
Posts: 39
Joined: Tue Sep 15, 2020 4:44 am

Re: MPG with Mach3 using mach3 controls

Post by macona » Mon Sep 28, 2020 6:11 am

I removed my /4 modification and it does not seems to runaway.

But no matter what I do when I change it to:

Code: Select all

	NewPos = chan[MPG_INPUT_AXIS].Position;
	Change1 = (NewPos - Pos)/4;
It just stops working, it compiles fine. Just there is no effect from the hand wheel. I tried other things like ((NewPos - Pos)/4), ((NewPos - Pos) * .25), adding another line below that with Change1 = Change1 / 4;

All have the same result, it kills the MPG. Eventually it hit me that when we are dividing it by 4 we are creating a floating point number at times and Change1 is defined as int. So I changed:

Code: Select all

int Change1, NewPos;
to

Code: Select all

double Change1, NewPos;
and everything seems to work now. Is this correct?

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

Re: MPG with Mach3 using mach3 controls

Post by TomKerekes » Mon Sep 28, 2020 4:28 pm

Hi Jerry,

Oops. Yes 1/4 as an integer is 0. I was thinking the encoder was changing by 4 but more probably a burst of 4 changes of 1.

Your method should work fine. Personally I would have left those integers then multiplied the Factor by 0.25.

Thanks for your patience.
Regards,

Tom Kerekes
Dynomotion, Inc.

macona
Posts: 39
Joined: Tue Sep 15, 2020 4:44 am

Re: MPG with Mach3 using mach3 controls

Post by macona » Mon Sep 28, 2020 6:55 pm

How does that work? Does the variable eventually accumulate to a whole number? So .25 will be zero but 4 .25s will show as 1?

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

Re: MPG with Mach3 using mach3 controls

Post by TomKerekes » Mon Sep 28, 2020 7:17 pm

Not exactly sure what you are asking. Both your method and my described method will behave exactly the same. Moving:

0.25 x increment x StepsPerUnit

For each encoder change of 1 count.

But my approach keeps encoder counts as integers and scales the movement later. Yours works in quarter counts as floating point numbers.

Btw it isn’t clear to me how the MPG is constructed. I’m guessing something like an encoder with 100 lines/rev (400 counts/Rev) with 100 graduation marks and with 100 detente you can feel?
Regards,

Tom Kerekes
Dynomotion, Inc.

macona
Posts: 39
Joined: Tue Sep 15, 2020 4:44 am

Re: MPG with Mach3 using mach3 controls

Post by macona » Mon Sep 28, 2020 7:50 pm

Yeah, all of the MPGs I have ever seen (I used to be a commercial CNC tech) use 100PPR encoders with 100 detents, so 400 quadrature counts per rev.

I use one of these. A bunch of them popped up on ebay years ago and Peter Homann of Homann designs in Australia reprogrammed them to run modbus to talk to Mach. I used it till I ditched the parallel ports and went kflop about 4 years ago and at which time the pendant became useless. So I brought out the A/B signals from the encoder and thats where this all started.

OK, I see what you are saying now on the code, I was thinking you wanted me to use the previous /4 change.

macona
Posts: 39
Joined: Tue Sep 15, 2020 4:44 am

Re: MPG with Mach3 using mach3 controls

Post by macona » Mon Sep 28, 2020 8:03 pm

Pic of my controller.
254FFEAA-15A2-4FD6-AF9A-591F86D96BDA.jpeg

Post Reply