June 13, 2024

Numeric word output formats in the Code Generator (CGT/tmp file)

Formats affect output only. Any expressions or calculations using a CGT word use the full precision of the word. 

Numeric system word persistent formats:
Persistent numeric formats in current code generators are assigned in the @DECLARE section of the CGT file using the #FMT() command, with a #F_format class and a numeric format.
 
Example:

@DECLARE
#FMT( #F_BlockNumber, T4.0)
#FMT( #F_Decimal, D3.4)    //precision must match smf21
#FMT( #F_Integer, T4.0)
#FMT( #F_Offset, T2.0)

...
etc
...
@

In the CGT Word Reference of Learning SmartCAM, for words of type Numeric, the FMT Class field will identify the persistent format assigned to the word. If not overridden, this is the format that will be used when the word is output.

Example:
 
Word #CYTIME
Type Numeric, Cycle Times
Description Total accumulating cycle time.
Value > 0
FMT Class F_Decimal
Related SMF Questions 141, 142, 144

The word is of type Numeric, and when output it will default to the #F_Decimal format that is assigned in the @DECLARE section. 

Note: If formats are not declared in the @DECLARE section, SmartCAM will look for them in the .SMF file.   

Numeric system word persistent overrides.
The persistent formatting of any numeric system word can be overridden by using the #FMT() command in the @DECLARE section.

For example, the #CYTIME word listed above has the #F_Decimal format assigned to it. If we want it to have a different output format throughout the CGT, we can specify a persistent override in the @DECLARE:
@DECLARE
#FMT( #F_BlockNumber, T4.0)
#FMT( #F_Decimal, D3.4)
#FMT( #F_Integer, T4.0)
...
#FMT( #CYTIME, P4.2) // Sets new persistent format for #CYTIME
...
@

Numeric user words' persistent formats:
Declaration of user words automatically assigns persistent decimal or integer formats when declaring as either #DEC, #INT, #CALCDEC or #CALCINT in the @DECLARE section. For example the #myXPos, #myYPos and #myCount words declared below: 
@DECLARE
#FMT( #F_BlockNumber, T4.0)
#FMT( #F_Decimal, D3.4)
#FMT( #F_Integer, T4.0)
....
#DEC #myXPos, #myYPos      // user declared words #myXPos and #myYPos that will automatically use the #F_Decimal format for output.
#INT #myCount                     // user declared word  #myCount that will automatically use the #F_Integer format for output.
....
@

Numeric user words persistent custom formats: 
A numeric user word can be given its own persistent format by declaring it using the #FMT() or #CALCFMT() commands in the @DECLARE section. For example the #myAngle word declared below:
@DECLARE
#FMT( #F_BlockNumber, T4.0)
#FMT( #F_Decimal, D3.4)
#FMT( #F_Integer, T4.0)
...
#DEC #myXPos, #myYPos
#INT #myCount 
#FMT( #myAngle, D3.3)   // user declared word #myAngle that will use D3.3 format for output.
....
@

Numeric word one time output format:
Any numeric word can be output with a different format than its persistent format by using the #FMT() function directly in line in the .CGT output @Sections. For example outputting #CYTIME to one place after the decimal in the program end codes:
@END
G00G91G28Z0
(Cycle time = #FMT(#CYTIME, D4.1) )
M30
@














No comments:

Post a Comment