mirror of
https://forge.apps.education.fr/blender-edutech/blender-edutech-tutoriels.git
synced 2024-01-27 09:42:33 +01:00
Tutoriel 3 : capteur imu achevé
This commit is contained in:
parent
87f20e7252
commit
09b234babe
Binary file not shown.
@ -1,5 +1,4 @@
|
||||
import bge # Bibliothèque Blender Game Engine (BGE)
|
||||
import bpy # Blender
|
||||
import serial # Liaison série
|
||||
import time
|
||||
|
||||
@ -18,8 +17,6 @@ import time
|
||||
|
||||
# Récupérer la scène 3D
|
||||
scene = bge.logic.getCurrentScene()
|
||||
eevee = bpy.context.scene.eevee
|
||||
fps_time=0.0
|
||||
# print("Objets de la scene : ", scene.objects) # Lister les objets de la scène
|
||||
|
||||
# Constantes
|
||||
@ -32,11 +29,9 @@ ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
||||
# Communication avec la carte Arduino
|
||||
###############################################################################
|
||||
|
||||
serial_baud=115200 # 7 fps
|
||||
# serial_baud=38400 # 6 fps
|
||||
# serial_baud=9600 # 2 fps
|
||||
serial_baud=115200
|
||||
# serial_comm = serial.Serial('COM4',serial_baud, timeout=0.016) # Windows
|
||||
serial_comm = serial.Serial('/dev/ttyACM0',serial_baud, timeout=0.016) # GNU/Linux
|
||||
serial_comm = serial.Serial('/dev/ttyACM1',serial_baud, timeout=0.016) # GNU/Linux
|
||||
print (serial_comm)
|
||||
|
||||
###############################################################################
|
||||
@ -45,8 +40,6 @@ print (serial_comm)
|
||||
|
||||
# Extraction d'un texte compris entre deux bornes textuelles
|
||||
def txt_extrac(txt, borne_avant, borne_apres):
|
||||
# print ("find sur (", txt ,") avec (",borne_avant,") -> ", txt.find(borne_avant))
|
||||
# print ("find sur (", txt ,") avec (",borne_apres,") -> ", txt.find(borne_apres))
|
||||
if txt.find(borne_avant)>0 and txt.find(borne_apres)>0:
|
||||
txt1 = txt.split(borne_avant, 2)
|
||||
txt2 = txt1[1].split(borne_apres, 2)
|
||||
@ -85,9 +78,8 @@ def applyRotationTo(obj, rx=None, ry=None, rz=None, Local=True):
|
||||
obj.applyRotation((0, 0, rres), Local)
|
||||
# print ("delta z ",rz-obj.worldOrientation.to_euler().z)
|
||||
|
||||
|
||||
# Lecture du capteur IMU
|
||||
def capteur(cont):
|
||||
# global fps_time
|
||||
obj = cont.owner # obj est l'objet associé au contrôleur donc 'Plateau'
|
||||
resolution = 0.2
|
||||
|
||||
@ -97,27 +89,20 @@ def capteur(cont):
|
||||
serial_comm.close()
|
||||
bge.logic.endGame()
|
||||
|
||||
# Désactivation du capteur pendant la chute
|
||||
if scene.objects['Bille']['chute']:
|
||||
return
|
||||
|
||||
# Lecture de la liaison série : programme Arduino : 3-labyrinthe-imu.ino
|
||||
obj['Rx']=obj.worldOrientation.to_euler().x
|
||||
obj['Ry']=obj.worldOrientation.to_euler().y
|
||||
obj['Rz']=obj.worldOrientation.to_euler().z
|
||||
serial_msg = str(serial_comm.readline())
|
||||
# print (serial_msg)
|
||||
if serial_msg.find(",")>0:
|
||||
# if ("\r\n") in serial_msg:
|
||||
# print (serial_msg)
|
||||
txt = serial_msg.split(',',2)
|
||||
# print (txt)
|
||||
x_txt = txt[0][2:]
|
||||
y_txt = txt[1][:-5]
|
||||
x=-(float(x_txt)/57.3) * resolution # 1/ 360 / (2 * pi)
|
||||
y=-(float(y_txt)/57.3) * resolution # 1/ 360 / (2 * pi)
|
||||
|
||||
# Roll et Pitch
|
||||
# applyRotationTo(scene.objects['Plateau'], x,0, 0)
|
||||
applyRotationTo(scene.objects['Plateau'], x,y, 0)
|
||||
# obj.applyRotation((0,0,-obj.worldOrientation.to_euler().z), False)
|
||||
|
||||
###############################################################################
|
||||
# Gameplay
|
||||
@ -126,7 +111,6 @@ def capteur(cont):
|
||||
# Initialisation de la scène
|
||||
def init(cont):
|
||||
obj = cont.owner # obj est l'objet associé au contrôleur donc 'Bille'
|
||||
# eevee_qualite(0)
|
||||
|
||||
# Mémorisation de la position de départ de la bille
|
||||
obj['init_x']=obj.worldPosition.x
|
||||
@ -146,19 +130,8 @@ def cycle(cont):
|
||||
|
||||
# Chute ?
|
||||
if obj['z'] < -10 and scene.objects['Panneau victoire'].visible == False:
|
||||
obj['chute']=True
|
||||
scene.objects['Plateau']['chute']=True
|
||||
|
||||
# Redémarrer la partie
|
||||
def chute(cont):
|
||||
obj = cont.owner # obj est l'objet associé au contrôleur donc 'Bille'
|
||||
obj_plateau = scene.objects['Plateau'] # obj_plateau est l'objet 'Plateau'
|
||||
print ("Chuuuu.....te")
|
||||
|
||||
# Replacement du plateau (tous les angles à 0 en plusieurs fois)
|
||||
# while obj_plateau.worldOrientation.to_euler().x != 0 and obj_plateau.worldOrientation.to_euler().y !=0 and obj_plateau.worldOrientation.to_euler().z !=0 :
|
||||
# obj_plateau.applyRotation((-obj_plateau.worldOrientation.to_euler().x, -obj_plateau.worldOrientation.to_euler().y, -obj_plateau.worldOrientation.to_euler().z), False)
|
||||
|
||||
# Mettre la bille à la position de départ avec une vitesse nulle
|
||||
obj.worldLinearVelocity=(0, 0, 0)
|
||||
obj.worldAngularVelocity=(0, 0, 0)
|
||||
@ -166,8 +139,6 @@ def chute(cont):
|
||||
obj.worldPosition.y = obj['init_y']
|
||||
obj.worldPosition.z = obj['init_z']+0.5 # On repose la bille
|
||||
time.sleep(0.1)
|
||||
obj['chute']=False
|
||||
scene.objects['Plateau']['chute']=False
|
||||
|
||||
# Victoire (colision de la bille avec l'arrivée)
|
||||
def victoire(cont):
|
||||
@ -203,84 +174,6 @@ def victoire_fermer(cont):
|
||||
scene.objects['Panneau victoire - plan'].suspendPhysics (True) # Suspendre la physique du panneau cliquable
|
||||
scene.objects['Bille']['z']= -21 # On provoque le redémarrage si la bille est ressortie
|
||||
|
||||
###############################################################################
|
||||
# Qualité du rendu EEVEE de 0 à 4
|
||||
###############################################################################
|
||||
|
||||
def eevee_qualite(qualite):
|
||||
|
||||
# Inconvenant
|
||||
if qualite== 0:
|
||||
eevee.use_eevee_smaa = False # Subpixel Morphological Antialiasing
|
||||
eevee.use_ssr = False # Screen space reflection
|
||||
eevee.use_gtao = False # Ambient occlusion
|
||||
eevee.taa_render_samples = 1
|
||||
eevee.taa_samples = 1
|
||||
eevee.use_volumetric_lights = False
|
||||
eevee.use_volumetric_shadows = False
|
||||
eevee.shadow_cascade_size='64'
|
||||
eevee.shadow_cube_size='64'
|
||||
|
||||
# Basse
|
||||
if qualite== 1:
|
||||
eevee.use_eevee_smaa = True
|
||||
eevee.smaa_quality= 'LOW'
|
||||
eevee.use_ssr = True # Screen space reflection
|
||||
eevee.use_ssr_refraction = False # Screen space refractions
|
||||
eevee.use_ssr_halfres = True
|
||||
eevee.use_gtao = False
|
||||
eevee.taa_render_samples = 32
|
||||
eevee.taa_samples = 8
|
||||
eevee.use_volumetric_lights = True
|
||||
eevee.use_volumetric_shadows = False
|
||||
eevee.shadow_cascade_size='1024'
|
||||
eevee.shadow_cube_size='512'
|
||||
|
||||
# Moyenne
|
||||
if qualite== 2:
|
||||
eevee.use_eevee_smaa = True
|
||||
eevee.smaa_quality= 'MEDIUM'
|
||||
eevee.use_ssr = True # Screen space reflection
|
||||
eevee.use_ssr_refraction = True # Screen space refractions
|
||||
eevee.use_ssr_halfres = True
|
||||
eevee.use_gtao = False
|
||||
eevee.taa_render_samples = 64
|
||||
eevee.taa_samples = 16
|
||||
eevee.use_volumetric_lights = True
|
||||
eevee.use_volumetric_shadows = False
|
||||
eevee.shadow_cascade_size='1024'
|
||||
eevee.shadow_cube_size='512'
|
||||
|
||||
# Haute
|
||||
if qualite== 3:
|
||||
eevee.use_eevee_smaa = True
|
||||
eevee.smaa_quality= 'HIGH'
|
||||
eevee.use_ssr = True
|
||||
eevee.use_ssr_refraction = True
|
||||
eevee.use_ssr_halfres = False
|
||||
eevee.use_gtao = False
|
||||
eevee.taa_render_samples = 64
|
||||
eevee.taa_samples = 16
|
||||
eevee.use_volumetric_lights = True
|
||||
eevee.use_volumetric_shadows = False
|
||||
eevee.shadow_cascade_size='1024'
|
||||
eevee.shadow_cube_size='512'
|
||||
|
||||
# Épique
|
||||
if qualite== 4:
|
||||
eevee.use_eevee_smaa = True
|
||||
eevee.smaa_quality= 'ULTRA'
|
||||
eevee.use_ssr = True
|
||||
eevee.use_ssr_refraction = True
|
||||
eevee.use_ssr_halfres = False
|
||||
eevee.use_gtao = True
|
||||
eevee.taa_render_samples = 64
|
||||
eevee.taa_samples = 16
|
||||
eevee.use_volumetric_lights = True
|
||||
eevee.use_volumetric_shadows = True
|
||||
eevee.shadow_cascade_size='4096'
|
||||
eevee.shadow_cube_size='4096'
|
||||
|
||||
###############################################################################
|
||||
# Gestion du Joystick USB
|
||||
###############################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user