Java Magazine, Sept/Oct 2016
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2016 28 internet of things PROBE_ OFFSET 85525 9157 5 PROBE_ OFFSET 1045 Once you have calculated the PROBE_ OFFSET for your machine you can accurately and repeatedly cut through objects to the top of your work surface To modify my program to use the new probe ofset value I calculated I am going to reset the coordinate system after performing the homing and probing steps To do this I use a G10L20 G code command This G code command enables you to specify X Y and Z values for the new coordinate space Here is a static string that has the new coordinates specified static final String COORDINATE_ RESET_ TEMPLATE G10 L20 P0 X220 Y205 Z is added based on PRB_ Z The P0 modifier specifies that you are modifying the default coordinate system The X and Y values should be about right for any Nomad 883 Pro but the Z value requires more precision and should be set using the PROBE_ OFFSET value you calculated earlier To set the Z value add the following line after the probe sequence sendCommandAndWait COORDINATE_ RESET_ TEMPLATE Z PROBE_ OFFSET listener prbZ Building a Path To demonstrate how you can generate G code from within Java programmatically Ill create a simple geometric algorithm to cut out a star pattern Because Im doing this in code I can make the number of points and the size of the inner and outer radius configurable The basic algorithm for creating a star is to calculate the location of equally spaced points along a circle For a circle of radius R and a star with P points you can find the location of an outer vertex v by using the following algorithm x cos v 360 P y sin v 360 P Converting this to radians where 180 degrees is equal to π radians you get the following x cos v 2π P y sin v 2π P To complete the algorithm you also need to calculate the inner vertices which occur halfway between each of the outer vertices A more generalized algorithm in Java code that gives you both inner and outer vertices is the following for int i 0 i points 2 i double r i 2 0 innerRadius outerRadius double x Math cos i Math PI points r double y Math sin i Math PI points r Now that I know the vertices for creating a star I can output G code that will tell the CNC router to trace the outline These are the relevant G code instructions G0 Rapidly move to a specific location G1 Perform a linear move to a location Both of these methods take optional X Y and Z parameters in decimal format for the location to move to To get the starting location of the star you simply need to calculate the position of the first vertex Conveniently sin 0 is 0 and cos 0 is 1 so the earlier algorithm is reduced to the following
You must have JavaScript enabled to view digital editions.