ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

noetic createTimer always segfault

asked 2022-12-23 07:12:04 -0500

qualiticsbe gravatar image

Hi,

After introducing ROS to my program with success, i wanted to use it more and added timer.
I am using the same code on both Ubuntu20/noetic and Ubuntu18/melodic without any issue.
But with timer i have a problem. On melodic it works fine, on noetic it always segfault when i call createTimer.

I tried the sample in the wiki for timers and that simple code also segfaults. I tried with different ways of calling createTimer with different callback binding style but all segfaults.

void callback1(const ros::TimerEvent&) {
    ROS_INFO("Callback 1 triggered");
}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "talker");
    ros::NodeHandle n;
    ros::Timer timer1 = n.createTimer(ros::Duration(0.1), callback1);
    ros::spin();
    return 0;
}

Some basics information

ROS_VERSION=1 ROS_PYTHON_VERSION=3
ROS_PACKAGE_PATH=/opt/ros/noetic/share
ROS_ETC_DIR=/opt/ros/noetic/etc/ros
ROS_MASTER_URI=http://localhost:11311
ROS_ROOT=/opt/ros/noetic/share/ros
ROS_DISTRO=noetic

noetic is installed with apt, all default packages on a new fresh install of Ubuntu20 server All parameters to start roscore or my test program are defaults.

Stack trace is not useful but i have no idea how i could have more details at one line it is actually crashing inside libroscpp

#0  0x00007ffff7f0a36e in ros::NodeHandle::createTimer(ros::Duration, boost::function<void (ros::TimerEvent const&)> const&, bool, bool) const () from /lib/x86_64-linux-gnu/libroscpp.so.2d
#1  0x0000555555558b97 in main (argc=1, argv=0x7fffffffe1e8) at /home/worker/main.cpp:11

To install i do

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo apt install ros-noetic-ros-base libroscpp-dev

To compile my code, i use cmake and link to roscpp using

pkg_check_modules(libros REQUIRED roscpp)
target_include_directories(mybin PUBLIC ${libros_INCLUDE_DIRS})
target_link_libraries(mybin ${libros_LIBRARIES})

Thanks for your help.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2022-12-24 02:42:07 -0500

gvdhoorn gravatar image

Stack trace is not useful but i have no idea how i could have more details at one line it is actually crashing inside libroscpp

#0  0x00007ffff7f0a36e in ros::NodeHandle::createTimer(ros::Duration, boost::function<void (ros::TimerEvent const&)> const&, bool, bool) const () from /lib/x86_64-linux-gnu/libroscpp.so.2d
#1  0x0000555555558b97 in main (argc=1, argv=0x7fffffffe1e8) at /home/worker/main.cpp:11

actually, it's very useful, and this most likely already shows the cause: /lib/x86_64-linux-gnu/libroscpp.so.2d.

There are no artefacts from ROS Noetic proper which install into anything else but /opt/ros/noetic.

In other words: the library /lib/x86_64-linux-gnu/libroscpp.so.2d is not part of ROS Noetic.

To install i do

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo apt install ros-noetic-ros-base libroscpp-dev

Similar to the above: libroscpp-dev is not part of ROS Noetic (in fact, libroscpp-dev is not really part of any ROS version).

All packages part of ROS Noetic will have the ros-noetic- prefix (like ros-noetic-ros-base).

What's most likely happening is you're mixing ROS Noetic proper with the UpstreamPackages. That won't work reliably, as you've already found out. See also “upstream packages” increasingly becoming a problem on ROS Discourse.

I'd recommend to purge all upstream variants of ROS packages and make sure you have a sane ROS Noetic install.

edit flag offensive delete link more

Comments

Oh wow! Ok that was a huge help and i figured it out. Linking to /lib/x86_64-linux-gnu/libroscpp.so.2d was indeed the root cause of my problem.

So first, i removed the package libroscpp-dev and only keep ros-noetic-ros-base

For cmake i do instead

find_package(libros REQUIRED COMPONENTS roscpp)

That way it links to libroscpp.so inside /opt/ros/noetic.
I don't know why i have python prompt for a cpp binary that way but it's working so i don't mind.

-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Using Debian Python package layout
-- Found PY_em: /home/god_kane/.local/lib/python3.8/site-packages/em.py  
-- Using empy: /home/god_kane/.local/lib/python3.8/site-packages/em.py

Guess i fell into that upstream package trap like many other new ros user.

Thanks!

qualiticsbe gravatar image qualiticsbe  ( 2022-12-27 02:32:21 -0500 )edit

I now know why i used pkg_check_modules(libros REQUIRED roscpp) before, it was not to be annoyed with python. In a cross-compiling environment i can't compile because catkin bothers me about it while i really don't care about python. Can i ignore python completely while still linking the proper librairies?

qualiticsbe gravatar image qualiticsbe  ( 2022-12-27 03:34:16 -0500 )edit

Question Tools

Stats

Asked: 2022-12-23 04:09:41 -0500

Seen: 73 times

Last updated: Dec 27 '22