On 02.07.11 13:47, cogoman wrote:
> In the past I have thought that it would be great to have a feature in 
> EMC2 like the C pre-processor, that would do some automatic replacements 
> to allow the original G-code to be more readable.

Yes, that wish is fairly widely expressed here, if only from time to
time. Reverse translation is useful too, I think.

[...]

> now we can have scripts to replace text subroutine names with the 
> numbers EMC2 seems to like so much, IE:
> 
>              s/rectangular-pocket/500/
>              s/peck-drill/501/
>              s/leave-a-tab/502/
> 
> Now you can use whatever names look good to you, and before EMC2 sees 
> the code, it will be changed to a simple number.  It will only replace 
> the first instance of the phrase on each line, so if you put the 
> subroutine name in a comment at the end of the line, it will survive 
> sed, but will let you keep track of subroutines in AXIS.
> 
> Comments anybody?

Back in 2009, I put together a gcode to human readable translator, which
is table driven, allowing the user to individualise the translation
without resort to programming. It also provides for two translation
levels; short, and verbose. But it doesn't clean up the cryptic O-word
stuff, or the unusual arithmetic syntax.

It would be straightforward and a bit of fun to implement the reverse
translation, allowing the human readable form to be used as input. Such
a filter could be used to generate a gcode file as intermediate (for
review or sending elsewhere), or as an AXIS filter, allowing EMC2 to
consume a readable form of gcode.

Since not every EMC2 user is a coder, yet may still have individual
views on what constitutes a human readable form, a table driven
translator is one way to please everyone to a greater degree than is
possible with a monolithic translator.

The attached "synonyms" file provides gcode and the two translation
alternatives. Why the underscores? It's more readable than enclosing
parentheses, I feel. It is easier to extend this table for the (less
usual) cases not yet covered, than to write more code, especially for
non-programmers.

The other two files show input gcode, and a first cut at a human
readable form, but it takes only a moment to hack that.

The human readable to gcode translator should use the same translation
table backwards. But it would be rather nice to also clean up the sadly
unreadable arithmetic, conditional, and general O-word guff in gcode,
but that is less amenable to table driven generic translation, so may
need hardcoding.

To avoid the need to feed the gcode output to EMC2's parser, before
encountering any syntax policing, it would also be helpful to users if
we specify and check a formal grammar for these programmatic elements. 

So a decision is required: Provide a quicker result with an ad-hoc table
driven parser with negligible syntax checking, or implement a rigorous
translator with a formally specified and fully checked BNF grammar,
implemented in e.g. lex and yacc.

Doing the lexer in lex is easy and pretty quick. Writing the BNF grammar
takes a few rainy sundays (and it is winter here). Writing the C code to
fill the yacc stubs, to implement each part of the grammar is time
consuming, but manageable because we're just translating text, not
implementing the gcode.

One benefit of using yacc and a BNF grammar is that we can fine tune the
input syntax with less effort than in an ad hoc parser. It is also self
documenting, with everyone able to discuss the grammar's suitability,
without the need to read any code. My initial thought is to take each
gcode arithmetic and flow control expression, and provide a (more or
less) Pythonesque input form.

Since it's sunday today, I'll figure out how best to make the rigourous
translator table driven for at least the plain gcode lines, to maximise
user freedom in determining what is human readable, then make a start on
the lexer.

If there's positive feedback, I might even keep going. ;-)

But while I begin to pick this up again, what other thoughts arise, what
have I forgotten, and would it actually be used?

Erik

-- 
"Necessity is the mother of invention" is a silly proverb. "Necessity is the
mother of futile dodges" is much closer to the truth. The basis of growth of
modern invention is science, and science is almost wholly the outgrowth of
pleasurable intellectual curiosity.                      -Alfred N. Whitehead

# Translation Control Table for hr2gc
# -----------------------------------
# A non-modal command applies to the current line only.
# A modal command applies to following commands, until overridden by another 
modal command.

G0       move     rapid_move

G1       cut      cut

G2       arc_cw   arc_cw_to
G3       arc_ccw  arc_ccw_to           # I J K or R  # In the current plane.

G4       dwell    dwell                # (seconds)

G10      set      set                  # L1 => tool, L2 => origin.

# Plane Selection (affects G2, G3, G81…G89, G40…G42)
G17      use_xy   use_xy_plane
G18      use_xz   use_xz_plane
G19      use_yz   use_yz_plane

# Units:
G20      use_in   use_inches
G21      use_mm   use_millimeters

# Homing:                              # Traverse VIA `axes` position, if 
present.
G28      home_a   home_a               # Soft home defined by parameters 
5161-5166.
G30      home_b   home_b               # Soft home defined by parameters 
5181-5186.

G40      no_trc   no_radius_compensation           # "_off" might be read as 
"_offset".
G43      set_tlc  set_tool_length_compensation
G43.1    set_tlc  set_tool_length_compensation
G49      no_tlc   no_tool_length_compensation

# Coordinate systems (workspaces):
G53      abs      absolute   prefix    # Non-modal command.

                                       # Call it wsp0, when used as modal G53?
G54      wsp1     use_workspace_1      # Default modal co-ord system == 
absolute system.
G55      wsp2     use_workspace_2      # 
G56      wsp3     use_workspace_3
G57      wsp4     use_workspace_4
G58      wsp5     use_workspace_5
G59      wsp6     use_workspace_6
G59.1    wsp7     use_workspace_7
G59.2    wsp8     use_workspace_8
G59.3    wsp9     use_workspace_9
                                       # P = 1-9
L2       org      origin               # P X Y Z A B C  Coordinate system 
origin setting
L1       tool     tool                 # See G10.

G80      freeze   cancel_modal_motion
# Predefined sequences:             # (AKA "canned cycles")
G81      drill    drill             # Needs G91 (use_incremental_mode) for 
multi_drill, i.e L>1 .
                                    # R overrides lower old_z, if offered by 
G98.
G82      dwell_drill dwell_drill
G83      peck_drill  peck_drill
G87      **NOT_SUPPORTED** **NOT_SUPPORTED**

G98      old_z    retract_to_prior_z

# Distance Mode:
G90      abs      absolute
G91      rel      relative

G92      Offset coordinate systems and set parameters
G92.1    Cancel offset coordinate systems and set parameters to zero
G92.2    Cancel offset coordinate systems but do not reset parameters
G92.3    Apply parameters to offset coordinate systems

# Feed Rate Mode:
G93   feed/time         inverse_time_feed
G94   feed/min          per_minute_feed
G95   feed/rev          per_revolution_feed

# Stopping:
M0    pause    pause_program
M2    end      end_program
M1    stop     stop
M30   stop     stop
M60   stop     stop
( Gcode allows only single line comments. :-)

( XY plane, mm mode, cancel diameter compensation, cancel length offset,       )
( coordinate system 1, cancel motion, non-incremental motion, feed/minute mode )

G18 G54 G20 G40 G49 G80 G90 G94 

G90 G81 G98 X4 Y5 Z1.5 R2.8      (Drill one hole)

G91 G81 G98 X4 Y5 Z-0.6 R1.8 L3  (Drill three holes)

G83 X1 Y1 Z1 R1.8 L5 Q0.100

G3 I5.00 J6.00 K7.00

G10 L1

G10 L1 P7 R8 X42 Z20 Q1

G10 L2 P3 X0.0 Y0.0            (Set the Current Location of Coordinate System 3 
to 0,0)

#3=42

#3=6 #5=[2*#3]

#3=6 G1 X#3
( Gcode allows only single line comments. :-)           

( XY plane, mm mode, cancel diameter compensation, cancel length offset, )      
        
( coordinate system 1, cancel motion, non-incremental motion, feed/minute mode 
)                

use_xz_plane use_workspace_1 use_inches no_radius_compensation 
no_tool_length_compensation cancel_modal_motion absolute per_minute_feed        
         

absolute drill retract_to_prior_z X4 Y5 Z1.5 retract_to 2.8 (Drill one hole)    
        

relative drill retract_to_prior_z X4 Y5 Z-0.6 retract_by 1.8 rpt=3 (Drill three 
holes)          

peck_drill X1 Y1 Z1 retract_by 1.8 rpt=5 peck=0.100             

arc_ccw_to centre_at 5.00 6.00 spiral_to 7.00            ### May be inaccurate 
### 

reload the tool table.          

set tool=7 radius=8 X42 Z20 orientation=1               

set workspace 3 origin to X0.0 Y0.0 (Set the Current Location of Coordinate 
System 3 to 0,0)            

#3=42           

#3=6 #5=[2*#3]          ### Assignments not effective until next line. ###

#3=6 cut X#3            
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to