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

Jordan9's profile - activity

2020-08-13 01:53:03 -0500 received badge  Nice Question (source)
2019-08-29 03:31:11 -0500 marked best answer Getting list of published topics from within C++ code

I'm using the vicon_bridge node, which publishes a topic "vicon/<subject_name>/<segment_name>" for every subject and segment it finds. In this example, consider that it publishes the topics:

vicon/subject1/segment1 vicon/subject2/segment1

Is there a way, from within C++ code, to get a list of all "vicon/*" topics that are being published? Something like 'rostopic list' that can be used from within the code and can search on a topic "subdirectory"?

2018-09-28 04:46:26 -0500 marked best answer Same Callback with Multiple Topics

I'm working with a package that publishes the same message type on multiple different topics, one topic for each of a set of objects it relates to. e.g. say we have 5 cars, car1 through car5, this package will publish a "velocity" custom msg on the topic /cars/CARNAME. So, I will have "velocity" msgs on /cars/car1, /cars/car2, etc. topics.

In the package I am building to subscribe to these messages (in C++), I would like to use the same callback function for each of the above topics (one topic for each car). However, since the message that is sent on each topic only contains a velocity and no information about which car it's for, then when the callback runs with a received message I have no idea what car that message is for.

My question is, is there some way with the NodeHandle.subscribe() function to pass a static argument to the callback every time it is called? Something like:

nh.subscribe("cars/car1", 1000, getVelocityCallback, "car1")
nh.subscribe("cars/car2", 1000, getVelocityCallback, "car2")
nh.subscribe("cars/car3", 1000, getVelocityCallback, "car3")

where the last argument is a string that would be available in the callback function, like so:

void getVelocityCallback(const carspack::Velocity::ConstPtr& msg, std::string carname)
{
   // process this message, knowing that it relates to "carname"
}

Thanks!

2017-03-17 09:53:30 -0500 received badge  Famous Question (source)
2017-02-02 06:12:58 -0500 received badge  Famous Question (source)
2017-01-29 16:20:11 -0500 marked best answer Using Boost with roscpp (Catkin errors)

I'm trying to use some boost functions in my C++ ROS code, but running into some frustrating issues with catkin.

In my CMakeLists.txt file, I have the following:

cmake_minimum_required(VERSION 2.8.3)

project(project_name)

find_package(
  catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  Boost
)
include_directories(
  include ${catkin_INCLUDE_DIRS} ${roscpp_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
)

add_executable(exec_name src/exec_name.cpp)

target_link_libraries(exec_name ${catkin_LIBRARIES})

And I have installed libboost-all-dev on my Ubuntu 14.04 machine with apt-get. When I try to compile my project, however, I get the following error:

CMake Error at /opt/ros/indigo/share/catkin/cmake/catkinConfig.cmake:75 (find_package): Could not find a package configuration file provided by "Boost" with any of the following names:

BoostConfig.cmake
boost-config.cmake

Add the installation prefix of "Boost" to CMAKE_PREFIX_PATH or set
"Boost_DIR" to a directory containing one of the above files. If "Boost"
provides a separate development package or SDK, be sure it has been
installed.

I have searched all the files on the machine and cannot find anywhere a file named "BoostConfig.cmake" or "boost-config.cmake", are they something that should be included when I installed Boost through apt-get? If anyone could help me figure out why CMake can't find Boost, it would be hugely appreciated.

2016-02-01 01:06:48 -0500 marked best answer Syntax for extracting string array from srv response in C++

I'm trying to call a service and get a response from my ROS package. The specific srv is gazebo_msgs/GetWorldProperties, which is as follows:

---
float64 sim_time
string[] model_names
bool rendering_enabled
bool success
string status_message

I can receive the response, but I cannot figure out how to extract the string array ("model_names") from it in C++. Could anyone give a snippet example of code that would allow me to loop through this string array? The current code (which I just took a wild guess at, but obviously doesn't work) is as follows:

#include "ros/ros.h"
#include <gazebo_msgs/GetWorldProperties.h>

int main(int argc, char **argv)
{
    ros::init(argc, argv, "simWrapper");
    ros::NodeHandle n;
    ros::ServiceClient client = n.serviceClient<gazebo_msgs::GetWorldProperties>("gazebo/get_world_properties");
    gazebo_msgs::GetWorldProperties worldPropSrv;
    if (client.call(worldPropSrv))
    {
        std::vector<String> models = worldPropSrv.response.model_names;
        ROS_INFO("Number of models: %i", models.size());
    }
    else
    {
        ROS_ERROR("Failed to call service get_world_properties");
        return 1;
    }
    return 0;
}

Thanks!

2015-11-26 14:27:38 -0500 received badge  Notable Question (source)
2015-11-26 14:27:38 -0500 received badge  Famous Question (source)
2015-11-08 18:50:53 -0500 received badge  Famous Question (source)
2015-10-01 02:24:24 -0500 received badge  Famous Question (source)
2015-09-29 08:42:46 -0500 received badge  Famous Question (source)
2015-07-22 01:06:36 -0500 received badge  Notable Question (source)
2015-07-22 01:06:36 -0500 received badge  Famous Question (source)
2015-07-11 07:28:34 -0500 received badge  Famous Question (source)
2015-06-11 01:54:29 -0500 received badge  Famous Question (source)
2015-05-27 14:57:34 -0500 commented answer roslaunch XML "if" comparison

I updated the OP to explain why it's way more complicated than I originally made it sound.

2015-05-27 12:27:51 -0500 commented answer roslaunch XML "if" comparison

So I can declare them going into the include file, is there a way to use arguments that are declared in the include file in the parent file? (i.e. the reverse direction)

2015-05-27 12:27:18 -0500 received badge  Notable Question (source)
2015-05-27 12:12:08 -0500 edited question Segregating roscolsole output (C++)

I'm running a node that has two main threads going on it it. I would like to segregate the output from these two threads by sending the text in ROS_INFO/ROS_ERROR/etc. to one of two different terminals. For example:

ROS_INFO("term1", "This should appear on Terminal 1");
ROS_INFO("term2", "This should appear on Terminal 2");

I want to do this because the two threads have quite different purposes, and I want to be able to easily see which output is from which thread and have it all together in one place. Is there any convenient way of doing this? I'm not overly familiar with Linux, but maybe piping the output to something other than stdout and then having a shell script that reads from the output and writes to stdout on a different terminal?

EDIT: is there a way to bump this question, or put a bounty on it or something? The two answers given do not, unfortunately, solve the problem.

2015-05-27 11:43:46 -0500 commented answer roslaunch XML "if" comparison

Yep, this could work. Having some difficulty with it though. If I define an argument inside the .launch file that gets included, that argument doesn't seem to be available in the parent .launch file (it just says it "needs to be set"). Also, arguments from the parent aren't available in the child.

2015-05-27 01:30:40 -0500 received badge  Popular Question (source)
2015-05-26 15:32:45 -0500 asked a question roslaunch XML "if" comparison

In the page on roslaunch XML, it discusses the use of "if" and "unless" attributes for tags. In the examples, however, it only shows how to do it if the argument you are checking is a boolean.

I need to do something like this:

<arg name="mode" default="simulate"/> 
<group unless="$(arg mode) == simulate">
     <!-- start a second node -->
</group>

where the "if" attribute is doing a comparison instead of checking a boolean. This syntax throws an error though. Is there an alternative way to do this?

EDIT: To give more info as to why this is complicated, I've edited the code sample a bit. Note that I need to start a new node unless the "mode" argument is of a specific type. That second node requires a whole bunch of arguments and parameters that are defined earlier in the master launch file. This makes the proposed solution of including sub-launch files more complex, because for each one of those files I would have to import a whole array of arguments to start that node, and there are a LOT of modes (and "simulate" is the only one where I don't want to start the second node). The reason I was asking about getting an argument back from a sub-launch file is because then I could just set a simple boolean in each sub-launch file, and in the master file (where all of the many arguments are available) I could start the second node if that boolean is true.

2015-05-22 10:55:23 -0500 commented answer Segregating roscolsole output (C++)

@tfoote yes I can do it with rqt_console, but as mentioned in a previous comment I need it to be terminal-based (non-gui) because I need to run it over an SSH tunnel.

2015-05-21 09:04:06 -0500 commented answer Segregating roscolsole output (C++)

So, since I can't get the logger name out of the /rosout message, I can't separate which ones were from ROS_INFO_NAMED("term1",...) and which ones were from ROS_INFO_NAMED("term2"...) if they originated from the same node.

2015-05-21 09:03:03 -0500 commented answer Segregating roscolsole output (C++)

Yeah, so I was looking at /rosout to try to find a way to just subscribe to the logs and print them in a different node. Unfortunately, the rosgraph_msgs/Log message that is published on /rosout only includes the name of the node, not the name of the logger that I provided in ROS_INFO_NAMED().

2015-05-21 09:00:40 -0500 received badge  Notable Question (source)
2015-05-21 05:23:22 -0500 received badge  Popular Question (source)
2015-05-20 11:01:23 -0500 commented answer Segregating roscolsole output (C++)

This sounds pretty much like what I need. Can you elaborate a little bit on the rqt_console bit? It looks like rqt_console is a GUI, but I need the output in a terminal because it's running over a simple SSH connection.

2015-05-20 10:53:47 -0500 received badge  Popular Question (source)
2015-05-19 23:05:38 -0500 commented answer Segregating roscolsole output (C++)

How would you select between them within the code though, to determine which ROS_INFO goes where?