Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: rellimmot on September 12, 2017, 01:24:15 PM

Title: Homing sequence triggering by limit switch possible?
Post by: rellimmot on September 12, 2017, 01:24:15 PM
I'm trying to trigger a homing sequence (Reference All Axes) via a limit switch.

I've got a machine which takes measurements on cotton bales, and I've switched to using Mach4 (I know now that I should have used a PLC in the first place, but I wasn't aware they could be had as cheap as they are) from Planet CNC due to a whole host of issues with that controller last year.

Every time a bale passes I would like it to home to the X and Y limit switches OR maybe every interval with inactivity have it home. The reason is the robot is left alone at a cotton gin and we're 6hrs away from it, so it has to be as redundant as possible.

Anybody have a good M code routine or something which can accomplish this? I'm afraid I'm not adept enough with the software to figure it out, though I've been trying.

Here's a video to give you an idea of what the robot does https://www.youtube.com/watch?v=XbuhTXTsVVk

Title: Re: Homing sequence triggering by limit switch possible?
Post by: rellimmot on September 12, 2017, 02:12:25 PM
I think I've got it figured out. It took me way too long to find the script library via Operator-->Lua Script. I was looking for the file, which I still haven't found-- I'm guessing its the wx4 that is indecipherable in either VS or notepad.

So I should [hopefully] be able to trigger some customization of refallhome function via an M code.

Next I have to figure out how if and how I can stop at the home limit switches every time rather than even using a move G code in the conventional sense. I realize how counter-intuitive this is, but I'm trying to make this a limit switch referencing system that's constantly checking itself. If something happens and the steppers skip a beat over the process of weeks, I wont be there to fix it. I'll be able to remote into the computer but that only goes so far.
Title: Re: Homing sequence triggering by limit switch possible?
Post by: joeaverage on September 13, 2017, 03:35:59 AM
Hi,
don't think I can answer your questions, I had a look at the vid but still unsure exactly what you wish to achieve...yet.

The comment I was going to make concerns the 'LUA Script'. Mach4 is composed of a whole bunch of scripts like screen load script,
PLC script, signal script and so on. Each has a particular use and you will when creating custom solutions modify and add to several or
possibly all of them to achieve a certain behaviour.

When Mach runs however ALL of those scripts get put together and compiled. The combined or super script is just called the 'LUA Script'
and as you've found available for your inspection at Operator/LUA Script. Note however you can't edit it or even run it, its just a text representation
of your combined scripts. If you wish to change it you have to edit the contributing script, screen load script for example.

You might ask why? I have on occasion found that having one large file to search for a given fragment of code much easier than searching in each
of the contributing scripts.

In recent times a feature called PMC has been added to Mach4 which is a ladder logic programing tool. It may be useful to you.

Keep talking about what your trying to achieve, it doesn't quite make sense to me that you are trying to use something like RefAllHome as a working
instruction.

Craig
Title: Re: Homing sequence triggering by limit switch possible?
Post by: rellimmot on September 20, 2017, 03:41:16 PM
Craig, thanks for the mental labor on this. You certainly made a few things make a little more sense with the layout of the software. The bit about the 'superscript' being a compiled output of multiple scripts made some loosely connected puzzle pieces click together.

Among some other issues I've been working on, I still hadn't been able to get a script/Mcode/MDI triggered homing sequence fully operational. It works great in the Lua editor, but when tried in the Mach4 GUI in any manner it just doesn't work. Visual Basic debugger pointed at Mach4 shows:
Exception thrown at 0x7506B832 in Mach4GUI.exe: Microsoft C++ exception: std::out_of_range at memory location 0x189AE36C.
Exception thrown at 0x7506B832 in Mach4GUI.exe: Microsoft C++ exception: std::bad_typeid at memory location 0x189AC6DC.
when I attempt to call the function. The code for the function is as such:
function m155()
local mInst=0;
local X_AXIS=0;
local Y_AXIS=1;
local HOMED_POS=0;
mc.mcAxisDerefAll(mInst);
mc.mcAxisHome(mInst, X_AXIS);
mc.mcAxisHome(mInst, Y_AXIS);
mc.mcAxisSetMachinePos(mInst, X_AXIS, HOMED_POS);
mc.mcAxisSetMachinePos(mInst, Y_AXIS, HOMED_POS);
mc.mcAxisSetPos(mInst, X_AXIS, HOMED_POS);
mc.mcAxisSetPos(mInst, Y_AXIS, HOMED_POS);
end

I didn't use refAllHome due to a post from PMDX mentioning that sequence of events, though not entirely relevant to my situation; refAllHome shoots out the same error anyhow.
http://www.machsupport.com/forum/index.php/topic,33545.msg232937.html#msg232937 (http://www.machsupport.com/forum/index.php/topic,33545.msg232937.html#msg232937)

The logs from the above Lua script and of a normal refAllHome and profile are attached, if you/anyone is interested into digging into it for clues.
Title: Re: Homing sequence triggering by limit switch possible?
Post by: joeaverage on September 21, 2017, 03:15:10 AM
Hi,
I follow your script and see what your trying to achieve. I don't know what the errors are and the log files don't mean much to me either.

I do have a couple of questions tho...
Code: [Select]
local mInst=0;
local X_AXIS=0;
local Y_AXIS=1;

Did you decide that you were going to ascribe a Mach instance? Whenever I've done any coding I've always set mInst by asking MachCore what the
current instance is:
local mInst=mc.mcGetInstance()

Also I thought X_AXIS and Y_AXIS are C++ constants, part of Mach. Redefining them seems counterproductive to me.

As you can tell I'm very much a LUA newbie but its fascinating none the less.

Craig
Title: Re: Homing sequence triggering by limit switch possible?
Post by: RICH on September 21, 2017, 07:56:19 AM
Hmm.........
Industrial application of Hobby software with free support.  >:D

Why not get Mach4-INDUSTRIAL version?

RICH
Title: Re: Homing sequence triggering by limit switch possible?
Post by: rellimmot on September 21, 2017, 03:16:00 PM
Rich,
I understand where you're coming from and I actually would if my budget allowed. I could also get away with stealing the software and nobody would notice but I got the hobby version anyways. This is an instrumentation research trial, in applying some measurement types whose use in this application has yet to leave the laboratory via hobby grade robot parts, hobby grade sensors, and a donated NIR spectrophotometer, into a willing cotton gin. I'm an undergraduate EE at a dead broke Louisiana college in an internship at a dead broke research lab; I've got no profit to gain from this other than course credit :)
I'd also be using a PLC if I had that industrial version money.
Title: Re: Homing sequence triggering by limit switch possible?
Post by: rellimmot on September 21, 2017, 03:19:15 PM
Craig,
I had been using mc.mcGetInstance previously and at some point I figured I'd cut one more variable off the list of things that might be going wrong and defined it as zero for testing since it usually is. I wasn't aware those were defined as constants in the program, good catch; I'll try changing those and see what happens. I think I'd seen them in someone else's code and they just stuck in my brain enough for me to unwittingly abuse them.
Title: Re: Homing sequence triggering by limit switch possible?
Post by: joeaverage on September 22, 2017, 10:35:28 AM
Hi,
I'm happy enuf with your explanation re industrial version of the software, If you had the gold you wouldn't be buying Mach4 for this job anyway.

I just noticed something that is worth thinking about maybe trying:

Quote
LUA Syntax:
rc = mc.mcMotorSetHomePos(
      number mInst,
      number motorId,
      number count)

Note the syntax that the position set occurs at a number 'count' in encoder counts from the switch. The C++ syntax for the same statement is that count is
integer. I'm thinking that because you've set count to zero then the switch will still be active whereas if you try backing off a wee bit....who knows?

Craig
Title: Re: Homing sequence triggering by limit switch possible?
Post by: RICH on September 23, 2017, 06:48:24 AM
Quote
I'm an undergraduate EE at a dead broke Louisiana college in an internship at a dead broke research lab; I've got no profit to gain from this other than course credit Smiley

Understand and maybe the folks in here can provide enough assistance to get you  4.0 out of the grade! ;)

RICH