# P2G
<img src="/docs/pytest.svg" alt=""><img src="/docs/mit.svg" alt=""><img src="/docs/coverage.svg" alt="">
## Demo.
<a href="https://youtu.be/PX818-iRb1Q">
<img src="/docs/png/vicecenter1.png" alt="link to youtube.">
</a>
## Introduction
### Version 0.3.10
P2G makes it simple to ensure that parts are in fixtures correctly, coordinate systems are adjusted to deal with stock placement and cope with movement and rotation of workpieces through multiple operations.
P2G is a compiler; it takes Python code, some definitions of machine specific variables, a little glue and makes G-code, so far, Haas ideomatic.
Thanks to magic it can do surprising things with python data structures, anything reasonably calculated statically during compilation can be used in the source, classes, dicts, and so on.
It comes with a set of macro variable definitions for a Haas mill with NCD. And a few example settings for my own VF-3SSYT.
## Install
### From pypi
```
$ pip install p2g
```
### From github
1. fetch dependencies, rebuild and install with pip
```
$ git clone https://github.com/0x5ac/attempt1 p2g
$ cd p2g
$ make install
```
2. fetch dependencies and rebuild
```
$ git clone https://github.com/0x5ac/attempt1 p2g
$ cd p2g
$ make
```
## Usage
```python
```
```
p2g - Turn Python into G-Code.
Usage:
p2g [options] <srcfile> [<dstfile>]
p2g help [ all | topics | maint | version | location | <topic> ]
p2g examples <dstdir>
For bare p2g:
p2g tram-rotary.py ~/_nc_/O{countdown}tr.nc
Makes an output of the form ~/_nc_/O1234tr.nc
p2g --func=thisone -
Read from stdin, look for the 'thisone' function and write to
to stdout.
Arguments:
<srcfile> Source python file. [default: stdin]
<dstfile> Destination G-Code file. [default: stdout]
{countdown} in file name creates a decrementing prefix
for the output file which makes looking for the .nc in
a crowded directory less painful - it's at the top.
(It's the number of seconds until midnight, so clear
the directory once a day.)
<topic> [ all | topics | maint | version | location | <topic> ]
all Print all readme.
topics List all topics.
maint Print maintenance options.
version Show version
location Show absdir of main
<topic> Print from readme starting at topic.
Options:
--job=<jobname> Olabel for output code.
--function=<fname> Function to be compiled,
default is last one in source file.
--narrow Emit comments on their own line,
makes text fit more easily into
a narrow program window.
--short-filenames Emit just the lsb of filenames.
```
## Examples
for a show:
```
$ p2g examples dstdir
```
---
### Simple demo
echo "
```python
import p2g
def simple_demo():
x = p2g.Var(199)
for y in range(10):
x += y
```
" ⇨ `directly` ⇨
```
O0001 (simple_demo: 0.3.10)
#100= 199. ( x = Var[199] )
#102= 0. ( for y in range[10]: )
N1000
IF [#102 GE 10.] GOTO 1002 ( for y in range[10]: )
#100= #100 + #102 ( x += y )
#102= #102 + 1.
GOTO 1000
N1002
M30
%
```
---
### Find largest number of flutes in tool table
```python
import p2g
# stop with alarm code showing largest
# flute count in table.
def maxflutes():
mx_flutes = p2g.Var(p2g.haas.TOOL_TBL_FLUTES[0])
for n_flutes in p2g.haas.TOOL_TBL_FLUTES:
if n_flutes > mx_flutes:
mx_flutes = n_flutes
p2g.haas.MESSAGE.var = mx_flutes
```
⇨ `p2g maxflutes.py` ⇨
```
O0001 (maxflutes: 0.3.10)
#100= #1601 ( mx_flutes = Var[haas.TOOL_TBL_FLUTES[0]])
#101= 1601. ( for n_flutes in haas.TOOL_TBL_FLUTES:)
N1000
IF [#101 GE 1801.] GOTO 1002 ( for n_flutes in haas.TOOL_TBL_FLUTES:)
IF [#[#101] LE #100] GOTO 1003 ( if n_flutes > mx_flutes: )
#100= #[#101] ( mx_flutes = n_flutes )
GOTO 1004
N1003
N1004
#101= #101 + 1.
GOTO 1000
N1002
#3006= #100 ( haas.MESSAGE.var = mx_flutes )
M30
%
```
---
### Less trivial example
```python
from p2g import *
from p2g.haas import *
class SearchParams:
def __init__(self, name, search_depth, iota, delta):
self.name = name
self.its = 10
self.search_depth = search_depth
self.iota = iota
self.delta = delta
self.probe = goto.probe.work.feed(30).all
self.go = goto.feed(640).work.all
def search(cursor, sch):
# stick from class SearchParams iterations into macro var
its = Var(sch.its)
while its > 0:
# goto start point
sch.go(cursor)
# down until hit - or not.
sch.probe(z=sch.search_depth)
# if probe is below (+some slack) hit
# point, then done.
if SKIP_POS.z < sch.search_depth + sch.iota:
break
# otherwise move to next point
cursor.xy += sch.delta
its -= 1
else:
sys.message(ALARM[0], f"too far {sch.name}.")
def less_trivial():
cursor = Var[3](2, 3, 4)
# searching right, look down 0.4", move
# 1.5" right if nothing hit.
sch1 = SearchParams(name="right", search_depth=-0.4, iota=-0.1, delta=(1.5, 0))
search(cursor, sch1)
```
⇨ `p2g less_trival.py` ⇨
```
O0001 (less_trivial: 0.3.10)
#100= 2. ( cursor = Var[3][2, 3, 4] )
#101= 3.
#102= 4.
#103= 10. ( its = Var[sch.its] )
N1000
IF [#103 LE 0.] GOTO 1002 ( while its > 0: )
( sch.go[cursor] )
G90 G01 G55 F640. x#100 y#101 z#102
G90 G31 G55 F30. z-0.4 ( sch.probe[z=sch.search_depth])
IF [#5063 LT -0.5] GOTO 1001 ( if SKIP_POS.z < sch.search_depth + sch.iota:)
#100= #100 + 1.5 ( cursor.xy += sch.delta )
#103= #103 - 1. ( its -= 1 )
GOTO 1000
N1002
#3000 = 101 (too far right.)
N1001
M30
%
```
# Table of contents
- [Introduction](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#introduction)
- [Video](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#vdemo)
- [Install](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#install)
- [Usage](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#usage)
- [Examples](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#examples)
- [Variables](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#variables)
- [Coordinates](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#coordinates)
- [Expressions](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#expressions)
- [Goto](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#goto)
- [Axes](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#axes)
- [When](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#when)
- [DPRNT](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#dprnt)
- [Notes](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#notes)
- [Authors](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#authors)
- [Thanks](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#thanks)
- [Video](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#video)
1. Copyright © 2023 Steve Chamberlain
Raw data
{
"_id": null,
"home_page": "https://github.com/0x5ac/p2g",
"name": "p2g",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "cnc,gcode,mill,haas,g-code,probe,vf",
"author": "sac",
"author_email": "sac@0x5ac.com",
"download_url": "https://files.pythonhosted.org/packages/34/03/5ad8eda008226263614a763b9ad8191797c1c89b7d7d23a543a1be5b65d6/p2g-0.3.10.tar.gz",
"platform": null,
"description": "# P2G\n\n<img src=\"/docs/pytest.svg\" alt=\"\"><img src=\"/docs/mit.svg\" alt=\"\"><img src=\"/docs/coverage.svg\" alt=\"\">\n\n\n## Demo.\n\n<a href=\"https://youtu.be/PX818-iRb1Q\">\n<img src=\"/docs/png/vicecenter1.png\" alt=\"link to youtube.\">\n</a>\n\n\n## Introduction\n\n\n### Version 0.3.10\n\nP2G makes it simple to ensure that parts are in fixtures correctly, coordinate systems are adjusted to deal with stock placement and cope with movement and rotation of workpieces through multiple operations.\n\nP2G is a compiler; it takes Python code, some definitions of machine specific variables, a little glue and makes G-code, so far, Haas ideomatic.\n\nThanks to magic it can do surprising things with python data structures, anything reasonably calculated statically during compilation can be used in the source, classes, dicts, and so on.\n\nIt comes with a set of macro variable definitions for a Haas mill with NCD. And a few example settings for my own VF-3SSYT.\n\n\n## Install\n\n\n### From pypi\n\n```\n\n$ pip install p2g\n\n```\n\n\n### From github\n\n1. fetch dependencies, rebuild and install with pip\n\n ```\n $ git clone https://github.com/0x5ac/attempt1 p2g\n $ cd p2g\n $ make install\n ```\n\n2. fetch dependencies and rebuild\n\n ```\n $ git clone https://github.com/0x5ac/attempt1 p2g\n $ cd p2g\n $ make\n ```\n\n\n## Usage\n\n```python\n\n```\n\n```\np2g - Turn Python into G-Code.\n\nUsage:\n p2g [options] <srcfile> [<dstfile>]\n p2g help [ all | topics | maint | version | location | <topic> ]\n p2g examples <dstdir>\n\n For bare p2g:\n p2g tram-rotary.py ~/_nc_/O{countdown}tr.nc\n Makes an output of the form ~/_nc_/O1234tr.nc\n\n p2g --func=thisone -\n Read from stdin, look for the 'thisone' function and write to\n to stdout.\n\n\nArguments:\n <srcfile> Source python file. [default: stdin]\n <dstfile> Destination G-Code file. [default: stdout]\n {countdown} in file name creates a decrementing prefix\n for the output file which makes looking for the .nc in\n a crowded directory less painful - it's at the top.\n (It's the number of seconds until midnight, so clear\n the directory once a day.)\n <topic> [ all | topics | maint | version | location | <topic> ]\n all Print all readme.\n topics List all topics.\n maint Print maintenance options.\n version Show version\n location Show absdir of main\n <topic> Print from readme starting at topic.\n\n\n\n\nOptions:\n --job=<jobname> Olabel for output code.\n --function=<fname> Function to be compiled,\n default is last one in source file.\n --narrow Emit comments on their own line,\n makes text fit more easily into\n a narrow program window.\n --short-filenames Emit just the lsb of filenames.\n```\n\n\n## Examples\n\nfor a show:\n\n```\n$ p2g examples dstdir\n```\n\n---\n\n\n### Simple demo\n\necho \"\n\n```python\n\nimport p2g\ndef simple_demo():\n x = p2g.Var(199)\n for y in range(10):\n x += y\n\n```\n\n\" \u21e8 `directly` \u21e8\n\n```\nO0001 (simple_demo: 0.3.10)\n #100= 199. ( x = Var[199] )\n #102= 0. ( for y in range[10]: )\nN1000\n IF [#102 GE 10.] GOTO 1002 ( for y in range[10]: )\n #100= #100 + #102 ( x += y )\n #102= #102 + 1.\n GOTO 1000\nN1002\n M30\n%\n```\n\n---\n\n\n### Find largest number of flutes in tool table\n\n```python\n\nimport p2g\n\n# stop with alarm code showing largest\n# flute count in table.\ndef maxflutes():\n\n mx_flutes = p2g.Var(p2g.haas.TOOL_TBL_FLUTES[0])\n for n_flutes in p2g.haas.TOOL_TBL_FLUTES:\n if n_flutes > mx_flutes:\n mx_flutes = n_flutes\n\n p2g.haas.MESSAGE.var = mx_flutes\n\n```\n\n\u21e8 `p2g maxflutes.py` \u21e8\n\n```\nO0001 (maxflutes: 0.3.10)\n #100= #1601 ( mx_flutes = Var[haas.TOOL_TBL_FLUTES[0]])\n #101= 1601. ( for n_flutes in haas.TOOL_TBL_FLUTES:)\nN1000\n IF [#101 GE 1801.] GOTO 1002 ( for n_flutes in haas.TOOL_TBL_FLUTES:)\n IF [#[#101] LE #100] GOTO 1003 ( if n_flutes > mx_flutes: )\n #100= #[#101] ( mx_flutes = n_flutes )\n GOTO 1004\nN1003\nN1004\n #101= #101 + 1.\n GOTO 1000\nN1002\n #3006= #100 ( haas.MESSAGE.var = mx_flutes )\n M30\n%\n```\n\n---\n\n\n### Less trivial example\n\n```python\nfrom p2g import *\nfrom p2g.haas import *\nclass SearchParams:\n def __init__(self, name, search_depth, iota, delta):\n self.name = name\n self.its = 10\n self.search_depth = search_depth\n self.iota = iota\n self.delta = delta\n self.probe = goto.probe.work.feed(30).all\n self.go = goto.feed(640).work.all\n\n\ndef search(cursor, sch):\n # stick from class SearchParams iterations into macro var\n its = Var(sch.its)\n while its > 0:\n # goto start point\n sch.go(cursor)\n # down until hit - or not.\n sch.probe(z=sch.search_depth)\n # if probe is below (+some slack) hit\n # point, then done.\n if SKIP_POS.z < sch.search_depth + sch.iota:\n break\n # otherwise move to next point\n cursor.xy += sch.delta\n its -= 1\n else:\n sys.message(ALARM[0], f\"too far {sch.name}.\")\n\n\ndef less_trivial():\n cursor = Var[3](2, 3, 4)\n # searching right, look down 0.4\", move\n # 1.5\" right if nothing hit.\n sch1 = SearchParams(name=\"right\", search_depth=-0.4, iota=-0.1, delta=(1.5, 0))\n search(cursor, sch1)\n\n```\n\n\u21e8 `p2g less_trival.py` \u21e8\n\n```\nO0001 (less_trivial: 0.3.10)\n #100= 2. ( cursor = Var[3][2, 3, 4] )\n #101= 3.\n #102= 4.\n #103= 10. ( its = Var[sch.its] )\nN1000\n IF [#103 LE 0.] GOTO 1002 ( while its > 0: )\n( sch.go[cursor] )\n G90 G01 G55 F640. x#100 y#101 z#102\n G90 G31 G55 F30. z-0.4 ( sch.probe[z=sch.search_depth])\n IF [#5063 LT -0.5] GOTO 1001 ( if SKIP_POS.z < sch.search_depth + sch.iota:)\n #100= #100 + 1.5 ( cursor.xy += sch.delta )\n #103= #103 - 1. ( its -= 1 )\n GOTO 1000\nN1002\n #3000 = 101 (too far right.)\nN1001\n M30\n%\n```\n\n\n# Table of contents\n\n- [Introduction](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#introduction)\n- [Video](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#vdemo)\n- [Install](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#install)\n- [Usage](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#usage)\n- [Examples](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#examples)\n- [Variables](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#variables)\n- [Coordinates](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#coordinates)\n- [Expressions](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#expressions)\n- [Goto](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#goto)\n- [Axes](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#axes)\n- [When](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#when)\n- [DPRNT](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#dprnt)\n- [Notes](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#notes)\n- [Authors](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#authors)\n- [Thanks](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#thanks)\n- [Video](https://github.com/0x5ac/p2g/blob/main/docs/howto.md#video)\n\n1. Copyright \u00a9 2023 Steve Chamberlain",
"bugtrack_url": null,
"license": "MIT",
"summary": "Transpile python into cnc gcode.",
"version": "0.3.10",
"project_urls": {
"Homepage": "https://github.com/0x5ac/p2g",
"Repository": "https://github.com/0x5ac/p2g"
},
"split_keywords": [
"cnc",
"gcode",
"mill",
"haas",
"g-code",
"probe",
"vf"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "659b012d0cdefed8f9b2b111df0d91d8feb148ac04f328d07f1cf962bf41ef68",
"md5": "f78555e5d73ce33ba0a8bdf940e224b3",
"sha256": "33e13ff9a8ac4132141debb6ebf0b98576f823c05bd7860572d75060c19dd60f"
},
"downloads": -1,
"filename": "p2g-0.3.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f78555e5d73ce33ba0a8bdf940e224b3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 79153,
"upload_time": "2023-08-13T09:21:07",
"upload_time_iso_8601": "2023-08-13T09:21:07.438753Z",
"url": "https://files.pythonhosted.org/packages/65/9b/012d0cdefed8f9b2b111df0d91d8feb148ac04f328d07f1cf962bf41ef68/p2g-0.3.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "34035ad8eda008226263614a763b9ad8191797c1c89b7d7d23a543a1be5b65d6",
"md5": "15c157aa317c1a342594f8f069a7710f",
"sha256": "6b3159a79d4f4666914b21b05e6e5855d4e084de0a9ecbe4b77c1274577803fc"
},
"downloads": -1,
"filename": "p2g-0.3.10.tar.gz",
"has_sig": false,
"md5_digest": "15c157aa317c1a342594f8f069a7710f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 70172,
"upload_time": "2023-08-13T09:21:09",
"upload_time_iso_8601": "2023-08-13T09:21:09.164020Z",
"url": "https://files.pythonhosted.org/packages/34/03/5ad8eda008226263614a763b9ad8191797c1c89b7d7d23a543a1be5b65d6/p2g-0.3.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-13 09:21:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "0x5ac",
"github_project": "p2g",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "p2g"
}