mirror of
https://forge.apps.education.fr/blender-edutech/ropy.git
synced 2024-01-27 08:23:20 +01:00
Lecteur série Arduino et Micro:bit
This commit is contained in:
parent
2eca28aa35
commit
73ea064622
BIN
ropy-29.blend
BIN
ropy-29.blend
Binary file not shown.
33
rp.py
33
rp.py
@ -11,7 +11,7 @@ import webbrowser # Lien internet
|
|||||||
import threading # Multithreading
|
import threading # Multithreading
|
||||||
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
||||||
import runpy # Execution de script Python légère (sans import)
|
import runpy # Execution de script Python légère (sans import)
|
||||||
# import serial # Liaison série (jumeau numérique)
|
import serial # Liaison série (jumeau numérique)
|
||||||
|
|
||||||
import rp_map1 as rp_map # Map definition
|
import rp_map1 as rp_map # Map definition
|
||||||
import rp_doc # Documentation
|
import rp_doc # Documentation
|
||||||
@ -126,15 +126,6 @@ def points_maj (cont):
|
|||||||
obj=scene.objects['Rover']
|
obj=scene.objects['Rover']
|
||||||
obj['w_position']=str(round(obj.worldPosition.x,3))+","+str(round(obj.worldPosition.y,3))+","+str(round(obj.worldPosition.z,3))
|
obj['w_position']=str(round(obj.worldPosition.x,3))+","+str(round(obj.worldPosition.y,3))+","+str(round(obj.worldPosition.z,3))
|
||||||
|
|
||||||
# Jumeau numérique
|
|
||||||
# if scene.objects['Commands']['twins'] and scene.objects['Points-Twins'].visible == False:
|
|
||||||
# scene.objects['Points-Twins'].setVisible(True,True)
|
|
||||||
# scene.objects['Points-Twins-text'].setVisible(True,False)
|
|
||||||
|
|
||||||
# scene.objects['Commands']['twins_port'] = port
|
|
||||||
# scene.objects['Commands']['twins_speed'] = speed
|
|
||||||
# scene.objects['Commands']['twins'] = True
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Terrain
|
# Terrain
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -347,6 +338,16 @@ def terrain_grid_anim ():
|
|||||||
if scene.objects['Grid-u']['timer']>= 1:
|
if scene.objects['Grid-u']['timer']>= 1:
|
||||||
scene.objects['Grid-u']['anim'] = False
|
scene.objects['Grid-u']['anim'] = False
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Jumeau
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
def twins_listen():
|
||||||
|
print ("a")
|
||||||
|
serial_tmp= serial.Serial(scene.objects['Commands']['twins_port'],scene.objects['Commands']['twins_speed'])
|
||||||
|
serial_msg = str(serial_tmp.readline())
|
||||||
|
print (serial_msg)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Sons
|
# Sons
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -1029,9 +1030,9 @@ def tablet_close ():
|
|||||||
|
|
||||||
# Overlay
|
# Overlay
|
||||||
scene.objects['Points'].setVisible(True,True)
|
scene.objects['Points'].setVisible(True,True)
|
||||||
if scene.objects['Commands']['twins'] ==False:
|
if scene.objects['Commands']['twins']:
|
||||||
scene.objects['Points-Twins'].setVisible(False,True)
|
scene.objects['Points-Twins'].setVisible(True,True)
|
||||||
scene.objects['Points-Twins-text'].setVisible(False,False)
|
scene.objects['Points-Twins-text'].setVisible(True,False)
|
||||||
scene.objects['Commands'].setVisible(True,True)
|
scene.objects['Commands'].setVisible(True,True)
|
||||||
scene.objects['Camera'].setVisible(True,True)
|
scene.objects['Camera'].setVisible(True,True)
|
||||||
scene.active_camera = scene.objects["Camera"]
|
scene.active_camera = scene.objects["Camera"]
|
||||||
@ -1273,9 +1274,9 @@ def store_close():
|
|||||||
|
|
||||||
# Overlay
|
# Overlay
|
||||||
scene.objects['Points'].setVisible(True,True)
|
scene.objects['Points'].setVisible(True,True)
|
||||||
if scene.objects['Commands']['twins'] ==False:
|
if scene.objects['Commands']['twins']:
|
||||||
scene.objects['Points-Twins'].setVisible(False,True)
|
scene.objects['Points-Twins'].setVisible(True,True)
|
||||||
scene.objects['Points-Twins-text'].setVisible(False,False)
|
scene.objects['Points-Twins-text'].setVisible(True,False)
|
||||||
scene.objects['Commands'].setVisible(True,True)
|
scene.objects['Commands'].setVisible(True,True)
|
||||||
scene.objects['Camera'].setVisible(True,True)
|
scene.objects['Camera'].setVisible(True,True)
|
||||||
scene.active_camera = scene.objects["Camera"]
|
scene.active_camera = scene.objects["Camera"]
|
||||||
|
46
rp_cmd.py
46
rp_cmd.py
@ -22,6 +22,10 @@ from rp_lib import * # Bibliothèque Ropy
|
|||||||
# Fonctions
|
# Fonctions
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
def mrp_avancer():
|
||||||
|
rp_avancer()
|
||||||
|
rp_marquer()
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Commandes
|
# Commandes
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -29,17 +33,43 @@ from rp_lib import * # Bibliothèque Ropy
|
|||||||
def commandes():
|
def commandes():
|
||||||
|
|
||||||
# Ecrire votre code ici ...
|
# Ecrire votre code ici ...
|
||||||
rp_jumeau('/dev/ttyACM0', 115200)
|
rp_jumeau('/dev/ttyACM1', 115200)
|
||||||
rp_jumeau_config(50, 20, 90) # (vitesse, temps_avancer, temps_rotation)
|
|
||||||
rp_tempo(1)
|
rp_tempo(1)
|
||||||
|
print (1)
|
||||||
|
rp_tempo(1)
|
||||||
|
print (2)
|
||||||
|
rp_tempo(1)
|
||||||
|
print (3)
|
||||||
|
rp_tempo(1)
|
||||||
|
print (4)
|
||||||
|
|
||||||
rp_gauche()
|
|
||||||
# rp_marquer()
|
|
||||||
rp_avancer()
|
|
||||||
# rp_marquer()
|
|
||||||
# rp_avancer()
|
|
||||||
# rp_marquer()
|
|
||||||
|
|
||||||
|
# rp_serie_msg("Go !")
|
||||||
|
# txt =""
|
||||||
|
# while True:
|
||||||
|
# rp_tempo(0.1)
|
||||||
|
# pass
|
||||||
|
# txt=rp_serie_rcpt()
|
||||||
|
# print (txt)
|
||||||
|
# if txt !="":
|
||||||
|
# print (txt)
|
||||||
|
# break
|
||||||
|
|
||||||
|
# rp_jumeau_config(50, 20, 90) # (vitesse, temps_avancer, temps_rotation)
|
||||||
|
# rp_tempo(1)
|
||||||
|
|
||||||
|
# rp_gauche()
|
||||||
|
# mrp_avancer()
|
||||||
|
# rp_droite()
|
||||||
|
# mrp_avancer()
|
||||||
|
# mrp_avancer()
|
||||||
|
# mrp_avancer()
|
||||||
|
# mrp_avancer()
|
||||||
|
# rp_droite()
|
||||||
|
# mrp_avancer()
|
||||||
|
# mrp_avancer()
|
||||||
|
|
||||||
|
rp_jumeau_close()
|
||||||
rp_fin() # A garder
|
rp_fin() # A garder
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
<speed>1.0</speed>
|
<speed>1.0</speed>
|
||||||
<sound>False</sound>
|
<sound>False</sound>
|
||||||
<cam>
|
<cam>
|
||||||
<worldPosition.x>0.0057830810546875</worldPosition.x>
|
<worldPosition.x>-10.94022274017334</worldPosition.x>
|
||||||
<worldPosition.y>-26.440298080444336</worldPosition.y>
|
<worldPosition.y>-40.040931701660156</worldPosition.y>
|
||||||
<worldPosition.z>20.22315788269043</worldPosition.z>
|
<worldPosition.z>30.490596771240234</worldPosition.z>
|
||||||
</cam>
|
</cam>
|
||||||
<screen>
|
<screen>
|
||||||
<width>1280</width>
|
<width>1280</width>
|
||||||
@ -14,12 +14,12 @@
|
|||||||
</config>
|
</config>
|
||||||
<mission>
|
<mission>
|
||||||
<current>1</current>
|
<current>1</current>
|
||||||
<level>1</level>
|
<level>2</level>
|
||||||
</mission>
|
</mission>
|
||||||
<upgrade>
|
<upgrade>
|
||||||
<battery>False</battery>
|
<battery>False</battery>
|
||||||
<beacon>False</beacon>
|
<beacon>False</beacon>
|
||||||
<paint>False</paint>
|
<paint>False</paint>
|
||||||
<speed>False</speed>
|
<speed>True</speed>
|
||||||
</upgrade>
|
</upgrade>
|
||||||
</data>
|
</data>
|
24
rp_lib.py
24
rp_lib.py
@ -219,6 +219,7 @@ def rp_avancer ():
|
|||||||
|
|
||||||
# Animation rapide
|
# Animation rapide
|
||||||
if scene.objects['Commands']['speed'] >= 10 and scene.objects['Points']['step']> 2: # A tendance à planter sur les premiers mouvements en rapide + balisage
|
if scene.objects['Commands']['speed'] >= 10 and scene.objects['Points']['step']> 2: # A tendance à planter sur les premiers mouvements en rapide + balisage
|
||||||
|
rp_tempo (0.1)
|
||||||
x0 = obj.worldPosition.x
|
x0 = obj.worldPosition.x
|
||||||
y0 = obj.worldPosition.y
|
y0 = obj.worldPosition.y
|
||||||
z0 = obj.worldPosition.z
|
z0 = obj.worldPosition.z
|
||||||
@ -250,7 +251,7 @@ def rp_avancer ():
|
|||||||
# rp_tempo (0.1*step)
|
# rp_tempo (0.1*step)
|
||||||
|
|
||||||
# Animation
|
# Animation
|
||||||
if scene.objects['Commands']['speed'] < 10:
|
if scene.objects['Commands']['speed'] < 10 or scene.objects['Points']['step']<=2:
|
||||||
start = 1
|
start = 1
|
||||||
end = 100
|
end = 100
|
||||||
layer = 0
|
layer = 0
|
||||||
@ -340,6 +341,7 @@ def rp_reculer ():
|
|||||||
|
|
||||||
# Animation rapide
|
# Animation rapide
|
||||||
if scene.objects['Commands']['speed'] >= 10 and scene.objects['Points']['step']> 2: # A tendance à planter sur les premiers mouvements en rapide + balisage
|
if scene.objects['Commands']['speed'] >= 10 and scene.objects['Points']['step']> 2: # A tendance à planter sur les premiers mouvements en rapide + balisage
|
||||||
|
rp_tempo (0.1)
|
||||||
x0 = obj.worldPosition.x
|
x0 = obj.worldPosition.x
|
||||||
y0 = obj.worldPosition.y
|
y0 = obj.worldPosition.y
|
||||||
z0 = obj.worldPosition.z
|
z0 = obj.worldPosition.z
|
||||||
@ -409,6 +411,7 @@ def rp_gauche ():
|
|||||||
|
|
||||||
# Animation rapide
|
# Animation rapide
|
||||||
if scene.objects['Commands']['speed'] >= 10:
|
if scene.objects['Commands']['speed'] >= 10:
|
||||||
|
rp_tempo (0.1)
|
||||||
obj.applyRotation((0, 0, step), True)
|
obj.applyRotation((0, 0, step), True)
|
||||||
rp_tempo (0.1)
|
rp_tempo (0.1)
|
||||||
return True
|
return True
|
||||||
@ -458,6 +461,7 @@ def rp_droite ():
|
|||||||
|
|
||||||
# Rapide
|
# Rapide
|
||||||
if scene.objects['Commands']['speed'] >= 10:
|
if scene.objects['Commands']['speed'] >= 10:
|
||||||
|
rp_tempo (0.1)
|
||||||
obj.applyRotation((0, 0, -step), True)
|
obj.applyRotation((0, 0, -step), True)
|
||||||
rp_tempo (0.1)
|
rp_tempo (0.1)
|
||||||
return True
|
return True
|
||||||
@ -896,6 +900,11 @@ def rover_goal ():
|
|||||||
print ("Goal !!")
|
print ("Goal !!")
|
||||||
obj['stop'] = True
|
obj['stop'] = True
|
||||||
|
|
||||||
|
# Jumeau numérique
|
||||||
|
if scene.objects['Commands']['twins']:
|
||||||
|
serial_msg = "OB\n"
|
||||||
|
twins_serial.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit )
|
||||||
|
|
||||||
# Animation
|
# Animation
|
||||||
start = 1
|
start = 1
|
||||||
end = 160
|
end = 160
|
||||||
@ -1165,10 +1174,17 @@ def rp_serie_msg(text):
|
|||||||
global twins_serial
|
global twins_serial
|
||||||
twins_serial.write(text.encode())
|
twins_serial.write(text.encode())
|
||||||
|
|
||||||
def rp_serie_rcpt():
|
def twins_listen():
|
||||||
global twins_serial
|
global twins_serial
|
||||||
print ("Not yet implemented") # FIXME
|
print ("a")
|
||||||
return ("Not yet implemented")
|
serial_msg = str(twins_serial.readline())
|
||||||
|
print (serial_msg)
|
||||||
|
|
||||||
|
def rp_serie_rcpt():
|
||||||
|
pass
|
||||||
|
# global twins_serial
|
||||||
|
# print (twins_serial.readline())
|
||||||
|
# return str(twins_serial.readline()) # Communication série : arduino|micro:bit -> modele 3d
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Fonction bas niveau
|
# Fonction bas niveau
|
||||||
|
103
twins/arduino-serialreader/arduino-serialreader.ino
Executable file
103
twins/arduino-serialreader/arduino-serialreader.ino
Executable file
@ -0,0 +1,103 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* arduino-serialreader.ino
|
||||||
|
* @title: Lecteur du port serie d'une carte arduino
|
||||||
|
* @project: Ropy (Blender-EduTech)
|
||||||
|
* @lang: fr
|
||||||
|
* @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||||
|
* @copyright: Copyright (C) 2022 Philippe Roy
|
||||||
|
* @license: GNU GPL
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Pupitre
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
// Adressage Led Arduino
|
||||||
|
/* const int led = 13; // Led de mouvement (onboard) */
|
||||||
|
/* const int led_com = 10; // Led de communication modele 3d-> arduino */
|
||||||
|
const int bt = 2; // Bouton
|
||||||
|
const int v = 3; // Voyant
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Communication serie
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
String serial_msg = ""; // Message
|
||||||
|
bool serial_msg_complet = false; // Flag de message complet
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Initialisation
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
pinMode(bt, INPUT); // Bouton
|
||||||
|
pinMode(v, OUTPUT); // Voyant
|
||||||
|
/* pinMode(led, OUTPUT); // Led de mouvement */
|
||||||
|
/* pinMode(led_com, OUTPUT); // Led de communication modele 3d-> arduino */
|
||||||
|
digitalWrite(v, LOW);
|
||||||
|
/* digitalWrite(led, LOW); */
|
||||||
|
/* digitalWrite(led_com, LOW); */
|
||||||
|
|
||||||
|
Serial.begin(115200); // Moniteur serie
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Boucle principale
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
/*****
|
||||||
|
* Communication : modele 3d -> arduino
|
||||||
|
*****/
|
||||||
|
|
||||||
|
if (serial_msg_complet) {
|
||||||
|
|
||||||
|
if (serial_msg =="S\n") bt_num=true; // S pour Set
|
||||||
|
if (serial_msg =="R\n") bt_num=false; // R pour Reset
|
||||||
|
|
||||||
|
Serial.println("Echo : "+serial_msg);
|
||||||
|
serial_msg = "";
|
||||||
|
serial_msg_complet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****
|
||||||
|
* Bouton (arduino -> modele 3d)
|
||||||
|
*
|
||||||
|
* Bouton physique : LOW = actif et HIGH = pas actif
|
||||||
|
*****/
|
||||||
|
|
||||||
|
if digitalRead(bt) == LOW {
|
||||||
|
Serial.println("B");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****
|
||||||
|
* Yoyant modele 3d-> arduino
|
||||||
|
*
|
||||||
|
* Bouton numérique (modele 3d) : true = actif et false = pas actif
|
||||||
|
*****/
|
||||||
|
|
||||||
|
if bt_num == true {
|
||||||
|
digitalWrite(v, HIGH);
|
||||||
|
}
|
||||||
|
if bt_num == false {
|
||||||
|
digitalWrite(v, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* delay(300); */
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Evenements provoques par la communication serie
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
void serialEvent() {
|
||||||
|
while (Serial.available()) {
|
||||||
|
char inChar = (char)Serial.read();
|
||||||
|
serial_msg += inChar;
|
||||||
|
if (inChar == '\n') {
|
||||||
|
serial_msg_complet = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ from microbit import uart, sleep
|
|||||||
from microbit import *
|
from microbit import *
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# microbit-lecteur_portserie.py
|
# microbit-serialreader.py
|
||||||
# @title: Lecteur du port serie d'une carte micro:bit
|
# @title: Lecteur du port serie d'une carte micro:bit
|
||||||
# @project: Ropy (Blender-EduTech)
|
# @project: Ropy (Blender-EduTech)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -12,9 +12,18 @@ uart.init(baudrate= 115200) # Initialisation du port série
|
|||||||
while True:
|
while True:
|
||||||
|
|
||||||
while not uart.any(): # Attente d'un message
|
while not uart.any(): # Attente d'un message
|
||||||
pass
|
|
||||||
|
|
||||||
display.scroll('ok : ') # Réception d'un message
|
# Envoi d'un message
|
||||||
|
if button_a.is_pressed() :
|
||||||
|
display.scroll("-> A")
|
||||||
|
uart.write("A")
|
||||||
|
if button_b.is_pressed() :
|
||||||
|
display.scroll("-> B")
|
||||||
|
uart.write("B")
|
||||||
|
# pass
|
||||||
|
|
||||||
|
# Réception d'un message
|
||||||
|
display.scroll('<- ')
|
||||||
msg = uart.readline()
|
msg = uart.readline()
|
||||||
display.scroll(msg[:-1]) # Affichage du message sans le '/n'
|
display.scroll(msg[:-1]) # Affichage du message sans le '/n'
|
||||||
display.scroll(str(msg[0])+" "+str(msg[1])) # Affichage du message en code ASCII
|
display.scroll(str(msg[0])+" "+str(msg[1])) # Affichage du message en code ASCII
|
@ -4,7 +4,7 @@ import radio
|
|||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# rp_twins_maqueen-relay.py
|
# rp_twins_maqueen-relay.py
|
||||||
# @title: Jumeau Maqueen : Programme de la carte microbit du relai
|
# @title: Jumeau Maqueen : Programme de la carte microbit du relais
|
||||||
# @project: Ropy (Blender-EduTech)
|
# @project: Ropy (Blender-EduTech)
|
||||||
# @lang: fr
|
# @lang: fr
|
||||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||||
@ -18,7 +18,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("33333:36663:36963:36663:33333")
|
||||||
radio.config(group=1, queue=4, length=8)
|
radio.config(group=1, queue=4, length=8)
|
||||||
radio.on()
|
radio.on()
|
||||||
|
|
||||||
@ -28,16 +28,21 @@ uart.init(baudrate= 115200) # Initialisation du port série
|
|||||||
# Écoute du port série en relayage vers la radio
|
# Écoute du port série en relayage vers la radio
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
temps_avancer=20
|
temps_avancer=10
|
||||||
temps_tourner=20
|
temps_tourner=10
|
||||||
temps_marquer=20
|
temps_marquer=100
|
||||||
temps_forer=40
|
temps_objectif=100
|
||||||
temps_colision=40
|
temps_forer=100
|
||||||
|
temps_colision=100
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
while not uart.any(): # Attente d'un message
|
while not uart.any(): # Attente d'un message
|
||||||
pass
|
|
||||||
|
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
|
||||||
|
|
||||||
display.show(' ') # Sinon bug ?
|
display.show(' ') # Sinon bug ?
|
||||||
msg = uart.readline()
|
msg = uart.readline()
|
||||||
@ -47,42 +52,48 @@ while True:
|
|||||||
display.show(Image.ARROW_N)
|
display.show(Image.ARROW_N)
|
||||||
radio.send("AV")
|
radio.send("AV")
|
||||||
sleep(temps_avancer)
|
sleep(temps_avancer)
|
||||||
radio.send("ST")
|
|
||||||
|
|
||||||
# Reculer : RE
|
# Reculer : RE
|
||||||
if msg[0] ==82 and msg[1] ==69 : # Code ASCII : 82 (R) puis 69 (E)
|
if msg[0] ==82 and msg[1] ==69 : # Code ASCII : 82 (R) puis 69 (E)
|
||||||
display.show(Image.ARROW_S)
|
display.show(Image.ARROW_S)
|
||||||
radio.send("RE")
|
radio.send("RE")
|
||||||
sleep(temps_avancer)
|
sleep(temps_avancer)
|
||||||
radio.send("ST")
|
|
||||||
|
|
||||||
# Gauche : GA
|
# Gauche : GA
|
||||||
if msg[0] ==71 and msg[1] ==65 : # Code ASCII : 71 (G) puis 65 (A)
|
if msg[0] ==71 and msg[1] ==65 : # Code ASCII : 71 (G) puis 65 (A)
|
||||||
display.show(Image.ARROW_W)
|
display.show(Image.ARROW_W)
|
||||||
radio.send("GA")
|
radio.send("GA")
|
||||||
sleep(temps_tourner)
|
sleep(temps_tourner)
|
||||||
radio.send("ST")
|
|
||||||
|
|
||||||
# Droite : DR
|
# Droite : DR
|
||||||
if msg[0] ==68 and msg[1] ==69 : # Code ASCII : 82 (D) puis 82 (R)
|
if msg[0] ==68 and msg[1] ==82 : # Code ASCII : 68 (D) puis 82 (R)
|
||||||
display.show(Image.ARROW_E)
|
display.show(Image.ARROW_E)
|
||||||
radio.send("DR")
|
radio.send("DR")
|
||||||
sleep(temps_tourner)
|
sleep(temps_tourner)
|
||||||
radio.send("ST")
|
|
||||||
|
|
||||||
# Marquer : MA
|
# Marquer : MA
|
||||||
if msg[0] ==77 and msg[1] ==65 : # Code ASCII : 77 (M) puis 65 (A)
|
if msg[0] ==77 and msg[1] ==65 : # Code ASCII : 77 (M) puis 65 (A)
|
||||||
display.show(balise_image)
|
display.show(balise_image)
|
||||||
|
radio.send("MA")
|
||||||
sleep(temps_marquer)
|
sleep(temps_marquer)
|
||||||
|
|
||||||
|
# Objectif atteint : OB
|
||||||
|
if msg[0] ==79 and msg[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
|
# Forer : FO
|
||||||
if msg[0] ==70 and msg[1] ==79 : # Code ASCII : 70 (F) puis 79 (O)
|
if msg[0] ==70 and msg[1] ==79 : # Code ASCII : 70 (F) puis 79 (O)
|
||||||
display.show(Image.DIAMOND)
|
display.show(Image.DIAMOND)
|
||||||
|
radio.send("FO")
|
||||||
sleep(temps_forer)
|
sleep(temps_forer)
|
||||||
|
|
||||||
# Colision : CO
|
# Colision : CO
|
||||||
if msg[0] ==67 and msg[1] ==79 : # Code ASCII : 67 (C) puis 79 (O)
|
if msg[0] ==67 and msg[1] ==79 : # Code ASCII : 67 (C) puis 79 (O)
|
||||||
display.show(Image.SKULL)
|
display.show(Image.SKULL)
|
||||||
|
radio.send("CO")
|
||||||
sleep(temps_colision)
|
sleep(temps_colision)
|
||||||
|
|
||||||
# Configuration : CF
|
# Configuration : CF
|
||||||
@ -96,7 +107,7 @@ while True:
|
|||||||
pass
|
pass
|
||||||
display.show(' ')
|
display.show(' ')
|
||||||
msg = uart.readline()
|
msg = uart.readline()
|
||||||
if msg[0] ==70 and msg[1] ==67 : # Code ASCII : 70 (F) puis 67 (C) -> sortie de la configuration
|
if msg[0] ==70 and msg[1] ==67 : # Code ASCII : 70 (F) puis 67 (C) -> fin de la configuration
|
||||||
break
|
break
|
||||||
# display.scroll (msg[:-1])
|
# display.scroll (msg[:-1])
|
||||||
radio.send(str(msg[:-1]))
|
radio.send(str(msg[:-1]))
|
||||||
@ -105,6 +116,7 @@ while True:
|
|||||||
|
|
||||||
# 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)
|
||||||
|
radio.send("FI")
|
||||||
display.show(attente_image) # Témoin de fonctionnement
|
display.show(attente_image) # Témoin de fonctionnement
|
||||||
|
|
||||||
sleep(400)
|
sleep(400)
|
||||||
|
@ -19,14 +19,19 @@ import time
|
|||||||
# Initialisation
|
# Initialisation
|
||||||
# ###############################################################################
|
# ###############################################################################
|
||||||
|
|
||||||
|
# Image
|
||||||
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
|
||||||
|
balise_image = Image("33333:36663:36963:36663:33333")
|
||||||
|
|
||||||
|
# Radio
|
||||||
radio.config(group=1, queue=4, length=8)
|
radio.config(group=1, queue=4, length=8)
|
||||||
radio.on()
|
radio.on()
|
||||||
|
|
||||||
vitesse = 50
|
# Paramétrage
|
||||||
distance = 50
|
vitesse = 50 # Vitesse
|
||||||
angle = 90
|
distance = 50 # Distance d'un pas
|
||||||
|
angle = 90 # Angle lors des rotations
|
||||||
|
|
||||||
vmax_roue = 85.5 # Vitesse maxi des roues en tr/min
|
vmax_roue = 85.5 # Vitesse maxi des roues en tr/min
|
||||||
diam_roue = 43 # Diamètre des roues en mm
|
diam_roue = 43 # Diamètre des roues en mm
|
||||||
@ -38,6 +43,11 @@ dist_essieu = 70 # Distance entre les roues en mm
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
# A propos
|
||||||
|
if button_a.is_pressed() or button_b.is_pressed():
|
||||||
|
display.scroll ("Ropy : Robot")
|
||||||
|
display.show(attente_image) # Témoin de fonctionnement
|
||||||
|
|
||||||
# Lecture de l'ordre
|
# Lecture de l'ordre
|
||||||
ordre=radio.receive()
|
ordre=radio.receive()
|
||||||
|
|
||||||
@ -81,12 +91,6 @@ while True:
|
|||||||
pin12.write_digital(0) # Led avant gauche
|
pin12.write_digital(0) # Led avant gauche
|
||||||
display.clear() # Effacer matrice de leds
|
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":
|
||||||
|
|
||||||
@ -106,12 +110,6 @@ while True:
|
|||||||
pin12.write_digital(0) # Led avant gauche
|
pin12.write_digital(0) # Led avant gauche
|
||||||
display.clear() # Effacer matrice de leds
|
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_E)
|
display.show(Image.ARROW_E)
|
||||||
@ -129,38 +127,15 @@ while True:
|
|||||||
pin8.write_digital(0) # Led avant gauche
|
pin8.write_digital(0) # Led avant gauche
|
||||||
display.clear() # Effacer matrice de leds
|
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
|
|
||||||
# if ordre=="AG":
|
|
||||||
# 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, v_tourner_faible])) # Moteur gauche
|
|
||||||
# i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit
|
|
||||||
|
|
||||||
# Reculer + gauche
|
|
||||||
# if ordre=="RG":
|
|
||||||
# display.show(Image.ARROW_W)
|
|
||||||
# pin8.write_digital(1) # Led avant gauche
|
|
||||||
# pin12.write_digital(0) # Led avant droit
|
|
||||||
# i2c.write(0x10, bytearray([0x00, 0x1, v_tourner_faible])) # Moteur gauche
|
|
||||||
# i2c.write(0x10, bytearray([0x02, 0x1, v_tourner])) # Moteur droit
|
|
||||||
|
|
||||||
# Droite
|
# Droite
|
||||||
if ordre=="DR":
|
if ordre=="DR":
|
||||||
|
|
||||||
display.show(Image.ARROW_W)
|
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, vitesse])) # Avance moteur gauche
|
i2c.write(0x10, bytearray([0x00, 0x0, vitesse])) # Avance moteur gauche
|
||||||
i2c.write(0x10, bytearray([0x02, 0x1, vitesse])) # Avance moteur droit
|
i2c.write(0x10, bytearray([0x02, 0x1, vitesse])) # Avance moteur droit
|
||||||
|
|
||||||
v_roue=(vmax_roue/255)*vitesse
|
v_roue=(vmax_roue/255)*vitesse
|
||||||
v_lin = ((v_roue/60)*2*math.pi)*(diam_roue/2) # Vitesse linéaire
|
v_lin = ((v_roue/60)*2*math.pi)*(diam_roue/2) # Vitesse linéaire
|
||||||
angle2=(angle/4)*(2*math.pi/360)
|
angle2=(angle/4)*(2*math.pi/360)
|
||||||
time.sleep((dist_essieu*angle2)/v_lin)
|
time.sleep((dist_essieu*angle2)/v_lin)
|
||||||
|
|
||||||
@ -169,35 +144,29 @@ while True:
|
|||||||
pin12.write_digital(0) # Led avant droit
|
pin12.write_digital(0) # Led avant droit
|
||||||
display.clear() # Effacer matrice de leds
|
display.clear() # Effacer matrice de leds
|
||||||
|
|
||||||
# display.show(Image.ARROW_E)
|
# Marquer
|
||||||
# pin8.write_digital(0) # Led avant gauche
|
if ordre=="MA":
|
||||||
# pin12.write_digital(1) # Led avant droit
|
display.show(balise_image)
|
||||||
# i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche
|
music.play("A7:0")
|
||||||
# i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Moteur droit
|
|
||||||
|
|
||||||
# Avancer + droite
|
# Objectif
|
||||||
# if ordre=="AD":
|
if ordre=="OB":
|
||||||
# display.show(Image.ARROW_W)
|
display.show(Image.HAPPY)
|
||||||
# pin8.write_digital(1) # Led avant gauche
|
music.play(music.ENTERTAINER)
|
||||||
# pin12.write_digital(0) # Led avant droit
|
display.show(attente_image) # Témoin de fonctionnement
|
||||||
# i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche
|
|
||||||
# i2c.write(0x10, bytearray([0x02, 0x0, v_tourner_faible])) # Moteur droit
|
|
||||||
|
|
||||||
# Reculer + droite
|
# Forer
|
||||||
# if ordre=="RD":
|
if ordre=="FO":
|
||||||
# display.show(Image.ARROW_W)
|
display.show(Image.DIAMOND)
|
||||||
# pin8.write_digital(1) # Led avant gauche
|
|
||||||
# pin12.write_digital(0) # Led avant droit
|
|
||||||
# i2c.write(0x10, bytearray([0x00, 0x1, v_tourner])) # Moteur gauche
|
|
||||||
# i2c.write(0x10, bytearray([0x02, 0x1, v_tourner_faible])) # Moteur droit
|
|
||||||
|
|
||||||
# Stop
|
# Colision : CO
|
||||||
# if ordre=="ST":
|
if ordre=="CO":
|
||||||
# display.show(attente_image) # Témoin de fonctionnement
|
display.show(Image.SKULL)
|
||||||
# pin8.write_digital(0) # Led avant gauche
|
music.play(music.FUNERAL)
|
||||||
# pin12.write_digital(0) # Led avant droit
|
|
||||||
# i2c.write(0x10, bytearray([0x00, 0x0, 0]))
|
# Fin
|
||||||
# i2c.write(0x10, bytearray([0x02, 0x1, 0]))
|
if ordre=="FI":
|
||||||
|
display.show(attente_image) # Témoin de fonctionnement
|
||||||
|
|
||||||
# Cadencement
|
# Cadencement
|
||||||
# sleep(100)
|
# sleep(100)
|
||||||
|
Loading…
Reference in New Issue
Block a user