Hello Guest it is April 26, 2024, 10:00:14 PM

Author Topic: Mach4 Set Motor Acc and Velocity via script  (Read 620 times)

0 Members and 1 Guest are viewing this topic.

Mach4 Set Motor Acc and Velocity via script
« on: November 06, 2021, 09:34:28 AM »
Hello,

I want to change the motor Acceleration and Velocity via M-code coded in LUA script.
I'm trying with next commands:
local inst mc.mcGetInstance()
mc.mcMotorSetMaxAccel(inst, 0, value for ACC)
mc.mcMotorSetMaxVel(inst, 0, value for Vel)
I now that value for Vel=[mm/sec] * [StepsPerUnit]
For Acc I'm not sure...
The main problem is that the SET command not make a change in Control Configuration>Motors...
Any experience or help?
Re: Mach4 Set Motor Acc and Velocity via script
« Reply #1 on: November 06, 2021, 10:05:52 AM »
Hi,
I haven't tried either of those APIs but they are similar to mc.mcAxisMapMotor() and similar ones which I have used.
They confused me to start because it did not appear that they were affecting the settings, and it was only then that I discovered
that only at certain times do the new settings get flushed to the .ini file and thence to the configuration values. The values you see
are the old ones, as stored in the .ini file, even though you have changed those values. Those values will change when the .ini file
is next loaded.

You can use mc.mcProfileFlush() and mc.mcProfileReload() if it concerns you that you cannot see the new values. Be careful with mcProfileReload(),
it can only be done in Idle State.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Set Motor Acc and Velocity via script
« Reply #2 on: November 06, 2021, 10:49:42 AM »
Thank you,
It is working after Save and Reload of the profile. You must not Disable the control to reload the profile.
Re: Mach4 Set Motor Acc and Velocity via script
« Reply #3 on: November 06, 2021, 02:35:43 PM »
Hi,
kool. If I'm not mistaken its not strictly necessary to do a Flush/Reload cycle.

Lets say for example that the current velocity setting in the .ini file is 5000 units/min (mm units implied) and you executed a macro
m120 for example, which reduced the velocity setting to 2500 units/min. Mach would apply the new setting to that axis immediately
and remain that way for the remainder of the Mach session.....unless you execute m121 which restored the setting back to 5000 units/min.
In absence of the restoring macro the 2500 units/mm setting would apply but the data in the configuration page would still show 5000 unit/min.

If you shut Mach down the setting (2500 units/min) would be flushed to the .ini file, its standard procedure to do a flush at shutdown.
Thus at the next Mach session the .ini file is loaded and viola the setting (2500 units/min) that you made from the last session have now been
propagated to the motor configuration page.

I imagine that you want to change the motor parameters during a job, but then set them back to normal afterwards. If that's the case there is no need
to do the Flush/Reload cycle, that the motor configuration data is not current during that phase is of academic interest only, so why bother with
the Flush/Reload cycle?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'