LiDAR
LiDAR は、たくさんの距離センサーを一度に使うように、ロボットの周囲全体の距離を メートル 単位で測ります。スターターロボットでは lidar という名前で、ロボットの上部にあります。
ロボットの周囲 512 点を、上下に積み重なった 4 つのレイヤーで、最大 1 m 先まで測ります。何にも当たらなかった点は inf になります。
距離を読み取る
Section titled “距離を読み取る”getLayerRangeImage(0) は、1 つのレイヤーの 512 個の距離を返します。最初の値はロボットの正面で、そこから 時計回り に並びます。4 分の 1 の位置が右、半分の位置が後ろ、4 分の 3 の位置が左です。
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 layerprint("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))#include <iostream>#include <webots/Robot.hpp>#include <webots/Lidar.hpp>
using namespace webots;using namespace std;
int main() { Robot *robot = new Robot(); int timeStep = (int)robot->getBasicTimeStep();
Lidar *lidar = robot->getLidar("lidar"); lidar->enable(timeStep); int n = lidar->getHorizontalResolution(); // Number of points in each layer cout << "Points per layer: " << n << " Layers: " << lidar->getNumberOfLayers() << endl;
while (robot->step(timeStep) != -1) { const float *distances = lidar->getLayerRangeImage(0); // One layer, in meters, clockwise from the front cout << "front: " << distances[0] << " right: " << distances[n / 4] << " back: " << distances[n / 2] << " left: " << distances[3 * n / 4] << endl; }
delete robot; return 0;}次の図は、world1.wbt でスターターロボットが測った 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)#include <iostream>#include <webots/Robot.hpp>#include <webots/Lidar.hpp>
using namespace webots;using namespace std;
int main() { Robot *robot = new Robot(); int timeStep = (int)robot->getBasicTimeStep();
Lidar *lidar = robot->getLidar("lidar"); lidar->enable(timeStep); lidar->enablePointCloud(); // Computing the point cloud takes extra time
while (robot->step(timeStep) != -1) { const LidarPoint *points = lidar->getPointCloud(); const LidarPoint &point = points[0]; // Positions relative to the lidar, in meters cout << "x: " << point.x << " y: " << point.y << " z: " << point.z << " layer: " << point.layer_id << endl; }
delete robot; return 0;}