Bonsoir,

voila, j'ai ma class Lidar qui me retourne un Lidar.distance qui est une distance et un Lidar.angle qui est un angle. j'ai créé une deuxieme class Affichage qui est sensé m'écrire les valeurs mais le probleme c'est que ca n'affiche rien sur mon terminal, avez vous une idée du probleme?

voici mon code :

Code:

import serial
import math
import time
from threading import Thread, RLock
import numpy as np 
#import motorControler
import RPi.GPIO as GPIO
 
 
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
 
 
led=23
GPIO.setup(led,GPIO.OUT)
GPIO.output(led,0)
 
PWM_motor=4
GPIO.setup(PWM_motor,GPIO.OUT)
LidarMotor = GPIO.PWM(PWM_motor,50)#50Hz
LidarMotor.start(0)
 
 
 
Start_Scan = "\xA5\x20" #Begins scanning
Force_Scan = "\xA5\x21" #Overrides anything preventing a scan
Health = "\xA5\x52" #Returns the state of the Lidar
Stop_Scan = "\xA5\x25" #Stops the scan
RESET = "\xA5\x40" #Resets the device
 
verrou = RLock()
 
class Lidar(Thread):
	distance = 0
	angle = 0
 
 
	def __init__(self,ser):
		Thread.__init__(self)
 
		self.port = ser  
 
	def run(self): 
		lock = False     
		lock = self.startScan(self.port)
 
		if lock == True:
			self.getPoints(self.port)
		else:
			print "Exiting"
 
 
 
	def startScan(self, port):
 
		print"connecting"
		lock = False
 
		while lock == False:
 
			print"..."
 
			port.write(RESET)
			time.sleep(1)
			port.write(Start_Scan)
			try:
				line=""
				for i in range(0, 250):
					line = port.read(7)
 
					if line[0:2] == "\xa5\x5a" :#flag 1&2
						lock = True
						print"lidar Enable"
						break;
					else:
						line = ""
			except KeyboardInterrupt:
				break
		return lock
 
	def getPoints(self, port):
		memory = 0
		count = 0
		i=0
 
		line = ""  #reset line
 
		while True:
 
			try:
 
 
				line = port.read(5) 
				if (len(line) )== 5 :# wait 5 bytes
 
 
					# if chackData1 = 1 trame is good
					checkData1= int((line[1].encode("hex")), 16)&0x01
 
					#if chackData2 = 1 trame is good
					checkData2= int((line[0].encode("hex")), 16)
					if ((checkData2&0x02)/2) != (checkData2&0x01) :
						checkData2=1
					else:
						checkData2=0
 
 
					if checkData1 ==1 and checkData2 ==1 :#trame is good
 
						Lidar.distance,Lidar.angle=self.point_Polar(line)
 
 
 
 
					else :#trame is not good
						print"ValueError : lidar disable"
						break
 
					line=""
 
			except KeyboardInterrupt:
				break
 
 
	def point_Polar(self,paquet):
		#Get Distance
		distance = paquet[4].encode("hex") + paquet[3].encode("hex")
		distance = int(distance, 16)
		distance = distance / 4 #instructions from data sheet
 
		#Get Angle
		angle = paquet[2].encode("hex") + paquet[1].encode("hex")
		angle = int(angle, 16)
		angle = angle/128 #instruction from data sheet
 
		return(distance, angle)
 
class Affichage(Thread):
	def __init__(self):
		Thread.__init__(self)
		self.u = 0
 
	def run(self):
 
		print("la distance : {0} mm   angle : {1}".format(Lidar.distance,Lidar.angle))
 
 
 
LidarMotor.start(40)
ser = serial.Serial('/dev/ttyAMA0', 115200, timeout = 1)
ser.setDTR(False)
print ser.name
while True:
 
 
	t1 = Lidar(ser)
	t2 = Affichage()
	t1.start()
	t2.start()
 
 
	t1.join()
	t2.join()
merci d'avance pour votre aide