Hello Guest it is March 28, 2024, 01:41:29 PM

Author Topic: Mach 4 Screen Editor GCode Help  (Read 2715 times)

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  562 562
    • View Profile
Re: Mach 4 Screen Editor GCode Help
« Reply #10 on: October 11, 2019, 03:09:21 PM »
Guess I should have looked closer at the code you gave him.
I see where you are getting the current position.
Not sure why you think it is a bad idea to change between g90 and g91 as long as you put things back where you need it when you are done.

Bill
Re: Mach 4 Screen Editor GCode Help
« Reply #11 on: October 22, 2019, 06:02:43 AM »
Quote
Is it quite straightforward to link this to an input on my motion controller so I can have a foot switch toggle the button as well?

Yes, get the button working first. You can then add the input to the sigLib in screenload script and set the buttons state based on the state of the input.


Thanks very much for your help Chaoticone! The on screen button works as intended which is great!

I've had a go at adding code to link a physical input button to change the state of the on screen button in the sigLib but cant get it to do anything :(
Could you please shed some light on how this is possible??
I noticed you can link an input to a toggle button in the buttons properties, but this just seems to toggle the appearance of the button but not change its state.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Mach 4 Screen Editor GCode Help
« Reply #12 on: October 22, 2019, 09:56:04 AM »
Quote
Is it quite straightforward to link this to an input on my motion controller so I can have a foot switch toggle the button as well?

Yes, get the button working first. You can then add the input to the sigLib in screenload script and set the buttons state based on the state of the input.


Thanks very much for your help Chaoticone! The on screen button works as intended which is great!

I've had a go at adding code to link a physical input button to change the state of the on screen button in the sigLib but cant get it to do anything :(
Could you please shed some light on how this is possible??
I noticed you can link an input to a toggle button in the buttons properties, but this just seems to toggle the appearance of the button but not change its state.

No problem.

I'm doing some testing right now. Let me get back to you later on this. If you don't hear from me by tomorrow afternoon give this topic a bump. The broad idea is to put your button script into a function in the screen load script, add your input signal used for it to the sigLib table and have the inputs state and the buttons clicked script call that function. But there may be a simpler way........ catch you soon i hope.

Not sure why you think it is a bad idea to change between g90 and g91 as long as you put things back where you need it when you are done.

Bill

Bill, no idea how you extracted that out of what I posted. However the simplest way is to avoid checking, changing and setting back all together (which is what my code does) when you can. But you made no mention of checking and setting back so I had to expand to clarify. Not doing so could cause someone unaware a ton of grief. Solutions posted need to be accurate and like good scripts should not assume anything. If not and I see them, I will correct/clarify it the best I can or just delete them all together. No telling how many will see the post over time.

You might want to have a g91 before those moves in case the current position is not at 0 then switch back to g90
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Mach 4 Screen Editor GCode Help
« Reply #13 on: October 22, 2019, 09:37:30 PM »
Hey  BGEvents, can you tell me what input signal in Mach you are using and the exact name of the toggle button you pasted the code into?
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach 4 Screen Editor GCode Help
« Reply #14 on: October 23, 2019, 02:53:33 AM »
Hey  BGEvents, can you tell me what input signal in Mach you are using and the exact name of the toggle button you pasted the code into?

I have the input linked to Input3 and the button name is move10

Thanks

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Mach 4 Screen Editor GCode Help
« Reply #15 on: October 23, 2019, 09:42:38 AM »
OK, below is a pretty simple way to do it. But it may not be as robust as it should be. There might need to be some checks/lockouts that prevent the function from being called again before the previous move is finished. What can happen now is you can click the button or pedal and while it is moving the 10 units let off the pedal or click the button again. This will make it move again in the same direction (like a step jog would) the next time the button or pedal changes states. But it will move another 10 form its current position at that time. You might even find that a bit helpful? But if you press the pedal down and hold until it has moved the 10 it will move in one direction when pressed and the other when released. Same with the button. If you click it one time and wait until it finishes moving before pressing it again up will move it one direction and down will move it in the other.

Add this to the top of the sigLib table in the screen load script.
Code: [Select]
[mc.ISIG_INPUT3] = function (state)
moveYhardStop(state)
end,

Add this function to the screen load script anywhere after the sigLib table.
Code: [Select]
function moveYhardStop(dir)
scr.SetProperty("togBGtest", "Button State", tostring(dir))
local inst, YMach, rc
inst = mc.mcGetInstance()
YMach, rc = mc.mcAxisGetMachinePos(inst, mc.Y_AXIS)
if (dir == 0) then --Up == "0" Down == "1"
rc = mc.mcCntlMdiExecute(inst, string.format("G0 G53 Y%4.4f", (YMach + 10)))
else
rc = mc.mcCntlMdiExecute(inst, string.format("G0 G53 Y%4.4f", (YMach - 10)))
end
end

Now for your toggle button. First clear the Input Signal property you have that input set to. Then in its Up and Down Script events put this code which calls the function you put in the screen load script passing it the direction parameter. The direction parameter (dir) needs to be the number 0 or 1. So, both Up and Down script events will have the same code. the only difference is one will have a 0 and the other will have a 1. I think your up script should have a 0 and down a 1 but that depends on how/when your foot pedal goes low and high and if you want pedal down to == button down or button up.
Code: [Select]
moveYhardStop(0)
Play with that and see if you like it, need to add some checks, etc.
« Last Edit: October 23, 2019, 09:50:50 AM by Chaoticone »
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach 4 Screen Editor GCode Help
« Reply #16 on: October 30, 2019, 02:56:56 PM »
Thanks Chaoticone - you've nailed it!

It took me a while to realise that the button will only work once I restart mach4  ::) ;D

I actually really like the double tap to move further and auto return when you hold, it works really well with my application.

Cheers,
Ben

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Mach 4 Screen Editor GCode Help
« Reply #17 on: October 30, 2019, 06:49:27 PM »
 :)
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!