Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Code Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
procom2022-robotise
Code Python
Commits
800f51c3
Commit
800f51c3
authored
2 years ago
by
TERRU Theo
Browse files
Options
Downloads
Patches
Plain Diff
Ajout prepare_command
parent
0a5a7fbd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bibliotheques/machine/script_flowmeter.py
+89
-58
89 additions, 58 deletions
bibliotheques/machine/script_flowmeter.py
with
89 additions
and
58 deletions
bibliotheques/machine/script_flowmeter.py
+
89
−
58
View file @
800f51c3
...
...
@@ -5,7 +5,10 @@ import sys
increment
=
0
nbrBoucle
=
0
nbrCyclesPompage
=
0
stop
=
0
currentQuantity
=
-
1
pwmMotor
=
0
args
=
[]
nbrArgs
=
len
(
sys
.
argv
)
# Ordre : Pompe1 Pompe2 Pompe3 EV1 EV2 EV3 EV4 EV5 EV6 EV7
...
...
@@ -22,36 +25,94 @@ EV7 = 9
args
=
[
1
,
1
,
0
]
def
testDebimetre
(
bec
,
quantite
):
# quantité en cl (int), bec (int)
# Setup des composants
def
prepare_commande
(
commande
):
for
bec
,
quantite
in
commande
:
setupGpio
()
print
(
"
in prepare commande, bec :
"
+
str
(
bec
)
+
"
, quantite :
"
+
str
(
quantite
))
#startLine(bec, quantite, 0)
# Setup des composants
def
setupGpio
():
global
pwmMotor
GPIO
.
setmode
(
GPIO
.
BCM
)
# set up BCM GPIO numbering
GPIO
.
setup
(
25
,
GPIO
.
IN
,
pull_up_down
=
GPIO
.
PUD_DOWN
)
# DEBITMETRE
GPIO
.
setup
(
24
,
GPIO
.
OUT
,
initial
=
GPIO
.
LOW
)
# ELECTROVANNE 1
GPIO
.
setup
(
21
,
GPIO
.
OUT
,
initial
=
GPIO
.
LOW
)
# ELECTROVANNE 2
GPIO
.
setup
(
23
,
GPIO
.
OUT
)
# POMPE
p
=
GPIO
.
PWM
(
23
,
1
00
)
p
wmMotor
=
GPIO
.
PWM
(
23
,
3
00
)
# Démarrage des composants requis
def
startPompage
(
quantite
):
global
increment
global
pwmMotor
PWM
=
0
increment
=
1
while
PWM
<=
50
:
pwmMotor
.
start
(
PWM
)
print
(
"
PWM =
"
,
PWM
)
PWM
+=
5
sleep
(
0.1
)
#sleep(0.3)
def
stopLine
():
global
pwmMotor
pwmMotor
.
stop
()
#GPIO.remove_event_detect(25)
GPIO
.
cleanup
()
# clean up after yourself
print
(
"
GPIO cleaned
"
)
def
startLine
(
bec
,
quantite
,
amorcage
):
# quantité en cl (int), bec (int)
global
currentQuantity
global
stop
currentQuantity
=
quantite
print
(
"
Start : Ligne
"
,
bec
)
print
(
"
Quantité voulue :
"
,
quantite
)
openMotorPompe1
=
0
stop
=
0
if
not
amorcage
:
if
bec
==
1
:
GPIO
.
output
(
24
,
GPIO
.
HIGH
)
print
(
"
Electrovanne1 ouverte
"
)
startMotorPompe1
=
1
elif
bec
==
2
:
GPIO
.
output
(
21
,
GPIO
.
HIGH
)
print
(
"
Electrovanne2 ouverte
"
)
startMotorPompe1
=
1
else
:
print
(
"
NON IMPLEMENTE
"
)
else
:
print
(
"
Phase amorcage
"
)
GPIO
.
output
(
24
,
GPIO
.
HIGH
)
print
(
"
Electrovanne1 ouverte
"
)
GPIO
.
output
(
21
,
GPIO
.
HIGH
)
print
(
"
Electrovanne2 ouverte
"
)
Q
=
int
(
quantite
/
5
)
q
=
int
(
quantite
%
5
)
print
(
"
Q =
"
,
Q
)
print
(
"
q =
"
,
q
)
startMotorPompe1
=
0
sleep
(
10
)
# Define a threaded callback function to run in another thread when events are detected
def
my_callback
(
channel
):
def
flowmeterTrigger
(
channel
):
global
nbrBoucle
global
increment
global
nbrCyclesPompage
global
currentQuantity
global
stop
global
nbrBoucle
# Si la quantité désirée a été pompée
if
nbrBoucle
==
Q
-
1
and
not
stop
:
if
increment
==
currentQuantity
:
# Arrêt de tous les composants
p
.
stop
()
#pwmMotor
.stop()
print
(
"
Pompe fermée
"
)
GPIO
.
output
(
24
,
GPIO
.
LOW
)
...
...
@@ -59,8 +120,9 @@ def testDebimetre(bec, quantite): # quantité en cl (int), bec (int)
GPIO
.
output
(
21
,
GPIO
.
LOW
)
print
(
"
Electrovanne 2 fermée
"
)
stopLine
()
stop
=
1
stop
=
1
# Tant qu'il manque du liquide on continue de pomper
elif
GPIO
.
input
(
25
):
# if port 25 == 1
...
...
@@ -68,61 +130,30 @@ def testDebimetre(bec, quantite): # quantité en cl (int), bec (int)
increment
+=
1
print
(
increment
)
# Ajout du
callback
débitmètre
GPIO
.
add_event_detect
(
25
,
GPIO
.
RISING
,
callback
=
my_callback
,
bouncetime
=
5
)
# Ajout du
trigger
débitmètre
GPIO
.
add_event_detect
(
25
,
GPIO
.
RISING
,
callback
=
flowmeterTrigger
,
bouncetime
=
5
)
if
args
[
EV1
]
:
GPIO
.
output
(
24
,
GPIO
.
HIGH
)
print
(
"
Electrovanne1 ouverte
"
)
if
startMotorPompe1
:
startPompage
(
currentQuantity
)
if
args
[
EV2
]:
GPIO
.
output
(
21
,
GPIO
.
HIGH
)
print
(
"
Electrovanne2 ouverte
"
)
# Démarrage des composants requis
if
args
[
Pompe1
]:
global
nbrBoucle
print
(
"
Pompe1 ouverte
"
)
for
i
in
range
(
Q
):
PWM
=
0
increment
=
1
while
PWM
<=
50
:
p
.
start
(
PWM
)
print
(
"
PWM =
"
,
PWM
)
PWM
+=
5
sleep
(
0.1
)
while
increment
%
5
!=
0
:
pass
increment
=
1
p
.
stop
()
nbrBoucle
+=
1
#sleep(0.3)
#GPIO.output(23, GPIO.HIGH)
try
:
# Thread du débitmètre tourne en fond
try
:
while
not
stop
:
pass
finally
:
print
(
"
CLEANUP
"
)
GPIO
.
cleanup
()
finally
:
# this block will run no matter how the try block exits
p
.
stop
()
#GPIO.remove_event_detect(25)
GPIO
.
cleanup
()
# clean up after yourself
print
(
"
GPIO cleaned
"
)
print
(
"
Fin du programme
"
)
increment
=
0
stop
=
0
if
__name__
==
"
__main__
"
:
args
=
[]
for
strParam
in
sys
.
argv
[
1
:]:
try
:
args
.
append
(
int
(
strParam
))
except
ValueError
:
print
(
"
Bad parameter value: %s
"
%
strParam
,
file
=
sys
.
stderr
)
testDebimetre
(
2
,
28
)
#setupGpio()
#stopLine()
setupGpio
()
startLine
(
2
,
100
,
0
)
#setupGpio()
#startLine(2, 30, 0)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment