Why does my executable get a segmentation fault (core dumped)?

asked 2017-10-29 23:44:58 -0500

Zaz gravatar image

Hello everyone,

I'm trying to run an executable called sample but it can't run and instead it gives out a "segmentation fault (core dumped)" error. Can you help me?

Here is my CMakeLists:

cmake_minimum_required(VERSION 2.8.3)
project(a3_help)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  message_generation
  roscpp
  sensor_msgs
  std_msgs
  OpenCV
)

add_definitions( -DANALYSIS=ON )

## System dependencies are found with CMake's conventions
find_package(Boost REQUIRED COMPONENTS system signals)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wdeprecated-declarations")
set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")

message ( STATUS " CMake C++ FLAGS ${CMAKE_CXX_FLAGS}")

find_package(OpenCV)
find_package(Eigen3 REQUIRED)

## Generate services in the 'srv' folder
add_service_files(
   FILES
   RequestGoal.srv
)

## Generate added messages and services with any dependencies listed here
generate_messages(
   DEPENDENCIES
   sensor_msgs
)

###########
## Build ##
###########

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${EIGEN3_INCLUDE_DIR}
  ${OpenCV_INCLUDE_DIRS}
)

add_executable(map_to_image_node src/map_to_image_node.cpp)
add_executable(sample src/sample.cpp)
add_executable(TBK src/TBK.cpp)

## Specify libraries to link a library or executable target against
target_link_libraries(map_to_image_node ${catkin_LIBRARIES})
target_link_libraries(sample ${catkin_LIBRARIES})
target_link_libraries(TBK ${catkin_LIBRARIES})

#############
## Testing ##
#############
catkin_add_gtest(${PROJECT_NAME}-test test/utest.cpp )
if(TARGET ${PROJECT_NAME}-test)
   target_link_libraries(${PROJECT_NAME}-test ${catkin_LIBRARIES})
endif()

Here's my sample.cpp file:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "gazebo_msgs/ModelStates.h"
#include "tf/transform_datatypes.h"

#include "sensor_msgs/LaserScan.h"
#include "sensor_msgs/image_encodings.h"
#include "nav_msgs/Odometry.h"
#include <opencv2/imgproc/imgproc.hpp>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>

#include "a3_help/RequestGoal.h"

#include <sstream>
#include <iostream>
#include <string>

#include <thread>
#include <chrono>
#include <deque>
#include <mutex>
#include <random>

namespace enc = sensor_msgs::image_encodings;

/**
 * This node shows some connections and publishing images
 */


class GazeboRetrieve{

    ros::NodeHandle nh_;
    image_transport::ImageTransport it_;
    image_transport::Publisher image_pub_;
    ros::Subscriber sub1_;
    ros::Subscriber sub2_;
    image_transport::Subscriber sub3_;
    cv_bridge::CvImagePtr cvPtr_;
    ros::ServiceServer service_;

    int count_;//! A counter to allow executing items on N iterations
    double resolution_;//! size of OgMap in pixels

    struct DataBuffer
    {
        std::deque<geometry_msgs::Pose> poseDeq;
        std::deque<ros::Time> timeStampDeq;
        std::mutex buffer_mutex_;
    };
    DataBuffer buffer;//! And now we have our container

    struct ImageDataBuffer
    {
        std::deque<cv::Mat> imageDeq;
        std::deque<ros::Time> timeStampDeq;
        std::mutex buffer_mutex_;
    };
    ImageDataBuffer imageBuffer;//! And now we have our container


public:
    GazeboRetrieve(ros::NodeHandle nh)
    : nh_(nh), it_(nh)
    {
        sub1_ = nh_.subscribe("odom", 1000, &GazeboRetrieve::odomCallback,this);
        sub2_ = nh_.subscribe("scan", 10, &GazeboRetrieve::laserCallback,this);
        image_transport::ImageTransport it(nh);
        sub3_ = it.subscribe("map_image/full", 1, &GazeboRetrieve::imageCallback,this);

        //Publishing an image ... just to show how
        image_pub_ = it_.advertise("test/image", 1);

        //Allowing an incoming service
        service_ = nh_.advertiseService("request_goal", &GazeboRetrieve::requestGoal,this);

        //Below is how to get parameters from command line, on command line they need to be _param:=value
        ros::NodeHandle pn("~");
        double mapSize;
        double resolution;
        pn.param<double>("map_size", mapSize, 20.0);
        pn.param<double>("resolution", resolution_, 0.1);

        count_ =0;
        cv::namedWindow("view",CV_WINDOW_NORMAL);
        cv::startWindowThread();
        cv::waitKey(5);

    }

    ~GazeboRetrieve()
    {
        cv::destroyWindow("view");
    }


    bool requestGoal(a3_help::RequestGoal::Request  &req,
             a3_help::RequestGoal::Response &res)
    {
      ROS_INFO("request: x=%ld, y=%ld", (long int)req.x, (long int)req.y);
      res.ack = true;
      ROS_INFO("sending back response: [%d]", res.ack);
      return true;
    }

    void odomCallback(const ...
(more)
edit retag flag offensive close merge delete

Comments

I am having a similar issue. See https://answers.ros.org/question/2756...

TomHe gravatar imageTomHe ( 2017-11-13 14:43:33 -0500 )edit