mirror of
https://forge.apps.education.fr/blender-edutech/ropy.git
synced 2024-01-27 08:23:20 +01:00
Exemples pour micro:bit et arduino
This commit is contained in:
parent
4117a7afdb
commit
8782ccad28
BIN
ropy-29.blend
BIN
ropy-29.blend
Binary file not shown.
17
rp.py
17
rp.py
@ -11,7 +11,6 @@ import webbrowser # Lien internet
|
||||
import threading # Multithreading
|
||||
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
||||
import runpy # Execution de script Python légère (sans import)
|
||||
import serial # Liaison série (jumeau numérique)
|
||||
|
||||
import rp_map1 as rp_map # Map definition
|
||||
import rp_doc # Documentation
|
||||
@ -338,16 +337,6 @@ def terrain_grid_anim ():
|
||||
if scene.objects['Grid-u']['timer']>= 1:
|
||||
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
|
||||
###############################################################################
|
||||
@ -1033,6 +1022,9 @@ def tablet_close ():
|
||||
if scene.objects['Commands']['twins']:
|
||||
scene.objects['Points-Twins'].setVisible(True,True)
|
||||
scene.objects['Points-Twins-text'].setVisible(True,False)
|
||||
else:
|
||||
scene.objects['Points-Twins'].setVisible(False,True)
|
||||
scene.objects['Points-Twins-text'].setVisible(False,False)
|
||||
scene.objects['Commands'].setVisible(True,True)
|
||||
scene.objects['Camera'].setVisible(True,True)
|
||||
scene.active_camera = scene.objects["Camera"]
|
||||
@ -1277,6 +1269,9 @@ def store_close():
|
||||
if scene.objects['Commands']['twins']:
|
||||
scene.objects['Points-Twins'].setVisible(True,True)
|
||||
scene.objects['Points-Twins-text'].setVisible(True,False)
|
||||
else:
|
||||
scene.objects['Points-Twins'].setVisible(False,True)
|
||||
scene.objects['Points-Twins-text'].setVisible(False,False)
|
||||
scene.objects['Commands'].setVisible(True,True)
|
||||
scene.objects['Camera'].setVisible(True,True)
|
||||
scene.active_camera = scene.objects["Camera"]
|
||||
|
44
rp_cmd.py
44
rp_cmd.py
@ -3,8 +3,8 @@ import time
|
||||
from rp_lib import * # Bibliothèque Ropy
|
||||
|
||||
###############################################################################
|
||||
# rp_cmd.py
|
||||
# @title: Commandes pour le Rover Ropy
|
||||
# rp_cmd-microbit.py
|
||||
# @title: Exemple pour le lecteur du port série Micro:bit
|
||||
# @project: Ropy (Blender-EduTech)
|
||||
###############################################################################
|
||||
|
||||
@ -22,10 +22,6 @@ from rp_lib import * # Bibliothèque Ropy
|
||||
# Fonctions
|
||||
###############################################################################
|
||||
|
||||
def mrp_avancer():
|
||||
rp_avancer()
|
||||
rp_marquer()
|
||||
|
||||
###############################################################################
|
||||
# Commandes
|
||||
###############################################################################
|
||||
@ -33,43 +29,7 @@ def mrp_avancer():
|
||||
def commandes():
|
||||
|
||||
# Ecrire votre code ici ...
|
||||
rp_jumeau('/dev/ttyACM1', 115200)
|
||||
rp_tempo(1)
|
||||
print (1)
|
||||
rp_tempo(1)
|
||||
print (2)
|
||||
rp_tempo(1)
|
||||
print (3)
|
||||
rp_tempo(1)
|
||||
print (4)
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
###############################################################################
|
||||
|
@ -3,9 +3,9 @@
|
||||
<speed>1.0</speed>
|
||||
<sound>False</sound>
|
||||
<cam>
|
||||
<worldPosition.x>-10.94022274017334</worldPosition.x>
|
||||
<worldPosition.y>-40.040931701660156</worldPosition.y>
|
||||
<worldPosition.z>30.490596771240234</worldPosition.z>
|
||||
<worldPosition.x>-1.8592177629470825</worldPosition.x>
|
||||
<worldPosition.y>-33.43065643310547</worldPosition.y>
|
||||
<worldPosition.z>27.0482177734375</worldPosition.z>
|
||||
</cam>
|
||||
<screen>
|
||||
<width>1280</width>
|
||||
|
63
rp_lib.py
63
rp_lib.py
@ -1112,26 +1112,25 @@ def rp_jumeau(port, speed):
|
||||
global twins_serial
|
||||
scene.objects['Points-Twins'].setVisible(True,True)
|
||||
scene.objects['Points-Twins-text'].setVisible(True,False)
|
||||
|
||||
twins_serial = getSerialOrNone(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_port'] = port
|
||||
scene.objects['Commands']['twins_speed'] = speed
|
||||
scene.objects['Points-Twins-text']['Text'] = "Connection\nouverte :\n"+port+"\n à "+str(speed)+" baud"
|
||||
scene.objects['Points-Twins-text']['Text'] = "Connection\nouverte :\n"+port+"\n"+str(speed)+" baud"
|
||||
print (twins_serial)
|
||||
else:
|
||||
scene.objects['Commands']['twins'] = False
|
||||
scene.objects['Points-Twins-text']['Text'] = "Port pas \nprêt"
|
||||
scene.objects['Points-Twins-text']['Text'] = "Port\n"+port+"\npas prêt"
|
||||
|
||||
# ser = serial.Serial('/dev/ttyACM0',38400) # 6 fps
|
||||
# ser = serial.Serial('/dev/ttyACM0',9600) # 2 fps
|
||||
#serial_port='COM5' # Windows
|
||||
# serial_port='/dev/ttyACM0' # GNU/Linux
|
||||
# 115200 -> 7 fps
|
||||
# 38400 -> 6 fps
|
||||
# 9600 -> 2 fps
|
||||
# # ser = serial.Serial('/dev/ttyACM0',38400) # 6 fps
|
||||
# # ser = serial.Serial('/dev/ttyACM0',9600) # 2 fps
|
||||
# #serial_port='COM5' # Windows
|
||||
# # serial_port='/dev/ttyACM0' # GNU/Linux
|
||||
# # 115200 -> 7 fps
|
||||
# # 38400 -> 6 fps
|
||||
# # 9600 -> 2 fps
|
||||
|
||||
def getSerialOrNone(port,speed):
|
||||
try:
|
||||
@ -1147,44 +1146,48 @@ def rp_jumeau_close():
|
||||
scene.objects['Points-Twins-text']['Text'] = "Connection\nfermée"
|
||||
|
||||
# Configuration de la vitesse et des temps
|
||||
# FIXME : Bug dans le transfert des données
|
||||
def rp_jumeau_config(speed, temps_avancer, temps_tourner):
|
||||
global twins_serial
|
||||
if scene.objects['Commands']['twins']:
|
||||
serial_msg1 = "CF\n"
|
||||
# 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())
|
||||
serial_msg3 = str(temps_avancer)+"\n"
|
||||
twins_serial.write(serial_msg3.encode())
|
||||
rp_tempo (1)
|
||||
serial_msg2 = str(temps_tourner)+"\n"
|
||||
# print (serial_msg2)
|
||||
twins_serial.write(serial_msg2.encode())
|
||||
serial_msg4 = str(temps_tourner)+"\n"
|
||||
twins_serial.write(serial_msg4.encode())
|
||||
rp_tempo (1)
|
||||
serial_msg1 = "FC\n"
|
||||
# print (serial_msg1)
|
||||
twins_serial.write(serial_msg1.encode())
|
||||
serial_msg5 = "FC\n"
|
||||
twins_serial.write(serial_msg5.encode())
|
||||
|
||||
def rp_serie_msg(text):
|
||||
global twins_serial
|
||||
twins_serial.write(text.encode())
|
||||
text2= text+"\n"
|
||||
twins_serial.write(text2.encode())
|
||||
|
||||
def twins_listen():
|
||||
def twins_listen(cont):
|
||||
global twins_serial
|
||||
print ("a")
|
||||
serial_msg = str(twins_serial.readline())
|
||||
print (serial_msg)
|
||||
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
|
||||
|
||||
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
|
||||
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"
|
||||
return scene.objects['Commands']['twins_readline']
|
||||
|
||||
###############################################################################
|
||||
# Fonction bas niveau
|
||||
|
47
twins/arduino_serialreader/arduino_serialreader.ino
Executable file → Normal file
47
twins/arduino_serialreader/arduino_serialreader.ino
Executable file → Normal file
@ -1,3 +1,5 @@
|
||||
#include "Wire.h"
|
||||
|
||||
/******************************************************************************
|
||||
* arduino-serialreader.ino
|
||||
* @title: Lecteur du port serie d'une carte arduino
|
||||
@ -12,11 +14,17 @@
|
||||
* 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
|
||||
// Adressage Led Arduino
|
||||
const int led_com = 13; // Led de communication modele 3d-> arduino (onboard)
|
||||
|
||||
// Adressage Entrees Arduino
|
||||
const int bt = 4; // Bouton
|
||||
|
||||
// Entrees numeriques (modele 3D)
|
||||
bool bt_num=false; // Bouton numérique
|
||||
|
||||
// Adressage Sorties Arduino
|
||||
const int v = 2; // Voyant
|
||||
|
||||
/******************************************************************************
|
||||
* Communication serie
|
||||
@ -33,11 +41,7 @@ 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); // Liaison série
|
||||
}
|
||||
@ -52,12 +56,14 @@ void loop() {
|
||||
* Communication : modele 3d -> arduino
|
||||
*****/
|
||||
|
||||
// digitalWrite(v, HIGH);
|
||||
|
||||
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.println("Echo : "+serial_msg);
|
||||
serial_msg = "";
|
||||
serial_msg_complet = false;
|
||||
}
|
||||
@ -68,24 +74,32 @@ void loop() {
|
||||
* Bouton physique : LOW = actif et HIGH = pas actif
|
||||
*****/
|
||||
|
||||
if digitalRead(bt) == LOW {
|
||||
Serial.println("B");
|
||||
//Serial.println("Bouton"+ digitalRead(bt));
|
||||
if (digitalRead(bt)== LOW) {
|
||||
Serial.println("Bouton actif");
|
||||
digitalWrite(v, HIGH);
|
||||
delay(300);
|
||||
}
|
||||
else {
|
||||
// Serial.println("Bouton repos");
|
||||
digitalWrite(v, LOW);
|
||||
}
|
||||
|
||||
|
||||
/*****
|
||||
* Yoyant modele 3d-> arduino
|
||||
* Voyant modele 3d-> arduino
|
||||
*
|
||||
* Bouton numérique (modele 3d) : true = actif et false = pas actif
|
||||
*****/
|
||||
|
||||
if bt_num == true {
|
||||
if (bt_num) {
|
||||
digitalWrite(v, HIGH);
|
||||
}
|
||||
if bt_num == false {
|
||||
else {
|
||||
digitalWrite(v, LOW);
|
||||
}
|
||||
|
||||
/* delay(300); */
|
||||
//delay(300);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -98,6 +112,7 @@ void serialEvent() {
|
||||
serial_msg += inChar;
|
||||
if (inChar == '\n') {
|
||||
serial_msg_complet = true;
|
||||
digitalWrite(v, HIGH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,15 +16,14 @@ while True:
|
||||
# Envoi d'un message
|
||||
if button_a.is_pressed() :
|
||||
display.scroll("-> A")
|
||||
uart.write("A")
|
||||
uart.write("A\n")
|
||||
if button_b.is_pressed() :
|
||||
display.scroll("-> B")
|
||||
uart.write("B")
|
||||
uart.write("B\n")
|
||||
# pass
|
||||
|
||||
# Réception d'un message
|
||||
display.scroll('<- ')
|
||||
msg = uart.readline()
|
||||
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
|
||||
sleep(400)
|
||||
|
49
twins/rp_cmd-arduino.py
Normal file
49
twins/rp_cmd-arduino.py
Normal file
@ -0,0 +1,49 @@
|
||||
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||
import time
|
||||
from rp_lib import * # Bibliothèque Ropy
|
||||
|
||||
###############################################################################
|
||||
# rp_cmd-arduino.py
|
||||
# @title: Exemple pour le lecteur du port série Arduino
|
||||
# @project: Ropy (Blender-EduTech)
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
# Initialisation du niveau :
|
||||
# Niveau 1 : Les premiers pas de Ropy
|
||||
# Niveau 2 : Ma première fonction
|
||||
# Niveau 3 : Sécuriser Ropy
|
||||
# Niveau 4 : Partir au bout du monde
|
||||
# Niveau 5 : Faire face à l'inconnu
|
||||
# Niveau 6 : Se rendre utile
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
# Fonctions
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
# Commandes
|
||||
###############################################################################
|
||||
|
||||
def commandes():
|
||||
|
||||
rp_jumeau('/dev/ttyACM0', 115200)
|
||||
|
||||
rp_serie_msg("S") # Allumer led
|
||||
rp_tempo(2)
|
||||
rp_serie_msg("R") # Etiendre led
|
||||
|
||||
print (rp_serie_rcpt()) # Afficher message reçu
|
||||
|
||||
rp_fin() # A garder
|
||||
|
||||
###############################################################################
|
||||
# En: Externals calls << DONT CHANGE THIS SECTION >>
|
||||
# Fr: Appels externes << NE PAS MODIFIER CETTE SECTION >>
|
||||
###############################################################################
|
||||
|
||||
if __name__=='start':
|
||||
thread_cmd_start(commandes)
|
||||
if __name__=='stop':
|
||||
thread_cmd_stop()
|
47
twins/rp_cmd-microbit.py
Normal file
47
twins/rp_cmd-microbit.py
Normal file
@ -0,0 +1,47 @@
|
||||
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||
import time
|
||||
from rp_lib import * # Bibliothèque Ropy
|
||||
|
||||
###############################################################################
|
||||
# rp_cmd-microbit.py
|
||||
# @title: Exemple pour le lecteur du port série Micro:bit
|
||||
# @project: Ropy (Blender-EduTech)
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
# Initialisation du niveau :
|
||||
# Niveau 1 : Les premiers pas de Ropy
|
||||
# Niveau 2 : Ma première fonction
|
||||
# Niveau 3 : Sécuriser Ropy
|
||||
# Niveau 4 : Partir au bout du monde
|
||||
# Niveau 5 : Faire face à l'inconnu
|
||||
# Niveau 6 : Se rendre utile
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
# Fonctions
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
# Commandes
|
||||
###############################################################################
|
||||
|
||||
def commandes():
|
||||
|
||||
rp_jumeau('/dev/ttyACM1', 115200)
|
||||
|
||||
rp_serie_msg("Press a button !") # Envoyer un message
|
||||
|
||||
print (rp_serie_rcpt()) # Réception d'un message (bouton appuyé)
|
||||
|
||||
rp_fin() # A garder
|
||||
|
||||
###############################################################################
|
||||
# En: Externals calls << DONT CHANGE THIS SECTION >>
|
||||
# Fr: Appels externes << NE PAS MODIFIER CETTE SECTION >>
|
||||
###############################################################################
|
||||
|
||||
if __name__=='start':
|
||||
thread_cmd_start(commandes)
|
||||
if __name__=='stop':
|
||||
thread_cmd_stop()
|
@ -58,17 +58,15 @@ while True:
|
||||
while True:
|
||||
conf=radio.receive()
|
||||
if conf=="FC": # Fin de la configuration
|
||||
# display.show(attente_image) # Témoin de fonctionnement
|
||||
display.scroll("Config : " +str(vitesse) + " - " +str(distance) + " - " +str(angle))
|
||||
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
|
||||
# display.scroll(conf) # Affichage du message complet
|
||||
if i == 1: # Configuration de la vitesse
|
||||
vitesse = int(str(conf[2:-1]))
|
||||
if i == 3: # Configuration de la distance
|
||||
if i == 2: # Configuration de la distance
|
||||
distance = int(str(conf[2:-1]))
|
||||
if i == 4: # Configuration de l'angle
|
||||
if i == 3: # Configuration de l'angle
|
||||
angle = int(str(conf[2:-1]))
|
||||
i+=1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user