Hello Guest it is March 07, 2021, 07:08:17 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 - Dusty91

Pages: 1
1
Mach4 General Discussion / Re: Mach4 MQTT Client
« on: January 11, 2019, 07:56:28 PM »
I was able to get Mach to respond to incoming messages. Here is what worked for me.
Pretty much just a copy of what has already been posted.

Add mqtt_library.lua and utility.lua to modules folder in Mach4 directory.
Edit the mqtt_library, search for the following lines, and replace as shown:
Code: [Select]
if (return_code <= table.getn(MQTT.CONACK.error_message)) then     ----->     if (return_code <= #MQTT.CONACK.error_message) then

local topic_count = table.getn(outstanding[2])     ----->     local topic_count = #outstanding[2]

Added the following to the end of the Screen Load Script:
Code: [Select]
---------------------------------------------------------------
--MQTT module
package.loaded.MqttModul = nil
mqtt = require "mqtt_library"

--Socket module
package.loaded.socket = nil
socket = require "socket"
---------------------------------------------------------------


function mqttCallback(
  topic,    -- string
  message)  -- string
  mc.mcCntlSetLastError(inst,"".. topic ..": ".. message .."")   --Example,   Node-Red: Cycle Stop
end

function SendMessage(msg)
    mc.mcCntlSetLastError(inst, msg);
    mqtt_client:publish("Mach4",msg)
end

function MQTT_Connect()
    mqtt_client = mqtt.client.create("192.168.1.44", nil, mqttCallback)
    mqtt_client:connect("mach4")
    mqtt_client:publish("mach4", "online")
    mqtt_client:subscribe({"Node-Red"})

    mqtt.Utility.set_debug(true)
end

MQTT_Connect()

Added this line to plc script.
Code: [Select]
mqtt_client:handler()

To test sending a message to Node-red I changed the CycleStop function in the Screen Load Script as shown below.
This publishes "Cycle Stopped" when the Stop button is pressed in Mach.
Code: [Select]
---------------------------------------------------------------
-- Cycle Stop function.
---------------------------------------------------------------
function CycleStop()
    mc.mcCntlCycleStop(inst);
    mc.mcSpindleSetDirection(inst, 0);
    mc.mcCntlSetLastError(inst, "Cycle Stopped");
    msg = "Cylce Stopped";
    SendMessage(msg)
end

To test sending a message/command to Mach from Node-Red I added the following to the plc script.
This pulls the incoming message from the LastError dro. Then using the conditional statement it will stop or start the machine depending on the received message.
Code: [Select]
local last_error = mc.mcCntlGetLastError(inst);

if (last_error == 'Node-Red: Cycle Stop') then

CycleStop()

elseif (last_error == 'Node-Red: Cycle Start') then

CycleStart()

end

Hope this helps.

-Dustin

2
Happy to help. I use one of these and have been pleased with the performance. Plus it has an overtravel switch that I programmed to the E-stop in case the probing portion doesn't register.
https://www.amazon.com/Automatic-Normally-Blowing-Setting-Presetter/dp/B01MYGDU3K/ref=sr_1_46?ie=UTF8&qid=1546371798&sr=8-46&keywords=cnc+tool+probe

3
My script is a little different but may be suitable for your needs. This does not have the manual positioning and makes use of spring plunger type tool probe. If you have a rigid tool probe then you will need to reduce the fast probe speed to avoid tool damage due to overtravel. I've added some comments to the code to describe the various lines.
This method keeps all the values of the tool table at zero. This means you are less likely to have issues when you set Z0 on a new part and forget to zero the table before hand or forget to enable tool length compensation.

Code: [Select]
function m6()

    local inst = mc.mcGetInstance();
    local selectedtool = mc.mcToolGetSelected(inst) --Variable for selected tool #
    local currenttool = mc.mcToolGetCurrent(inst) --Variable for current tool #

    if selectedtool == currenttool then --Compare tool numbers to see if tool change is required
    return
    mc.mcCntlSetLastError(inst, "Tool Change Not Required")
else
    mc.mcCntlGcodeExecuteWait(inst, "G00")
    mc.mcCntlGcodeExecuteWait(inst, "G49") --Cancel tool length compensation if active
    mc.mcCntlGcodeExecuteWait(inst, "G91 G28 G0 Z0") --Raises Z-axis to home position
    mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X1.8810 Y25.2330")         --Goes to probe postion in machine coordinates
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-7.0 F20") --Probes current tool at fast speed
mc.mcCntlGcodeExecuteWait(inst, "G91 G0 Z+0.1") --Retract from the probe
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-0.15 F1") --Probes at slow speed
local measure_1 = mc.mcAxisGetPos(inst,2) --Saves probed Z position

mc.mcCntlGcodeExecuteWait(inst, "G91 G0 Z+0.1") --Retracts from the probe
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-0.15 F1") --Probes at slow speed
local measure_2 = mc.mcAxisGetPos(inst,2) --Saves probed Z position

local measured_average = (measure_1 + measure_2)/2 --Averages two probed values

mc.mcCntlGcodeExecuteWait(inst, "G00")
    mc.mcCntlGcodeExecuteWait(inst, "G91 G28 G0 Z0") --Raises Z-axis to home position
mc.mcCntlGcodeExecuteWait(inst, "G91 G28 G0 X0 Y0") --Send spindle to XY home position

wx.wxMessageBox("Change to Tool "..selectedtool.." and Press OK to Continue") --Prompt to change tool. Press OK only after tool has been exchanged.

mc.mcCntlGcodeExecuteWait(inst, "G00")
    mc.mcCntlGcodeExecuteWait(inst, "G49") --Cancel tool length compensation if active
    mc.mcCntlGcodeExecuteWait(inst, "G91 G28 G0 Z0") --Raises Z-axis to home position
    mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X1.8810 Y25.2330")         --Goes to probe postion in machine coordinates
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-7.0 F20") --Probes new tool at fast speed

mc.mcCntlGcodeExecuteWait(inst, "G91 G0 Z+0.1") --Retracts from the probe
mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-0.15 F1") --Probes at slow speed
mc.mcAxisSetPos(inst,2,measured_average) --Sets current Z postion to saved position from previous tool

mc.mcCntlGcodeExecuteWait(inst, "G00")
mc.mcCntlGcodeExecuteWait(inst, "G91 G28 G0 Z0") --Raises Z-axis to home position
mc.mcToolSetCurrent(inst, selectedtool) --Update current tool DRO
mc.mcCntlGcodeExecuteWait(inst, "G90") --Switch back to absolute mode
mc.mcCntlSetLastError(inst, "Tool Change Complete")

--mc.mcCntlToolChangeManual(inst, true); --Uncomment to require Cycle Start press to resume G-code
    end
   
end

if (mc.mcInEditor() == 1) then
 m6()
end

4
Hey Tom,

Glad to here you got it working.

Unrelated question. Assuming your fourth motor is not for a fourth axis, how did you go about tuning the slave motor? I've been considering upgrading to a dual drive for my X but was not sure how the tuning portion worked.

Thanks

5
Craig, Thanks, I will look into the c10. That would probably account for the occasional random stop. Enough to stop the machine but not enough to trigger any actual faults.

Tom, I just checked and the code does work without the SignalTable portion. Just use the following and change mc.ISIG_INPUT0 for whatever inputs you use.

-----
if (sig == mc.ISIG_INPUT0) and (state == 1) then
    local inst = mc.mcGetInstance()
    mc.mcCntlCycleStop(inst)
    mc.mcCntlSetLastError(inst, "HLFB Servo Error");
end
-----

Side note, from my experience if one of your motors trips you will have to disable and enable mach to restart the motor. And its best to re-home the machine afterward.

The pmdx-126 is connected to ports 1 and 2 of the ESS but only has 9 inputs. My home switches are wired separately so all axis can be homed at the same time. + limits are wired in series. Three auxiliary buttons, HLFB, and a touch probe for tool length. Plus a dedicated estop.

Dustin

6
Tom, I have the code in the signal script. Have a look at the screen editor manual in the docs folder or your Mach4 directory if you have some trouble finding it.

Craig, The code is in the signal script only. Nothing in the plc. I'm not sure if every line I posted is required. I pulled the code from page 12 and 13 of the scripting manual about three years ago. The SignalTable portion may be redundant.
Good point about the voltage. That is not something I considered. I am running three motors and checked the voltage to be 1.4V normal and 4.8v when tripped.
I currently have all the inputs saturated on the pmdx-126. Do you know any lone BoBs that can be hooked up the the third port of the ESS for expansion?

Dustin


7
Hi,

I am using clearpaths with pmdx-126 and ESS. I have the HLFB lines wired in series to a single input on the PMDX-126. The input I believe is configured as active high on ESS, red arrow up, and mapped to input 0 in mach.
The following code is used in the signal script of your screen set. The code just activates a cycle stop if the HLFB is tripped. I have had the HLFB trip quite a few times and the machine has always stopped as desired.


-------------------------
-- HLFB Error --
-------------------------
if (sig == mc.ISIG_INPUT0) and (state == 1) then
    local inst = mc.mcGetInstance()
    mc.mcCntlCycleStop(inst)
    mc.mcCntlSetLastError(inst, "HLFB Servo Error");
end

SignalTable = {
    [mc.ISIG_INPUT0] = function (on_off)
        if (on_off == 1) then
            mc.mcCntlCycleStop(inst)
            mc.mcCntlSetLastError(inst, "HLFB Servo Error");
        end
    end
}

8
Mach4 General Discussion / Re: Possible Feed Rate Bug?
« on: February 27, 2018, 06:13:50 PM »
Steve,

Thank you. Turns out that was the problem after all. I first noticed the discrepancy last year when I was designing a new screen set and just assumed, something about an a** out of you an me, the issue would translate to my actual motion controller so I reverted back to an older version of MACH.
I would check new versions as they were released but only with the simulator to see if the issue was resolved. So anyway I tried the latest development version on my machine last night and the current feed rate was correctly displayed.

Thanks for the assistance guys. I hope a I didn't waste too much of your time.

Dustin

9
Mach4 General Discussion / Re: Possible Feed Rate Bug?
« on: February 25, 2018, 12:32:33 PM »
Thank you for the feedback. I am still leaning toward this being a bug rather than a feature.

joeaverage: That would make sense with CV feed rate turned on and the machine slowed down for a corner. Though with CV on or off, if you MDI G1 X10 F100 the dro will show the machine running at 90 units/min.
                  It also doesnt matter what the feed rate is, it always returns 90%.

roaster: Not likely as that would change the spindle speed and not the feed rate. G96 vs G97. Also my tool table in MACH is blank and all tool comp is handled in CAM software.

smurph: Bug is present on completely stock install of MACH using simulator motion controller with zero third party plugins installed. I would see that as best case scenario so MACH should feedback exactly what was it was told.

totallyrc: Bug is only present on versions of MACH4 after 3233. All previous versions display the correct feed rate. Curious to learn what version you are running.

10
Mach4 General Discussion / Possible Feed Rate Bug?
« on: February 23, 2018, 11:32:32 PM »
I have been using MACH4 for quite some time now and noticed that the "Current Feed Rate" DRO displays 90% of the commanded feed rate. This potential error has been present in all versions following 3233, industrial also.
I am not sure if this is just a DRO issue or if the machine is actually only running at 90%. In case you ask, yes the feed rate slider is set to 100% and also using the simulator as motion controller to eliminate any plugin issue.

In September of last year I submitted a support ticket regarding this issue with no response. There also doesn't appear to be any other posts pointing out this potential bug.
I don't know for certain but it seems like this could be an issue for anyone out there rigid tapping, assuming this isn't just a DRO issue, causing desync between spindle speed an feed.

Has anybody else noticed this and is it an actual issue? Curious because I have been reluctant to move from version 3233.

Pages: 1