Hello Guest it is April 24, 2024, 08:08:13 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.


Topics - rhtuttle

Pages: « 1 2 3 4 5 6 7 8 9 »
71
Mach4 General Discussion / Lua Macro Parameters
« on: February 24, 2017, 12:10:04 PM »
The following code compiles and executes in the script editor.  After it executes the editor I get a message saying the editor has failed and is closed yet it is open.  hParam is always 'error' when run in the editor.  When I try to run in Mach4 mdi 'm6690 D.9' the last error line says 'Do MDI 1' and nothing happens.  What am I doing wrong and how do you track down/test this?

Code: [Select]
--Reel Seat Insert
--Turn from current Z down to 0 from current X down to parameter D or .850

function m6690(hParam)
  local xNow,zNow,maxVal
  local TS,TR,TT --timer values Mach3 niy
  local plungeFeed=6
  local roughDOC=0.015
  local roughFeed=15
  local roughSpeed=900
  local finishDOC=0.004
  local finishFeed=8
  local finishSpeed=1400
  local inst=mc.mcGetInstance()
  local endX=.850 --param1()
 
  local inst=mc.mcGetInstance()

  mc.mcCntlSetLastError(inst,'')

  if (hParam ~= nil) then
    local DFlag = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_D)
    if(DFlag == 1) then
      endX = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_D)
    end
  end

  xNow = mc.mcAxisGetPos(inst,0)
  zNow = mc.mcAxisGetPos(inst,2)
  if xNow<=endX then
    wx.wxMessageBox("start X is less than end Diameter of "..tostring(endX))
    return
  end
  if zNow<=0 then
    wx.wxMessageBox("start Z is less than or = to 0")
    return
  end
  --ts=Timer
 
--rough cuts 
  mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(roughSpeed))
  while (mc.mcAxisGetPos(inst,0)>(endX+finishDOC*2)) do
    currPos=mc.mcAxisGetPos(inst,0)
    maxVal=math.max(endX+2*finishDOC,currPos)
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(maxVal-roughDOC))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z0")
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    currPos=mc.mcAxisGetPos(inst,0)
    maxVal=math.max(endX+2*finishDOC,currPos)
    if currPos==endX+2*finishDOC then
      break
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(math.max(endX+2*finishDOC,currPos-roughDOC)))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z"..tostring(zNow))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end 
    if currPos==endX+2*finishDOC then
      break
    end 
  end
  -- tr=Timer-ts
  --wx.wxMessageBox("Roughing Time: "..tostring(tr))

  --finish cuts
  mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(finishSpeed))

  while (mc.mcAxisGetPos(inst,0)>=(endX+finishDOC)) do
    currPos=mc.mcAxisGetPos(inst,0)
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(currPos-finishDOC))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z0")
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
        return
    end
    currPos=mc.mcAxisGetPos(inst,0)
    if currPos==endX then
      break
    end 
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(currPos-finishDOC))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z"..tostring(zNow))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    currPos=mc.mcAxisGetPos(inst,0)
    if currPos==endX then
      break
    end 
  end
  mc.mcCntlGcodeExecuteWait(inst,"M5\nM9")
--te=Timer-ts
--wx.wxMessageBox("Roughing Time: "..tostring(tr).." - Total Time: "..tostring(te))
end
 
if (mc.mcInEditor() == 1) then
    m6690()
end   

Thanks for any help,

RT

72
Mach4 General Discussion / Simulate Probe Strike
« on: February 20, 2017, 03:48:47 PM »
I am converting my Mach3 lathe probe script to Mach4.  I want to simulate a probe strike as I rewrite this.

I have tried adding a button to the screen and writing scripts for the down and up key presses to change the state to on and off.  My code is:

local inst=mc.mcGetInstance()
local hSig=mc.mcSignalGetHandle(inst,ISIG_PROBE)
       mc.mcSignalSetState(hSig,1)


and

local inst=mc.mcGetInstance()
local hSig=mc.mcSignalGetHandle(inst,ISIG_PROBE)
       mc.mcSignalSetState(hSig,0)

What should I be doing since this doesn't work? 

TIA

RT

RT



73
Thought I would throw out an example of how to connect and utilize Mach4's Mach4IPC.dll  This dll contains all of the listed APIs.  This example only has a few of those listed.  Enough to demonstrate

This code would be used by any application:

Code: [Select]
unit Mach4DllWrapper;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes;

  //define each function that you might call
  type TmcIpcInit = function(ipAddr: pChar):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  type TmcGetInstance = function:integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  type TmcIpcCleanup = function:integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  type TmcRegGetValue =  function( hReg:integer;value:pdouble):integer ;{$IFDEF WIN32} stdcall; {$ENDIF}
  type TmcCntlLoadGcodeFile = function(mInst:integer;FileToLoad:pChar):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcCntlCloseGCodeFile = function(mInst:integer):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcCntlRewindFile = function(mInst:integer):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  type TmcCntlEStop = function( mInst:integer):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcCntlEnable =function( mInst:integer;State:Boolean):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  type TmcCntlReset = function( mInst:integer):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcAxisGetPos = function( mInst:integer; axisId:integer; val:pdouble):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcAxisSetPos = function( mInst:integer; axisId:integer; val:pdouble):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcCntlCycleStart = function(mInst:integer):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcCntlCycleStop = function(mInst:integer):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcCntlGcodeExecuteWait = function(mInst:integer;commands:pChar):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcAxisHome = function( mInst:integer; axisId:integer):integer;{$IFDEF WIN32} stdcall; {$ENDIF}
  Type TmcAxisIsHomed = function( mInst:integer;axisId:integer;homed:pBoolean):integer;{$IFDEF WIN32} stdcall; {$ENDIF}

type TMach4Control=class(TObject)
  private
    fLoaded    : Boolean;
    fConnected : Boolean;
  public
    mcIpcInit          :TmcIpcInit;
    mcGetInstance      :TmcGetInstance;
    mcIpcCleanup       :TmcIpcCleanup;
    mcCntlEStop        :TmcCntlEStop;
    mcCntlEnable       :TmcCntlEnable;
    mcCntlReset        :TmcCntlReset;
    mcRegGetValue      :TmcRegGetValue;
    mcCntlLoadGcodeFile:TmcCntlLoadGcodeFile;
    mcCntlCloseGcodeFile:TmcCntlCloseGcodeFile;
    mcCntlRewindFile   :TmcCntlRewindFile;
    mcAxisGetPos       :TmcAxisGetPos;
    mcAxisSetPos       :TmcAxisSetPos;
    mcCntlCycleStart   :TmcCntlCycleStart;
    mcCntlCycleStop    :TmcCntlCycleStop;
    mcCntlGcodeExecuteWait:TmcCntlGcodeExecuteWait;
    mcAxisHome        :TmcAxisHome;
    mcAxisIsHomed     :TmcAxisIsHomed;

    Handle             :Thandle;
    mInst              :Integer;
    property Loaded    :Boolean read fLoaded write fLoaded;
    property Connected :Boolean read fConnected write fConnected;

    function init(dllLoc:pChar):Boolean;
    procedure doConnect(myIP:pChar);
    procedure cleanUp;
    constructor create;
end;

function ErrGetProcAddress(h:THandle;procName:pAnsiChar):FARPROC;

type handle = Integer;


implementation

function ErrGetProcAddress(h:THandle;procName:pAnsiChar):FARPROC;
begin
  result:=getProcAddress(h,procName);
  if not assigned(result) then
    raise exception.Create('DLL does not contain function: '+ProcName);
    // usually a typo in the function name if failed
end;

constructor TMach4Control.create;
begin
  inherited;
end;

function TMach4Control.init(dllLoc:pChar):Boolean;
begin
  //get the address of each function in the dll
  Handle := LoadLibrary(dllLoc);//'c:\Mach4Hobby\mach4IPC.dll');
  Loaded:= Handle <> 0 ;
  mcIpcInit:=ErrGetProcAddress(handle,'mcIpcInit');
  mcIpcCleanup:=ErrGetProcAddress(handle,'mcIpcCleanup');
  mcCntlEStop:=ErrGetProcAddress(handle,'mcCntlEStop');
  mcCntlEnable:=ErrGetProcAddress(handle,'mcCntlEnable');
  mcCntlReset:=ErrGetProcAddress(handle,'mcCntlReset');
  mcCntlLoadGcodeFile:=ErrGetProcAddress(handle,'mcCntlLoadGcodeFile');
  mcCntlCloseGcodeFile:=ErrGetProcAddress(handle,'mcCntlCloseGCodeFile');
  mcCntlRewindFile:=ErrGetProcAddress(handle,'mcCntlRewindFile');
  mcAxisGetPos:=ErrGetProcAddress(handle,'mcAxisGetPos');
  mcAxisSetPos:=ErrGetProcAddress(handle,'mcAxisSetPos');
  mcCntlCycleStart:=ErrGetProcAddress(handle,'mcCntlCycleStart');
  mcCntlCycleStop:=ErrGetProcAddress(handle,'mcCntlCycleStop');
  mcCntlGcodeExecuteWait:=ErrGetProcAddress(handle,'mcCntlGcodeExecuteWait');
  mcAxisHome:=ErrGetProcAddress(handle,'mcAxisHome');
  mcAxisIsHomed:=ErrGetProcAddress(handle,'mcAxisIsHomed');
end;

procedure TMach4Control.doConnect(myIP:pChar);
begin
  // connect to a running of Mach4
  if @mcIpcInit <> nil then
  begin
    mInst:=mcIpcInit(myIP);
    Connected:=(mInst=0);
  end;
end;

procedure TMach4Control.cleanUp;
begin
   if @mcIpcCleanup <> nil then
        mcIpcCleanup;
end;

end.


This code is for the application shown in the jpg

Code: [Select]
unit frmMach4AccessMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, JvExStdCtrls, JvEdit, JvValidateEdit, Mask,
  JvExMask, JvToolEdit, JvExControls, JvSpeedButton, TILed,
  MachLed, ExtCtrls,  Mach4DllWrapper;


type
  TForm1 = class(TForm)
    btnLoadFile: TButton;
    stat1: TStatusBar;
    btnEnable: TButton;
    btnCycleStart: TButton;
    btnCycleStop: TButton;
    btnRewind: TButton;
    btnCloseFile: TButton;
    btnMDIexecute: TButton;
    mmo1: TMemo;
    eGCodeFile: TJvFilenameEdit;
    pnl1: TPanel;
    lbl1: TLabel;
    eXdro: TJvValidateEdit;
    btnZeroXdro: TJvSpeedButton;
    btnXhome: TJvSpeedButton;
    MachLedxDro: tMachLed;
    MachLed2: tMachLed;
    pnl2: TPanel;
    lbl3: TLabel;
    btnZeroZdro: TJvSpeedButton;
    btnZhome: TJvSpeedButton;
    MachLedZdro: tMachLed;
    MachLed5: tMachLed;
    eZdro: TJvValidateEdit;
    procedure btnLoadFileClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure btnEnableClick(Sender: TObject);
    procedure btnCycleStartClick(Sender: TObject);
    procedure btnCycleStopClick(Sender: TObject);
    procedure btnCloseFileClick(Sender: TObject);
    procedure btnRewindClick(Sender: TObject);
    procedure btnMDIexecuteClick(Sender: TObject);
    procedure btnZeroXdroClick(Sender: TObject);
    procedure btnXhomeClick(Sender: TObject);
    procedure btnZhomeClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form1: TForm1;
  myIP: string = '127.0.0.1';
  dllLocation: string = 'c:\Mach4Hobby\mach4IPC.dll';
  mc:TMach4Control;

implementation

{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
var
  d:Double;
  homed:boolean;
begin
   mc:=TMach4Control.create;
   mc.init(pChar(DllLocation));      //load the dll and find the function locations
   if mc.Loaded then
   begin
     stat1.Panels[0].Text:='Loaded';  //Status: successfully Loaded
     btnLoadFile.Enabled:=mc.Loaded;  //determine whoter to enable or not
     btnEnable.Enabled:=mc.Loaded;    //determine whoter to enable or not
   end else
   begin
     stat1.Panels[0].Text:='Load Failure';
     exit;
   end;
   stat1.Panels[1].Text:='Connecting...';
   application.ProcessMessages;
  if mc=nil then
    exit;
  if mc.Connected then
    exit;
  mc.doConnect(pChar(myIP));    //connect to a running Mach4 instance
  if mc.Connected then
    stat1.Panels[1].Text:='Connected to Mach4'
  else
    stat1.Panels[1].Text:='Failed to Connect';
  application.ProcessMessages;
  mc.mcAxisGetPos(mc.mInst,0,@d);  //get the Xdro position-need to write a thread to update
  eXdro.Value:=d;
  mc.mcAxisGetPos(mc.mInst,2,@d);  //get the Zdro position-need to write a thread to update
  eZdro.Value:=d;
  mc.mcAxisIsHomed(mc.mInst,0,@homed);
  if homed then
    MachLedxDro.Color:=clGreen
  else
    MachLedxDro.Color:=clMaroon;
  mc.mcAxisIsHomed(mc.mInst,2,@homed);
  if homed then
    MachLedzDro.Color:=clGreen
  else
    MachLedzDro.Color:=clMaroon;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//clean up before exiting
  if mc<>nil then
    mc.mcIpcCleanup;
  freeLibrary(mc.Handle);
end;

procedure TForm1.btnLoadFileClick(Sender: TObject);
var
  i:integer;
  s:string;
begin
  //load GCodeFile listed in edit control
    stat1.Panels[2].Text:='Loading GCode file';
    application.ProcessMessages;
    s:=eGcodeFile.FileName;
    i:=mc.mcCntlLoadGcodeFile(mc.mInst,pChar(eGcodeFile.filename));
    stat1.Panels[2].Text:='Return Code: '+intToStr(i);
end;

procedure TForm1.btnEnableClick(Sender: TObject);
begin
  //code to enable and disable Mach and update button state
  if  btnEnable.Caption='&Enable' then
  begin
    mc.mcCntlEnable(mc.mInst,True);
    btnEnable.Caption:='&Disable';
  end else
  begin
    mc.mcCntlEStop(mc.mInst);
    btnEnable.Caption:='&Enable';
  end;
  btnCycleStart.Enabled:=btnEnable.Caption<>'&Enable';
  btnCycleStop.Enabled:=btnEnable.Caption<>'&Enable';
end;

procedure TForm1.btnCycleStartClick(Sender: TObject);
begin
  mc.mcCntlCycleStart(mc.mInst);
  btnCycleStop.SetFocus;
end;

procedure TForm1.btnCycleStopClick(Sender: TObject);
begin
  mc.mcCntlCycleStop(mc.mInst);
end;

procedure TForm1.btnCloseFileClick(Sender: TObject);
begin
  mc.mcCntlCloseGcodeFile(mc.mInst);
  mc.mcCntlRewindFile(mc.mInst);//close file doesnt clear gcode window
end;

procedure TForm1.btnRewindClick(Sender: TObject);
begin
  mc.mcCntlRewindFile(mc.mInst);
end;

procedure TForm1.btnMDIexecuteClick(Sender: TObject);
begin
  //execute gcode in the momo component
  mc.mcCntlGcodeExecuteWait(mc.mInst,pChar(mmo1.Text));
end;

procedure TForm1.btnZeroXdroClick(Sender: TObject);
var
  d:double;
begin
  d:=0;
  mc.mcAxisSetPos(mc.mInst,0,@d);
end;

procedure TForm1.btnXhomeClick(Sender: TObject);
begin
  if mc.mcAxisHome(mc.mInst,0)=0 then
    MachLedxDro.color:=clGreen;
end;

procedure TForm1.btnZhomeClick(Sender: TObject);
begin
  if mc.mcAxisHome(mc.mInst,2)=0 then
    MachLedxDro.color:=clGreen;
end;

end.


Hope this saves someone some time.


RT


74
Mach4 General Discussion / Change in Value Event
« on: February 15, 2017, 11:55:46 AM »
How would you go about capturing a change in the current jog increment?

TIA

RT

75
Mach4 General Discussion / Connecting to Mach4
« on: February 05, 2017, 04:39:51 PM »
Does anyone have an example of an application connecting to Mach4?  Like telling Mach4 to load a gcode file?

TIA

RT

76
General Mach Discussion / I/O card help
« on: February 05, 2017, 04:13:05 PM »
I am electronically challenged so please be kind.

I bought a CNC control box several years ago for my DIY gantry style mill. It has a smooth stepper, soundLogic combo board and a FP-48 I/O board controlled by Mach3. The SoundLogic board inputs are totally used and connects to the Smooth Stepper port 1. I have attached a picture of the FP48 card. The db25 cable goes to port2 of the smooth stepper and the Q0 and Q1 control relays to my water pump and dust collector and work well. The two wires on the bottom right I believe are pulse width management wires to another card that sends signals to my VFD.

I want to hook up a probe for touch off. I have connected to I0 (lower right hand corner) a red an black wire. When I put a voltmeter on they register nothing. When I test for continuity it stays at 1. Can anyone tell my how I should be wiring this? Do I need jumper pins in J3 or J4 or ? I have asked the person who put this together but he has no clue what to do even though the box has worked flawlessly for several years and is well put together. Like I said I am an electronic idiot.

TIA

RT

77
General Mach Discussion / Lathe question
« on: February 03, 2017, 11:14:32 AM »

I was looking at Soctt's threading wizard since I now have a need to do a ½-13 left handed internal thread.  Seems like it is what I am looking for, but, as I was reading the readme file he made the comment that If you swapped the start and end points you could do reverse threading.  Not being an experienced machinist I somehow imagined that this produces the same result as left handed threading.  What/is there a difference between reverse and left hand threading?

Thanks,

Ralph Tuttle

78
General Mach Discussion / Auto stop on spindle overload.
« on: January 09, 2017, 04:59:55 PM »
Sometimes on my lathe I get a little over aggressive on my cuts and overload the spindle in which case the board trips and the spindle stops.  When that does happen a light bulb is lit and I have to manually flip the spindle direction off and on.  All good except that Mach doesn't know that the spindle stopped and continues to go merrily on its way with the rest of the GCode.  Ouch!

Query, I'm sure that I can wire to capture when that light is lit and use it as a signal to EStop Mach.  I assume that is the correct way to stop movement as quickly as possible.  But, since I have a tach, I was wondering though if I could use a brain that checked if the spindle was supposed to be turning and if wasn't, issue an EStop?  Thoughts?  Other ideas?

TIA

RT

79
General Mach Discussion / Requested spindle speed versus actual
« on: January 09, 2017, 04:48:48 PM »
Well, I finally got my spindle tach installed and sending Mach3 speeds throughout my spindle range, nice!  My setup:

Seig 7x14
Gecko 540
UC100
Mach3

Silly me, I thought that when I got that done that Mach would automatically increase/decrease voltage to the motor to get the actual to match the requested speed.  My setup doesn't. 

I have a couple of questions now that I have an accurate spindle speed but I will post each in its own message.

First one, is it just my spindle board or is that the way Mach3 is designed to work, ask for a speed and then you can observe what your machine actually spins at and you request/ adjust to get what you really desire?  If it is supposed to auto adjust what spindle/other boards do you use or recommend?

TIA

RT

80
General Mach Discussion / Spindle Speed Sensor Wiring
« on: January 04, 2017, 11:13:00 AM »
I need help wiring an optical sensor for spindle feedback. I am
electrically challenged so any help is greatly appreciated. My setup:

Mach3

UC100

Gecko G540

FC-03 sensor -


http://qqtrading.com.my/motor-rpm-speed-counter-sensor-module-fc-03

I have a 5 volt 1200ma wall wart.

I have connected the 5v power supply to the VCC and Gnd pins. Both the red
and green LED's light and when I break the sensor the green LED goes out, so
it seems it is powered. If I put a volt meter to the DO and Gnd pin and
break the sensor I get 5.5 volts.

I thought all I had to do is connect a wire from the DO pin to the Gecko
input pin(12 for this, third connector on the Gecko), set the ports and pins
to 1,12, enable and should be able to get the signal. No Joy. No
indication that the UC100 or Mach3 is receiving any signal. I have check
the continuity of the wiring and it is good.

I have pin 10 set for probe, pin 11 set for limits and these work well. If I connect the probe
to pin 12 it does register both through the UC100 and in Mach3 so I believe it is
not a problem with either of those. I have also tried connecting the sensor
on pin 10 and it does not register on that pin either.

I have to be doing something wrong with the wiring. I thought using the
wall wart was the easiest way to go since the Gecko has 11 volts.

What am I missing?

Pages: « 1 2 3 4 5 6 7 8 9 »