BASIC to G-Code

Description:

basictogcode allows advanced scripting of of RS274D g-code directly into EMC2 using BASIC (Beginner's All-Purpose Symbolic Instruction Code).

It allows you to draw geometric shapes programmatically.

Example:


import cnc
cnc.SAFEZ=1.2
cnc.header(120) rem 120ipm
FOR Z = 0 TO -1 STEP -0.1
	cnc.drawCircle(0,0,Z,1)
NEXT Z
cnc.footer()


Warning: With this and all G-Code generating scripts do "air cutting" first to make sure the machine will do what you think it will do.

 
Source:
V 0.0.1
  • basictogcode001.zip 4.0K this is alpha software.
 
Installation:

To use basictogcode directly in EMC2 you will need to edit your *.ini file manually. If you are unsure how to do that please see this tutorial.

  1. Make a backup of your EMC2 installation.
  2. download basictogcodexxx.zip
  3. unzip to somewhere in your home directory example: /home/user/basictogcode/
  4. Ensure yabasic is installed: sudo apt-get install yabasic
  5. Start gedit or your favorite editor and load your config file located in /home/"username"/emc2/configs/"configname"/"configname".ini
  6. Add these lines to the config file in the [FILTER] section:
  7. Now restart axis with the config that was modified.
  8. File -> Open (Change "Files of Type" to YABasic Script (*.bas, *,yab) then load the test.yab file
  9. If everything is working right you should see a circle and a square centered around 0,0,0 and some other demo moves.

 
Functions:
Setup functions:
  • gcodeHeader(#) - #ipm - output a g-code header
  • gcodeFooter() - output a g-code footer
Calculation functions:
  • cartesiantopolar(x,y) - returns an object with $obj->r,$obj->t, $obj->deg
  • polartocartesian(radius,degree) - returns an object with $obj->x, $obj->y
  • calculateArc(x,y,z,radius,start,stop) - returns an object with $obj->p1x, $obj->p1y, $obj->p2x, $obj->p2y
Drawing functions:
  • drawLine(x1,y1,z1,x2,y2,z2) -
  • drawBox(x1,y1,z1,x2,y2,z2) -
  • drawCircle(x,y,z,radius) -
  • drawCircleDeep(x,y,z,radius,depth,step) -
  • drawArc(x,y,z,radius,start,stop) -
  • drawPoint(x,y,z); - moves the cnc to a specified point
Formatting Functions: (mainly for internal use)
  • fd(number) - format a number for g-code
  • number_format( number, decimals, dec_point, thousands_sep ) - format a number
  • roundNumber(num, dec) -
Notes:
  • After every draw function the cnc code will move back to $safeZ
  • The safeZ move can be overridden on some functions like drawCircleDeep
 
Notes:

I chose YABasic as the interpreter for basictogcode because it is available in EMC2 as a simple apt-get. And it has the ability to easily extend the language with simple libraries.

 
License:

Copyright 2010 © James Delaney

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Copyright © 2009 James Delaney