<fix> 1. optimize dense depth demo, now one-to-one with image_undistort

2. fix per-point time_offset for raw point cloud data
3. optimize how data rx fps is calculated
4. optimize log file structure
This commit is contained in:
mt-lifan
2025-10-21 11:03:31 +08:00
parent bd2f80d82d
commit 28c17e5611
17 changed files with 1084 additions and 290 deletions
+232
View File
@@ -0,0 +1,232 @@
/*
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "camera_pose_visualization.h"
const Eigen::Vector3d camera_pose_visualization::imlt = Eigen::Vector3d(-1.0, -0.5, 1.0);
const Eigen::Vector3d camera_pose_visualization::imrt = Eigen::Vector3d( 1.0, -0.5, 1.0);
const Eigen::Vector3d camera_pose_visualization::imlb = Eigen::Vector3d(-1.0, 0.5, 1.0);
const Eigen::Vector3d camera_pose_visualization::imrb = Eigen::Vector3d( 1.0, 0.5, 1.0);
const Eigen::Vector3d camera_pose_visualization::lt0 = Eigen::Vector3d(-0.7, -0.5, 1.0);
const Eigen::Vector3d camera_pose_visualization::lt1 = Eigen::Vector3d(-0.7, -0.2, 1.0);
const Eigen::Vector3d camera_pose_visualization::lt2 = Eigen::Vector3d(-1.0, -0.2, 1.0);
const Eigen::Vector3d camera_pose_visualization::oc = Eigen::Vector3d(0.0, 0.0, 0.0);
#ifdef ROS2
using GeometryPoint = geometry_msgs::msg::Point;
#else
using GeometryPoint = geometry_msgs::Point;
#endif
void Eigen2Point(const Eigen::Vector3d& v, GeometryPoint& p) {
p.x = v.x();
p.y = v.y();
p.z = v.z();
}
camera_pose_visualization::camera_pose_visualization(float r, float g, float b, float a)
: m_marker_ns("camera_pose_visualization"), m_scale(0.3), m_line_width(0.03) {
m_image_boundary_color.r = r;
m_image_boundary_color.g = g;
m_image_boundary_color.b = b;
m_image_boundary_color.a = a;
m_optical_center_connector_color.r = r;
m_optical_center_connector_color.g = g;
m_optical_center_connector_color.b = b;
m_optical_center_connector_color.a = a;
}
void camera_pose_visualization::setImageBoundaryColor(float r, float g, float b, float a) {
m_image_boundary_color.r = r;
m_image_boundary_color.g = g;
m_image_boundary_color.b = b;
m_image_boundary_color.a = a;
}
void camera_pose_visualization::setOpticalCenterConnectorColor(float r, float g, float b, float a) {
m_optical_center_connector_color.r = r;
m_optical_center_connector_color.g = g;
m_optical_center_connector_color.b = b;
m_optical_center_connector_color.a = a;
}
void camera_pose_visualization::setScale(double s) {
m_scale = s;
}
void camera_pose_visualization::setLineWidth(double width) {
m_line_width = width;
}
void camera_pose_visualization::add_edge(const Eigen::Vector3d& p0, const Eigen::Vector3d& p1) {
Marker marker;
marker.ns = m_marker_ns;
marker.id = m_markers.size() + 1;
#ifdef ROS2
marker.type = Marker::LINE_LIST;
marker.action = Marker::ADD;
#else
marker.type = visualization_msgs::Marker::LINE_LIST;
marker.action = visualization_msgs::Marker::ADD;
#endif
marker.scale.x = 0.005;
marker.color.g = 1.0f;
marker.color.a = 1.0;
GeometryPoint point0, point1;
Eigen2Point(p0, point0);
Eigen2Point(p1, point1);
marker.points.push_back(point0);
marker.points.push_back(point1);
m_markers.push_back(marker);
}
void camera_pose_visualization::add_loopedge(const Eigen::Vector3d& p0, const Eigen::Vector3d& p1) {
Marker marker;
marker.ns = m_marker_ns;
marker.id = m_markers.size() + 1;
#ifdef ROS2
marker.type = Marker::LINE_LIST;
marker.action = Marker::ADD;
#else
marker.type = visualization_msgs::Marker::LINE_LIST;
marker.action = visualization_msgs::Marker::ADD;
#endif
marker.scale.x = 0.04;
//marker.scale.x = 0.3;
marker.color.r = 1.0f;
marker.color.b = 1.0f;
marker.color.a = 1.0;
GeometryPoint point0, point1;
Eigen2Point(p0, point0);
Eigen2Point(p1, point1);
marker.points.push_back(point0);
marker.points.push_back(point1);
m_markers.push_back(marker);
}
void camera_pose_visualization::add_pose(const Eigen::Vector3d& p, const Eigen::Quaterniond& q) {
Marker marker;
marker.ns = m_marker_ns;
marker.id = m_markers.size() + 1;
#ifdef ROS2
marker.type = Marker::LINE_STRIP;
marker.action = Marker::ADD;
#else
marker.type = visualization_msgs::Marker::LINE_STRIP;
marker.action = visualization_msgs::Marker::ADD;
#endif
marker.scale.x = m_line_width;
marker.pose.position.x = 0.0;
marker.pose.position.y = 0.0;
marker.pose.position.z = 0.0;
marker.pose.orientation.w = 1.0;
marker.pose.orientation.x = 0.0;
marker.pose.orientation.y = 0.0;
marker.pose.orientation.z = 0.0;
GeometryPoint pt_lt, pt_lb, pt_rt, pt_rb, pt_oc, pt_lt0, pt_lt1, pt_lt2;
Eigen2Point(q * (m_scale * imlt) + p, pt_lt);
Eigen2Point(q * (m_scale * imlb) + p, pt_lb);
Eigen2Point(q * (m_scale * imrt) + p, pt_rt);
Eigen2Point(q * (m_scale * imrb) + p, pt_rb);
Eigen2Point(q * (m_scale * lt0 ) + p, pt_lt0);
Eigen2Point(q * (m_scale * lt1 ) + p, pt_lt1);
Eigen2Point(q * (m_scale * lt2 ) + p, pt_lt2);
Eigen2Point(q * (m_scale * oc ) + p, pt_oc);
// image boundaries
marker.points.push_back(pt_lt);
marker.points.push_back(pt_lb);
marker.colors.push_back(m_image_boundary_color);
marker.colors.push_back(m_image_boundary_color);
marker.points.push_back(pt_lb);
marker.points.push_back(pt_rb);
marker.colors.push_back(m_image_boundary_color);
marker.colors.push_back(m_image_boundary_color);
marker.points.push_back(pt_rb);
marker.points.push_back(pt_rt);
marker.colors.push_back(m_image_boundary_color);
marker.colors.push_back(m_image_boundary_color);
marker.points.push_back(pt_rt);
marker.points.push_back(pt_lt);
marker.colors.push_back(m_image_boundary_color);
marker.colors.push_back(m_image_boundary_color);
// top-left indicator
marker.points.push_back(pt_lt0);
marker.points.push_back(pt_lt1);
marker.colors.push_back(m_image_boundary_color);
marker.colors.push_back(m_image_boundary_color);
marker.points.push_back(pt_lt1);
marker.points.push_back(pt_lt2);
marker.colors.push_back(m_image_boundary_color);
marker.colors.push_back(m_image_boundary_color);
// optical center connector
marker.points.push_back(pt_lt);
marker.points.push_back(pt_oc);
marker.colors.push_back(m_optical_center_connector_color);
marker.colors.push_back(m_optical_center_connector_color);
marker.points.push_back(pt_lb);
marker.points.push_back(pt_oc);
marker.colors.push_back(m_optical_center_connector_color);
marker.colors.push_back(m_optical_center_connector_color);
marker.points.push_back(pt_rt);
marker.points.push_back(pt_oc);
marker.colors.push_back(m_optical_center_connector_color);
marker.colors.push_back(m_optical_center_connector_color);
marker.points.push_back(pt_rb);
marker.points.push_back(pt_oc);
marker.colors.push_back(m_optical_center_connector_color);
marker.colors.push_back(m_optical_center_connector_color);
m_markers.push_back(marker);
}
void camera_pose_visualization::reset() {
m_markers.clear();
}
void camera_pose_visualization::publish_by( Publisher& pub, const Header& header ) {
MarkerArray markerArray_msg;
for (auto& marker : m_markers) {
marker.header = header;
markerArray_msg.markers.push_back(marker);
}
pub.publish(markerArray_msg);
}
+13
View File
@@ -1,3 +1,16 @@
/*
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "depth_image_ros2_node.hpp"
#include <functional>
+13
View File
@@ -1,3 +1,16 @@
/*
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "depth_image_ros_node.hpp"
#include <boost/bind.hpp>
+201 -68
View File
@@ -1,3 +1,16 @@
/*
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "host_sdk_sample.h"
#include "yaml_parser.h"
#include "rawCloudRender.h"
@@ -31,7 +44,7 @@
#include <ros/package.h>
#include <ros/ros.h>
#endif
#define ros_driver_version "0.5.0"
#define ros_driver_version "0.5.2"
// Global variable declarations
static device_handle odinDevice = nullptr;
static std::atomic<bool> deviceConnected(false);
@@ -71,42 +84,52 @@ int g_sendrgb_compressed = 0;
int g_sendrgb_undistort = 0;
int g_record_data = 0;
int g_devstatus_log = 0;
int g_pub_intensity_gray = 0;
int g_show_path = 0;
int g_show_camerapose = 0;
std::filesystem::path log_root_dir_;
const char* DEV_STATUS_CSV_FILE = "dev_status.csv";
FILE* dev_status_csv_file = nullptr;
typedef struct {
struct timespec start = {0, 0};
double frame_count = 0.0;
std::atomic<double> fps;
struct timespec last = {0, 0};
int count = 0;
std::mutex fps_mutex;
} fpsHandle;
static void sensor_fps(fpsHandle* handle, const char* name, bool print = false)
{
void update_count(fpsHandle* handle) {
struct timespec now;
std::lock_guard<std::mutex> lock(handle->fps_mutex);
clock_gettime(CLOCK_MONOTONIC, &now);
if (handle->start.tv_sec == 0 && handle->start.tv_nsec == 0) {
if (handle->count == 0) {
handle->start = now;
} else {
handle->last = now;
}
handle->count++;
}
handle->frame_count += 1.0;
double elapsed = (now.tv_sec - handle->start.tv_sec)
+ (now.tv_nsec - handle->start.tv_nsec) / 1e9;
if (elapsed >= 1.0) {
handle->fps.store(handle->frame_count / elapsed);
if (print) {
#ifdef ROS2
RCLCPP_INFO(rclcpp::get_logger("device_cb"), "%s FPS: %f", name, handle->fps.load());
#else
ROS_INFO("%s FPS: %f", name, handle->fps.load());
#endif
}
handle->frame_count = 0;
handle->start = now;
double cal_fps(fpsHandle* handle, const char* name, bool print = false)
{
std::lock_guard<std::mutex> lock(handle->fps_mutex);
if (handle->count < 2) {
return 0.0;
}
double elapsed = (handle->last.tv_sec - handle->start.tv_sec)
+ (handle->last.tv_nsec - handle->start.tv_nsec) / 1e9;
double fps = (handle->count - 1) / elapsed;
if (print) {
#ifdef ROS2
RCLCPP_INFO(rclcpp::get_logger("device_cb"), "%s FPS: %f (count: %d, elapsed: %f)", name, fps, handle->count, elapsed);
#else
ROS_INFO("%s FPS: %f (count: %d, elapsed: %f)", name, fps, handle->count, elapsed);
#endif
}
handle->start = handle->last;
handle->count = 1;
return fps;
}
static fpsHandle rgb_rx_fps;
@@ -136,6 +159,51 @@ RosNodeControlInterface* getRosNodeControl() {
return &g_rosNodeControlImpl;
}
// Return resident memory (RSS) in **megabytes** for a given PID
double read_rss_mb(pid_t pid) {
std::string path = "/proc/" + std::to_string(pid) + "/status";
std::ifstream in(path);
if (!in) return 0.0;
std::string key;
long kb = 0;
while (in >> key) {
if (key == "VmRSS:") { // VmRSS is reported in kB
in >> kb;
break;
}
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
return kb / 1024.0; // convert to MB
}
double read_pss_mb(pid_t pid) {
std::string path = "/proc/" + std::to_string(pid) + "/smaps_rollup";
std::ifstream in(path);
if (!in) return 0.0;
std::string key;
long kb = 0;
while (in >> key) {
if (key == "Pss:") { // Proportional Set Size in kB
in >> kb;
break;
}
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
return kb / 1024.0; // convert to MB
}
// Recursively collect child PIDs of the given pid
void collect_children(pid_t pid, std::vector<pid_t>& all) {
std::string task_path = "/proc/" + std::to_string(pid) +
"/task/" + std::to_string(pid) + "/children";
std::ifstream in(task_path);
pid_t child;
while (in >> child) {
all.push_back(child);
collect_children(child, all);
}
}
void clear_all_queues();
// detect USB3.0
@@ -403,6 +471,11 @@ static void lidar_data_callback(const lidar_data_t *data, void *user_data)
imu_convert_data_t *imudata = nullptr;
lidar_device_status_t *dev_info_data;
pid_t self = getpid();
std::vector<pid_t> pids;
double total_mb = 0.0;
switch(data->type) {
case LIDAR_DT_NONE:
printf("empty lidar data type: %x\n", data->type);
@@ -411,35 +484,45 @@ static void lidar_data_callback(const lidar_data_t *data, void *user_data)
if (g_sendrgb) {
g_ros_object->publishRgb((capture_Image_List_t *)&data->stream);
}
sensor_fps(&rgb_rx_fps, "rgb_rx");
update_count(&rgb_rx_fps);
break;
case LIDAR_DT_RAW_IMU:
if (g_sendimu) {
imudata = (imu_convert_data_t *)data->stream.imageList[0].pAddr;
g_ros_object->publishImu(imudata);
}
sensor_fps(&imu_rx_fps, "imu_rx");
update_count(&imu_rx_fps);
break;
case LIDAR_DT_RAW_DTOF:
if (g_senddtof ) {
g_ros_object->publishIntensityCloud((capture_Image_List_t *)&data->stream, 1);
}
sensor_fps(&dtof_rx_fps, "dtof_rx");
if (g_pub_intensity_gray) {
g_ros_object->publishGrayUInt8((capture_Image_List_t *)&data->stream, 2);
}
update_count(&dtof_rx_fps);
break;
case LIDAR_DT_SLAM_CLOUD:
if (g_sendcloudslam) {
g_ros_object->publishPC2XYZRGBA((capture_Image_List_t *)&data->stream, 0);
}
sensor_fps(&slam_cloud_rx_fps, "slam_cloud_rx");
update_count(&slam_cloud_rx_fps);
break;
case LIDAR_DT_SLAM_ODOMETRY:
if (g_sendodom) {
g_ros_object->publishOdometry((capture_Image_List_t *)&data->stream, false);
g_ros_object->publishOdometry((capture_Image_List_t *)&data->stream, false, g_show_path, g_show_camerapose);
}
sensor_fps(&slam_odom_rx_fps, "slam_odom_rx");
update_count(&slam_odom_rx_fps);
break;
case LIDAR_DT_DEV_STATUS:
dev_info_data = (lidar_device_status_t *)data->stream.imageList[0].pAddr;
pids.push_back(self);
collect_children(self, pids);
for (pid_t p : pids) {
total_mb += read_pss_mb(p); // read_rss_mb(p);
}
if (g_devstatus_log) {
if (dev_status_csv_file) {
// append the data row
@@ -471,7 +554,8 @@ static void lidar_data_callback(const lidar_data_t *data, void *user_data)
rc = std::fprintf(dev_status_csv_file, "%.2f,%.2f,%.2f,",
((float)dev_info_data->rgb_sensor.configured_odr)/1000,
((float)dev_info_data->rgb_sensor.tx_odr)/1000,
(rgb_rx_fps.fps.load()));
cal_fps(&rgb_rx_fps, "rgb_rx")
);
if (rc < 0) {
printf("Failed to write to dev_status_csv_file\n");
}
@@ -479,7 +563,8 @@ static void lidar_data_callback(const lidar_data_t *data, void *user_data)
rc = std::fprintf(dev_status_csv_file, "%.2f,%.2f,%.2f,",
((float)dev_info_data->dtof_sensor.configured_odr)/1000,
((float)dev_info_data->dtof_sensor.tx_odr)/1000,
(dtof_rx_fps.fps.load()));
cal_fps(&dtof_rx_fps, "dtof_rx")
);
if (rc < 0) {
printf("Failed to write to dev_status_csv_file\n");
}
@@ -487,18 +572,24 @@ static void lidar_data_callback(const lidar_data_t *data, void *user_data)
rc = std::fprintf(dev_status_csv_file, "%.2f,%.2f,%.2f,",
((float)dev_info_data->imu_sensor.configured_odr)/1000,
((float)dev_info_data->imu_sensor.tx_odr)/1000,
(imu_rx_fps.fps.load()));
cal_fps(&imu_rx_fps, "imu_rx")
);
if (rc < 0) {
printf("Failed to write to dev_status_csv_file\n");
}
rc = std::fprintf(dev_status_csv_file, "%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\n",
rc = std::fprintf(dev_status_csv_file, "%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,",
((float)dev_info_data->slam_cloud_tx_odr)/1000,
(slam_cloud_rx_fps.fps.load()),
cal_fps(&slam_cloud_rx_fps, "slam_cloud_rx"),
((float)dev_info_data->slam_odom_tx_odr)/1000,
(slam_odom_rx_fps.fps.load()),
cal_fps(&slam_odom_rx_fps, "slam_odom_rx"),
((float)dev_info_data->slam_odom_highfreq_tx_odr)/1000,
(slam_odom_highfreq_rx_fps.fps.load()));
cal_fps(&slam_odom_highfreq_rx_fps, "slam_odom_highfreq_rx"));
if (rc < 0) {
printf("Failed to write to dev_status_csv_file\n");
}
rc = std::fprintf(dev_status_csv_file, "%.2f\n", total_mb);
if (rc < 0) {
printf("Failed to write to dev_status_csv_file\n");
}
@@ -531,12 +622,14 @@ static void lidar_data_callback(const lidar_data_t *data, void *user_data)
printf("\n [dev_info] [rgb]: configured_odr: %.2f HZ, tx_odr: %.2f HZ, rx_odr: %.2f HZ \n",
((float)dev_info_data->rgb_sensor.configured_odr)/1000,
((float)dev_info_data->rgb_sensor.tx_odr)/1000,
(rgb_rx_fps.fps.load()));
cal_fps(&rgb_rx_fps, "rgb_rx")
);
printf("\n [dev_info] [dtof]: configured_odr: %.2f HZ, tx_odr: %.2f HZ, rx_odr: %.2f HZ \n",
((float)dev_info_data->dtof_sensor.configured_odr)/1000,
((float)dev_info_data->dtof_sensor.tx_odr)/1000,
(dtof_rx_fps.fps.load()));
cal_fps(&dtof_rx_fps, "dtof_rx")
);
printf("\n [dev_info] [dtof]: subframe_odr: %.2f \n",
((float)dev_info_data->dtof_sensor.subframe_odr)/1000);
printf("\n [dev_info] [dtof]: txtemp:%dC, rxtemp:%dC \n", dev_info_data->dtof_sensor.tx_temp, dev_info_data->dtof_sensor.rx_temp);
@@ -544,33 +637,39 @@ static void lidar_data_callback(const lidar_data_t *data, void *user_data)
printf("\n [dev_info] [imu]: configured_odr: %.2f HZ, tx_odr: %.2f HZ, rx_odr: %.2f HZ\n",
((float) dev_info_data->imu_sensor.configured_odr)/1000,
((float) dev_info_data->imu_sensor.tx_odr)/1000,
(imu_rx_fps.fps.load())
cal_fps(&imu_rx_fps, "imu_rx")
);
printf("\n [dev_info] [slam]: slam_cloud_tx_odr: %.2f HZ, rx_odr: %.2f HZ \n",
((float)dev_info_data->slam_cloud_tx_odr)/1000,
(slam_cloud_rx_fps.fps.load())
cal_fps(&slam_cloud_rx_fps, "slam_cloud_rx")
);
printf("\n [dev_info] [slam]: slam_odom_tx_odr: %.2f HZ, rx_odr: %.2f HZ \n",
((float)dev_info_data->slam_odom_tx_odr)/1000,
(slam_odom_rx_fps.fps.load())
cal_fps(&slam_odom_rx_fps, "slam_odom_rx")
);
printf("\n [dev_info] [slam]: slam_odom_highfreq_tx_odr: %.2f HZ, rx_odr: %.2f HZ \n",
((float)dev_info_data->slam_odom_highfreq_tx_odr)/1000,
(slam_odom_highfreq_rx_fps.fps.load())
cal_fps(&slam_odom_highfreq_rx_fps, "slam_odom_highfreq_rx")
);
#ifdef ROS2
RCLCPP_INFO(rclcpp::get_logger("dev_info"), "Total RAM (parent + children): %.2f MB", total_mb);
#else
ROS_INFO("Total RAM (parent + children): %.2f MB", total_mb);
#endif
printf("\n------------------------------------------\n");
}
break;
case LIDAR_DT_SLAM_ODOMETRY_HIGHFREQ:
{
if (g_sendodom) {
g_ros_object->publishOdometry((capture_Image_List_t *)&data->stream, true);
g_ros_object->publishOdometry((capture_Image_List_t *)&data->stream, true, false, false);
}
sensor_fps(&slam_odom_highfreq_rx_fps, "slam_odom_highfreq_rx");
update_count(&slam_odom_highfreq_rx_fps);
}
break;
default:
@@ -762,6 +861,46 @@ static void lidar_device_callback(const lidar_device_info_t* device, bool attach
odinDevice = nullptr;
return;
}
auto con_time = std::chrono::system_clock::now();
std::time_t t = std::chrono::system_clock::to_time_t(con_time);
std::tm tm{};
#ifdef _WIN32
localtime_s(&tm, &t);
#else
localtime_r(&t, &tm);
#endif
char buf[32];
std::strftime(buf, sizeof(buf), "%Y%m%d_%H%M%S", &tm);
std::string folder_name = std::string("Conn_") + std::string(buf);
std::filesystem::path per_con_log_root_dir_ = log_root_dir_ / folder_name;
std::filesystem::create_directories(per_con_log_root_dir_);
std::string dev_status_csv_file_path_ = per_con_log_root_dir_ / "dev_status.csv";
if (dev_status_csv_file) {
std::fflush(dev_status_csv_file);
fclose(dev_status_csv_file);
dev_status_csv_file = nullptr;
}
// Open the file in append mode
dev_status_csv_file = fopen(dev_status_csv_file_path_.c_str(), "a");
if (!dev_status_csv_file) {
#ifdef ROS2
RCLCPP_ERROR(rclcpp::get_logger("init"), "Failed to open dev_status CSV file");
#else
ROS_ERROR("Failed to open dev_status CSV file");
#endif
} else {
const char* header =
"uptime_seconds,package_temp,cpu_temp,center_temp,gpu_temp,npu_temp,dtof_tx_temp,dtof_rx_temp,"
"cpu0,cpu1,cpu2,cpu3,cpu4,cpu5,cpu6,cpu7,ram_use(%),"
"rgb_configured_odr,rgb_tx_odr,rgb_rx_odr,dtof_configured_odr,dtof_tx_odr,dtof_rx_odr,imu_configured_odr,imu_tx_odr,imu_rx_odr,"
"slam_cloud_tx_odr,slam_cloud_rx_odr,slam_odom_tx_odr,slam_odom_rx_odr,slam_odom_highfreq_tx_odr,slam_odom_highfreq_rx_odr,"
"host_ram_use(mb)\n";
fprintf(dev_status_csv_file, "%s", header);
std::fflush(dev_status_csv_file);
}
uint32_t dtof_subframe_odr = 0;
if (lidar_start_stream(odinDevice, type, dtof_subframe_odr)) {
@@ -800,7 +939,8 @@ static void lidar_device_callback(const lidar_device_info_t* device, bool attach
deviceConnected = true;
deviceDisconnected = false;
if (g_sendrgb_undistort && g_ros_object->loadCameraParams(calib_config) == 0) {
bool load_status = g_ros_object->loadCameraParams(calib_config);
if (g_sendrgb_undistort && load_status == 0) {
g_ros_object->buildUndistortMap();
}
@@ -825,6 +965,12 @@ static void lidar_device_callback(const lidar_device_info_t* device, bool attach
clear_all_queues();
if (dev_status_csv_file) {
std::fflush(dev_status_csv_file);
fclose(dev_status_csv_file);
dev_status_csv_file = nullptr;
}
#ifdef ROS2
RCLCPP_INFO(rclcpp::get_logger("device_cb"), "Waiting for device reconnection...");
#else
@@ -883,6 +1029,9 @@ int main(int argc, char *argv[])
g_record_data = get_key_value("recorddata", 0);
g_show_fps = get_key_value("showfps", 0);
g_devstatus_log = get_key_value("devstatuslog", 0);
g_pub_intensity_gray = get_key_value("pubintensitygray", 0);
g_show_path = get_key_value("showpath", 0);
g_show_camerapose = get_key_value("showcamerapose", 0);
g_log_level = get_key_value("log_devel", LOG_LEVEL_INFO);
lidar_log_set_level(LIDAR_LOG_INFO);
@@ -925,28 +1074,9 @@ int main(int argc, char *argv[])
#endif
char buf[32];
std::strftime(buf, sizeof(buf), "%Y%m%d_%H%M%S", &tm);
std::filesystem::path log_root_dir_ = std::filesystem::path(log_dir) / buf;
std::string folder_name = std::string("Driver_") + std::string(buf);
log_root_dir_ = std::filesystem::path(log_dir) / folder_name;
std::filesystem::create_directories(log_root_dir_);
std::string dev_status_csv_file_path_ = log_root_dir_ / "dev_status.csv";
// Open the file in append mode
dev_status_csv_file = fopen(dev_status_csv_file_path_.c_str(), "a");
if (!dev_status_csv_file) {
#ifdef ROS2
RCLCPP_ERROR(rclcpp::get_logger("init"), "Failed to open dev_status CSV file");
#else
ROS_ERROR("Failed to open dev_status CSV file");
#endif
} else {
const char* header =
"uptime_seconds,package_temp,cpu_temp,center_temp,gpu_temp,npu_temp,dtof_tx_temp,dtof_rx_temp,"
"cpu0,cpu1,cpu2,cpu3,cpu4,cpu5,cpu6,cpu7,ram_use,"
"rgb_configured_odr,rgb_tx_odr,rgb_rx_odr,dtof_configured_odr,dtof_tx_odr,dtof_rx_odr,imu_configured_odr,imu_tx_odr,imu_rx_odr,"
"slam_cloud_tx_odr,slam_cloud_rx_odr,slam_odom_tx_odr,slam_odom_rx_odr,slam_odom_highfreq_tx_odr,slam_odom_highfreq_rx_odr\n";
fprintf(dev_status_csv_file, "%s", header);
std::fflush(dev_status_csv_file);
}
}
if (lidar_system_init(lidar_device_callback)) {
@@ -1121,8 +1251,11 @@ int main(int argc, char *argv[])
// lidar_close_device(odinDevice);
// lidar_destory_device(odinDevice);
std::fflush(dev_status_csv_file);
fclose(dev_status_csv_file);
if (dev_status_csv_file) {
std::fflush(dev_status_csv_file);
fclose(dev_status_csv_file);
dev_status_csv_file = nullptr;
}
}
// lidar_system_deinit();
+13
View File
@@ -1,3 +1,16 @@
/*
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <ros/ros.h>
#include <fstream>
#include <sys/stat.h>
+13
View File
@@ -1,3 +1,16 @@
/*
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <rclcpp/rclcpp.hpp>
#include <fstream>
#include <sys/stat.h>
+16 -13
View File
@@ -1,3 +1,16 @@
/*
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "pointcloud_depth_converter.hpp"
#include <cmath>
#include <iostream>
@@ -23,7 +36,7 @@ void PointCloudToDepthConverter::initializeInternalParams()
Kl_ = Eigen::Matrix3d::Identity();
Kl_(0, 0) = params_.A11 / params_.scale;
Kl_(0, 1) = params_.A12 / params_.scale;
Kl_(0, 1) = 0.0;
Kl_(0, 2) = params_.u0 / params_.scale;
Kl_(1, 1) = params_.A22 / params_.scale;
Kl_(1, 2) = params_.v0 / params_.scale;
@@ -241,16 +254,7 @@ cv::Mat PointCloudToDepthConverter::postProcessDepthImage(const cv::Mat &depth_i
return cv::Mat();
}
cv::Mat depth_img_distorted;
try {
depth_undistorted_ = depth_img_upsampled.clone();
cv::remap(depth_img_upsampled, depth_img_distorted, map_x_, map_y_, cv::INTER_LINEAR);
} catch (const cv::Exception& e) {
std::cerr << "ERROR: Remap failed: " << e.what() << std::endl;
return cv::Mat();
}
return depth_img_distorted;
return depth_img_upsampled;
}
cv::Mat PointCloudToDepthConverter::customResize(const cv::Mat& src, const cv::Size& size) {
@@ -291,9 +295,8 @@ pcl::PointCloud<pcl::PointXYZRGB> PointCloudToDepthConverter::generateColoredClo
const cv::Mat &depth_img, const cv::Mat &color_img)
{
cv::Mat depth_undistorted, color_undistorted;
depth_undistorted = depth_undistorted_.clone();
depth_undistorted = depth_img.clone();
cv::remap(color_img, color_undistorted, inv_map_x_, inv_map_y_, cv::INTER_LINEAR);
pcl::PointCloud<pcl::PointXYZRGB> cloud_colored;
+13
View File
@@ -1,3 +1,16 @@
/*
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "rawCloudRender.h"
#include <yaml-cpp/yaml.h>
#include <iostream>
+13
View File
@@ -1,3 +1,16 @@
/*
Copyright 2025 Manifold Tech Ltd.(www.manifoldtech.com.co)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "yaml_parser.h"
#include <fstream>
#include <filesystem>