Java Magazine, Sept/Oct 2016
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2016 29 internet of things x innerRadius y 0 Using an offset to help center the star in the work area and applying the previously mentioned G code functions you get the following function for moving to the starting location of the star static void moveToStart double innerRadius double offset throws Exception sendCommandAndWait G0X String format 3f innerRadius offset Y String format 3f offset Z String format 3f MATERIAL_ THICKNESS 1 This uses a modified version of the sendSequenceAndWait function that takes a single command Here is the code for that function static void sendCommandAndWait String sequence throws Exception synchronized listener grblController queueCommand sequence listener fileStreamComplete false grblController beginStreaming while listener fileStreamComplete listener wait And the full drawStar function to create the G code for tracing all of the points of the star is shown here static List String drawStar int points double innerRadius double outerRadius double offset List String gcode new ArrayList points 2 1 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 gcode add G1X String format 3f x offset Y String format 3f y offset gcode add gcode get 0 return gcode To complete the example I need a few extra G code sequences static final List String START_ SPINDLE Arrays asList G21 G90 M3 S9000 static final List String END_ SEQUENCE Arrays asList M5 H M30 These sequences are used at different times The first sequence in the code above sets the units to metric G21 sets absolute distance mode G90 and starts the spindle M3 S9000 The second sequence is an end sequence that stops the spindle M5 homes the head H and then
You must have JavaScript enabled to view digital editions.