콘텐츠로 이동
한국어

라이다

라이다는 여러 개의 거리 센서를 한꺼번에 쓰는 것처럼 로봇 주위 전체의 거리를 미터 단위로 측정해요. 스타터 로봇에서는 로봇 위에 달려 있고, 이름은 lidar예요.

로봇 주위의 점 512개를, 위아래로 쌓인 레이어 4개에 걸쳐 최대 1 m까지 측정해요. 아무것에도 닿지 않은 점은 inf가 돼요.

getLayerRangeImage(0)은 한 레이어의 512개 거리를 줘요. 첫 번째 값은 로봇의 정면이고, 시계 방향으로 이어져요. 4분의 1 지점은 오른쪽, 절반은 뒤쪽, 4분의 3 지점은 왼쪽이에요.

로봇 주위의 라이다 레이어의 점. 0은 앞, 128은 오른쪽, 256은 뒤, 384는 왼쪽

from controller import Robot
robot = Robot()
timeStep = int(robot.getBasicTimeStep())
lidar = robot.getDevice("lidar")
lidar.enable(timeStep)
n = lidar.getHorizontalResolution() # Number of points in each layer
print("Points per layer:", n, "Layers:", lidar.getNumberOfLayers())
while robot.step(timeStep) != -1:
distances = lidar.getLayerRangeImage(0) # One layer, in meters, clockwise from the front
front = distances[0]
right = distances[n // 4]
back = distances[n // 2]
left = distances[3 * n // 4]
print("front:", round(front, 3), "right:", round(right, 3), "back:", round(back, 3), "left:", round(left, 3))

다음은 world1.wbt에서 스타터 로봇이 측정한 레이어 하나를, 로봇을 가운데에 두고 위에서 본 그림이에요. 주위의 벽이 점의 줄로 나타나요.

위에서 본 라이다 레이어 하나. 로봇 주위의 벽이 점의 줄로 보여요

라이다는 각 점을 라이다 기준의 상대 위치로 줄 수도 있어서, 로봇이 보는 것을 지도로 그릴 때 유용해요. 계산에 시간이 더 걸리므로 사용할 때만 활성화하세요.

from controller import Robot
robot = Robot()
timeStep = int(robot.getBasicTimeStep())
lidar = robot.getDevice("lidar")
lidar.enable(timeStep)
lidar.enablePointCloud() # Computing the point cloud takes extra time
while robot.step(timeStep) != -1:
points = lidar.getPointCloud()
point = points[0] # Positions relative to the lidar, in meters
print("x:", round(point.x, 3), "y:", round(point.y, 3), "z:", round(point.z, 3), "layer:", point.layer)