我在ROS中问过这个问题,但我想再问一下,看看能否更快地得到这个答案。
你好,全部,
我正在尝试实时显示点云。我已将数据从pointcloud2
转移到pointcloud<T>
。然后我使用PCLVisualization来可视化点云。查看器处于回调函数中。它在开始时工作正常,然后回调函数刚刚因分段错误而崩溃。为了检查哪个部分是回调函数的错误,我使用了一个非常愚蠢的方法,在每个句子后放置一个ROS_INFO
,并发现它在spinonce()
中崩溃了。但是我无法弄清楚spinonce在这里出了什么问题。你能帮我调试吗?
#include <ros/ros.h>
// #include <timer.h>
// PCL specific includes
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl_ros/point_cloud.h>
#include <boost/thread/thread.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/console/parse.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/visualization/point_cloud_color_handlers.h>
typedef pcl::PointCloud<pcl::PointXYZI> PCLCloud;
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
void
cloud_cb (const PCLCloud::ConstPtr& input)
{
// ros::Time begin = ros::Time::now();
viewer->removePointCloud("m8_data");
// boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
viewer->setBackgroundColor(0, 0, 0);
viewer->addCoordinateSystem(1.0);
pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI> intensity_distribution(input, "intensity");
// if(!viewer->updatePointCloud<pcl::PointXYZI> (input, intensity_distribution, "pc_data"))
viewer->addPointCloud<pcl::PointXYZI> (input, intensity_distribution, "pc_data");
viewer->spinOnce ();
// boost::this_thread::sleep (boost::posix_time::microseconds (100000));
// viewer->spinOnce();
ROS_INFO("[%d]",5);
// ros::Time final = ros::Time::now();
// ros::Time dura=final - begin;
// ROS_INFO("%f",dura);
}
int
main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "point_cloud");
ros::NodeHandle nh;
// Create a ROS subscriber for the input point cloud
ros::Subscriber sub = nh.subscribe ("output", 1, cloud_cb);
ros::Rate rate(10.0);
while (nh.ok())
{
ros::spinOnce();
rate.sleep();
}
// Spin
// ros::spin ();
}
输出主题每100ms发布一次点云数据。我只是担心,在回调函数的过程中,新数据会订阅节点而无法继续处理。
这是我的假设,我真的不确定。我真的需要你的帮助。
感谢您的帮助。
嗨,我刚收到GDB关于此故障的追踪信息。我复制它们并希望它可以帮助你找出问题所在。
Program received signal SIGSEGV, Segmentation fault.
0x00007fffd9605ad7 in ?? () from /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so
(gdb) backtrace
#0 0x00007fffd9605ad7 in ?? ()
from /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so
#1 0x00007ffff6e4919a in vtkOpenGLPainterDeviceAdapter::SendAttribute(int, int, int, void const*, long long) () from /usr/lib/libvtkRendering.so.5.8
#2 0x00007ffff6d70768 in vtkPointsPainter::RenderPrimitive(unsigned long, vtkDataArray*, vtkUnsignedCharArray*, vtkDataArray*, vtkRenderer*) ()
from /usr/lib/libvtkRendering.so.5.8
#3 0x00007ffff6d7d6db in vtkPrimitivePainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#4 0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#5 0x00007ffff6c8a5c1 in vtkChooserPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#6 0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#7 0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#8 0x00007ffff6e63480 in vtkOpenGLRepresentationPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#9 0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#10 0x00007ffff6e480de in vtkOpenGLLightingPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
---Type <return> to continue, or q <return> to quit---frame 2
#11 0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#12 0x00007ffff6e372ce in vtkOpenGLDisplayListPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#13 0x00007ffff6e36803 in vtkOpenGLClipPlanesPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#14 0x00007ffff6e63ac5 in vtkOpenGLScalarsToColorsPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#15 0x00007ffff6d4646a in vtkPainterPolyDataMapper::RenderPiece(vtkRenderer*, vtkActor*) () from /usr/lib/libvtkRendering.so.5.8
#16 0x00007ffff6d7530e in vtkPolyDataMapper::Render(vtkRenderer*, vtkActor*) ()
from /usr/lib/libvtkRendering.so.5.8
#17 0x00007ffff6c9187c in vtkDataSetMapper::Render(vtkRenderer*, vtkActor*) ()
from /usr/lib/libvtkRendering.so.5.8
#18 0x00007ffff6e359c2 in vtkOpenGLActor::Render(vtkRenderer*, vtkMapper*) ()
from /usr/lib/libvtkRendering.so.5.8
#19 0x00007ffff6d36259 in vtkLODActor::Render(vtkRenderer*, vtkMapper*) ()
from /usr/lib/libvtkRendering.so.5.8
#20 0x00007ffff6d35b0f in vtkLODActor::RenderOpaqueGeometry(vtkViewport*) ()
from /usr/lib/libvtkRendering.so.5.8
#21 0x00007ffff6d93407 in vtkRenderer::UpdateGeometry() ()
from /usr/lib/libvtkRendering.so.5.8
#22 0x00007ffff6e5efc2 in vtkOpenGLRenderer::DeviceRender() ()
---Type <return> to continue, or q <return> to quit---return
from /usr/lib/libvtkRendering.so.5.8
#23 0x00007ffff6d951dc in vtkRenderer::Render() ()
from /usr/lib/libvtkRendering.so.5.8
#24 0x00007ffff6d9177a in vtkRendererCollection::Render() ()
from /usr/lib/libvtkRendering.so.5.8
#25 0x00007ffff78519ee in pcl::visualization::PCLVisualizerInteractorStyle::OnTimer() () from /usr/lib/libpcl_visualization.so.1.7
#26 0x00007ffff6cd1678 in vtkInteractorStyle::ProcessEvents(vtkObject*, unsigned long, void*, void*) () from /usr/lib/libvtkRendering.so.5.8
#27 0x00007ffff7328009 in vtkCallbackCommand::Execute(vtkObject*, unsigned long, void*) () from /usr/lib/libvtkCommon.so.5.8
#28 0x00007ffff73f51b0 in ?? () from /usr/lib/libvtkCommon.so.5.8
#29 0x00007ffff6e1f732 in vtkXRenderWindowInteractorTimer(void*, unsigned long*) () from /usr/lib/libvtkRendering.so.5.8
#30 0x00007ffff0387a26 in ?? () from /usr/lib/x86_64-linux-gnu/libXt.so.6
#31 0x00007ffff038858f in XtAppNextEvent ()
from /usr/lib/x86_64-linux-gnu/libXt.so.6
#32 0x00007ffff6e1e40c in vtkXRenderWindowInteractor::Start() ()
from /usr/lib/libvtkRendering.so.5.8
#33 0x00007ffff7879b12 in pcl::visualization::PCLVisualizer::spinOnce(int, bool) () from /usr/lib/libpcl_visualization.so.1.7
#34 0x0000000000435c23 in cloud_cb(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&) ()
---Type <return> to continue, or q <return> to quit---
#35 0x0000000000440d59 in boost::detail::function::void_function_invoker1<void (*)(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&), void, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&>::invoke(boost::detail::function::function_buffer&, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&) ()
#36 0x00000000004437d7 in boost::function1<void, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&>::operator()(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&) const ()
#37 0x0000000000442405 in boost::detail::function::void_function_obj_invoker1<boost::function<void (boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&)>, void, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> >::invoke(boost::detail::function::function_buffer&, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const>) ()
#38 0x00000000004469ae in boost::function1<void, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> >::operator()(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const>) const ()
#39 0x0000000000445ba0 in ros::SubscriptionCallbackHelperT<boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&, void>::call(ros::SubscriptionCallbackHelperCallParams&) ()
#40 0x00007ffff69099b5 in ros::SubscriptionQueue::call() ()
from /opt/ros/jade/lib/libroscpp.so
#41 0x00007ffff68c7767 in ros::CallbackQueue::callOneCB(ros::CallbackQueue::TLS*) () from /opt/ros/jade/lib/libroscpp.so
---Type <return> to continue, or q <return> to quit---
#42 0x00007ffff68c8573 in ros::CallbackQueue::callAvailable(ros::WallDuration)
() from /opt/ros/jade/lib/libroscpp.so
#43 0x00007ffff68f4b05 in ros::spinOnce() ()
from /opt/ros/jade/lib/libroscpp.so
#44 0x0000000000435f9d in main ()
非常感谢你。喵