first commit
This commit is contained in:
@@ -29,23 +29,27 @@
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "laser_geometry/laser_geometry.hpp"
|
||||
#include "laser_geometry/data_convert.h"
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include "rclcpp/time.hpp"
|
||||
#include "sensor_msgs/msg/laser_scan.hpp"
|
||||
#include "sensor_msgs/msg/point_cloud2.hpp"
|
||||
#include <robot/time.h>
|
||||
#include <robot/duration.h>
|
||||
#include <sensor_msgs/LaserScan.h>
|
||||
#include <sensor_msgs/PointCloud2.h>
|
||||
|
||||
#include "tf2/LinearMath/Transform.hpp"
|
||||
#include <tf2/buffer_core.h>
|
||||
#include<tf2/convert.h>
|
||||
#include "tf2/LinearMath/Transform.h"
|
||||
|
||||
namespace laser_geometry
|
||||
{
|
||||
void LaserProjection::projectLaser_(
|
||||
const sensor_msgs::msg::LaserScan & scan_in,
|
||||
sensor_msgs::msg::PointCloud2 & cloud_out,
|
||||
const sensor_msgs::LaserScan & scan_in,
|
||||
sensor_msgs::PointCloud2 & cloud_out,
|
||||
double range_cutoff,
|
||||
int channel_options)
|
||||
{
|
||||
@@ -85,15 +89,15 @@ void LaserProjection::projectLaser_(
|
||||
cloud_out.fields.resize(3);
|
||||
cloud_out.fields[0].name = "x";
|
||||
cloud_out.fields[0].offset = 0;
|
||||
cloud_out.fields[0].datatype = sensor_msgs::msg::PointField::FLOAT32;
|
||||
cloud_out.fields[0].datatype = sensor_msgs::PointField::FLOAT32;
|
||||
cloud_out.fields[0].count = 1;
|
||||
cloud_out.fields[1].name = "y";
|
||||
cloud_out.fields[1].offset = 4;
|
||||
cloud_out.fields[1].datatype = sensor_msgs::msg::PointField::FLOAT32;
|
||||
cloud_out.fields[1].datatype = sensor_msgs::PointField::FLOAT32;
|
||||
cloud_out.fields[1].count = 1;
|
||||
cloud_out.fields[2].name = "z";
|
||||
cloud_out.fields[2].offset = 8;
|
||||
cloud_out.fields[2].datatype = sensor_msgs::msg::PointField::FLOAT32;
|
||||
cloud_out.fields[2].datatype = sensor_msgs::PointField::FLOAT32;
|
||||
cloud_out.fields[2].count = 1;
|
||||
|
||||
// Define 4 indices in the channel array for each possible value type
|
||||
@@ -106,7 +110,7 @@ void LaserProjection::projectLaser_(
|
||||
size_t field_size = cloud_out.fields.size();
|
||||
cloud_out.fields.resize(field_size + 1);
|
||||
cloud_out.fields[field_size].name = "intensity";
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::msg::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size].offset = offset;
|
||||
cloud_out.fields[field_size].count = 1;
|
||||
offset += 4;
|
||||
@@ -117,7 +121,7 @@ void LaserProjection::projectLaser_(
|
||||
size_t field_size = cloud_out.fields.size();
|
||||
cloud_out.fields.resize(field_size + 1);
|
||||
cloud_out.fields[field_size].name = "index";
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::msg::PointField::INT32;
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::PointField::INT32;
|
||||
cloud_out.fields[field_size].offset = offset;
|
||||
cloud_out.fields[field_size].count = 1;
|
||||
offset += 4;
|
||||
@@ -128,7 +132,7 @@ void LaserProjection::projectLaser_(
|
||||
size_t field_size = cloud_out.fields.size();
|
||||
cloud_out.fields.resize(field_size + 1);
|
||||
cloud_out.fields[field_size].name = "distances";
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::msg::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size].offset = offset;
|
||||
cloud_out.fields[field_size].count = 1;
|
||||
offset += 4;
|
||||
@@ -139,7 +143,7 @@ void LaserProjection::projectLaser_(
|
||||
size_t field_size = cloud_out.fields.size();
|
||||
cloud_out.fields.resize(field_size + 1);
|
||||
cloud_out.fields[field_size].name = "stamps";
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::msg::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size].offset = offset;
|
||||
cloud_out.fields[field_size].count = 1;
|
||||
offset += 4;
|
||||
@@ -151,19 +155,19 @@ void LaserProjection::projectLaser_(
|
||||
cloud_out.fields.resize(field_size + 3);
|
||||
|
||||
cloud_out.fields[field_size].name = "vp_x";
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::msg::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size].datatype = sensor_msgs::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size].offset = offset;
|
||||
cloud_out.fields[field_size].count = 1;
|
||||
offset += 4;
|
||||
|
||||
cloud_out.fields[field_size + 1].name = "vp_y";
|
||||
cloud_out.fields[field_size + 1].datatype = sensor_msgs::msg::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size + 1].datatype = sensor_msgs::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size + 1].offset = offset;
|
||||
cloud_out.fields[field_size + 1].count = 1;
|
||||
offset += 4;
|
||||
|
||||
cloud_out.fields[field_size + 2].name = "vp_z";
|
||||
cloud_out.fields[field_size + 2].datatype = sensor_msgs::msg::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size + 2].datatype = sensor_msgs::PointField::FLOAT32;
|
||||
cloud_out.fields[field_size + 2].offset = offset;
|
||||
cloud_out.fields[field_size + 2].count = 1;
|
||||
offset += 4;
|
||||
@@ -265,8 +269,8 @@ void LaserProjection::projectLaser_(
|
||||
|
||||
void LaserProjection::transformLaserScanToPointCloud_(
|
||||
const std::string & target_frame,
|
||||
const sensor_msgs::msg::LaserScan & scan_in,
|
||||
sensor_msgs::msg::PointCloud2 & cloud_out,
|
||||
const sensor_msgs::LaserScan & scan_in,
|
||||
sensor_msgs::PointCloud2 & cloud_out,
|
||||
tf2::Quaternion quat_start,
|
||||
tf2::Vector3 origin_start,
|
||||
tf2::Quaternion quat_end,
|
||||
@@ -364,7 +368,7 @@ void LaserProjection::transformLaserScanToPointCloud_(
|
||||
|
||||
// if the user didn't request the index field, then we need to copy the PointCloud and drop it
|
||||
if (!requested_index) {
|
||||
sensor_msgs::msg::PointCloud2 cloud_without_index;
|
||||
sensor_msgs::PointCloud2 cloud_without_index;
|
||||
|
||||
// copy basic meta data
|
||||
cloud_without_index.header = cloud_out.header;
|
||||
@@ -415,29 +419,35 @@ void LaserProjection::transformLaserScanToPointCloud_(
|
||||
|
||||
void LaserProjection::transformLaserScanToPointCloud_(
|
||||
const std::string & target_frame,
|
||||
const sensor_msgs::msg::LaserScan & scan_in,
|
||||
sensor_msgs::msg::PointCloud2 & cloud_out,
|
||||
const sensor_msgs::LaserScan & scan_in,
|
||||
sensor_msgs::PointCloud2 & cloud_out,
|
||||
tf2::BufferCore & tf,
|
||||
double range_cutoff,
|
||||
int channel_options)
|
||||
{
|
||||
rclcpp::Time start_time(scan_in.header.stamp, RCL_ROS_TIME);
|
||||
rclcpp::Time end_time(scan_in.header.stamp, RCL_ROS_TIME);
|
||||
robot::Time start_time;
|
||||
start_time.sec = scan_in.header.stamp.sec;
|
||||
start_time.nsec = scan_in.header.stamp.nsec;
|
||||
robot::Time end_time = start_time;
|
||||
|
||||
// TODO(anonymous): reconcile all the different time constructs
|
||||
if (!scan_in.ranges.empty()) {
|
||||
end_time = start_time + rclcpp::Duration::from_seconds(
|
||||
static_cast<double>(scan_in.ranges.size() - 1) * static_cast<double>(scan_in.time_increment));
|
||||
robot::Duration duration(static_cast<double>(scan_in.ranges.size() - 1) * static_cast<double>(scan_in.time_increment));
|
||||
end_time = start_time + duration;
|
||||
}
|
||||
|
||||
std::chrono::nanoseconds start(start_time.nanoseconds());
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> st(start);
|
||||
geometry_msgs::msg::TransformStamped start_transform = tf.lookupTransform(
|
||||
tf2::Time st = convertTime(start_time);
|
||||
tf2::Time e = convertTime(end_time);
|
||||
|
||||
tf2::TransformStampedMsg start_transform_msg = tf.lookupTransform(
|
||||
target_frame, scan_in.header.frame_id, st);
|
||||
std::chrono::nanoseconds end(end_time.nanoseconds());
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> e(end);
|
||||
geometry_msgs::msg::TransformStamped end_transform = tf.lookupTransform(
|
||||
|
||||
tf2::TransformStampedMsg end_transform_msg = tf.lookupTransform(
|
||||
target_frame, scan_in.header.frame_id, e);
|
||||
|
||||
geometry_msgs::TransformStamped start_transform = convertToTransformStamped(start_transform_msg);
|
||||
geometry_msgs::TransformStamped end_transform = convertToTransformStamped(end_transform_msg);
|
||||
|
||||
tf2::Quaternion quat_start(start_transform.transform.rotation.x,
|
||||
start_transform.transform.rotation.y,
|
||||
start_transform.transform.rotation.z,
|
||||
|
||||
Reference in New Issue
Block a user