Skip to content

Commit

Permalink
Merge pull request #4 from fragmuffin/develop
Browse files Browse the repository at this point in the history
v0.1.2
  • Loading branch information
fragmuffin authored Aug 15, 2017
2 parents 24e92a8 + eb52cd0 commit 75022b6
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 21 deletions.
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

4 changes: 3 additions & 1 deletion deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ to make sure it's sane

# Deployment in Git

merge deployed branch to `master`
merge deployed branch to `master`, then...

```
git checkout master
git pull
git tag ${version} -m "<change description>"
git push --tags origin master
```
Expand Down
15 changes: 15 additions & 0 deletions dist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Change History

## 0.1.2

Changes to accommodate implementation of [grbl-stream](https://github.com/fragmuffin/grbl-stream)

### Improvements

- added `NullMachine`, `NullState`, and `NullMode` (not assuming any machine state)
- `Block` length is the number of gcodes + 1 if modal parameters exists

### Bugfixes

- `%` enclosed lines are considered to be _macros_ when parsing
- added axes `ABCXYZ` as valid parameters for `G10` (eg: `G10 L20 X0 Y0 Z0`)
Binary file removed dist/pygcode-0.1.1.tar.gz
Binary file not shown.
Binary file not shown.
Binary file added dist/pygcode-0.1.2.tar.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions media/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
Screenshots of arc linearizing methods for the `pygcode-norm` script.

credit to _nraynaud_ for [this awesome online gcode interpreter](https://nraynaud.github.io/webgcode/)

## `grbl-stream-*.png`

Screenshots of the `grbl-stream` script at work
4 changes: 4 additions & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# GCode files (dropped into this folder during development)
*.gcode
*.ngc
*.g
8 changes: 5 additions & 3 deletions scripts/pygcode-norm
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ omit_redundant_modes = utils.omit_redundant_modes
if args.full:
omit_redundant_modes = lambda gcode_iter: gcode_iter # bypass

def write(gcodes, modal_params=tuple(), comment=None):
def write(gcodes, modal_params=tuple(), comment=None, macro=None):
"""
Write to output, while enforcing the flags:
args.singles
Expand Down Expand Up @@ -234,6 +234,8 @@ def write(gcodes, modal_params=tuple(), comment=None):
line_list.append(block_str)
if comment:
line_list.append(str(comment))
if macro:
line_list.append(str(macro))
line_str = ' '.join(line_list)
if line_str or not args.rm_blanks:
print(line_str)
Expand Down Expand Up @@ -309,7 +311,7 @@ for line_str in args.infile.readlines():

else:
if args.full:
write(effective_gcodes, comment=line.comment)
write(effective_gcodes, comment=line.comment, macro=line.macro)
else:
write(line.block.gcodes, modal_params=line.block.modal_params, comment=line.comment)
write(line.block.gcodes, modal_params=line.block.modal_params, comment=line.comment, macro=line.macro)
machine.process_block(line.block)
2 changes: 1 addition & 1 deletion src/pygcode.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: pygcode
Version: 0.1.1
Version: 0.1.2
Summary: Basic g-code parser, interpreter, and encoder library.
Home-page: https://github.com/fragmuffin/pygcode
Author: Peter Boin
Expand Down
11 changes: 7 additions & 4 deletions src/pygcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# 1.x - Development Status :: 5 - Production/Stable
# <any above>.y - developments on that version (pre-release)
# <any above>*.dev* - development release (intended purely to test deployment)
__version__ = "0.1.1"
__version__ = "0.1.2"

__title__ = "pygcode"
__description__ = "Basic g-code parser, interpreter, and encoder library."
Expand All @@ -24,7 +24,10 @@
# =========================== Imports ===========================
__all__ = [
# Machine
'Machine', 'Position', 'CoordinateSystem', 'State', 'Mode',
'Machine', 'State', 'Mode',
'NullMachine', 'NullState', 'NullMode',
'Position', 'CoordinateSystem',

# Line
'Line',
# Block
Expand Down Expand Up @@ -165,8 +168,8 @@
# Machine
from .machine import (
Position, CoordinateSystem,
State, Mode,
Machine,
Machine, State, Mode,
NullMachine, NullState, NullMode,
)

# Line
Expand Down
10 changes: 10 additions & 0 deletions src/pygcode/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ def __getattr__(self, k):
key=k
))

def __len__(self):
"""
Block length = number of identified gcodes (+ 1 if any modal parameters are defined)
:return: block length
"""
length = len(self.gcodes)
if self.modal_params:
length += 1
return length

def __bool__(self):
return bool(self.words)

Expand Down
6 changes: 3 additions & 3 deletions src/pygcode/gcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,8 @@ class GCodeAnalogOutputImmediate(GCodeAnalogOutput):
# G10 L1 P Q R Set Tool Table
# G10 L10 P Set Tool Table
# G10 L11 P Set Tool Table
# G10 L2 P R Set Coordinate System
# G10 L20 P Set Coordinate System
# G10 L2 P R ABCXYZ Set Coordinate System
# G10 L20 P ABCXYZ Set Coordinate System
# G28, G28.1 Go/Set Predefined Position
# G30, G30.1 Go/Set Predefined Position
# G53 Move in Machine Coordinates
Expand Down Expand Up @@ -1242,7 +1242,7 @@ class GCodeToolSetCurrent(GCodeNonModal):

class GCodeSet(GCodeNonModal):
"""G10: Set stuff"""
param_letters = set('LPQR')
param_letters = set('LPQRABCXYZ')
word_key = Word('G', 10)
exec_order = 230

Expand Down
15 changes: 13 additions & 2 deletions src/pygcode/line.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import re

from .comment import split_line
from .block import Block

class Line(object):

line_regex = re.compile(r'^(?P<block_and_comment>.*?)?(?P<macro>%.*%?)?\s*$')

def __init__(self, text=None):
self._text = text

# Initialize
self.block = None
self.comment = None
self.macro = None

# Split line into block text, and comments
if text is not None:
(block_str, comment) = split_line(text)
match = self.line_regex.search(text)

block_and_comment = match.group('block_and_comment')
self.macro = match.group('macro')

(block_str, comment) = split_line(block_and_comment)
self.block = Block(block_str)
if comment:
self.comment = comment
Expand All @@ -28,4 +39,4 @@ def gcodes(self):
return self.block.gcodes

def __str__(self):
return ' '.join([str(x) for x in [self.block, self.comment] if x])
return ' '.join([str(x) for x in [self.block, self.comment, self.macro] if x])
21 changes: 19 additions & 2 deletions src/pygcode/machine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from copy import copy, deepcopy
from collections import defaultdict

Expand Down Expand Up @@ -290,9 +291,12 @@ class Mode(object):
def __init__(self, set_default=True):
self.modal_groups = defaultdict(lambda: None)

# Initialize
# Initialize (from multiline self.default_mode)
if set_default:
self.set_mode(*Line(self.default_mode).block.gcodes)
gcodes = []
for m in re.finditer(r'\s*(?P<line>.*)\s*\n?', self.default_mode):
gcodes += Line(m.group('line')).block.gcodes
self.set_mode(*gcodes)

def __copy__(self):
obj = self.__class__(set_default=False)
Expand Down Expand Up @@ -499,3 +503,16 @@ def move_to(self, rapid=False, **coords):
new_pos = self.pos
new_pos.update(**coords) # only change given coordinates
self.pos = new_pos


# Null Machine
# A machine that presumes nothing
class NullMode(Mode):
default_mode = ''

class NullState(State):
pass # no change (yet)

class NullMachine(Machine):
MODE_CLASS = NullMode
STATE_CLASS = NullState
30 changes: 26 additions & 4 deletions tests/test_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import sys
import os
import inspect

import unittest

# Add relative pygcode to path
Expand All @@ -27,3 +23,29 @@ def test_line_comment_brackets_multi(self):
line = Line('G02 X10.75 (x coord) Y47.44 (y coord) I-0.11 J-1.26 F70 (eol)')
self.assertEqual(line.comment.text, 'x coord. y coord. eol')
self.assertEqual(len(line.block.words), 6)

def test_line_macros(self):
# (blank)
line = Line('')
self.assertIsNone(line.macro)

# (no macro)
line = Line('G02 X10.75 Y47.44 I-0.11 J-1.26 F70 (blah blah)')
self.assertIsNone(line.macro)

# %
line = Line('%')
self.assertEqual(str(line.macro), '%')

# %%
line = Line('%%')
self.assertEqual(str(line.macro), '%%')

# % blah blah %
line = Line('% blah blah %')
self.assertEqual(str(line.macro), '% blah blah %')

# Combined at end of line (not sure if this is legit)
line = Line('G02 X10.75 Y2 ; abc %something%')
self.assertEqual(line.comment.text.strip(), 'abc')
self.assertEqual(line.macro, '%something%')

0 comments on commit 75022b6

Please sign in to comment.