boutons ajoutés
This commit is contained in:
164
control.py
164
control.py
@@ -9,28 +9,36 @@ lock = threading.Lock()
|
||||
phrase = "";
|
||||
continue_thread = 1
|
||||
est_stop = 0
|
||||
actions_a_faire = []
|
||||
|
||||
def getProcess(a_dire):
|
||||
return subprocess.Popen(["espeak",
|
||||
"-v",
|
||||
"mb/mb-fr1",
|
||||
"-s",
|
||||
"155",
|
||||
a_dire
|
||||
], stdout=subprocess.PIPE)
|
||||
|
||||
def dis_phrase_thread():
|
||||
global continue_thread
|
||||
global phrase
|
||||
global actions_a_faire
|
||||
prev_phrase = ""
|
||||
while (continue_thread == 1) :
|
||||
lock.acquire()
|
||||
actions_a_faire2 = actions_a_faire.copy()
|
||||
actions_a_faire.clear()
|
||||
# Énoncer le déplacement
|
||||
if phrase is not "" :
|
||||
a_dire = phrase
|
||||
if phrase is prev_phrase :
|
||||
if not (phrase == "STOP !") :
|
||||
a_dire = "Continue !"
|
||||
a_dire = "Continue le déplacement !"
|
||||
else :
|
||||
a_dire = ""
|
||||
if a_dire is not "" :
|
||||
process = subprocess.Popen(["espeak",
|
||||
"-v",
|
||||
"mb/mb-fr1",
|
||||
"-s",
|
||||
"120",
|
||||
a_dire
|
||||
], stdout=subprocess.PIPE)
|
||||
process = getProcess(a_dire)
|
||||
lock.release()
|
||||
prev_phrase = phrase
|
||||
output, error = process.communicate()
|
||||
@@ -38,13 +46,26 @@ def dis_phrase_thread():
|
||||
lock.release()
|
||||
else :
|
||||
lock.release()
|
||||
# Énoncer les actions à faire, pas besoin de lock ici puisque l'on
|
||||
# utilise une copie locale d'actions à faire
|
||||
if len(actions_a_faire2)>0 :
|
||||
getProcess("Actions !").communicate()
|
||||
for action_a_faire in actions_a_faire2 :
|
||||
process = getProcess(action_a_faire)
|
||||
process.communicate()
|
||||
|
||||
def ajoute_action(action) :
|
||||
global actions_a_faire
|
||||
lock.acquire()
|
||||
if action not in actions_a_faire :
|
||||
actions_a_faire.append(action)
|
||||
lock.release()
|
||||
|
||||
# propose la phrase à dire au thread qui parle
|
||||
def dis_phrase(phrase1):
|
||||
global phrase
|
||||
lock.acquire()
|
||||
phrase = phrase1
|
||||
print("propose {}".format(phrase1))
|
||||
lock.release()
|
||||
|
||||
# raffinerie des entrées
|
||||
@@ -145,57 +166,57 @@ def tourne_droite():
|
||||
def accroupis_toi():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Jusqu'à nouvel ordre, déplace toi accroupi !")
|
||||
ajoute_action("Jusqu'à nouvel ordre, déplace toi accroupi !")
|
||||
|
||||
def releve_toi():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Jusqu'à nouvel ordre, déplace toi debout !")
|
||||
ajoute_action("Jusqu'à nouvel ordre, déplace toi debout !")
|
||||
|
||||
def tends_bras_droit():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Jusqu'à nouvel ordre, tends le bras droit !")
|
||||
ajoute_action("Jusqu'à nouvel ordre, tends le bras droit !")
|
||||
|
||||
def tends_bras_gauche():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Jusqu'à nouvel ordre, tends le bras gauche !")
|
||||
ajoute_action("Jusqu'à nouvel ordre, tends le bras gauche !")
|
||||
|
||||
def detends_bras_droit():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Jusqu'à nouvel ordre, détends le bras droit !")
|
||||
ajoute_action("Jusqu'à nouvel ordre, détends le bras droit !")
|
||||
|
||||
def detends_bras_gauche():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Jusqu'à nouvel ordre, détends le bras gauche !")
|
||||
ajoute_action("Jusqu'à nouvel ordre, détends le bras gauche !")
|
||||
|
||||
def attrape():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Attrape !")
|
||||
ajoute_action("Attrape !")
|
||||
|
||||
def lache():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Lâche !")
|
||||
ajoute_action("Lâche !")
|
||||
|
||||
def saute():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Saute !")
|
||||
ajoute_action("Saute !")
|
||||
|
||||
def coup_pied_gauche():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Coup de pied gauche !")
|
||||
ajoute_action("Coup de pied gauche !")
|
||||
|
||||
def coup_pied_droit():
|
||||
global est_stop
|
||||
est_stop = 0
|
||||
dis_phrase("Coup de pied droit !")
|
||||
ajoute_action("Coup de pied droit !")
|
||||
|
||||
print(inputs.devices.gamepads)
|
||||
|
||||
@@ -242,6 +263,33 @@ absy = -1
|
||||
absrx = -1
|
||||
absry = -1
|
||||
|
||||
prev_L3 = -1
|
||||
L3 = -1
|
||||
accroupi = 0
|
||||
|
||||
prev_X = -1
|
||||
X = -1
|
||||
attrape = 0
|
||||
|
||||
prev_TL = -1
|
||||
TL = -1
|
||||
pied_gauche= 0
|
||||
|
||||
prev_TR = -1
|
||||
TR = -1
|
||||
pied_droit = 0
|
||||
|
||||
prev_A = -1
|
||||
A = -1
|
||||
|
||||
prev_brase_gauche = -1
|
||||
bras_gauche = -1
|
||||
bras_gauche_tendu = 0
|
||||
|
||||
prev_brase_droit = -1
|
||||
bras_droit = -1
|
||||
bras_droit_tendu = 0
|
||||
|
||||
prev_action = -1
|
||||
|
||||
while (True) :
|
||||
@@ -256,11 +304,25 @@ while (True) :
|
||||
absrx = raffine_entree(event.state)
|
||||
if event.code =="ABS_RY":
|
||||
absry = raffine_entree(event.state)
|
||||
|
||||
if event.code == "BTN_THUMBL" :
|
||||
L3 = event.state
|
||||
if event.code =="ABS_Z":
|
||||
bras_gauche = event.state
|
||||
if event.code =="ABS_RZ":
|
||||
bras_droit = event.state
|
||||
if event.code == "BTN_NORTH" :
|
||||
X = event.state
|
||||
if event.code == "BTN_SOUTH" :
|
||||
A = event.state
|
||||
if event.code == "BTN_TL" :
|
||||
TL = event.state
|
||||
if event.code == "BTN_TR" :
|
||||
TR = event.state
|
||||
|
||||
if abs(absx) < DEAD_ZONE and abs(absy) < DEAD_ZONE and abs(absrx) < DEAD_ZONE :
|
||||
neutral = 3
|
||||
|
||||
# Traitement des déplacements
|
||||
action_voulue = -1
|
||||
if abs(absx) > DEAD_ZONE :
|
||||
if absx < -80 :
|
||||
@@ -275,8 +337,6 @@ while (True) :
|
||||
action_voulue = 7
|
||||
|
||||
if abs(absx) > DEAD_ZONE and abs(absy) > DEAD_ZONE :
|
||||
print("absy : {}".format(absx))
|
||||
print("absx : {}".format(absy))
|
||||
if (absx <0 and absx < -40) and (absy <0 and absy < -40) :
|
||||
action_voulue = 5
|
||||
elif (absx >0 and absx > 40) and (absy <0 and absy < -40) :
|
||||
@@ -293,8 +353,6 @@ while (True) :
|
||||
action_voulue = 16
|
||||
|
||||
if abs(absrx) > DEAD_ZONE and abs(absy) > DEAD_ZONE :
|
||||
print("absy : {}".format(absx))
|
||||
print("absx : {}".format(absy))
|
||||
if (absrx <0 and absrx < -DEAD_ZONE) and (absy <0 and absy < -40) :
|
||||
action_voulue = 3
|
||||
elif (absrx >0 and absrx > DEAD_ZONE) and (absy <0 and absy < -40) :
|
||||
@@ -310,3 +368,59 @@ while (True) :
|
||||
if action_voulue > -1 :
|
||||
actions[action_voulue]()
|
||||
|
||||
# Traitements des actions à faire
|
||||
|
||||
if L3 > -1 and not L3 == prev_L3 :
|
||||
if L3 == 1 :
|
||||
if accroupi == 0 :
|
||||
accroupi = 1
|
||||
actions[17]()
|
||||
else :
|
||||
accroupi = 0
|
||||
actions[18]()
|
||||
prev_L3 = L3
|
||||
|
||||
if bras_gauche > -1 :
|
||||
if bras_gauche > 200 :
|
||||
if bras_gauche_tendu == 0 :
|
||||
bras_gauche_tendu = 1
|
||||
actions[20]()
|
||||
elif bras_gauche < 30 :
|
||||
if bras_gauche_tendu == 1 :
|
||||
bras_gauche_tendu = 0
|
||||
actions[22]()
|
||||
|
||||
if bras_droit > -1 :
|
||||
if bras_droit > 200 :
|
||||
if bras_droit_tendu == 0 :
|
||||
bras_droit_tendu = 1
|
||||
actions[19]()
|
||||
elif bras_droit < 30 :
|
||||
if bras_droit_tendu == 1 :
|
||||
bras_droit_tendu = 0
|
||||
actions[21]()
|
||||
|
||||
if X > -1 and not X == prev_X :
|
||||
if X == 1 :
|
||||
if attrape == 0 :
|
||||
attrape = 1
|
||||
actions[23]()
|
||||
else :
|
||||
attrape = 0
|
||||
actions[24]()
|
||||
prev_X = X
|
||||
|
||||
if A > -1 and not A == prev_A :
|
||||
if A == 1 :
|
||||
actions[25]()
|
||||
prev_A = A
|
||||
|
||||
if TL > -1 and not TL == prev_A :
|
||||
if TL == 1 :
|
||||
actions[26]()
|
||||
prev_A = TL
|
||||
|
||||
if TR > -1 and not TR == prev_A :
|
||||
if TR == 1 :
|
||||
actions[27]()
|
||||
prev_A = TR
|
||||
|
||||
Reference in New Issue
Block a user