17 #include <pcl/common/common.h> 18 #include <pcl/common/transforms.h> 19 #include <pcl/conversions.h> 20 #include <pcl/io/pcd_io.h> 21 #include <pcl/point_types.h> 29 namespace grid_map_pcl {
32 bool isSetVerbosityLevelToDebug;
33 nh.
param<
bool>(
"set_verbosity_to_debug", isSetVerbosityLevelToDebug,
false);
35 if (!isSetVerbosityLevelToDebug) {
46 std::string pathToConfig;
47 nh.
param<std::string>(
"config_file_path", pathToConfig, defaultPath);
52 std::string pathToOutputBag;
54 nh.
param<std::string>(
"output_grid_map", pathToOutputBag, defaultPath);
55 return pathToOutputBag;
59 std::string pathToCloud, folderPath;
60 const std::string defaultPathToCloud =
"/data/input_cloud.pcd";
62 nh.
param<std::string>(
"pcd_filename", pathToCloud, defaultPathToCloud);
63 nh.
param<std::string>(
"folder_path", folderPath, defaultFolderPath);
64 return folderPath +
"/" + pathToCloud;
69 nh.
param<std::string>(
"map_frame", mapFrame,
"map");
74 std::string mapRosbagTopic;
75 nh.
param<std::string>(
"map_rosbag_topic", mapRosbagTopic,
"grid_map");
76 return mapRosbagTopic;
80 std::string mapLayerName;
81 nh.
param<std::string>(
"map_layer_name", mapLayerName,
"elevation");
88 ROS_INFO_STREAM(
"Saving grid map successful: " << std::boolalpha << savingSuccessful);
92 const auto stop = std::chrono::high_resolution_clock::now();
93 const auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count() / 1000.0;
98 const auto start = std::chrono::high_resolution_clock::now();
107 Eigen::Affine3f rigidBodyTransform;
108 rigidBodyTransform.setIdentity();
109 rigidBodyTransform.translation() << translation.x(), translation.y(), translation.z();
110 Eigen::Matrix3f rotation(Eigen::Matrix3f::Identity());
114 rigidBodyTransform.rotate(rotation);
116 return rigidBodyTransform;
120 Eigen::Matrix3f rotationMatrix = Eigen::Matrix3f::Identity();
123 rotationMatrix = Eigen::AngleAxisf(angle, Eigen::Vector3f::UnitX());
127 rotationMatrix = Eigen::AngleAxisf(angle, Eigen::Vector3f::UnitY());
131 rotationMatrix = Eigen::AngleAxisf(angle, Eigen::Vector3f::UnitZ());
135 ROS_ERROR(
"Unknown axis while trying to rotate the pointcloud");
137 return rotationMatrix;
141 Eigen::Vector3d mean = Eigen::Vector3d::Zero();
142 for (
const auto& point : inputCloud->points) {
143 mean += Eigen::Vector3d(point.x, point.y, point.z);
145 mean /= inputCloud->points.size();
151 Pointcloud::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
152 pcl::PCLPointCloud2 cloudBlob;
154 pcl::fromPCLPointCloud2(cloudBlob, *cloud);
158 Pointcloud::Ptr
transformCloud(Pointcloud::ConstPtr inputCloud,
const Eigen::Affine3f& transformMatrix) {
159 Pointcloud::Ptr transformedCloud(
new Pointcloud());
160 pcl::transformPointCloud(*inputCloud, *transformedCloud, transformMatrix);
161 return transformedCloud;
void printTimeElapsedToRosInfoStream(const std::chrono::system_clock::time_point &start, const std::string &prefix)
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
std::string getParameterPath(const ros::NodeHandle &nh)
void initializeGridMapGeometryFromInputCloud()
std::string getPcdFilePath(const ros::NodeHandle &nh)
std::string getOutputBagPath(const ros::NodeHandle &nh)
Eigen::Matrix3f getRotationMatrix(double angle, XYZ axis)
Eigen::Vector3d calculateMeanOfPointPositions(Pointcloud::ConstPtr inputCloud)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
static bool saveToBag(const grid_map::GridMap &gridMap, const std::string &pathToBag, const std::string &topic)
void addLayerFromInputCloud(const std::string &layer)
int loadPCDFile(const std::string &file_name, sensor_msgs::PointCloud2 &cloud)
void processPointcloud(grid_map::GridMapPclLoader *gridMapPclLoader, const ros::NodeHandle &nh)
Pointcloud::Ptr loadPointcloudFromPcd(const std::string &filename)
void preProcessInputCloud()
std::string getMapLayerName(const ros::NodeHandle &nh)
ROSLIB_DECL std::string getPath(const std::string &package_name)
Pointcloud::Ptr transformCloud(Pointcloud::ConstPtr inputCloud, const Eigen::Affine3f &transformMatrix)
#define ROS_INFO_STREAM(args)
void setVerbosityLevelToDebugIfFlagSet(const ros::NodeHandle &nh)
void saveGridMap(const grid_map::GridMap &gridMap, const ros::NodeHandle &nh, const std::string &mapTopic)
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
::pcl::PointCloud< Point > Pointcloud
Eigen::Affine3f getRigidBodyTransform(const Eigen::Vector3d &translation, const Eigen::Vector3d &intrinsicRpy)
std::string getMapFrame(const ros::NodeHandle &nh)
#define ROSCONSOLE_DEFAULT_NAME
std::string getMapRosbagTopic(const ros::NodeHandle &nh)