Ask Your Question
0

Strange segfault when running node on raspberry pi 3

asked 2016-08-10 10:30:44 -0500

roach gravatar image

updated 2016-08-11 04:31:32 -0500

Hi all,

I have recently installed ROS kinetic on a raspberry pi 3 (raspbian jessie), as explained in this tutorial.

Everything worked fine (except rviz, but I don't need it). However, when I wanted to test some C++ nodes I wrote on my laptop, it didn't worked.

I just copied my packages in the raspi's catkin_ws, then catkin_maked it. I didn't meet any problem when compiling. The python-coded nodes worked fine, but not the C++ ones. Then I tried to make a very simple C++ node saying hello world, and I build it the same way. And it didn't work (Segmentation Fault). Then I discovered, that if, in the CMakeLists, I did not link the catkin/opencv libraries (with target_link_libraries, which worked on my laptop), the program worked well, but it obviously couldn't interact with ROS/opencv.

Would you have any suggestion, feel free to answer ;)

Thanking you in advance

EDIT

I have included the codes below. The nodes aims at reading a webcam and sending OpenCV images. It works on my laptop (Ubuntu 16.04, ROS kinetic).

Here is the code :

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <sstream>

int main(int argc, char** argv)
{
    // Initialization of ROS node and ROS topic
    ros::init(argc, argv, "i_Camera");
    ros::NodeHandle nh;
    image_transport::ImageTransport it(nh);
    image_transport::Publisher pub = it.advertise("/sensors/camera", 1);
    int cam = 0;
    nh.param<int>("camera_id",cam,0);

    cv::VideoCapture cap(cam);
    // Check if video device can be opened with the given index
    if(!cap.isOpened()) return 1;
    cv::Mat frame;
    sensor_msgs::ImagePtr msg;

    ros::Rate loop_rate(60);

    // Main loop, grab frames and publish them on the topic
    while (nh.ok()) {
        cap >> frame;
        // Check if grabbed frame is not empty
        if(!frame.empty()) {
            msg = cv_bridge::CvImage(std_msgs::Header(), sensor_msgs::image_encodings::BGR8, frame).toImageMsg();
            pub.publish(msg);
            cv::waitKey(1);
        }

        ros::spinOnce();
        loop_rate.sleep();
    }
}

And the CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(vision)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(catkin REQUIRED COMPONENTS
    geometry_msgs
    roscpp
    rospy
    std_msgs
    visualization_msgs
    image_transport
    cv_bridge
    )

find_package(OpenCV)

catkin_package(
    INCLUDE_DIRS include
    #  LIBRARIES vision
    CATKIN_DEPENDS geometry_msgs roscpp rospy std_msgs visualization_msgs image_transport cv_bridge
    #  DEPENDS system_lib
    )

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

add_executable(i_Camera src/i_Camera.cpp)

target_link_libraries(i_Camera
    ${OpenCV_LIBS}
    ${catkin_LIBRARIES}
    )
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-08-11 09:29:30 -0500

Marcin Bogdanski gravatar image

updated 2016-08-11 09:30:28 -0500

Not a direct answer, but maybe some things to try:

  • Does segfault on any particular line of code?
  • I didn't use rasbian or OpenCV, so this might be complete miss, but maybe try Ubuntu Mate 16.04? It should correspond more closely to what you have on laptop? I have a lot of ROS stuff running or RPi3 with Ubuntu without issues.

Marcin

edit flag offensive delete link more

Comments

Thank you very much for your answer !

Segfault happens when running the node, and I think while loading libraries in memory. I have tried to print something before doing anything else, but it also segfaults.

I'll try Ubuntu Mate right now and keep you informed.

roach gravatar imageroach ( 2016-08-11 10:25:48 -0500 )edit

I have tried with Ubuntu Mate, and it works very well, using exactly the same codes.

roach gravatar imageroach ( 2016-08-18 09:58:24 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-08-10 10:30:44 -0500

Seen: 492 times

Last updated: Aug 11 '16