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

Ariel's profile - activity

2023-06-16 07:40:04 -0500 received badge  Famous Question (source)
2022-04-14 11:35:22 -0500 received badge  Notable Question (source)
2022-03-30 06:29:53 -0500 commented question Slow publisher with callback

Publishing directly is reduces a bit the frequency but not that much. The processor is running at 666MHz, so copying a 6

2022-03-29 10:02:59 -0500 received badge  Popular Question (source)
2022-03-28 15:14:15 -0500 received badge  Notable Question (source)
2022-03-28 07:50:56 -0500 asked a question Slow publisher with callback

Slow publisher with callback Hi, I am publishing images with the usb_cam package on a PC and subscribing to them with a

2022-03-14 00:40:29 -0500 received badge  Famous Question (source)
2022-02-03 16:33:27 -0500 received badge  Self-Learner (source)
2022-01-13 15:28:43 -0500 received badge  Popular Question (source)
2022-01-13 07:56:15 -0500 marked best answer Launch same node multiple times

Hi,

I have a simple publisher which I want to launch with different parameters (rate and length) using the same code:

#include "ros/ros.h"
#include "std_msgs/String.h"

int main(int argc, char **argv)
{
    std::string NODE_NAME = "pc_pub_string";
    ros::init(argc, argv, NODE_NAME);
    ros::NodeHandle n;

    ros::Publisher string_pub = n.advertise<std_msgs::String>(NODE_NAME, 100);

    // Get the sample rate of this node (set in the launch file)
    ros::NodeHandle np("~");
    int loop_rate_p, data_length_p;
    if(np.getParam("loop_rate", loop_rate_p)){
        ROS_INFO("Initialized [%s] node at %d Hz", NODE_NAME.c_str(), loop_rate_p);
    }
    else{
        ROS_ERROR("Couldn't get rate parameter");
        return 0;
    }
    if(np.getParam("data_length", data_length_p)){
        ROS_INFO("Initialized [%s] node with %d elements in data", NODE_NAME.c_str(), data_length_p);
    }
    else{
        ROS_ERROR("Couldn't get data length parameter");
        return 0;
    }
    ros::Rate loop_rate(loop_rate_p);

    // Populate string message (content doesn't matter for proof of concept)
    std_msgs::String str;
    for(int i=0; i<data_length_p; i++)
        str.data.push_back(i);

    while(ros::ok())
    {
        string_pub.publish(str);
        ros::spinOnce();
        loop_rate.sleep();
    }


    return 0;
}

For this, I am using this launch file:

<launch>

  <group ns="publisher">
    <node pkg="proof_of_concept_string_ips" name="pc_pub_string0" type="pc_pub_string">
      <param name="loop_rate" type="int" value="2" />
      <param name="data_length" type="int" value="4" />
      <remap from="publisher/pc_pub_string" to="publisher/pc_pub_string0"/>
    </node>

    <node pkg="proof_of_concept_string_ips" name="pc_pub_string1" type="pc_pub_string">
      <param name="loop_rate" type="int" value="4" />
      <param name="data_length" type="int" value="2" />
      <remap from="publisher/pc_pub_string" to="publisher/pc_pub_string1"/>
    </node>    

  </group>

</launch>

The issue is that in the topic list, I only see what I wrote in NODE_NAME = "pc_pub_string". However, with ros info I can see that there are two publisher. I was hoping to have two topics, one called pc_pub_string0 and another pc_pub_string1. This could be achieved by having 2 .cpp files and compile 2 different executables, but their code would be the same.

Is it possible to avoid having two executables and use only one to manipulate their parameters (also topic names to have multiple) from the launch file?

Thanks for the help.

2022-01-13 07:56:07 -0500 answered a question Launch same node multiple times

The error is in the launch file. The remap should not include the group name: <remap from="pc_pub_string" to="pc_pub_

2022-01-13 07:56:07 -0500 received badge  Rapid Responder (source)
2022-01-13 07:56:03 -0500 edited question Launch same node multiple times

Launch same node multiple times Hi, I have a simple publisher which I want to launch with different parameters (rate an

2022-01-13 07:55:24 -0500 edited question Launch same node multiple times

Launch same node multiple times Hi, I have a simple publisher which I want to launch with different parameters (rate an

2022-01-13 05:42:23 -0500 asked a question launch same node multiple times

launch same node multiple times Hi, I have a simple publisher which I want to launch with different parameters (rate an

2022-01-13 05:41:22 -0500 asked a question launch same node multiple times

launch same node multiple times Hi, I have a simple publisher which I want to launch with different parameters (rate an

2022-01-13 05:41:21 -0500 asked a question Launch same node multiple times

Launch same node multiple times Hi, I have a simple publisher which I want to launch with different parameters (rate an

2021-09-30 07:23:38 -0500 edited answer How to check callback queue?

According to the documentation (as suggested by @gvdhoorn) the code should look something like this: #include "ros/ros.

2021-09-30 07:23:12 -0500 commented answer How to check callback queue?

Removing the commented things during tested I deleted the ros::spinOnce(); (edited). The code now implements a solution

2021-09-30 04:14:33 -0500 marked best answer How to check callback queue?

Hello,

I have a node that subscribes to 3 topics that are being published by individual nodes. In the subscriber node, I have 3 callbacks, one for each. I would like to know if it is possible to know whether there are messages in callback queue. What I am trying to do is to avoid that the same topic triggers its callback twice in a row if there are messages from the other 2 topics available in the callback queue.

This is the code I have now:

#include "ros/ros.h"
#include "sensor_msgs/Image.h"
#include "sensor_msgs/LaserScan.h"
#include "geometry_msgs/TwistStamped.h"

// Callbacks
void pc_pub_img_callback(const sensor_msgs::Image::ConstPtr& msg){
      //ROS_INFO("Received from pc_pub_img");
      ROS_INFO("Img:Callback(%d)", msg->header.seq);
      ros::Duration(0.2).sleep();
      // Serialization
      sensor_msgs::Image Image;
      uint32_t serial_size = ros::serialization::serializationLength(*msg);
      boost::shared_array<uint8_t> buffer(new uint8_t[serial_size]);
      ROS_INFO("Img:Serialized");
}

void pc_pub_laser_callback(const sensor_msgs::LaserScan::ConstPtr& msg){
      //ROS_INFO("Received from pc_pub_laser");
      ROS_INFO("Laser:Callback(%d)", msg->header.seq);

      // Serialization
      sensor_msgs::Image LaserScan;
      uint32_t serial_size = ros::serialization::serializationLength(*msg);
      boost::shared_array<uint8_t> buffer(new uint8_t[serial_size]);
      ROS_INFO("Laser:Serialized");
}

void pc_pub_twist_callback(const geometry_msgs::TwistStamped::ConstPtr& msg){
      //ROS_INFO("Received from pc_pub_img");
      ROS_INFO("Twist:Callback(%d)", msg->header.seq);

      // Serialization
      geometry_msgs::Twist Twist;
      uint32_t serial_size = ros::serialization::serializationLength(*msg);
      boost::shared_array<uint8_t> buffer(new uint8_t[serial_size]);
      ROS_INFO("Twist:Serialized");
}

int main(int argc, char **argv)
{

    ros::init(argc, argv, "arm_to_fpga");
    ros::NodeHandle n;

    ros::Subscriber sub_img = n.subscribe("/pc_pub_img", 1000, pc_pub_img_callback);
    ros::Subscriber sub_laser = n.subscribe("/pc_pub_laser", 1000, pc_pub_laser_callback);
    ros::Subscriber sub_twist = n.subscribe("/pc_pub_twist", 1000, pc_pub_twist_callback);

    ros::spin();

    return 0;
}

Thanks.

EDIT: I've changed the frequencies for the 3 publishers at 30, 60 and 60 respectively and removed the serialization part to make the output simpler. Then, I got the following:

[ INFO] [1632761598.718118783]: Twist:Callback
[ INFO] [1632761598.720308913]: Laser:Callback
[ INFO] [1632761598.735116602]: Img:Callback
[ INFO] [1632761598.736248825]: Twist:Callback
[ INFO] [1632761598.736324787]: Laser:Callback
[ INFO] [1632761598.750847497]: Twist:Callback
[ INFO] [1632761598.753741510]: Laser:Callback
[ INFO] [1632761598.762706367]: Img:Callback
[ INFO] [1632761598.764424037]: Twist:Callback
[ INFO] [1632761598.766623670]: Laser:Callback
[ INFO] [1632761598.778012548]: Img:Callback
[ INFO] [1632761598.781003259]: Twist:Callback
[ INFO] [1632761598.783278070]: Laser:Callback
[ INFO] [1632761598.798151580]: Twist:Callback
[ INFO] [1632761598.800334432]: Laser:Callback
[ INFO] [1632761598.817158784]: Img:Callback
[ INFO] [1632761598.817276101]: Twist:Callback
[ INFO] [1632761598.817368705]: Laser:Callback
[ INFO] [1632761598.831502251]: Twist:Callback
[ INFO] [1632761598.833594552]: Laser:Callback
[ INFO] [1632761598.848181492]: Twist:Callback
[ INFO] [1632761598.850259481]: Laser:Callback
[ INFO] [1632761598.853909133]: Img:Callback
[ INFO] [1632761598.864712495]: Twist:Callback
[ INFO] [1632761598.866926431]: Laser:Callback
[ INFO] [1632761598.881360624]: Twist:Callback
[ INFO] [1632761598.885404560]: Img:Callback
[ INFO] [1632761598.885498932]: Laser:Callback
[ INFO] [1632761598.898164827]: Twist:Callback
[ INFO] [1632761598.900324819]: Laser:Callback
[ INFO] [1632761598.914681449]: Twist:Callback
[ INFO] [1632761598.918684480]: Img:Callback
[ INFO] [1632761598.918797223]: Laser:Callback
[ INFO] [1632761598.931412780]: Twist:Callback
[ INFO] [1632761598.953476288]: Img:Callback
[ INFO] [1632761598.953735208]: Twist:Callback
[ INFO] [1632761598.960459469]: Laser:Callback
[ INFO] [1632761598.960576034]: Laser:Callback
[ INFO] [1632761598.965029298]: Twist:Callback
[ INFO] [1632761598.980162791]: Img:Callback
[ INFO] [1632761598.981067892]: Twist:Callback
[ INFO] [1632761598.997919124]: Twist ...
(more)
2021-09-30 04:14:29 -0500 commented answer How to check callback queue?

True, it is not fully working like posted there, but seems to be the way to go with respect to the queues. I believe the

2021-09-30 04:14:01 -0500 edited answer How to check callback queue?

According to the documentation (as suggested by @gvdhoorn) the code should look something like this: #include "ros/ros.

2021-09-29 11:29:00 -0500 edited answer How to check callback queue?

According to the documentation (as suggested by @gvdhoorn) the code should look something like this: int main(int argc,

2021-09-29 11:23:03 -0500 commented answer How to check callback queue?

True, it is not fully working like posted there, but seems to be the way to go with respect to the queues. I believe the

2021-09-29 11:07:07 -0500 answered a question How to check callback queue?

According to the documentation (as suggested by @gvdhoorn) the code should look something like this: int main(int argc,

2021-09-28 02:41:04 -0500 commented answer How to check callback queue?

Those are quite interesting points. You are right, there is no need to reserialize to increase the overhead. However, th

2021-09-28 02:26:28 -0500 commented answer How to check callback queue?

Yes, exactly. I want to implement a round-robin scheduling to forward the incoming messages over a single hardware resou

2021-09-27 12:26:00 -0500 edited question How to check callback queue?

How to check callback queue? Hello, I have a node that subscribes to 3 topics that are being published by individual no

2021-09-27 11:16:26 -0500 commented question How to check callback queue?

it seems this is the way to go. Unfortunately I haven't found any example that shows how to check which queue for the me

2021-09-27 10:54:14 -0500 commented question How to check callback queue?

it seems this is the way to go. Unfortunately I haven't found any example that shows how to check which queue for the me

2021-09-27 10:19:57 -0500 commented question How to check callback queue?

it seems this is the way to go. Unfortunately I haven't found any example that shows how to check which queue for the me

2021-09-13 09:33:52 -0500 received badge  Famous Question (source)
2021-09-11 16:11:27 -0500 received badge  Notable Question (source)
2021-09-10 15:11:17 -0500 received badge  Popular Question (source)
2021-09-10 09:33:15 -0500 edited question How to check callback queue?

How to check callback queue? Hello, I have a node that subscribes to 3 topics that are being published by individual no

2021-09-10 09:27:51 -0500 asked a question How to check callback queue?

How to check callback queue? Hello, I have a node that subscribes to 3 topics that are being published by individual no

2021-08-04 19:51:55 -0500 received badge  Famous Question (source)
2021-05-11 17:25:15 -0500 received badge  Notable Question (source)
2021-04-19 07:07:58 -0500 received badge  Famous Question (source)
2021-04-12 09:07:33 -0500 received badge  Famous Question (source)
2021-04-02 02:09:07 -0500 received badge  Popular Question (source)
2021-03-09 14:03:02 -0500 received badge  Popular Question (source)
2021-03-09 09:38:16 -0500 received badge  Notable Question (source)
2021-02-23 12:24:21 -0500 received badge  Popular Question (source)
2021-02-22 12:10:37 -0500 edited question How to use to_yaml() function or std::cout for messages in ROS2?

How to use to_yaml() function in ROS2? Hello, I want to print a message and save it in a file (std::cout << msg).