카테고리 없음

(YDLidar G2) Health Status 조회

미친토끼 2025. 3. 22. 19:26

출력 결과 0은 normal이고 1은 abnormal입니다.

-- 출력 결과

시리얼이 열렸습니다. 읽어옵니다.
len(read_data) :  10
idx =  0
content length:  3 bytes
6
the state of the image sensor:  0
the status of the angle detection module:  0
the stauts of the wireless power supply module:  0
the status of the laser feedback voltage:  0
the status of the laser drive current:  0
the status of the lidar data is normal:  0

#!/bin/python3
# filename: stop
# chmod +x stop 해서 $PATH 걸린 곳에 복사할 것.
import serial
import time

s = serial.Serial('/dev/ttyUSB0', 230400)
s.write(b'\xa5\x92')  # for health status info

s.timeout = 3

if s.isOpen():
  print("시리얼이 열렸습니다. 읽어옵니다.")
read_data = s.read(20)
print("len(read_data) : ", len(read_data))
idx = read_data.find(b'\xa5\x5a')
data = read_data[idx:]

print("idx = ", idx)
print("content length: ", data[2], "bytes")

print(data[6])

status_code = data[7]

bit0 = status_code & 0b01
print("the state of the image sensor: ", bit0)

bit1 = (status_code > 1) & 0b01
print("the status of the angle detection module: ", bit1)

bit2 = (status_code > 2) & 0b01
print("the stauts of the wireless power supply module: ", bit2)

bit3 = (status_code > 3) & 0b01
print("the status of the laser feedback voltage: ", bit3)

bit4 = (status_code > 4) & 0b01
print("the status of the laser drive current: ", bit4)

bit5 = (status_code > 5) & 0b01
print("the status of the lidar data is normal: ", bit5)

s.close()