Hello Guest it is March 28, 2024, 06:20:00 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Mckinleyrb

Pages: 1
1
Mach4 General Discussion / Mach4 Gantry Squaring
« on: December 09, 2020, 04:19:31 PM »
I created the following to square a gantry if you do not have the capability built into your controller, such as the PMDX-424  It works but I could use a little input on cleaning up the code.  When I enable the machine, it does not have time to enable all motors before it tries to start motion.  I tried to use mc.mcsignalwait as well as wx.wxsleep but did not have any luck.  The only thing I found to work was to use mc.mcCntlEnable six times in a row.  Here is the code, hopefully someone will find it useful, and im hopeful someone can provide me with a suggestion on cleaning up the code. 

Button script:
Code: [Select]
local inst = mc.mcGetInstance();

SquareAxesSetup();

mc.mcCntlEnable(inst,1);  --Not sure why it must be turned on 6 times to work.
mc.mcCntlEnable(inst,1);
mc.mcCntlEnable(inst,1);
mc.mcCntlEnable(inst,1); 
mc.mcCntlEnable(inst,1);
mc.mcCntlEnable(inst,1);

wx.wxMessageBox("Start Squaring?","Click OK",2);

AxesReset = coroutine.create (function()
mc.mcCntlGcodeExecute(inst,"G91 G28.1 X0 Y0 C0")
coroutine.yield()
ResetAxes()
end)

Screen load script
Code: [Select]
----------------------------------------------------------------------
--SQUARE SETUP FUNCTION--
----------------------------------------------------------------------
function SquareAxesSetup()
local inst = mc.mcGetInstance();
mc.mcCntlConfigStart(inst);
mc.mcAxisUnmapMotor(inst,0,0);
mc.mcAxisMapMotor(inst,5,0);
mc.mcAxisRegister(inst,5);
mc.mcAxisEnable(inst,5,1);
mc.mcProfileSave (inst);
mc.mcCntlConfigStop(inst);
mc.mcCntlSetLastError(inst,"Axes set to squaring mode");

end


----------------------------------------------------------------------
--RESETAXES FUNCTION--
----------------------------------------------------------------------
function ResetAxes()
local inst = mc.mcGetInstance();
mc.mcCntlConfigStart(inst);
mc.mcAxisUnmapMotor(inst,5,0);
mc.mcAxisMapMotor(inst,0,0);
mc.mcAxisRegister(inst,0);
mc.mcAxisEnable(inst,0,1);
mc.mcAxisEnable(inst,5,0);
mc.mcProfileSave (inst);
--mc.mcProfileReload(inst);
mc.mcCntlConfigStop(inst);
mc.mcCntlSetLastError(inst,"Axes set normal opperating mode");
end

PLC Script:
Code: [Select]
----------------------------------------------------------------------
--Yeild to reset Axes--
----------------------------------------------------------------------
if (AxesReset ~=nill) and (machState == 0) then
local state = coroutine.status(AxesReset)
if state =="suspended" then
coroutine.resume (AxesReset)
end
end

Here is the Log for the run.  As you can see, not every axis is enabled untill the 4th call of mc.mcCntlEnable:

Quote
2020-12-09 16:04:50.533 - API: mcCntlConfigStart(inst = 0) (Mach4GUI LUA script)
2020-12-09 16:04:50.533 - Attempt transition from "Idle" on event "Config" machapi.cpp:3673
2020-12-09 16:04:50.533 - S_IDLE_on_exit
2020-12-09 16:04:50.533 - ACTION_start_config
2020-12-09 16:04:50.533 - S_CONFIG_on_entry
2020-12-09 16:04:50.786 - API: mcCntlConfigStop(inst = 0) (Mach4GUI LUA script)
2020-12-09 16:04:50.786 - Attempt transition from "Config" on event "Stop Config" machapi.cpp:3687
2020-12-09 16:04:50.787 - S_CONFIG_on_exit
2020-12-09 16:04:50.787 - S_CONFIG_on_exit: Reloading config from profile.
2020-12-09 16:04:50.918 - Signal id 60, (Input #59), forced to LOW.
2020-12-09 16:04:50.920 - Signal id 61, (Input #60), forced to LOW.
2020-12-09 16:04:50.922 - Signal id 65, (Motor 0 Home), forced to LOW.
2020-12-09 16:04:50.923 - Signal id 66, (Motor 1 Home), forced to LOW.
2020-12-09 16:04:50.925 - Signal id 67, (Motor 2 Home), forced to LOW.
2020-12-09 16:04:50.954 - Signal id 1090, (Output #40), forced to LOW.
2020-12-09 16:04:50.980 - ACTION_stop_config
2020-12-09 16:04:50.980 - S_IDLE_on_entry
2020-12-09 16:04:50.990 - API: mcCntlEnable(inst = 0, TRUE) (Mach4GUI LUA script)
2020-12-09 16:04:50.993 - API: mcCntlEnable(inst = 0, TRUE) (Mach4GUI LUA script)
2020-12-09 16:04:50.993 - Signal id 1018, (Enable #0), changed from LOW to HIGH.
2020-12-09 16:04:50.995 - Signal id 1019, (Enable #1), changed from LOW to HIGH.
2020-12-09 16:04:50.995 - API: mcCntlEnable(inst = 0, TRUE) (Mach4GUI LUA script)
2020-12-09 16:04:50.997 - Signal id 1020, (Enable #2), changed from LOW to HIGH.
2020-12-09 16:04:50.997 - Signal id 1120, (Machine Enabled), changed from LOW to HIGH.
2020-12-09 16:04:50.998 - API: mcCntlEnable(inst = 0, TRUE) (Mach4GUI LUA script)
2020-12-09 16:04:50.999 - [NEURON] Mach enabled state has changed neuron.cpp:469
2020-12-09 16:04:51.001 - [NEURON] Mach enabled state has changed neuron.cpp:469
2020-12-09 16:04:51.002 - API: mcCntlEnable(inst = 0, TRUE) (Mach4GUI LUA script)
2020-12-09 16:04:51.004 - [NEURON] Mach enabled state has changed neuron.cpp:469
2020-12-09 16:04:51.004 - API: mcCntlEnable(inst = 0, TRUE) (Mach4GUI LUA script)
2020-12-09 16:04:51.005 - [NEURON] Mach enabled state has changed neuron.cpp:469
2020-12-09 16:04:51.007 - [NEURON] Mach enabled state has changed neuron.cpp:469
2020-12-09 16:04:51.008 - [NEURON] Mach enabled state has changed neuron.cpp:469
2020-12-09 16:04:51.013 - SoftSync()! Clearing planner. controller.cpp:5107
2020-12-09 16:04:51.079 - SoftSync()! Clearing planner. controller.cpp:5107
2020-12-09 16:04:51.111 - SoftSync()! Clearing planner. controller.cpp:5107
2020-12-09 16:04:51.121 - SoftSync()! Clearing planner. controller.cpp:5107
2020-12-09 16:04:51.129 - SoftSync()! Clearing planner. controller.cpp:5107
2020-12-09 16:04:51.139 - SoftSync()! Clearing planner. controller.cpp:5107
2020-12-09 16:04:52.392 - API: mcCntlGcodeExecute(inst = 0, commands = 'G91 G28.1 X0 Y0 C0') (Mach4GUI LUA script)
2020-12-09 16:04:52.598 - Attempt transition from "Idle" on event "MDI Start" controller.cpp:2256
2020-12-09 16:04:52.598 - S_IDLE_on_exit
2020-12-09 16:04:52.598 - ACTION_start_mdi
2020-12-09 16:04:52.598 - SoftSync()! Clearing planner.
2020-12-09 16:04:52.620 - S_MDI_RUNNING_on_entry
2020-12-09 16:04:52.620 - SoftSync()! Clearing planner. stateinterface.cpp:1250
2020-12-09 16:04:52.621 - S_MDI_RUNNING2_on_entry
2020-12-09 16:04:52.624 - Signal id 1114, (Gcode Running), changed from LOW to HIGH.
2020-12-09 16:04:52.640 - AxisHome(): Axis 5 is already homing.
2020-12-09 16:04:52.640 - Waiting on home operation(s).
2020-12-09 16:04:52.641 - Attempt transition from "MDI Running" on event "Home" command.cpp:1006
2020-12-09 16:04:52.641 - S_MDI_RUNNING2_on_exit
2020-12-09 16:04:52.641 - Signal id 1114, (Gcode Running), changed from HIGH to LOW.
2020-12-09 16:04:52.641 - Attempt transition from "MDI Running" on event "Home" command.cpp:1006
2020-12-09 16:04:52.643 - ACION_start_homing
2020-12-09 16:04:52.643 - S_MDI_HOMING_on_entry
2020-12-09 16:04:53.024 - [NEURON] (Delayed) Enabling the Neuron controller neuron.h:867

Pages: 1