Commit ae3f61bb authored by Fabrice Salvaire's avatar Fabrice Salvaire

improved data

parent b313bb09
......@@ -30,7 +30,9 @@ __all__ = [
'Letters',
'Gcode',
'Gcodes',
'ModalGroup',
'ModalGroups',
'ExecutionGroup',
'ExecutionOrder',
]
......@@ -67,9 +69,14 @@ class RstMixin:
##############################################
def _make_rst(self, headers, columns=None, show_line_number=False, str_item=None):
def _make_rst(self, headers, columns, **kwargs):
lengths = []
number_of_columns = len(headers)
if len(columns) != number_of_columns:
raise ValueError('Number of columns mismatch')
number_of_lines = len(self)
table = []
rule = ''
line_format = ''
for c, title in enumerate(headers):
......@@ -77,36 +84,28 @@ class RstMixin:
rule += ' '
line_format += ' '
length = len(title)
if columns is not None:
column = columns[c]
column = columns[c]
str_columns = []
if hasattr(self, 'sorted_iter'):
it = self.sorted_iter()
else:
column = None
for line_number, item in enumerate(self):
if c == 0 and show_line_number:
text = str(line_number)
else:
if column is not None:
text = str(getattr(item, column))
else:
text = str(item)
it = self
for line_number, item in enumerate(it):
formater = kwargs.get('str_' + column, str)
field = getattr(item, column)
text = formater(field)
length = max(len(text), length)
str_columns.append(text)
rule += '='*length
line_format += '{:' + str(length) + '}'
lengths.append(length)
table.append(str_columns)
rst = ''
rst += rule + '\n'
rst += line_format.format(*headers) + '\n'
rst += rule + '\n'
for line_number, item in enumerate(self):
if columns is not None:
fields = [getattr(item, column) for column in columns]
elif str_item:
fields = [str_item(item)]
else:
fields = [str(item)]
if show_line_number:
fields = [str(line_number)] + fields
for line_number in range(number_of_lines):
fields = [table[c][line_number] for c in range(number_of_columns)]
rst += line_format.format(*fields) + '\n'
rst += rule + '\n'
......@@ -267,6 +266,13 @@ class Gcodes(YamlMixin, RstMixin):
def __getitem__(self, code):
return self._gcodes[code]
##############################################
def sorted_iter(self):
items = list(self)
items.sort(key=lambda item: str(ord(item.code[0])*1000) + item.code[1:])
return items
##############################################
......@@ -276,6 +282,27 @@ class Gcodes(YamlMixin, RstMixin):
headers=('G-code', 'Meaning'),
columns=('code', 'meaning'),
)
####################################################################################################
class ExecutionGroup(MeaningMixin):
##############################################
def __init__(self, index, gcodes, meaning):
MeaningMixin.__init__(self, meaning)
self._index = int(index)
self._gcodes = list(gcodes)
##############################################
@property
def index(self):
return self._index
@property
def gcodes(self):
return self._gcodes
####################################################################################################
......@@ -288,13 +315,15 @@ class ExecutionOrder(YamlMixin, RstMixin):
data = self._load_yaml(yaml_path)
self._order = []
count = 1
for index, gcodes in data.items():
for index, d in data.items():
if index != count:
raise ValueError('Unexpected index {} versus {}'.format(index, count))
count += 1
gcodes = d['gcodes']
if not isinstance(gcodes, list):
gcodes = list(gcodes)
self._order.append(gcodes)
gcodes = [gcodes]
group = ExecutionGroup(index, gcodes, d['meaning'])
self._order.append(group)
##############################################
......@@ -312,13 +341,35 @@ class ExecutionOrder(YamlMixin, RstMixin):
def to_rst(self, path):
self._write_rst(
path,
headers=('Order', 'G-codes'),
show_line_number=True,
str_item=lambda item: '(' + ', '.join(item) + ')'
headers=('Order', 'G-codes', 'Comment'),
columns=('index', 'gcodes', 'meaning'),
str_gcodes=lambda item: ', '.join(item),
)
####################################################################################################
class ModalGroup(MeaningMixin):
##############################################
def __init__(self, index, gcodes, meaning):
MeaningMixin.__init__(self, meaning)
self._index = int(index)
self._gcodes = list(gcodes)
##############################################
@property
def index(self):
return self._index
@property
def gcodes(self):
return self._gcodes
####################################################################################################
class ModalGroups(YamlMixin, RstMixin):
##############################################
......@@ -327,8 +378,12 @@ class ModalGroups(YamlMixin, RstMixin):
data = self._load_yaml(yaml_path)
self._groups = {}
for index, gcodes in data.items():
self._groups[index] = list(gcodes)
for index, d in data.items():
gcodes = d['gcodes']
if not isinstance(gcodes, list):
gcodes = [gcodes]
group = ExecutionGroup(index, gcodes, d['meaning'])
self._groups[index] = group
##############################################
......@@ -339,16 +394,24 @@ class ModalGroups(YamlMixin, RstMixin):
return iter(self._groups.values())
def __getitem__(self, index):
return self._groups[index_]
return self._groups[index]
##############################################
def sorted_iter(self):
items = list(self)
items.sort(key=lambda item: item.index)
return items
##############################################
def to_rst(self, path):
self._write_rst(
path,
headers=('Group', 'G-codes'),
show_line_number=True,
str_item=lambda item: '(' + ', '.join(item) + ')'
headers=('Group', 'G-codes', 'Comment'),
columns=('index', 'gcodes', 'meaning'),
str_gcodes=lambda item: '(' + ', '.join(item) + ')',
)
####################################################################################################
......
# Table 8. Order of Execution
1: COMMENT # (includes message]
2: [G93, G94] # set feed rate mode (inverse time or per minute]
3: F # set feed rate
4: S # set spindle speed
5: T # select tool
6: M6 # change tool
7: [M3, M4, M5] # spindle on or off
8: [M7, M8, M9] # coolant on or off
9: [M48, M49] # enable or disable overrides
10: G4 # dwell
11: [G17, G18, G19] # set active plane
12: [G20, G21] # set length units
13: [G40, G41, G42] # cutter radius compensation on or off
14: [G43, G49] # cutter length compensation on or off
15: [G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3] # coordinate system selection
16: [G61, G61.1, G64] # set path control mode
17: [G90, G91] # set distance mode
18: [G98, G99] # set retract mode
19: [G28, G30, G10, G92, G92.1, G92.2, G94] # home or change coordinate system data or set axis offsets
20: ['G0-G3', 'G80-G89', G53] # perform motion, as modified (possibly) by G53
21: [M0, M1, M2, M30, M60] # stop
1:
gcodes: COMMENT
meaning: includes message
2:
gcodes: [G93, G94]
meaning: set feed rate mode (inverse time or per minute)
3:
gcodes: F
meaning: set feed rate
4:
gcodes: S
meaning: set spindle speed
5:
gcodes: T
meaning: select tool
6:
gcodes: M6
meaning: change tool
7:
gcodes: [M3, M4, M5]
meaning: spindle on or off
8:
gcodes: [M7, M8, M9]
meaning: coolant on or off
9:
gcodes: [M48, M49]
meaning: enable or disable overrides
10:
gcodes: G4
meaning: dwell
11:
gcodes: [G17, G18, G19]
meaning: set active plane
12:
gcodes: [G20, G21]
meaning: set length units
13:
gcodes: [G40, G41, G42]
meaning: cutter radius compensation on or off
14:
gcodes: [G43, G49]
meaning: cutter length compensation on or off
15:
gcodes: [G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3]
meaning: coordinate system selection
16:
gcodes: [G61, G61.1, G64]
meaning: set path control mode
17:
gcodes: [G90, G91]
meaning: set distance mode
18:
gcodes: [G98, G99]
meaning: set retract mode
19:
gcodes: [G28, G30, G10, G92, G92.1, G92.2, G94]
meaning: home or change coordinate system data or set axis offsets
20:
gcodes: ['G0-G3', 'G80-G89', G53]
meaning: perform motion, as modified (possibly) by G53
21:
gcodes: [M0, M1, M2, M30, M60]
meaning: stop
# Table 4. Modal Groups
# The modal groups for G codes are
1: [G0, G1, G2, G3, G38.2, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89]
2 : [G17, G18, G19] # plane selection
3 : [G90, G91] # distance mode
5 : [G93, G94] # feed rate mode
6 : [G20, G21] # units
7 : [G40, G41, G42] # cutter radius compensation
8 : [G43, G49] # tool length offset
10 : [G98, G99] # return mode in canned cycles
12 : [G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3] # coordinate system selection
13 : [G61, G61.1, G64] # path control mode
1:
gcodes: [G0, G1, G2, G3, G38.2, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89]
meaning:
2 :
gcodes: [G17, G18, G19]
meaning: plane selection
3 :
gcodes: [G90, G91]
meaning: distance mode
5 :
gcodes: [G93, G94]
meaning: feed rate mode
6 :
gcodes: [G20, G21]
meaning: units
7 :
gcodes: [G40, G41, G42]
meaning: cutter radius compensation
8 :
gcodes: [G43, G49]
meaning: tool length offset
10 :
gcodes: [G98, G99]
meaning: return mode in canned cycles
12 :
gcodes: [G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3]
meaning: coordinate system selection
13 :
gcodes: [G61, G61.1, G64]
meaning: path control mode
# The modal groups for M codes are
4 : [M0, M1, M2, M30, M60] # stopping
6 : [M6] # tool change
7 : [M3, M4, M5] # spindle turning
8 : [M7, M8, M9] # coolant (special case: M7 and M8 may be active at the same time)
9 : [M48, M49] # enable/disable feed and speed override switches
4 :
gcodes: [M0, M1, M2, M30, M60]
meaning: stopping
6 :
gcodes: [M6]
meaning: tool change
7 :
gcodes: [M3, M4, M5]
meaning: spindle turning
8 :
gcodes: [M7, M8, M9]
meaning: 'coolant (special case: M7 and M8 may be active at the same time)'
9 :
gcodes: [M48, M49]
meaning: enable/disable feed and speed override switches
# In addition to the above modal groups, there is a group for non-modal G codes
0 : [G4, G10, G28, G30, G53, G92, G92.1, G92.2, G92.3]
0 :
gcodes: [G4, G10, G28, G30, G53, G92, G92.1, G92.2, G92.3]
meaning: group for non-modal G codes
......@@ -299,6 +299,9 @@ millimeters. A machining center may be in many modes at the same time, with one
group being in effect.
.. The modal groups are shown in Table 4.
.. Table . Modal Groups
The modal groups are
.. include:: modal_groups.rst
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment