This commit is contained in:
Sélène Corbineau 2025-02-07 19:11:44 +01:00
parent 85a848ddbf
commit 5f1c810e49
6 changed files with 383 additions and 12 deletions

136
main.py
View file

@ -1,23 +1,135 @@
import hardware as hw import hardware as hw
import controller as ctl import controller as ctl
import GCode_Interpreterdc as gci import GCode_Interpreterdc as gci
import svgtroppagcode as sgc #import svgtroppagcode as sgc
instr = sgc.svg_to_gcode("clock.svg").split("\n") #instr = sgc.svg_to_gcode("clock.svg").split("\n")
instr = [
"G1 X3.000 Y5.500 F2.000",
"G1 X3.222 Y5.278 F0.297",
"G1 X3.444 Y5.056 F0.354",
"G1 X3.667 Y4.833 F0.391",
"G1 X3.889 Y4.611 F0.420",
"G1 X4.111 Y4.389 F0.445",
"G1 X4.333 Y4.167 F0.465",
"G1 X4.556 Y3.944 F0.484",
"G1 X4.778 Y3.722 F0.500",
"G1 X5.000 Y3.500 F0.500",
"G0 X21.000 Y5.500",
"G1 X20.778 Y5.278 F0.297",
"G1 X20.556 Y5.056 F0.354",
"G1 X20.333 Y4.833 F0.391",
"G1 X20.111 Y4.611 F0.420",
"G1 X19.889 Y4.389 F0.445",
"G1 X19.667 Y4.167 F0.465",
"G1 X19.444 Y3.944 F0.484",
"G1 X19.222 Y3.722 F0.500",
"G1 X19.000 Y3.500 F0.500",
"G0 X12.000 Y8.500",
"G1 X12.000 Y8.944 F0.297",
"G1 X12.000 Y9.389 F0.354",
"G1 X12.000 Y9.833 F0.354",
"G1 X12.000 Y10.278 F0.354",
"G1 X12.000 Y10.722 F0.354",
"G1 X12.000 Y11.167 F0.354",
"G1 X12.000 Y11.611 F0.354",
"G1 X12.000 Y12.056 F0.354",
"G1 X12.000 Y12.500 F0.354",
"G1 X12.000 Y12.500 F0.354",
"G1 X12.222 Y12.722 F0.354",
"G1 X12.444 Y12.944 F0.354",
"G1 X12.667 Y13.167 F0.354",
"G1 X12.889 Y13.389 F0.354",
"G1 X13.111 Y13.611 F0.354",
"G1 X13.333 Y13.833 F0.354",
"G1 X13.556 Y14.056 F0.354",
"G1 X13.778 Y14.278 F0.354",
"G1 X14.000 Y14.500 F0.354",
"G0 X20.000 Y12.500",
"G1 X19.971 Y13.190 F0.185",
"G1 X19.884 Y13.864 F0.195",
"G1 X19.743 Y14.520 F0.195",
"G1 X19.549 Y15.154 F0.195",
"G1 X19.306 Y15.764 F0.196",
"G1 X19.015 Y16.349 F0.196",
"G1 X18.679 Y16.905 F0.196",
"G1 X18.300 Y17.431 F0.197",
"G1 X17.881 Y17.924 F0.197",
"G1 X17.424 Y18.381 F0.198",
"G1 X16.931 Y18.800 F0.198",
"G1 X16.405 Y19.179 F0.198",
"G1 X15.849 Y19.515 F0.199",
"G1 X15.264 Y19.806 F0.199",
"G1 X14.654 Y20.049 F0.200",
"G1 X14.020 Y20.243 F0.200",
"G1 X13.364 Y20.384 F0.200",
"G1 X12.690 Y20.471 F0.201",
"G1 X12.000 Y20.500 F0.201",
"G1 X12.000 Y20.500 F0.202",
"G1 X11.310 Y20.471 F0.202",
"G1 X10.636 Y20.384 F0.203",
"G1 X9.981 Y20.243 F0.203",
"G1 X9.346 Y20.049 F0.204",
"G1 X8.736 Y19.806 F0.204",
"G1 X8.151 Y19.515 F0.205",
"G1 X7.595 Y19.179 F0.206",
"G1 X7.069 Y18.800 F0.206",
"G1 X6.576 Y18.381 F0.207",
"G1 X6.119 Y17.924 F0.207",
"G1 X5.700 Y17.431 F0.208",
"G1 X5.321 Y16.905 F0.209",
"G1 X4.985 Y16.349 F0.209",
"G1 X4.694 Y15.764 F0.210",
"G1 X4.451 Y15.154 F0.211",
"G1 X4.257 Y14.520 F0.211",
"G1 X4.116 Y13.864 F0.212",
"G1 X4.029 Y13.190 F0.213",
"G1 X4.000 Y12.500 F0.214",
"G1 X4.000 Y12.500 F0.214",
"G1 X4.029 Y11.810 F0.215",
"G1 X4.116 Y11.136 F0.216",
"G1 X4.257 Y10.481 F0.217",
"G1 X4.451 Y9.846 F0.218",
"G1 X4.694 Y9.236 F0.219",
"G1 X4.985 Y8.651 F0.219",
"G1 X5.321 Y8.095 F0.220",
"G1 X5.700 Y7.569 F0.221",
"G1 X6.119 Y7.076 F0.222",
"G1 X6.576 Y6.619 F0.223",
"G1 X7.069 Y6.200 F0.224",
"G1 X7.595 Y5.821 F0.225",
"G1 X8.151 Y5.485 F0.226",
"G1 X8.736 Y5.194 F0.227",
"G1 X9.346 Y4.951 F0.228",
"G1 X9.981 Y4.757 F0.230",
"G1 X10.636 Y4.616 F0.231",
"G1 X11.310 Y4.529 F0.232",
"G1 X12.000 Y4.500 F0.233",
"G1 X12.000 Y4.500 F0.235",
"G1 X12.690 Y4.529 F0.236",
"G1 X13.364 Y4.616 F0.237",
"G1 X14.020 Y4.757 F0.239",
"G1 X14.654 Y4.951 F0.240",
"G1 X15.264 Y5.194 F0.239",
"G1 X15.849 Y5.485 F0.237",
"G1 X16.405 Y5.821 F0.236",
"G1 X16.931 Y6.200 F0.235",
"G1 X17.424 Y6.619 F0.233",
"G1 X17.881 Y7.076 F0.232",
"G1 X18.300 Y7.569 F0.231",
"G1 X18.679 Y8.095 F0.230",
"G1 X19.015 Y8.651 F0.228",
"G1 X19.306 Y9.236 F0.227",
"G1 X19.549 Y9.846 F0.226",
"G1 X19.743 Y10.481 F0.225",
"G1 X19.884 Y11.136 F0.224",
"G1 X19.971 Y11.810 F0.223",
"G1 X20.000 Y12.500 F0.222",]
b = "socket.sock" b = "socket.sock"
sh = hw.SimuHardware(b) sh = hw.SimuHardware(b)
ctrl = ctl.DummyController() ctrl = ctl.DummyController()
gtm1 = gci.GCodeToMotors(ctrl, sh) gtm1 = gci.GCodeToMotors(ctrl, sh)
for i in instr[2:]: for i in instr[0:]:
gtm1.instruction_converter(i) gtm1.instruction_converter(i)
# gtm1.instruction_converter("G1 X25.000 Y25.000 F2.000")
# gtm1.instruction_converter("G1 X30.000 Y25.000 F2.000")
# gtm1.instruction_converter("G3 X30.000 Y45.000 I0 J10 F0.100")
# gtm1.instruction_converter("G5 X50.000 Y45.000 I-5 J-5 P10 J5 F0.5000")
# gtm1.instruction_converter("G1 X50.000 Y50.000 F2.000")
# gtm1.instruction_converter("G1 X50.000 Y100.000 F2.000")
# gtm1.instruction_converter("G1 X100.000 Y-50.000 F2.000")
# gtm1.instruction_converter("G1 X-50.000 Y-100.000 F2.000")
# gtm1.instruction_converter("G1 X-100.000 Y50.000 F2.000")

13
rapport.aux Normal file
View file

@ -0,0 +1,13 @@
\relax
\providecommand\babel@aux[2]{}
\@nameuse{bbl@beforestart}
\catcode `:\active
\catcode `;\active
\catcode `!\active
\catcode `?\active
\babel@aux{french}{}
\@writefile{toc}{\contentsline {section}{\numberline {1}Positionnement}{1}{}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {2}Réalisation}{1}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Contrôle de l'entrée}{1}{}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {3}Fonctionnement}{2}{}\protected@file@percent }
\gdef \@abspage@last{2}

164
rapport.log Normal file
View file

@ -0,0 +1,164 @@
This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023/nixos.org) (preloaded format=pdflatex 1980.1.1) 7 FEB 2025 19:03
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**rapport
(./rapport.tex
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-02-20>
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/lat
ex/base/article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/lat
ex/base/size10.clo
File: size10.clo 2023/05/17 v1.4n Standard LaTeX file (size option)
)
\c@part=\count188
\c@section=\count189
\c@subsection=\count190
\c@subsubsection=\count191
\c@paragraph=\count192
\c@subparagraph=\count193
\c@figure=\count194
\c@table=\count195
\abovecaptionskip=\skip48
\belowcaptionskip=\skip49
\bibindent=\dimen140
)
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/lat
ex/base/fontenc.sty
Package: fontenc 2021/04/29 v2.0v Standard LaTeX package
)
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/gen
eric/babel/babel.sty
Package: babel 2024/02/07 v24.2 The Babel package
\babel@savecnt=\count196
\U@D=\dimen141
\l@unhyphenated=\language89
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/gen
eric/babel/txtbabel.def)
\bbl@readstream=\read2
\bbl@dirlevel=\count197
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/gen
eric/babel-french/french.ldf
Language: french 2024-02-29 v3.5s French support from the babel system
Package babel Info: Hyphen rules for 'acadian' set to \l@french
(babel) (\language31). Reported on input line 91.
Package babel Info: Hyphen rules for 'canadien' set to \l@french
(babel) (\language31). Reported on input line 92.
\FB@stdchar=\count198
Package babel Info: Making : an active character on input line 420.
Package babel Info: Making ; an active character on input line 421.
Package babel Info: Making ! an active character on input line 422.
Package babel Info: Making ? an active character on input line 423.
\FBguill@level=\count199
\FBold@everypar=\toks17
\FB@Mht=\dimen142
\mc@charclass=\count266
\mc@charfam=\count267
\mc@charslot=\count268
\std@mcc=\count269
\dec@mcc=\count270
\FB@parskip=\dimen143
\listindentFB=\dimen144
\descindentFB=\dimen145
\labelindentFB=\dimen146
\labelwidthFB=\dimen147
\leftmarginFB=\dimen148
\parindentFFN=\dimen149
\FBfnindent=\dimen150
))
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/gen
eric/babel/locale/fr/babel-french.tex
Package babel Info: Importing font and identification data for french
(babel) from babel-fr.ini. Reported on input line 11.
)
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/lat
ex/carlisle/scalefnt.sty)
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/lat
ex/graphics/keyval.sty
Package: keyval 2022/05/29 v1.15 key=value parser (DPC)
\KV@toks@=\toks18
)
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/lat
ex/l3backend/l3backend-pdftex.def
File: l3backend-pdftex.def 2024-02-20 L3 backend support: PDF output (pdfTeX)
\l__color_backend_stack_int=\count271
\l__pdf_internal_box=\box51
) (./rapport.aux)
\openout1 = `rapport.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Info: Redefining \degres on input line 9.
LaTeX Info: Redefining \up on input line 9.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <12> on input line 10.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <8> on input line 10.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <6> on input line 10.
LaTeX Font Info: Trying to load font information for T1+cmtt on input line 3
0.
(/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/tex/lat
ex/base/t1cmtt.fd
File: t1cmtt.fd 2023/04/13 v2.5m Standard LaTeX font definitions
) [1
{/nix/store/99r9zgqml63mjnnc1pll5mb3x6w3p67g-texlive-2023-env/share/texmf-var/f
onts/map/pdftex/updmap/pdftex.map}{/nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-
texlive-2023-env-texmfdist/fonts/enc/dvips/cm-super/cm-super-t1.enc}]
Overfull \hbox (3.37326pt too wide) in paragraph at lines 56--63
\T1/cmr/m/n/10 Ce GCode est parsé, puis une boucle de contrôle est ins-tan-ciée
avec le [][]\T1/cmtt/m/n/10 Controller
[]
[2] (./rapport.aux)
***********
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-02-20>
***********
)
Here is how much of TeX's memory you used:
2553 strings out of 474116
44167 string characters out of 5720541
1932187 words of memory out of 5000000
24945 multiletter control sequences out of 15000+600000
566418 words of font info for 53 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
52i,6n,50p,213b,428s stack positions out of 10000i,1000n,20000p,200000b,200000s
</nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/fonts
/type1/public/cm-super/sfbx1200.pfb></nix/store/3sqpmm9zizph3l68bcchchva3cqp8mf
v-texlive-2023-env-texmfdist/fonts/type1/public/cm-super/sfbx1440.pfb></nix/sto
re/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/fonts/type1/publ
ic/cm-super/sfrm1000.pfb></nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2
023-env-texmfdist/fonts/type1/public/cm-super/sfrm1200.pfb></nix/store/3sqpmm9z
izph3l68bcchchva3cqp8mfv-texlive-2023-env-texmfdist/fonts/type1/public/cm-super
/sfrm1728.pfb></nix/store/3sqpmm9zizph3l68bcchchva3cqp8mfv-texlive-2023-env-tex
mfdist/fonts/type1/public/cm-super/sfti1000.pfb></nix/store/3sqpmm9zizph3l68bcc
hchva3cqp8mfv-texlive-2023-env-texmfdist/fonts/type1/public/cm-super/sftt1000.p
fb>
Output written on rapport.pdf (2 pages, 128270 bytes).
PDF statistics:
47 PDF objects out of 1000 (max. 8388607)
28 compressed objects within 1 object stream
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)

BIN
rapport.pdf Normal file

Binary file not shown.

81
rapport.tex Normal file
View file

@ -0,0 +1,81 @@
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\title{Contrôleur de petite machine à bois}
\author{Matthieu Boyer, Sélène Corbineau}
\begin{document}
\maketitle
\section{Positionnement}
Nous nous sommes intéressés au contrôle de la petite machine à bois d'hackens
(une fraiseuse à commande numérique). Pour simplifier le problème et rendre
les échecs moins dangereux, nous l'avons considérée comme un \emph{plotter} :
la tête de la PMB tient un stylo et l'on trace une image. La monture du
stylo sur la tête est munie d'un ressort. De cette manière, la hauteur exacte
de la tête importe peu pour obtenir un trait correct. L'asservissement porte
alors principalement sur les axes X et Y.
Le format naturel de dessin ici est un format vectoriel comme le SVG. Comme
représentation intermédiaire, nous avons choisi le format de commande traditionnel
des machines à commande numérique, le GCode. Le GCode est une suite d'instruction
précisant des déplacements (linéaires, circulaires voire selon des courbes
de Bézier) et, pour chaque déplacement, une vitesse cible. Le choix des vitesses
cible et la manière de les réaliser à été au coeur du projet.
\section{Réalisation}
Dans le rendu fourni, le contrôleur n'est capable d'intéragir qu'avec le
simulateur. Pour ce faire, on lance le simulateur physique \verb|simulator.py|
puis le contrôleur \verb|main.py|. Afin de générer le GCode exécuté par
le contrôleur, on peut utiliser l'exécutable \verb|svgtroppagcode.py|.
Ce dernier exécutable est séparé, car, utilisant la bibliothèque \verb|toppra|,
il faut une version compatible de NumPy d'au plus 1.21.6, qui implique une
version de Python antérieure à 3.6. Pour avoir un environnement adéquat,
nous avons utilisé les machines des salles informatiques, qui ne sont pas
à jour. N'hésitez pas à revenir vers nous si vous rencontrez des difficultés.
\subsection{Contrôle de l'entrée}
L'entrée SVG est convertie en GCode. Pour ce faire, deux méthodes sont proposées:
% TODO: Comment on choisit?
\begin{itemize}
\item Un convertisseur naïf convertit fidèlement un SVG en GCode, les feedrates
étant choisis arbitrairement.
\item Un convertisseur utilisant \verb|toppra| : on convertit le SVG en chemins,
puis on rééchantillone ce chemin en prenant en compte les contraintes en
vitesse et accélération. Cette méthode à l'inconvénient de transformer les
courbes en lignes brisées au niveau du GCode (et non plus au niveau du contrôleur).
\end{itemize}
\section{Fonctionnement}
% Blablah conversion vers SVG?
%
Nous nous sommes concentrés sur l'architecture de contrôle. Une classe
\verb|GCodeToMotors| supervise le processus de dessin, prenant en entrée du
GCode. Ce GCode est parsé, puis une boucle de contrôle est instanciée avec
le \verb|Controller| et le \verb|Hardware|. Le contrôleur décide de la commande
à appliquer étant donné la cible et l'état de la machine. L'instance
de \verb|Hardware| elle, expose deux fonctions, pour appliquer une commande et
examiner l'état de la machine.
Cette architecture modulaire permet au \verb|Hardware| d'implémenter des
interfaces diverses (commande directe du matériel, communication réseau, etc.).
Ici toutefois, on s'est restreint à une communication par socket à un processus
externe de simulation. Il est également facile de choisir la politique de contrôle
en implémentant des \verb|Controller| différents. Nous avons implémenté un
contrôleur naïf d'ordre 0, qui commande la machine à la vitesse spécifiée par
le GCode (constante par morceaux donc) et dans la direction nécessaire pour
atteindre le prochain point de contrôle. Nous avons tenté d'implémenter un
contrôleur PID, mais nous n'avons pas trouvé de coefficients donnant une
réponse intéressante : en pratique, les moteurs de la fraiseuse numérique
sont suffisamment puissants pour qu'aux vitesses raisonnables ne déchirant pas
le papier, l'inertie soit de fait négligeable.
Le simulateur fourni dans le rapport simule en temps réel, les pas de calcul
étant choisis les plus petits possibles. La communication asynchrone par socket
UNIX permet de mettre cela en oeuvre facilement.
\end{document}

View file

@ -10,4 +10,5 @@ pkgs.mkShell {
ps.scipy ps.scipy
])) ]))
]; ];
LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib/";
} }