Hello Guest it is May 09, 2021, 10:41:00 PM

Author Topic: re-mapping motors and home switch inputs through lua script  (Read 4231 times)

0 Members and 1 Guest are viewing this topic.

re-mapping motors and home switch inputs through lua script
« on: December 21, 2016, 04:11:13 PM »
I'm running a CNC hotwire and require all axes to be homed independently (essentially gantry squaring). The PMDX Smart BOB unfortunately does not support homing slaved motors so we currently have to run two separate profiles of Mach4, one just for homing of all the axes every day. I read in the forums that someone had tried to create a script to decouple the motors and re-map them but haven't found anything past the rumors.

I looked through the API and found mcMotorGetAxis(), however I don't see any method of setting or changing the axis label. Is it possible to edit the axis that motors are assigned to through lua scripting? Possibly through some other sort of IO commands?

I haven't been able to do testing on modifying the home switch labels, however I believe I can do it using mcIoSetState() to modify the "Home 2 Motor" input. Please correct me if I am wrong, I'm new to lua but understand scripting and coding.

Any input is appreciated.
Re: re-mapping motors and home switch inputs through lua script
« Reply #1 on: December 22, 2016, 04:36:48 AM »
Hi Cal892,
if I understand what you want to do is when you wish to reference your machine you wish to 'uncouple' two
motors, home them individually and then slave one back to the master when the gantry is square?

Would  mcAxisMapMotor and mcAxisUnmapMotor be of any use?

I was thinking the process might be:

1) home Xaxis with both motors coupled to one home switch on your nominal master rail
2) unmap the slave motor and jiggle it back and forward until the gantry is square with a secondary home switch
3) remap the slave to the master
4) issue mcAxisHomeComplete.

In the API all of those calls have LUA syntax and I imagine therefore could be used in a script.

Craig
My wife left with my best friend...
     and I miss him!
Re: re-mapping motors and home switch inputs through lua script
« Reply #2 on: December 22, 2016, 10:15:08 AM »
Thanks Craig, I wasn't aware of the mcAxisMotor. It's not listed in the motor commands in the API.
I'll give it a shot and update after.
Re: re-mapping motors and home switch inputs through lua script
« Reply #3 on: December 22, 2016, 12:42:23 PM »
Hi Cal892,
I started experimenting after posting and have been thinking about it overnight. I'm now unsure that what looked like promising
instructions will be of use.

Even if you can couple/uncouple motors in Machs Core using them will the controller follow suit? If memory serves, when I set up the ESS
plugin it registered and mapped the axes which suggests that temporary rearrangements would have to be made there.

Craig
My wife left with my best friend...
     and I miss him!
Re: re-mapping motors and home switch inputs through lua script
« Reply #4 on: December 22, 2016, 01:23:28 PM »
Thanks Craig,
I've been experimenting as well, but without much luck.
I haven't been able to successfully un-map or re-map the axis yet. Also running into difficulties with modifying the home switch input values.

I'm going to open a support ticket and see if Mach can offer any help. I'll update the thread with Mach's suggestions.

Cal
Re: re-mapping motors and home switch inputs through lua script
« Reply #5 on: December 22, 2016, 11:33:51 PM »
Hi Cal,
I've been thinking about this all day. I think what we are considering here is the heart of how Mach4 works with a motion
controller.

I think axis slaving is done by the controller, at least I understand this is the case for the SmoothStepper. The SmoothStepper configuration
plugin registers and maps the axes and motors and informs Machs core with API calls like those above. I don't believe Warp9 the plugin developer
has left functions exposed that may be manipulated programmatically other than through the configuration dialogue.

One possibility that occurs to me is that it might be possible to configure Mach to run the master/slave setup. The Mach configurator Axis Mapping
tab seems to suggest it might be possible. Under that circumstance I imagine that Mach would produce two nominally identical position/velocity over
time commands which would be in the controller mapped to two different and independent motors that happen to be on each end of the gantry.
As we can communicate to Machs core via API commands it would be possible to temporarily break the 'indentical' streams so each motor could act
independently to square the gantry.

As it stands Mach issues one position/velocity command which the controller applies identically to two motors.

The only other solution would be to have two axes, say X and A configured indentically and modify your G code:

G1 X1.5 Y5  say would become
G1 X1.5 A1.5 Y5

Doable but time consuming. How it would work with arc moves or canned cycles makes my head hurt.

Discounting the G code manipulation I think the question to be posed to those who know Mach and perhaps controller plugins
best is 'Can Mach control its own assignment of master/slave or MUST it be done by the controller plugin?'

I've noted in the API that there are a number of commands that have C/C++ syntax but no LUA syntax, ie those commands can only be
used by plugins or modules in C/C++. The commands that we're thinking about which do have LUA syntax does not
necessarily mean that they could be used in a script to achieve anything useful.

Craig
My wife left with my best friend...
     and I miss him!
Re: re-mapping motors and home switch inputs through lua script
« Reply #6 on: December 23, 2016, 06:36:34 AM »
Hi,
I have been experimenting with M4 in Sim and discovered a few useful things.

First is that if you go to the Configure/Mach/Axis Mapping tab and even if you change nothing as you click OK then those
settings are made. I have tried:

mcAxisEnable(inst,0,true); it as expected enables/disables axis 0 in this example,

mc.mcAxisUnmapMotors(inst,0); it unmaps all motors from axis 0 in this example,

mc.mcAxisMapMotor(inst,0,0); it maps motor0 to axis0 in this example;

mc.mcAxisMapMotor(inst,0,4); it maps motor4 to the axis0, and this is the kicker now two motors are mapped to axis 0 exactly as Cal requires
and can be temporarily undone by:
mc.mcAxisUnmapMotor(inst,0,4); there again as Cal requires. Under this circumstance motor 0 is still mapped and could be jogged/MDI'ed into position
and then motor4 could again be slaved back to motor0. Don't bother to go to the Configure/Mach/Axis Mapping tab it won't reflect your hand coded
mappings/unmappings and worse will overwrite them just to screw with your head!.....Go on...tell me you didn't go there to try for yourself and now
all your mappings are up the duff right, I bloody told you!

I have been observing the results of various experiments with the sim diagnostic pinned to be always on top, really useful. The reason I chose motor4
rather than motor3, the next spare one, is that the velocity trace which should be solid black doesn't show up whereas all the others do. The string of
position data in the pane above suggests that motor3 is moving as anticipated just that the velocity trace doesn't show, a bug maybe.

What I propose is that if Cal were to write a macro it would in the first instance read ALL the existing enable states and mappings. Then home all axes,
uncouple the master/slave pair, jiggle the remaining motor until square and recouple. Then as an important last before exiting the macro restore
ALL the enable states and mappings to avoid having some hapless operator go to the Configure/Mach/Axis Mappings tab and inadvertently change
everything.

I am still of the opinion when you set up your controller that the two motors would have to be assigned independent 'channels'. The experimenting
I've done suggests that it is possible to have Machs core run the master/slave assignments and they can programmatically be manipulated. This would
obviate the need for the motion controller plugin to handle squaring. A good result I think!

Craig
My wife left with my best friend...
     and I miss him!
Re: re-mapping motors and home switch inputs through lua script
« Reply #7 on: December 23, 2016, 09:37:31 AM »
I showed, how to do axis squaring using LUA scripting Sept 2015
admit I have not tried it in over a year, as things might have changed.

but the principle steps I am sure would be the same.
Note: you might have to add some wait states for motors to finish.
as I never tested on a master slave router
I just seen in the sim it runs very fast.

http://www.machsupport.com/forum/index.php/topic,27162.msg214343.html#msg214343
Re: re-mapping motors and home switch inputs through lua script
« Reply #8 on: December 23, 2016, 02:26:16 PM »
Hi Ya-Nvr-No,
kool, very kool indeed!

When you ran the script did your reassignments show up on Axis Mapping page?. They don't when using sim on my laptop.

I can map motor4 to the X axis as a slave to motor 0 but it doesn't show on the table and if I inspect the table the table
takes precedence an overwrites the assignment made in my script. How I tumbled to this was that I disabled all
axes and unmapped all motors on the table, and then no axis movement would occur when I issued any MDI commands.
Then I would run my script which enabled axes 0,1,3 and mapped motors 0 and 4 to axis 0, motor1 to axis 1, motor2 to axis2
and the sim diagnostic would show motor movements when I issued MDI moves. When I went back to the Configure/Mach/Axis Mapping
page none of my assignments were there and when I clicked OK to get out of there I was back to a totally disabled machine.

Once I understood this behaviour the rest of my experimentation went a lot smoother. It forms the basis of my suggestion that
the existing enable/mapping states should be read prior to any manipulation for squaring and once done the enable/mapping
states should be restored so the assignment table reflects the machines actual state.

I haven't fiddled yet with any to the SetHome/IsHomed/Home Complete type API commands yet but from your post I'm sure they
will prove to be equally valuable.

Have to say that M4 is VERY crafty! Light years ahead of M3.

I think Cal892 has everything he needs to script his squaring procedure, very kool indeed.

Craig
My wife left with my best friend...
     and I miss him!
Re: re-mapping motors and home switch inputs through lua script
« Reply #9 on: December 25, 2016, 11:52:59 AM »
Hi,
small thing I learnt last night...

I have been confused that the Configure/Mach/Axis Mapping page does not reflect actual enable/mapping states
when you start manipulating them programmatically.

I chanced to view the status when I was working on another issue and found that it reflected the assignments I'd
made with the wee script I had been experimenting with for Cal892. Turns out that if you restart Mach the assignments
you program will indeed show in the page.

Craig
My wife left with my best friend...
     and I miss him!