Ciao,
visto che il GCode è un codice strutturato in cui se trovi dei comandi
specifici hai delle funzioni apposite; puoi definire una classe con gli
oggetti che la compongono così che poi ti puoi gestire tutto il codice
strutturato secondo le varie funzioni che ti servono perchè in realtà nono
sono a caso.

Il giorno mar 13 feb 2024 alle ore 14:32 Perini Matteo <
perini.mat...@gmail.com> ha scritto:

> Ciao a tutti,
>
> è da un po' che non scrivo.
>
> Vi chiedo aiuto perchè sto cercando di leggere delle coordinate da un file 
> Gcode.
>
> Un esempio del testo da parsare è:
>
> ;LAYER:1
> ;MESH:untitled.stl
> G0 F7200 X1298 Y1798 Z4
> ;TYPE:WALL-OUTER
> G1 F1800 X702 Y1798 E1494.81223
> G1 X702 Y1202 E2242.21834
> G92 E0
> G1 X1298 Y1202 E747.40611
> G1 Y1798 X1298 E1494.81223
> ;TIME_ELAPSED:177.752007
> ;CHANGE;
> ;LAYER:2
> ;MESH:untitled.stl
> G0 F7200 X1298 Y1798 Z6
> ;TYPE:WALL-OUTER
> G1 F1800 X702 Y1798 E2242.21834
> G92 E0
> G1 X702 Y1202 E747.40611
>
> non ho grossi problemi ad effettuare un parsing corretto ma lo sto facendo 
> con vari if, elif, case,  ecc. cosa che non mi piace molto.
>
> Stavo provando ad utilizzare le regex ma non sto riuscendo a fare quello che 
> voglio (in modo pulito) ovvero identificare le coordinate X, Y e Z anche se 
> in alcuni casi hanno posizioni invertite.
> Vorrei anche attribuire un nome al gruppo identificato in modo da usarlo come 
> dizionario.
> Stavo usando alcuni pattern tipo ".*Z(?P<Z>\d+[.]?\d*)" che vanno bene per 
> individuare le coordinate di un asse ma capita che le righe contengano x y e 
> z oppure solo Z oppure solo x e y.
> Importante, in alcuni casi potrebbero essere anche in ordine differente tipo 
> z y e x.
>
> Per ora i numeri dopo E e F posso trascurarli ma vi chiederei aiuto per 
> riuscire ad ottenere le coordinate da ogni riga.
>
> se tutte le righe rispettassero lo stesso pattern non avrei problemi ma non 
> so come affrontare soprattutto il problema di avere pattern diversi in ordine 
> (quasi) random.
>
> Spero di essere stato abbastanza chiaro.
>
> Grazie a tutti
>
> Matteo
>
>
>
>
> _______________________________________________
> Python mailing list
> Python@lists.python.it
> https://lists.python.it/mailman/listinfo/python
>


-- 


mobile phone : +39 348 002 8107
tel: +39 0721 1630292
Per appuntamento: https://zcal.co/massimiliano_tornati

TORNATI PROJECT SRL
via Callegari 9-11
61122 Pesaro (PU)
P.IVA/C.F.  02533270415
site: TORNATI PROJECT <http://www.tornatiproject.com>
site:https://itofood.com/

<https://api.whatsapp.com/send/?phone=393496736011&text=%F0%9F%98%8ATornatiProject%C2%A0%20HERE!!!%20how%20can%20help%20you%3F>

<https://api.whatsapp.com/send?phone=393480028107&text=Hello%21+%0A+Can+you+help+me%3F+>

e-mail t...@tornatiproject.com
Whatapp:https://wa.me/message/G6CHK7323ZODI1

The information contained in this e-mail and any attachment is
confidential. It is intended only for the named addressee(s).
If you are not the named addressee(s) please notify us immediately at the
e-mail  t...@tornatiproject.com and then destroy this message.The copy or
distribution of the contents to any other person other than the intended
addressee(s) is strictly prohibited and will be punished according to  the
relevant laws on privacy and Intellectual Property.

Think before you print!
Before you print, please consider if it is necessary. Printing uses
electricity, ink and paper.
_______________________________________________
Python mailing list
Python@lists.python.it
https://lists.python.it/mailman/listinfo/python

Rispondere a