Hello Guest it is January 20, 2020, 01:46:54 PM

Author Topic: How to process analog inputs  (Read 106 times)

0 Members and 1 Guest are viewing this topic.

How to process analog inputs
« on: November 28, 2019, 06:40:17 PM »
Hi,

I have some analog inputs (potentiometers) which are supposed to control the feed and spindle rate. How would one script that in Mach 4? What would be the proper way to access analog values? There does not seem to be any analog input related page in the configuration menu. My controller is a CSMIO which comes with analog inputs.

I already have tried the awesome lua features in Mach 4 to program my toolchanger. But this consist of mainly boolean IO operations.

Best regards

brandon

Re: How to process analog inputs
« Reply #1 on: November 28, 2019, 07:57:57 PM »
Hi,
Mach cannot in itself handle analogue values, the motion controller can.

If the CSMIO works similarly to other controllers the analogue value is converted to a digital number and that number is stored
in a register within Mach, but the register is 'owned' by the CSMIO plugin.

Consult the CSMIO plugin documentation and you should be able to find the name and path of the register used.

Craig
My wife left with my best friend...
     and I miss him!
Re: How to process analog inputs
« Reply #2 on: November 28, 2019, 08:58:13 PM »
Thanks for your help Craig,

What you say makes sense. But i cannot find any mention of registers in the manual of the controller.

Is there somehow a way to list all registers in Mach? Maybe I can spot the CSMIO Registers then.

Best regards

Brandon
Re: How to process analog inputs
« Reply #3 on: November 28, 2019, 09:33:07 PM »
Hi,

Quote
Is there somehow a way to list all registers in Mach? Maybe I can spot the CSMIO Registers then.

Yes, with Mach4 open click the <Diagnostics> tab, select Regfile and that will display ALL of  Machs registers.

Craig
My wife left with my best friend...
     and I miss him!
Re: How to process analog inputs
« Reply #4 on: November 28, 2019, 11:09:08 PM »
Awesome. Thank you very much Craig.

It works now. The analog values are being picked up and stored to the properties of Mach 4. I use the following code to set the jog rate:

Code: [Select]
local hReg, rc, val;
hReg, rc = mc.mcRegGetHandle(inst, "CSMIO-IP/Analog Input 0");
val, rc = mc.mcRegGetValue(hReg);

-- covert 0..10 V to 0..100 %
val = val * 10.0;

mc.mcJogSetRate(inst, mc.X_AXIS, val);
mc.mcJogSetRate(inst, mc.Y_AXIS, val);
mc.mcJogSetRate(inst, mc.Z_AXIS, val);
mc.mcJogSetRate(inst, mc.A_AXIS, val);
mc.mcJogSetRate(inst, mc.B_AXIS, val);
mc.mcJogSetRate(inst, mc.C_AXIS, val);

scr.SetProperty("droJogRate", "Value", string.format (val))

Best regards

Brandon