Hello Guest it is August 14, 2020, 08:04:29 PM

Author Topic: VB Coding help  (Read 2315 times)

0 Members and 1 Guest are viewing this topic.

VB Coding help
« on: April 02, 2014, 08:42:32 PM »
Hello all,

I have been using mach3 to run my lathe for 5 or 6 years now and love it.  I use the turn wizards provided and find them excellent.

Recently I decided to learn how to develop my own wizards.  I have set up screens in machscreen and all looks good.

I could use a bit of help with the (post GCODE) vb.
I have referenced some of the turn wizard code to learn.  I get the OEM DROs, the various math involved, the initial coding to setup the script, etc.

Where I get stuck is a few things,

1.) The  Pass_Num.  I guess this is "the pass number used for calculating how many passes there would be in an operation?"  I see it as Pass_Num = 1   Then see it in the math coding,,,,  (Xstart - Xend * Pass_Num)    etc.


2.) The "Openteachfile"  Can I type any name I want here, or does a file have to exist somewhere for it to reference?


Example of a simple wizard.

I have user input DROs as
ZSTART - start
ZEND - end
ZINC - increment
ZDwell - dwell time between movements

I want the user to be able to enter the ZSTART, ZEND and an increment to move along the way, (ZINC) along with a dwell time between each movement.

ZSTART = 0
ZEND = 1 meter
ZINC = .1 meter
ZDwell = 5 sec

Z would move from zero to 0.1, dwell for 5 sec, then move to 0.2, dwell, etc...

How would I write this simple code?

Thanks all for any help !!


Steve

 
TheDude,
Re: VB Coding help
« Reply #1 on: April 28, 2014, 03:00:55 PM »
this will do the move and dwell, all in lowercase, but that is just how i prefer to type, note dwell is in ms. there may be soem erros as i hav enot tested this but the logic is there to do it.

sub tap(byval zstart as double,byval zend as double,byval zinc as double,byval dwell as double,byval speed as double)
dim zpos as double
zpos = zstart

while zpos >= zend
code "g01 z " & zpos & " f " & speed
while IsMoving()
sleep(10)
wend
sleep(dwell)
if zpos = zend then
zpos = zend - 1
elseif zpos > zend then
zpos = zpos - zinc
if zpos <= zend then
zpos = zend
endif
endif
wend
Re: VB Coding help
« Reply #2 on: May 02, 2014, 10:13:55 PM »
Thanks for taking the time to write the code for me.
Although, I was hoping for a bit of advice, direction and explanations.  not just the code itself.

Is there a link to a document that explains the terminology of this code and how/why it is used?
I would like to learn the code.



sub tap(byval zstart as double,byval zend as double,byval zinc as double,byval dwell as double,byval speed as double)
dim zpos as double

zpos = zstart

while zpos >= zend
code "g01 z " & zpos & " f " & speed
while IsMoving()
sleep(10)
wend
sleep(dwell)
if zpos = zend then
zpos = zend - 1
elseif zpos > zend then
zpos = zpos - zinc
if zpos <= zend then
zpos = zend
endif
endif
wend

 

 
 
 
TheDude,
Re: VB Coding help
« Reply #3 on: May 05, 2014, 08:01:15 PM »
it is a bit of a dry read but thankfully [crtl]-F works in it.
http://www.machsupport.com/wp-content/uploads/2013/02/VBScript_Commands.pdf

Hope fully the comments explain a bit of what is going on here then. A single quote ' is the standard ascii character for comments in mach3 so ill use them for comments.  Hopefully the spaces make it a bit easier to read too.


sub tap(byval zstart as double,byval zend as double,byval zinc as double,byval dwell as double,byval speed as double) ' sub is asking for the start height, end height, the increment distance, dwell time and speed of movement to be given to it.

dim zpos as double ' i am defining a variable called zpos and the current z location so that i do not edit the variable i am given at the start
zpos = zstart ' set zpos to be zstart if zstart is too high up it will take a while so set it close to the material.

while zpos >= zend ' will continue the loop until the desired position is less than or equal to the end position
  code "g01 z " & zpos & " f " & speed ' Gcode to move to current z location at specified speed
  while IsMoving() ' IsMoving() is true while the cnc is in motion, it is needed since your dwell sleep would start as soon the movement starts if this was not blocking
    sleep(10) ' pause for small amount of time, you will acutlaly dwell there for your dwell time and an extra amount of time any where between 0 and 10ms
  wend
  sleep(dwell) ' your dwell time
  if zpos = zend then ' checks to see if it is at the final location, and if so it decrements it one more to make while loop stop
    zpos = zend - 1
  elseif zpos > zend then ' if zpos is still greater than zend
    zpos = zpos - zinc ' change zpos by the defined amount
    if zpos <= zend then ' check to see if zpos was decremented too far and if it was set it to the end value
      zpos = zend
    endif
  endif
wend

end sub