Hello Guest it is April 24, 2024, 05:30:29 PM

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.


Topics - pjcevallos@gmail.com

Pages: 1
1
Mach4 General Discussion / PLC script to write to a text file
« on: March 09, 2024, 08:37:05 PM »
Hi

I have been trying to debug a code without success for the PLC script (See below). I want to record X,Y,Z vs time in an external text file activated by an output that will start data acquisition of another hardware.

I can successfully monitor the values I want in registers. However, I get an error as soon as I want to use
Code: [Select]
file = io.open(MyFile, "a") --open the file in append mode,
--attempt to index a nil value (global 'file')
--strack traceback
-- in function 'Mach_PLC_script'


I can open, write, save, and close files in Macros, but that is inconvenient.

Does any one have any idea how to approach this problem or what I am doing wrong?


Code that is added to the PLC:




Code: [Select]
-------------------------------------------------------
--  position Data
-------------------------------------------------------
local val_x = mc.mcAxisGetPos(inst, mc.X_AXIS) -- get X position
local val_y= mc.mcAxisGetPos(inst, mc.Y_AXIS) -- get Y position
WriteRegister("X_pos",val_x) -- to monitor in register diagnostics ok
WriteRegister("Y_pos",val_y) -- to monitor in register diagnostics ok

local LoadCellSignal = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9 ) -- monitor output 9 activated by macro
local LoadCellSignalState = mc.mcSignalGetState(LoadCellSignal)

if (LoadCellSignalState == 1) then -- if output 9 is activated

local hregTime_LC = mc.mcRegGetHandle(inst, "iRegs0/Time_LC") -- get register Time_LC = 0
local LoadCellTime= mc.mcRegGetValue(hregTime_LC)

if (LoadCellTime==0) then
local Path = GetRegister(Layer_path) -- get File path from register
local MyFile = wx.wxGetCwd() .. Path -- define the file path in Mach4
file = io.open(MyFile, "a") -- open file in append mode
end


LoadCellTime = LoadCellTime+0.05 - follow PLC cycle time as sample rate
WriteRegister("Time_LC",LoadCellTime) --  monitor in register ok


local text = string.format ("%.4f, %.4f, %.4f \n", val_x, val_y, LoadCellTime );
file:write (text ) --Write the Gcode file
file:flush (MyFile) --Save written data
file:close (MyFile) --Close file
end


2
Mach4 General Discussion / Homing for Absolute Encoders
« on: November 12, 2023, 06:03:38 AM »
Hi

Following this thread, https://www.machsupport.com/forum/index.php?topic=47822.0

I wonder what is the procedure when you have absolute encoders for homing operation.

At the moment we do not home the machine as the absolute encoders remove the need for a physical limit switch.
In fact, the Origin is set as an offset. Whenever we need to go to "home", we put G53 x0 y0 z0, and it goes to place.

We have tried to "home in place" when the machine is in its origin, but it tries to move and makes a bad noise.

Just wondering if our approach is wrong. Maybe I am overthinking it.

kind regards

Pablo

3
Mach4 General Discussion / Read Register from a text file
« on: August 08, 2022, 06:51:35 PM »
Hi

Is it possible to read registers or variables from a text file using Lua scripts?

The idea is to overwrite the text file when needed while a gcode is running, and therefore change the registers/variables in the process but from the text file.

Hope you can help me

Pablo

4
Hi

Is there any way to enable an output when a specific axis is running?

For example for the X axis

G21 G90 X10 Y10 (output is enable)
G21 G90 Y15 (output is disable)

kind regards

Pablo


5
Hi

We need a piece of advice to see if an automated defect detection and correction program can run in Mach4. For example, our current gcode program has different sections such as:
Section 1 – Gcode blocks (lines 1-10)
Section 2 – Gcode blocks (lines 11-20)
Section 3 - Gcode blocks (lines 21-30)
Etc.

Defect Scanning
To implement the defect detection, we can easily insert a block that activates and output (M64 p#) and waits a specific time to do a scanning (G4 P#). It is just moving the piece below the camera and scanning. Easy. The new program should be written as:
Section 1 – Gcode blocks (lines 1-11)
Subsection 1 – gcode block for defect detection
Section 2 – Gcode blocks (lines 12-21)
Subsection 1 – gcode block for defect detection
Section 3 - Gcode blocks (lines 22-32)
   Subsection 1 – gcode block for defect detection
Etc.

Defect detection and correction
Then, the post-processing of the image will be done in another software (python, Matlab, etc). It will detect if there is an error, and here is our problem, How do we inform Mach4 there is an error and how to correct it.
Problem 1. How do we inform mach4 there is an error? 
I think it will be easy to write on the signal script to actively search for a digital input to STOP the program. This is something similar than having a limit switch. We are using soft limits because we have absolute encoders, and the systems works perfectly with that. Can we use a limit axis input if the soft limits are active? I think this would be the fastest solution. However, if a limit switch is activated, it disables mach4 rather than stopping the program, and restart the program from a different gcode line, which is the stated in the problem 2.

Problem 2. How to correct the defect.

Our strategy to correct the defect is “simple” as we only need to Re-Start the gcode program in a previous section decided by the external software. We can do it manually once we see the software indicates an error, but the idea is to automate it and eliminate human interaction. In the following program, the first phase corresponds to “defect detection and stopping the program”, and the second phase correspond to start the program in a previous fcode line commanded by the software as shown below:
(First phase: defect detection)
Section 1 – Gcode blocks (lines 1-11)
Subsection 1 – gcode block for defect detection
Section 2 – Gcode blocks (lines 12-21)
Subsection 1 – gcode block for defect detection
Section 3 - Gcode blocks (lines 22-32)
   Subsection 1 – gcode block for defect detection
(-comment: defect detected, digital input is activaded, program is stopped)
Section 4 - Gcode blocks (lines 33-42)
   Subsection 1 – gcode block for defect detection
Etc

(second phase: defect detection)
Section 1 – Gcode blocks (lines 1-11)
Subsection 1 – gcode block for defect detection
Section 2 – Gcode blocks (lines 12-21) – New start of the program
Subsection 1 – gcode block for defect detection
Section 3 - Gcode blocks (lines 22-32)
   Subsection 1 – gcode block for defect detection
Section 4 - Gcode blocks (lines 33-42)
   Subsection 1 – gcode block for defect detection
Etc

The question here is how we can tell mach4 to start the program at a specific line? Which communication to use? We are using an EtherCAT controller with several several GPIO, also we can have analog inputs and outputs. Maybe, there is another type of communication to inform mach4 which line to start in the program. I believe it shouldn’t be something that complicated, but not sure if mach4 can do it.

The second option is if the loading and running of a gcode program can be automated. Python, Matlab, etc then will chop the original program and upload the new one. is it possible?

What thoughts do you have? is it possible?

Kind regards


Pablo

6
Mach4 General Discussion / How to set up analog outputs in Mach4?
« on: February 07, 2022, 11:22:16 AM »
Hi everyone

The control tab in Mach4 allows using analog outputs, DIFFERENT from the analog output that controls the spindle. I have extra analog outputs 0-10V that I need to use to control other equipment.

Does anybody have experience setting them up, and then how to activate it and control it in Mach4?
Do I need to create a macro?

I am a newbie in Mach4 so any guidance is appreciated.

Best wishes

Pablo

Pages: 1