Ask Your Question

ipiano's profile - activity

2020-09-18 13:33:19 -0500 received badge  Teacher (source)
2020-09-18 13:33:19 -0500 received badge  Self-Learner (source)
2019-01-28 03:45:23 -0500 received badge  Famous Question (source)
2019-01-01 06:47:37 -0500 received badge  Notable Question (source)
2018-08-12 14:01:43 -0500 received badge  Popular Question (source)
2018-08-12 12:42:52 -0500 marked best answer ROS2 C++ Re-Created Subscriber Not Listening

I'd like to be able to disable a subscription temporarily, but as far as I know, the Subscription<t> type does not support that. Rather than use if(!disabled) in all of my message handlers, I've taken the approach of destroying my subscriptions when they are not in use via shared_ptr::reset() and then calling node::create_subscription() again when I want to start listening.

I've been seeing a lot of cases of dropped communications, where I need to restart my C++ application to get it to start listening again, which kind of defeats the purpose of trying to do this.

I've put together a minimal test case, included below. The node subscribes to channel A and publishes every second on channel B. You can run two instances built with different topic names or run a python script to work in tandem with it, the result will be the same, as far as I can tell (I've tried both). If any command line arguments are given, then after publishing, the node has a 20% chance of resetting its subscriber and creating a new one.

Running this, against another node to publish and listen, this is what I find:

  • If the subscription is never reset, either node can drop and restart and messaging continues
  • If the subscription IS reset, it continues working, but only until the node publishing to it dies; if that node is started again, the subscription never reconnects

I would expect that destroying and re-creating the subscription would reconnect and continue listening as it does in the case where it's never destroyed.

So, is this an incorrect use of ROS, or is it a bug? If I am using subscriptions incorrectly, what is the correct way to achieve the effect I want? One of the things my application does is allow users to change the topics at runtime, so if they change to topic from A to B, and then back to A, isn't that going to yield the same behavior I am seeing here?

System Details:

  • Ubuntu 16.04 Kernel 4.15.0-30-generic
  • ROS2 Ardent binaries installed through apt-get
  • I have not set the RMW_IMPLEMENTATION environment variable, so my understanding is that FastRTPS will be used

 int main(int argc, char** argv)
 {
    bool doResets = argc > 1;

    rclcpp::init(argc, argv);
    shared_ptr<rclcpp::Node> node = make_shared<rclcpp::Node>("pub1");

    auto publisher = node->create_publisher<std_msgs::msg::String>("world", 10);
    auto msg = make_shared<std_msgs::msg::String>();

    auto subFunc =
    [](std_msgs::msg::String::ConstSharedPtr str)
    {
        cout << "I heard: " << str->data << endl;
    };

    auto subscriber = node->create_subscription<std_msgs::msg::String>("hello", subFunc);

    auto timer = node->create_wall_timer(1000ms,
    [&]()
    {
        cout << "Publish!" << endl;
        msg->data = "Hello World Pub3";
        publisher->publish(msg);

        if(doResets && rand() % 100 > 80)
        {
            cout << "Rebuild subscriber" << endl;
            subscriber.reset();
            subscriber = node->create_subscription<std_msgs::msg::String>("hello", subFunc);
        }
    });

    rclcpp::spin(node);
    rclcpp::shutdown();
}
2018-08-12 12:42:42 -0500 commented answer ROS2 C++ Re-Created Subscriber Not Listening

Done https://github.com/eProsima/Fast-RTPS/issues/246

2018-08-11 22:52:39 -0500 answered a question ROS2 C++ Re-Created Subscriber Not Listening

I noticed that this didn't appear to be an issue on the Windows side of my machine. Sure enough, specifying OpenSplice f

2018-08-11 15:29:01 -0500 asked a question ROS2 C++ Re-Created Subscriber Not Listening

ROS2 C++ Re-Created Subscriber Not Listening I'd like to be able to disable a subscription temporarily, but as far as I

2018-08-01 04:20:19 -0500 received badge  Famous Question (source)
2018-06-18 05:07:42 -0500 received badge  Famous Question (source)
2018-04-20 07:19:37 -0500 received badge  Taxonomist
2018-03-29 01:55:11 -0500 received badge  Notable Question (source)
2018-03-27 14:00:22 -0500 received badge  Notable Question (source)
2018-02-05 02:14:31 -0500 received badge  Popular Question (source)
2018-01-17 22:45:44 -0500 received badge  Popular Question (source)
2018-01-17 22:38:01 -0500 commented answer [ros2] ros2 run [package] [executable] cannot find executable

Right now i'm just trying to get the migration to work on Ubuntu; step two will be to try it all on Windows. Was there s

2018-01-17 22:37:41 -0500 marked best answer [ros2] ros2 run [package] [executable] cannot find executable

I have a C++ project which consists of a number of packages that I'm migrating from ROS1 to ROS2; under ROS1 with catkin, I could build the project with catkin_make and run the executable with rosrun [package] [executable] (One of the packages is an executable, the rest are libraries or plugins).

I have installed ROS2 as per the binary install instructions https://github.com/ros2/ros2/wiki/Lin...

I have a workspace with my project cloned into it, and I believe I've finished migrating all of the package.xml and CMakeLists.txt files. The project can be built fully and the executable and libraries get put into the install directory as expected.

Unfortunately, after sourcing ./install/local_setup.bash (/opt/ros/ardent/setup.bash was sourced before building), the call ros2 run [package] [executable] returns "No executable found"

If I source the argcomplete setup in /opt/ros/ardent, I can try to tabcomplete after typing ros2 run and I can see that my package is listed as a possible completion, but if I run ros2 pkg executables, my package/executable pair is not listed.

I don't know what I have set up incorrectly.

Package.xml

<?xml version="1.0"?>
<package format="2">
  <name>sdsmt_simulator</name>
  <version>0.0.1</version>
  <description>2D simulation environment for robots running in ROS</description>

  <maintainer email="andrew.stelter@mines.sdsmt.edu">Andrew Stelter</maintainer>

  <license>TODO</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>sdsmt_simulator_box2d</depend>
  <depend>rclcpp</depend>
  <depend>rmw_implementation</depend>
  <depend>std_msgs</depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

CMakeLists.txt

###########
## SETUP ##
###########
cmake_minimum_required(VERSION 3.5)
project(sdsmt_simulator)

## Compile as C++11
if(NOT WIN32)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
endif()

## Find required ROS packages
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)

find_package(rmw_implementation REQUIRED)
find_package(sdsmt_simulator_box2d REQUIRED)

## Find and configure QT
find_package(Qt5 REQUIRED COMPONENTS
  Core
  Widgets
  Gui
)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

include_directories( include ${CMAKE_BINARY_DIR} )

## TODO If possible: Figure out how to mark Qt as a dependency
ament_export_dependencies(    
    rclcpp
    std_msgs
    sdsmt_simulator_box2d
)

ament_export_include_directories( include )

    ament_export_libraries(sdsmt_simulator_objs)

    Message("Own includes:" ${sdsmt_simulator_INCLUDE_DIRS})

    ###################
    ## FILE LISTINGS ##
    ###################

    ## Files that have any Qt macros or keywords in them
## Q_OBJECT, Q_PROPERTY, signals, slots.... etc.
set(MOC_HDRS

    include/sdsmt_simulator/drivetrain_if.h
    include/sdsmt_simulator/sensor_if.h
    include/sdsmt_simulator/robotcomponent_if.h
    include/sdsmt_simulator/property.h
    include/sdsmt_simulator/world_object_component_if.h

    include/interfaces/simulator_physics_if.h
    include/interfaces/simulator_ui_if.h
    include/interfaces/simulator_visual_if.h
    include/interfaces/old_world_object_if.h

    include/basic_physics.h
    include/basic_viewer.h
    include/simulator_core.h
    include/robot.h
    include/map.h

    include/ui/mainwindow.h
    )

set(LIB_MOC_HDRS
    include/sdsmt_simulator/world_object.h
    include/sdsmt_simulator/model.h
    )

    ## .ui qt widgets form files
set(UI_FILES
    ui/mainwindow.ui)

## Any other source files
set(CPP_SRCS
    src/basic_physics.cpp
    src/basic_viewer.cpp
    src/simulator_core.cpp
    src/robot.cpp

    src/map.cpp
    src/ui/mainwindow.cpp
    src/main.cpp
    )

set(LIB_SRCS
    src/world_object.cpp
    )

set(RCC_FILES ui/resources.qrc)
qt5_add_resources(RCC_SRCS ${RCC_FILES})

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

## Run MOC on files with Qt Keywords and Macros
qt5_wrap_cpp(LIB_MOC_SRCS ${LIB_MOC_HDRS})
qt5_wrap_cpp(MOC_SRCS ${MOC_HDRS})
## Wrap .ui files as cpp files
qt5_wrap_ui(UI_SRCS ${UI_FILES ...
(more)
2018-01-17 22:37:39 -0500 commented answer [ros2] ros2 run [package] [executable] cannot find executable

Right now i'm just trying to get the migration to work on Ubuntu; step two will be to try it all on Windows.

2018-01-17 19:12:56 -0500 asked a question [ros2] ros2 run [package] [executable] cannot find executable

[ros2] ros2 run [package] [executable] cannot find executable I have a C++ project which consists of a number of package

2018-01-17 19:00:04 -0500 marked best answer [ros2/rclcpp] Threadsafety of Node::create_publisher<>

I can't find any documentation of whether or not creating and working with nodes is threadsafe in rclcpp. My specific use case is that I would like to

create node A <- In thread 1

rclcpp::spin(A) <- in thread 2

Add/remove publishers/subscribers <- In thread 1

A link to the documentation on this topic or a direct answer would be appreciated.

2018-01-17 19:00:04 -0500 received badge  Scholar (source)
2018-01-17 17:46:17 -0500 received badge  Student (source)
2018-01-17 13:42:17 -0500 asked a question [ros2/rclcpp] Threadsafety of Node::create_publisher<>

[ros2/rclcpp] Is threadsafety of Node::create_publisher<> I can't find any documentation of whether or not creatin