mirror of
https://forge.apps.education.fr/blender-edutech/ropy.git
synced 2024-01-27 08:23:20 +01:00
Ajout du relais : télécommande -> ropy
This commit is contained in:
parent
057668decd
commit
f9336f9610
BIN
ropy-29.blend
BIN
ropy-29.blend
Binary file not shown.
19
rp_cmd.py
19
rp_cmd.py
@ -28,9 +28,24 @@ from rp_lib import * # Bibliothèque Ropy
|
||||
|
||||
def commandes():
|
||||
|
||||
rp_jumeau('/dev/ttyACM0', 115200)
|
||||
|
||||
rp_jumeau('/dev/ttyACM1', 115200)
|
||||
rp_avancer()
|
||||
rp_gauche()
|
||||
|
||||
# while True :
|
||||
# ordre = rp_serie_rcpt()
|
||||
# print (ordre)
|
||||
# if "AV" in ordre :
|
||||
# rp_avancer()
|
||||
# rp_marquer()
|
||||
# if "RE" in ordre :
|
||||
# rp_reculer()
|
||||
# if "GA" in ordre :
|
||||
# rp_gauche()
|
||||
# if "DR" in ordre :
|
||||
# rp_droite()
|
||||
# if "ST" in ordre :
|
||||
# break
|
||||
|
||||
rp_fin() # A garder
|
||||
|
||||
|
31
rp_lib.py
31
rp_lib.py
@ -1116,13 +1116,16 @@ def rp_jumeau(port, speed):
|
||||
if twins_serial is not None:
|
||||
# twins_serial.set_buffer_size(rx_size = 12800, tx_size = 12800)
|
||||
scene.objects['Commands']['twins'] = True
|
||||
scene.objects['Commands']['twins_close'] = False
|
||||
scene.objects['Commands']['twins_port'] = port
|
||||
scene.objects['Commands']['twins_speed'] = speed
|
||||
scene.objects['Points-Twins-text']['Text'] = "Connection\nouverte :\n"+port+"\n"+str(speed)+" baud"
|
||||
scene.objects['Commands']['twins_readline'] = ""
|
||||
scene.objects['Points-Twins-text']['Text'] = "Connection ouverte :\n"+port+" - "+str(speed)+" baud"
|
||||
rp_tempo (0.1)
|
||||
print (twins_serial)
|
||||
else:
|
||||
scene.objects['Commands']['twins'] = False
|
||||
scene.objects['Points-Twins-text']['Text'] = "Port\n"+port+"\npas prêt"
|
||||
scene.objects['Points-Twins-text']['Text'] = "Port "+port+" pas prêt"
|
||||
|
||||
# # ser = serial.Serial('/dev/ttyACM0',38400) # 6 fps
|
||||
# # ser = serial.Serial('/dev/ttyACM0',9600) # 2 fps
|
||||
@ -1143,7 +1146,7 @@ def rp_jumeau_close():
|
||||
global twins_serial
|
||||
twins_serial.close() # Fermer proprement le port série
|
||||
scene.objects['Commands']['twins'] = False
|
||||
scene.objects['Points-Twins-text']['Text'] = "Connection\nfermée"
|
||||
scene.objects['Points-Twins-text']['Text'] = "Connection fermée"
|
||||
|
||||
# Configuration de la vitesse et des temps
|
||||
# FIXME : Bug dans le transfert des données
|
||||
@ -1172,21 +1175,27 @@ def rp_serie_msg(text):
|
||||
|
||||
def twins_listen(cont):
|
||||
global twins_serial
|
||||
if cont.sensors['Property'].positive:
|
||||
if scene.objects['Commands']['twins_listen'] :
|
||||
serial_msg = twins_serial.readline()
|
||||
if serial_msg is not None:
|
||||
scene.objects['Commands']['twins_readline'] = str(serial_msg)
|
||||
scene.objects['Commands']['twins_listen'] = False
|
||||
if scene.objects['Commands']['twins']:
|
||||
if scene.objects['Commands']['twins_readline'] != "":
|
||||
scene.objects['Points-Twins-text']['Text'] = "Écoute de la connection\nfigeage de la scène\nMessage reçu : "+scene.objects['Commands']['twins_readline']
|
||||
else:
|
||||
scene.objects['Points-Twins-text']['Text'] = "Écoute de la connection\nfigeage de la scène"
|
||||
if cont.sensors['Property'].positive:
|
||||
if scene.objects['Commands']['twins_listen'] :
|
||||
serial_msg = twins_serial.readline()
|
||||
if serial_msg is not None:
|
||||
scene.objects['Commands']['twins_readline'] = str(serial_msg)
|
||||
# scene.objects['Points-Twins-text']['Text'] = "Message reçu : "+str(serial_msg)
|
||||
scene.objects['Commands']['twins_listen'] = False
|
||||
|
||||
def rp_serie_rcpt():
|
||||
scene.objects['Points-Twins-text']['Text'] = "Écoute de la \nconnection\n figeage de \n la scène"
|
||||
# scene.objects['Points-Twins-text']['Text'] = "Écoute de la \nconnection\n figeage de \n la scène"
|
||||
scene.objects['Commands']['twins_readline'] = ""
|
||||
scene.objects['Commands']['twins_listen'] = True
|
||||
while scene.objects['Commands']['twins_readline'] == "":
|
||||
if scene.objects['Commands']['twins_readline'] != "":
|
||||
break
|
||||
scene.objects['Points-Twins-text']['Text'] = "Connection\nouverte :\n"+scene.objects['Commands']['twins_port']+"\n"+str(scene.objects['Commands']['twins_speed'])+" baud"
|
||||
# scene.objects['Points-Twins-text']['Text'] = "Connection\nouverte :\n"+scene.objects['Commands']['twins_port']+"\n"+str(scene.objects['Commands']['twins_speed'])+" baud"
|
||||
return scene.objects['Commands']['twins_readline']
|
||||
|
||||
###############################################################################
|
||||
|
@ -3,7 +3,7 @@ from microbit import *
|
||||
import radio
|
||||
|
||||
###############################################################################
|
||||
# rp_twins_maqueen-relay.py
|
||||
# rp_maqueen-relay.py
|
||||
# @title: Jumeau Maqueen : Programme de la carte microbit du relais
|
||||
# @project: Ropy (Blender-EduTech)
|
||||
# @lang: fr
|
||||
@ -25,7 +25,7 @@ radio.on()
|
||||
uart.init(baudrate= 115200) # Initialisation du port série
|
||||
|
||||
###############################################################################
|
||||
# Écoute du port série en relayage vers la radio
|
||||
# Écoute du port série et de la radio pour relayage
|
||||
###############################################################################
|
||||
|
||||
temps_avancer=10
|
||||
@ -37,67 +37,113 @@ temps_colision=100
|
||||
|
||||
while True:
|
||||
|
||||
while not uart.any(): # Attente d'un message
|
||||
while not uart.any(): # Attente d'un message du port série
|
||||
|
||||
if button_a.is_pressed() or button_b.is_pressed(): # A propos
|
||||
display.scroll ("Ropy : Relais")
|
||||
display.show(attente_image) # Témoin de fonctionnement
|
||||
# pass
|
||||
|
||||
ordre_radio=radio.receive()
|
||||
|
||||
##########################
|
||||
# Transmission d'un ordre radio (venant de la télécommande -> série)
|
||||
##########################
|
||||
|
||||
# Avancer : AV
|
||||
if ordre_radio=="AV":
|
||||
display.show(Image.ARROW_N)
|
||||
uart.write("AV\n")
|
||||
|
||||
# Reculer : RE
|
||||
if ordre_radio=="RE":
|
||||
display.show(Image.ARROW_S)
|
||||
uart.write("RE\n")
|
||||
|
||||
# Gauche : GA
|
||||
if ordre_radio=="GA":
|
||||
display.show(Image.ARROW_W)
|
||||
uart.write("GA\n")
|
||||
|
||||
# Droite : DR
|
||||
if ordre_radio=="DR":
|
||||
display.show(Image.ARROW_E)
|
||||
uart.write("DR\n")
|
||||
|
||||
# Marquer : MA
|
||||
if ordre_radio=="MA":
|
||||
display.show(balise_image)
|
||||
uart.write("MA\n")
|
||||
|
||||
# Stop : ST (arrêt de la télécommande)
|
||||
if ordre_radio=="ST":
|
||||
display.show(Image.NO)
|
||||
uart.write("ST\n")
|
||||
|
||||
# Fin : FI (fin du mouvement)
|
||||
if ordre_radio=="FI":
|
||||
display.show(attente_image) # Témoin de fonctionnement
|
||||
|
||||
##########################
|
||||
# Transmission d'un ordre série (venant du jumeau numérique -> radio)
|
||||
##########################
|
||||
|
||||
display.show(' ') # Sinon bug ?
|
||||
msg = uart.readline()
|
||||
|
||||
ordre_serie = uart.readline()
|
||||
|
||||
# Avancer : AV
|
||||
if msg[0] ==65 and msg[1] ==86 : # Code ASCII : 65 (A) puis 86 (V)
|
||||
if ordre_serie[0] ==65 and ordre_serie[1] ==86 : # Code ASCII : 65 (A) puis 86 (V)
|
||||
display.show(Image.ARROW_N)
|
||||
radio.send("AV")
|
||||
sleep(temps_avancer)
|
||||
|
||||
# Reculer : RE
|
||||
if msg[0] ==82 and msg[1] ==69 : # Code ASCII : 82 (R) puis 69 (E)
|
||||
if ordre_serie[0] ==82 and ordre_serie[1] ==69 : # Code ASCII : 82 (R) puis 69 (E)
|
||||
display.show(Image.ARROW_S)
|
||||
radio.send("RE")
|
||||
sleep(temps_avancer)
|
||||
|
||||
# Gauche : GA
|
||||
if msg[0] ==71 and msg[1] ==65 : # Code ASCII : 71 (G) puis 65 (A)
|
||||
if ordre_serie[0] ==71 and ordre_serie[1] ==65 : # Code ASCII : 71 (G) puis 65 (A)
|
||||
display.show(Image.ARROW_W)
|
||||
radio.send("GA")
|
||||
sleep(temps_tourner)
|
||||
|
||||
# Droite : DR
|
||||
if msg[0] ==68 and msg[1] ==82 : # Code ASCII : 68 (D) puis 82 (R)
|
||||
if ordre_serie[0] ==68 and ordre_serie[1] ==82 : # Code ASCII : 68 (D) puis 82 (R)
|
||||
display.show(Image.ARROW_E)
|
||||
radio.send("DR")
|
||||
sleep(temps_tourner)
|
||||
|
||||
# Marquer : MA
|
||||
if msg[0] ==77 and msg[1] ==65 : # Code ASCII : 77 (M) puis 65 (A)
|
||||
if ordre_serie[0] ==77 and ordre_serie[1] ==65 : # Code ASCII : 77 (M) puis 65 (A)
|
||||
display.show(balise_image)
|
||||
radio.send("MA")
|
||||
sleep(temps_marquer)
|
||||
|
||||
# Objectif atteint : OB
|
||||
if msg[0] ==79 and msg[1] ==66 : # Code ASCII : 79 (O) puis 66 (B)
|
||||
if ordre_serie[0] ==79 and ordre_serie[1] ==66 : # Code ASCII : 79 (O) puis 66 (B)
|
||||
display.show(Image.HAPPY)
|
||||
radio.send("OB")
|
||||
sleep(temps_objectif)
|
||||
display.show(attente_image) # Témoin de fonctionnement
|
||||
|
||||
# Forer : FO
|
||||
if msg[0] ==70 and msg[1] ==79 : # Code ASCII : 70 (F) puis 79 (O)
|
||||
if ordre_serie[0] ==70 and ordre_serie[1] ==79 : # Code ASCII : 70 (F) puis 79 (O)
|
||||
display.show(Image.DIAMOND)
|
||||
radio.send("FO")
|
||||
sleep(temps_forer)
|
||||
|
||||
# Colision : CO
|
||||
if msg[0] ==67 and msg[1] ==79 : # Code ASCII : 67 (C) puis 79 (O)
|
||||
if ordre_serie[0] ==67 and ordre_serie[1] ==79 : # Code ASCII : 67 (C) puis 79 (O)
|
||||
display.show(Image.SKULL)
|
||||
radio.send("CO")
|
||||
sleep(temps_colision)
|
||||
|
||||
# Configuration : CF
|
||||
if msg[0] ==67 and msg[1] ==70 : # Code ASCII : 67 (C) puis 70 (F)
|
||||
# FIXME : bugé
|
||||
|
||||
if ordre_serie[0] ==67 and ordre_serie[1] ==70 : # Code ASCII : 67 (C) puis 70 (F)
|
||||
display.scroll ("CF")
|
||||
radio.send("CF")
|
||||
|
||||
@ -106,16 +152,16 @@ while True:
|
||||
while not uart.any(): # Attente d'un message
|
||||
pass
|
||||
display.show(' ')
|
||||
msg = uart.readline()
|
||||
if msg[0] ==70 and msg[1] ==67 : # Code ASCII : 70 (F) puis 67 (C) -> fin de la configuration
|
||||
ordre_serie = uart.readline()
|
||||
if ordre_serie[0] ==70 and ordre_serie[1] ==67 : # Code ASCII : 70 (F) puis 67 (C) -> fin de la configuration
|
||||
break
|
||||
# display.scroll (msg[:-1])
|
||||
radio.send(str(msg[:-1]))
|
||||
# display.scroll (ordre_serie[:-1])
|
||||
radio.send(str(ordre_serie[:-1]))
|
||||
# display.scroll ("FC")
|
||||
radio.send("FC")
|
||||
|
||||
# Fin : FI
|
||||
if msg[0] ==70 and msg[1] ==73 : # Code ASCII : 70 (F) puis 73 (I)
|
||||
if ordre_serie[0] ==70 and ordre_serie[1] ==73 : # Code ASCII : 70 (F) puis 73 (I)
|
||||
radio.send("FI")
|
||||
display.show(attente_image) # Témoin de fonctionnement
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user