Jumeau numérique Maqueen configurable depuis Ropy

This commit is contained in:
Philippe Roy 2022-11-05 05:08:39 +01:00
parent bac3e837e0
commit 2eca28aa35
5 changed files with 187 additions and 69 deletions

Binary file not shown.

View File

@ -30,14 +30,15 @@ def commandes():
# Ecrire votre code ici ... # Ecrire votre code ici ...
rp_jumeau('/dev/ttyACM0', 115200) rp_jumeau('/dev/ttyACM0', 115200)
# rp_jumeau_config("50", "50", "90") # (vitesse, temps_avancer, temps_rotation) rp_jumeau_config(50, 20, 90) # (vitesse, temps_avancer, temps_rotation)
rp_tempo(1)
rp_gauche() rp_gauche()
rp_marquer() # rp_marquer()
rp_avancer() rp_avancer()
rp_marquer() # rp_marquer()
rp_avancer() # rp_avancer()
rp_marquer() # rp_marquer()
rp_fin() # A garder rp_fin() # A garder

View File

@ -1106,6 +1106,7 @@ def rp_jumeau(port, speed):
twins_serial = getSerialOrNone(port,speed) twins_serial = getSerialOrNone(port,speed)
if twins_serial is not None: 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'] = True
scene.objects['Commands']['twins_port'] = port scene.objects['Commands']['twins_port'] = port
scene.objects['Commands']['twins_speed'] = speed scene.objects['Commands']['twins_speed'] = speed
@ -1125,7 +1126,8 @@ def rp_jumeau(port, speed):
def getSerialOrNone(port,speed): def getSerialOrNone(port,speed):
try: try:
return serial.Serial(port,speed) # return serial.Serial(port,speed, bytesize=100)
return serial.Serial(port,speed)
except: except:
return None return None
@ -1135,12 +1137,29 @@ def rp_jumeau_close():
scene.objects['Commands']['twins'] = False scene.objects['Commands']['twins'] = False
scene.objects['Points-Twins-text']['Text'] = "Connection\nfermée" scene.objects['Points-Twins-text']['Text'] = "Connection\nfermée"
# Configuration de la vitesse et des temps (deux caractères (0-99)) # Configuration de la vitesse et des temps
def rp_jumeau_config(speed, temps_avancer, temps_rotation): def rp_jumeau_config(speed, temps_avancer, temps_tourner):
global twins_serial global twins_serial
if scene.objects['Commands']['twins']: if scene.objects['Commands']['twins']:
serial_msg = "CF"+str(speed)+str(temps_avancer)+str(temps_tourner)+"\n" serial_msg1 = "CF\n"
twins_serial.write(serial_msg.encode()) # print (serial_msg1)
twins_serial.write(serial_msg1.encode())
rp_tempo (1)
serial_msg2 = str(speed)+"\n"
# print (serial_msg2)
twins_serial.write(serial_msg2.encode())
rp_tempo (1)
serial_msg2 = str(temps_avancer)+"\n"
# print (serial_msg2)
twins_serial.write(serial_msg2.encode())
rp_tempo (1)
serial_msg2 = str(temps_tourner)+"\n"
# print (serial_msg2)
twins_serial.write(serial_msg2.encode())
rp_tempo (1)
serial_msg1 = "FC\n"
# print (serial_msg1)
twins_serial.write(serial_msg1.encode())
def rp_serie_msg(text): def rp_serie_msg(text):
global twins_serial global twins_serial

View File

@ -19,7 +19,7 @@ import radio
attente_image = Image("00000:00000:00300:00000:00000") attente_image = Image("00000:00000:00300:00000:00000")
display.show(attente_image) # Témoin de fonctionnement display.show(attente_image) # Témoin de fonctionnement
balise_image = Image("00300:03630:36963:03630:00300") balise_image = Image("00300:03630:36963:03630:00300")
radio.config(group=1, queue=1, length=8) radio.config(group=1, queue=4, length=8)
radio.on() radio.on()
uart.init(baudrate= 115200) # Initialisation du port série uart.init(baudrate= 115200) # Initialisation du port série
@ -87,11 +87,21 @@ while True:
# Configuration : CF # Configuration : CF
if msg[0] ==67 and msg[1] ==70 : # Code ASCII : 67 (C) puis 70 (F) if msg[0] ==67 and msg[1] ==70 : # Code ASCII : 67 (C) puis 70 (F)
# display.scroll ("Configuration :", msg[2],msg[3], msg[4],msg[5], msg[6],msg[7]) display.scroll ("CF")
display.scroll ("Configuration :", msg[2:-1]) radio.send("CF")
radio.send(msg[:-1])
sleep(10) # Boucle d'écoute spécifique à la configuration
# FIXME 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) -> sortie de la configuration
break
# display.scroll (msg[:-1])
radio.send(str(msg[:-1]))
# display.scroll ("FC")
radio.send("FC")
# Fin : FI # Fin : FI
if msg[0] ==70 and msg[1] ==73 : # Code ASCII : 70 (F) puis 73 (I) if msg[0] ==70 and msg[1] ==73 : # Code ASCII : 70 (F) puis 73 (I)

View File

@ -2,6 +2,8 @@ from microbit import *
from machine import * from machine import *
import music import music
import radio import radio
import math
import time
############################################################################### ###############################################################################
# rp_maqueen-robot.py # rp_maqueen-robot.py
@ -19,97 +21,183 @@ import radio
attente_image = Image("00000:00000:00900:00000:00000") attente_image = Image("00000:00000:00900:00000:00000")
display.show(attente_image) # Témoin de fonctionnement display.show(attente_image) # Témoin de fonctionnement
radio.config(group=1, queue=1, length=8) radio.config(group=1, queue=4, length=8)
radio.on() radio.on()
# ###############################################################################
# Boucle principale
# ###############################################################################
vitesse = 50 vitesse = 50
distance = 50 distance = 50
angle = 90 angle = 90
v_avancer = 50 vmax_roue = 85.5 # Vitesse maxi des roues en tr/min
v_tourner = 50 diam_roue = 43 # Diamètre des roues en mm
v_tourner_faible = 25 dist_essieu = 70 # Distance entre les roues en mm
# ###############################################################################
# Boucle principale
# ###############################################################################
while True: while True:
# Lecture de l'ordre # Lecture de l'ordre
ordre=radio.receive() ordre=radio.receive()
# Avancer # Configuration
if ordre=="CF":
display.scroll("CF")
i=1
while True:
conf=radio.receive()
if conf=="FC": # Fin de la configuration
# display.show(attente_image) # Témoin de fonctionnement
break
if conf is not None:
if i != 1:
text = str(i) + " : "+str(conf[2:-1])
# display.scroll(text)
if i == 2: # Configuration de la vitesse
vitesse = int(str(conf[2:-1]))
if i == 3: # Configuration de la distance
distance = int(str(conf[2:-1]))
if i == 4: # Configuration de l'angle
angle = int(str(conf[2:-1]))
i+=1
# Avancer d'un pas
if ordre=="AV": if ordre=="AV":
display.show(Image.ARROW_N)
display.show(Image.ARROW_N) # Afficher flèche avancer
pin8.write_digital(1) # Led avant gauche pin8.write_digital(1) # Led avant gauche
pin12.write_digital(1) # Led avant gauche pin12.write_digital(1) # Led avant gauche
i2c.write(0x10, bytearray([0x00, 0x0, v_avancer])) # Moteur gauche i2c.write(0x10, bytearray([0x00, 0x0, vitesse])) # Avance moteur gauche
i2c.write(0x10, bytearray([0x02, 0x0, v_avancer])) # Moteur droit i2c.write(0x10, bytearray([0x02, 0x0, vitesse])) # Avance moteur droit
v_roue=(vmax_roue/255)*vitesse
v_lin = ((v_roue/60)*2*math.pi)*(diam_roue/2) # Vitesse linéaire
time.sleep(distance/v_lin)
i2c.write(0x10, bytearray([0x00, 0x0, 0])) # Stop moteur gauche
i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Stop moteur droit
pin8.write_digital(0) # Led avant gauche
pin12.write_digital(0) # Led avant gauche
display.clear() # Effacer matrice de leds
# display.show(Image.ARROW_N)
# pin8.write_digital(1) # Led avant gauche
# pin12.write_digital(1) # Led avant gauche
# i2c.write(0x10, bytearray([0x00, 0x0, v_avancer])) # Moteur gauche
# i2c.write(0x10, bytearray([0x02, 0x0, v_avancer])) # Moteur droit
# Reculer # Reculer
if ordre=="RE": if ordre=="RE":
display.show(Image.ARROW_S)
display.show(Image.ARROW_S) # Afficher flèche reculer
pin8.write_digital(1) # Led avant gauche pin8.write_digital(1) # Led avant gauche
pin12.write_digital(1) # Led avant gauche pin12.write_digital(1) # Led avant gauche
i2c.write(0x10, bytearray([0x00, 0x1, v_avancer])) # Moteur gauche i2c.write(0x10, bytearray([0x00, 0x1, vitesse])) # Avance moteur gauche
i2c.write(0x10, bytearray([0x02, 0x1, v_avancer])) # Moteur droit i2c.write(0x10, bytearray([0x02, 0x1, vitesse])) # Avance moteur droit
v_roue=(vmax_roue/255)*vitesse
v_lin = ((v_roue/60)*2*math.pi)*(diam_roue/2) # Vitesse linéaire
time.sleep(distance/v_lin)
i2c.write(0x10, bytearray([0x00, 0x0, 0])) # Stop moteur gauche
i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Stop moteur droit
pin8.write_digital(0) # Led avant gauche
pin12.write_digital(0) # Led avant gauche
display.clear() # Effacer matrice de leds
# display.show(Image.ARROW_S)
# pin8.write_digital(1) # Led avant gauche
# pin12.write_digital(1) # Led avant gauche
# i2c.write(0x10, bytearray([0x00, 0x1, v_avancer])) # Moteur gauche
# i2c.write(0x10, bytearray([0x02, 0x1, v_avancer])) # Moteur droit
# Gauche # Gauche
if ordre=="GA": if ordre=="GA":
display.show(Image.ARROW_W) display.show(Image.ARROW_E)
pin8.write_digital(1) # Led avant gauche pin8.write_digital(1) # Led avant gauche
pin12.write_digital(0) # Led avant droit i2c.write(0x10, bytearray([0x00, 0x1, vitesse])) # Avance moteur gauche
i2c.write(0x10, bytearray([0x00, 0x0, 0])) # Moteur gauche i2c.write(0x10, bytearray([0x02, 0x0, vitesse])) # Avance moteur droit
i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit
v_roue=(vmax_roue/255)*vitesse
v_lin = ((v_roue/60)*2*math.pi)*(diam_roue/2) # Vitesse linéaire
angle2=(angle/4)*(2*math.pi/360)
time.sleep((dist_essieu*angle2)/v_lin)
i2c.write(0x10, bytearray([0x00, 0x0, 0])) # Stop moteur gauche
i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Stop moteur droit
pin8.write_digital(0) # Led avant gauche
display.clear() # Effacer matrice de leds
# display.show(Image.ARROW_W)
# pin8.write_digital(1) # Led avant gauche
# pin12.write_digital(0) # Led avant droit
# i2c.write(0x10, bytearray([0x00, 0x0, 0])) # Moteur gauche
# i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit
# Avancer + gauche # Avancer + gauche
if ordre=="AG": # if ordre=="AG":
display.show(Image.ARROW_W) # display.show(Image.ARROW_W)
pin8.write_digital(1) # Led avant gauche # pin8.write_digital(1) # Led avant gauche
pin12.write_digital(0) # Led avant droit # pin12.write_digital(0) # Led avant droit
i2c.write(0x10, bytearray([0x00, 0x0, v_tourner_faible])) # Moteur gauche # i2c.write(0x10, bytearray([0x00, 0x0, v_tourner_faible])) # Moteur gauche
i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit # i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit
# Reculer + gauche # Reculer + gauche
if ordre=="RG": # if ordre=="RG":
display.show(Image.ARROW_W) # display.show(Image.ARROW_W)
pin8.write_digital(1) # Led avant gauche # pin8.write_digital(1) # Led avant gauche
pin12.write_digital(0) # Led avant droit # pin12.write_digital(0) # Led avant droit
i2c.write(0x10, bytearray([0x00, 0x1, v_tourner_faible])) # Moteur gauche # i2c.write(0x10, bytearray([0x00, 0x1, v_tourner_faible])) # Moteur gauche
i2c.write(0x10, bytearray([0x02, 0x1, v_tourner])) # Moteur droit # i2c.write(0x10, bytearray([0x02, 0x1, v_tourner])) # Moteur droit
# Droite # Droite
if ordre=="DR": if ordre=="DR":
display.show(Image.ARROW_E)
pin8.write_digital(0) # Led avant gauche display.show(Image.ARROW_W)
pin12.write_digital(1) # Led avant droit pin12.write_digital(1) # Led avant droit
i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche i2c.write(0x10, bytearray([0x00, 0x0, vitesse])) # Avance moteur gauche
i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Moteur droit i2c.write(0x10, bytearray([0x02, 0x1, vitesse])) # Avance moteur droit
v_roue=(vmax_roue/255)*vitesse
v_lin = ((v_roue/60)*2*math.pi)*(diam_roue/2) # Vitesse linéaire
angle2=(angle/4)*(2*math.pi/360)
time.sleep((dist_essieu*angle2)/v_lin)
i2c.write(0x10, bytearray([0x00, 0x0, 0])) # Stop moteur gauche
i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Stop moteur droit
pin12.write_digital(0) # Led avant droit
display.clear() # Effacer matrice de leds
# display.show(Image.ARROW_E)
# pin8.write_digital(0) # Led avant gauche
# pin12.write_digital(1) # Led avant droit
# i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche
# i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Moteur droit
# Avancer + droite # Avancer + droite
if ordre=="AD": # if ordre=="AD":
display.show(Image.ARROW_W) # display.show(Image.ARROW_W)
pin8.write_digital(1) # Led avant gauche # pin8.write_digital(1) # Led avant gauche
pin12.write_digital(0) # Led avant droit # pin12.write_digital(0) # Led avant droit
i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche # i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche
i2c.write(0x10, bytearray([0x02, 0x0, v_tourner_faible])) # Moteur droit # i2c.write(0x10, bytearray([0x02, 0x0, v_tourner_faible])) # Moteur droit
# Reculer + droite # Reculer + droite
if ordre=="RD": # if ordre=="RD":
display.show(Image.ARROW_W) # display.show(Image.ARROW_W)
pin8.write_digital(1) # Led avant gauche # pin8.write_digital(1) # Led avant gauche
pin12.write_digital(0) # Led avant droit # pin12.write_digital(0) # Led avant droit
i2c.write(0x10, bytearray([0x00, 0x1, v_tourner])) # Moteur gauche # i2c.write(0x10, bytearray([0x00, 0x1, v_tourner])) # Moteur gauche
i2c.write(0x10, bytearray([0x02, 0x1, v_tourner_faible])) # Moteur droit # i2c.write(0x10, bytearray([0x02, 0x1, v_tourner_faible])) # Moteur droit
# Stop # Stop
if ordre=="ST": # if ordre=="ST":
display.show(attente_image) # Témoin de fonctionnement # display.show(attente_image) # Témoin de fonctionnement
pin8.write_digital(0) # Led avant gauche # pin8.write_digital(0) # Led avant gauche
pin12.write_digital(0) # Led avant droit # pin12.write_digital(0) # Led avant droit
i2c.write(0x10, bytearray([0x00, 0x0, 0])) # i2c.write(0x10, bytearray([0x00, 0x0, 0]))
i2c.write(0x10, bytearray([0x02, 0x1, 0])) # i2c.write(0x10, bytearray([0x02, 0x1, 0]))
# Cadencement # Cadencement
# sleep(100) # sleep(100)