motohawk_flexencoder_create_nx_pattern_xml

The motohawk_flexencoder_create_nx_pattern_xml M-script creates a flexible encoder XML pattern definition for an NX encoder. An NX encoder is a pattern with N equidistant teeth distributed about the wheel. Such patterns often have many teeth (upward of 150), which makes definition by hand a time consuming process. Such patterns can also consume more memory than maybe necessary because of the way they have been defined. This script supports an optimization facility to define the pattern in a manner that will use the minimum possible amount of system memory.

success = motohawk_flexencoder_create_nx_pattern_xml
        (XmlName, N, ['-overwrite'], ['-noedit'], ['-optimize'])

success

Non zero if the script generated the file successfully, zero otherwise. The non zero value is a compression estimate. The smaller the number the higher the compression that is possible.

XmlName

The name of the pattern. The file and optionally the full path of the xml file to be created can be implied by this string too.

success = motohawk_flexencoder_create_nx_pattern_xml('C:\MyEncoderPatterns\MyPattern.xml', 190)

This creates MyPattern.xml under 'C:\MyEncoderPatterns' with a pattern name of 'MyPattern'. The pattern will define 190 teeth and can be referenced by a Pattern Definition block by the string 'MyPattern' (this assumes the assigned name has not been altered after the file was created).

success = motohawk_flexencoder_create_nx_pattern_xml('MyPattern', 190, '-overwrite')

This creates MyPattern.xml in the current working folder with a pattern name of 'MyPattern'. The pattern will define 190 teeth and can be referenced by a Pattern Definition block by the string 'MyPattern' (this assumes the assigned name has not been altered after the file was created). The script will overwrite the file if it already exists.

N

The number of equally spaced teeth on the wheel. This value must be a scalar whole number numeric greater than 0.

'-overwrite'

Use this optional argument to explicitly allow the script to overwrite an existing file. By default, the script will error if the input file name already exists and this flag is not set.

'-noedit'

Use this optional argument to tell the script to not automatically open the file for editing when successfully created.

'-optimize'

Use this optional argument to generate a memory optimized pattern. The flexible encoder system will arrange the defined teeth into blocks of teeth with the same characteristics. Internally position is encoded into 0.0625deg increments. High tooth wheels (like one with 151 teeth) can't resolve tooth position exactly when there is only 0.0625deg of resolution available and so rounding occurs. The rounding results in neighbouring teeth having slightly different displacements. Teeth with different intervals of displacement can't be grouped together. Using the optimize option allows a larger error band of 0.05 to be used instead of the most accurate 0.03125. This means that some teeth can be defined (because of rounding) up to 0.05deg from their exact position instead of the default midway point of 0.03125deg. A slight increase in the allowed error can significantly increase the number of like teeth that can be grouped together, which will reduce the internal memory needed to define the pattern.

The pattern will optimize for accuracy rather than size if this attribute is omitted.

An analysis of the optimization is possible by examining the informational nodes <DesiredDeg> and <DesiredLogicalErrorDeg> relative to <LogicalDeg> that are populated in the generated flexible encoder pattern XML. <LogicalDeg>is the angle used by MotoHawk to define tooth position. <LogicalDeg> includes rounding needed to account for the internal 0.0625 fixed point representation. The <DesiredDeg> angle represents the angle without rounding. The difference between <DesiredDeg> and <LogicalDeg> is captured by <DesiredLogicalErrorDeg>.

The success return code estimates the compression achieved. Creating the same pattern with and without the -optimize option provides a relative indication of the improvement in compression that can be achieved when using this option. For example a 190 tooth pattern will give almost 50% better compression when -optimize is used, but the compression improvement offered by a 151 tooth pattern is very little.

e.g.
motohawk_flexencoder_create_nx_pattern_xml('MyPattern', 190, '-optimize', '-overwrite') reports an answer of 61
motohawk_flexencoder_create_nx_pattern_xml('MyPattern', 190, '-overwrite') reports an answer of 120

An XML comment within the generated pattern will also state the compression of a particular instantiation of a pattern.

eTPU Flexible Encoder Implementation

The eTPU Flexible Encoder implementation will reflect an insufficient memory issue via a fault status return by the IO Fault Status block that has selected the eTPU resource.

Some tools may also have access to the eTPU_RAMBytesFree variable. This variable, when available, will allow an absolute comparison of the memory saved through optimization to be determined. This could be done by comparing the memory consumed when the pattern had optimization enabled versus having it disabled (and no other changes in the system).

'-optimize=Error'

The behavior is the same as using '-optimize' except the error band can be specified instead of defaulting to 0.05. Using a larger error will potentially increase the compression that can be achieved by further sacrificing accuracy.

The specified error should be less than 0.0625 and no smaller than 0.03125.