コンテンツにスキップ
日本語

LiDAR

LiDAR は、たくさんの距離センサーを一度に使うように、ロボットの周囲全体の距離を メートル 単位で測ります。スターターロボットでは lidar という名前で、ロボットの上部にあります。

ロボットの周囲 512 点を、上下に積み重なった 4 つのレイヤーで、最大 1 m 先まで測ります。何にも当たらなかった点は inf になります。

getLayerRangeImage(0) は、1 つのレイヤーの 512 個の距離を返します。最初の値はロボットの正面で、そこから 時計回り に並びます。4 分の 1 の位置が右、半分の位置が後ろ、4 分の 3 の位置が左です。

ロボットの周りの LiDAR のレイヤーの点。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 でスターターロボットが測った 1 つのレイヤーを、ロボットを中心にして上から見たものです。周りの壁が点の並びとして現れています。

上から見た LiDAR の 1 つのレイヤー。ロボットの周りの壁が点の並びになっている

LiDAR は、各点を LiDAR からの相対位置として返すこともできます。これは、ロボットが見ているものの地図を描くのに便利です。計算に余分な時間がかかるので、使うときだけ有効にしましょう。

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)