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

anuppari's profile - activity

2022-05-12 15:31:07 -0500 received badge  Good Question (source)
2018-04-23 02:47:28 -0500 received badge  Nice Question (source)
2017-03-18 09:11:43 -0500 received badge  Famous Question (source)
2017-03-01 05:38:48 -0500 received badge  Famous Question (source)
2017-02-08 10:29:05 -0500 received badge  Enthusiast
2017-02-07 19:52:25 -0500 received badge  Notable Question (source)
2017-02-07 17:52:55 -0500 answered a question ROS not calling callbacks fast enough

Based on Dirk's suggestion, I tried the noTcpDelay transport hint, and that seems to have fixed the issue. Thanks!

2017-02-07 11:47:37 -0500 received badge  Popular Question (source)
2017-02-07 10:28:51 -0500 commented question ROS not calling callbacks fast enough

However, they are communicating on separate topics, so why would the simulation interfere? My CPU usage is still around 50%.

2017-02-07 10:28:13 -0500 commented question ROS not calling callbacks fast enough

I made a simple talker/listener package to test this. When I just run the the talker and listener nodes with nothing else running, both run fine at 1kHz, and even at 10kHz. If I also have my simulation running in parallel, then I get msg drop.

2017-02-06 19:01:51 -0500 asked a question ROS not calling callbacks fast enough

EDIT:

Here's a basic talker/listener example that reproduces the problem, if anyone else wants to try it. The talker is sending msgs of type gazebo_msgs::LinkStates, at 1kHz. When less than 5 links are in the message, the listener callback is called at 1kHz. When there are more than 5 links, the listener callback only gets called at ~170 Hz.


Original Post:

There is something wrong with how ROS is calling subscriber callbacks at a much slower rate than msgs are being published. Here's a minimal example.

class DataHandler
{
private:
  ros::NodeHandle nh;
  ros::Publisher test_pub;
public:
  DataHandler() { test_pub = nh.advertise<geometry_msgs::PoseStamped>("test",10); }
  void callback(const gazebo_msgs::LinkStatesConstPtr& msg)
  {
    test_pub.publish(geometry_msgs::PoseStamped());
  }
};

int main(int argc, char** argv)
{
  ros::init(argc, argv, "gazebo_to_ros");
  ros::NodeHandle nh;

  DataHandler callbacks;
  ros::Subscriber linkSub = nh.subscribe("gazebo/link_states",1,&DataHandler::callback,&callbacks);

  ros::spin();
  return 0;
}

The topic "gazebo/link_states" is being published to at 500 Hz (using rostopic hz at the command line). The code in the callback takes a trivial amount of time to run (using std::chrono, less than 1ms => can run >1000Hz). The topic "test" is only being published to at ~70 Hz. Time between callback calls fluctuates between 1e-5 s and 0.04s, => 100kHz to 25 Hz, yielding an average of ~70 Hz.

Resource monitor shows cpu usage at less than 50%. Even setting high priority for this process changes nothing, so I don't think its a bottleneck in the hardware.

I'm on Ubuntu 16.04 LTS, with ROS Kinetic. Anyone have any idea at what I should look at next to help troubleshoot? Thanks for your help.

2017-01-27 15:53:51 -0500 received badge  Nice Question (source)
2017-01-24 06:45:03 -0500 received badge  Notable Question (source)
2017-01-10 03:51:16 -0500 received badge  Popular Question (source)
2016-11-29 14:18:45 -0500 asked a question Subscriber callback missing messages

Summary: I have a node publishing messages at ~300hz, but a callback subscribing to the topic in another node only gets called at ~25hz. The spinOnce in the subscriber node is being called at ~700hz, so I don't know why it's missing messages.

Publisher node:

#include <ros/ros.h>
#include <ros/console.h>
#include <nav_msgs/Odometry.h>

...

int main(int argc, char** argv)
{
    ros::init(argc, argv, "sim_node");
    ros::NodeHandle nh;

    ...

    // Publishers
    tf::TransformBroadcaster tfbr;
    ros::Publisher odomPub = nh.advertise<nav_msgs::Odometry>("pose",10);

   ...

    ros::Rate r(300); // loop rate
    while(ros::ok())
    {
        ...

        // Publish pose and velocity
            ...
        odomPub.publish(msg);

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

    ros::waitForShutdown();
    return 0;
}

Subscriber node:

#include <ros/ros.h>
#include <ros/console.h>
#include <nav_msgs/Odometry.h>

...

std::mutex mtx1, mtx2;

class DataHandler
{
private:
    ros::NodeHandle nh;
    ros::Publisher odomPub;
    double lastTime;
    int lastSeq;

public:
    Eigen::Vector3d x, xDot, w;
    Eigen::Vector3d xDes, xDesDot, xDesDotDot, b1Des, b1DesDot;
    Eigen::Matrix3d R;

    DataHandler()
    {
        // Initialize data
        xDes = Eigen::Vector3d(1,0,1);
        xDesDot = Eigen::Vector3d::Zero();
        xDesDotDot = Eigen::Vector3d::Zero();
        b1Des = Eigen::Vector3d(1,0,0);
        b1DesDot = Eigen::Vector3d::Zero();
        x = Eigen::Vector3d::Zero();
        xDot = Eigen::Vector3d::Zero();
        R = Eigen::Matrix3d::Identity();

        odomPub = nh.advertise<nav_msgs::Odometry>("controller_pose",10);
        trajPub = nh.advertise<asap_control::DesiredTrajectory>("controller_desTraj",10);
        lastTime = ros::Time::now().toSec();
        lastSeq = 0;
    }

    // Get current pose and velocity
    void odomCB(const nav_msgs::OdometryConstPtr& odomMsg)
    {

        mtx1.lock();
            // Get data
        double time1 = ros::Time::now().toSec();
        x << odomMsg->pose.pose.position.x, odomMsg->pose.pose.position.y, ...;
        xDot << odomMsg->twist.twist.linear.x, odomMsg->twist.twist.linear.y, ...;
        R = Eigen::Quaterniond(odomMsg->pose.pose.orientation.w, odomMsg->pose.pose.orientation.x,...;
        w << odomMsg->twist.twist.angular.x, odomMsg->twist.twist.angular.y, ...;
        double time2 = ros::Time::now().toSec();

            // Time to extract data, < 1ms
        double delTproc = time2 - time1;
        std::cout << "\n\n";
        std::cout << "proc elapsed time: " << delTproc << "\n";
        std::cout << "proc frequency: " << 1.0/delTproc << "\n";

        odomPub.publish(odomMsg); // rostopic hz says this is publishing at ~25Hz

            // Time between callback calls, ~25Hz
        double timeNow = ros::Time::now().toSec();
        double delT = timeNow - lastTime;
        lastTime = timeNow;
        std::cout << "elapsed time: " << delT << "\n";
        std::cout << "frequency: " << 1.0/delT << "\n";

            // Message sequence IDs, shows 12 msgs skipped every call
        int seqNow = odomMsg->header.seq;
        int delSeq = seqNow - lastSeq;
        lastSeq = seqNow;
        std::cout << "delta seq: " << delSeq << "\n";
        mtx1.unlock();
    }

};

...

int main(int argc, char** argv)
{
    ros::init(argc, argv, "asap_control");
    ros::NodeHandle nh;

    ...

    // Publishers
    ros::Publisher outputPub = nh.advertise<geometry_msgs::WrenchStamped>("wrench_command",10);
    ros::Publisher debugPub = nh.advertise<asap_control::ControllerSignals>("controller_debug",10);
    tf::TransformBroadcaster tfbr;

    // Subscribers
    DataHandler callbacks;
    ros::Subscriber poseSub = nh.subscribe("pose",10,&DataHandler::odomCB,&callbacks);

    // Asynchronous threads for callback handling
    //ros::AsyncSpinner spinner(2);
    //spinner.start();

    double lastTime = ros::Time::now().toSec();


    // Main loop
    ros::Rate r(700); // loop rate
    while(ros::ok())
    {
        // Data (extracted for cleanliness further down, and thread safety)
        mtx1.lock();
        Eigen::Vector3d x = callbacks.x;
        Eigen::Vector3d xDot = callbacks.xDot;
        Eigen::Matrix3d R = callbacks.R;
        Eigen::Vector3d w = callbacks.w;
        mtx1.unlock();

            ...

        // Publish
            ...
        outputPub.publish ...
(more)
2016-11-29 13:00:54 -0500 received badge  Famous Question (source)
2016-11-29 13:00:54 -0500 received badge  Notable Question (source)
2016-11-29 13:00:54 -0500 received badge  Popular Question (source)
2016-01-27 12:19:05 -0500 asked a question How to include opencv headers using short paths

While trying to compile old code, I run into the error:

node.cpp:13:31: fatal error: opencv2/imgproc.hpp: No such file or directory
 #include <opencv2/imgproc.hpp>

If I change the include line in the code to

#include <opencv2/imgproc/imgproc.hpp>

then it compiles fine.

Is there something that has changed in my environment? How do I get the first version to compile consistently?

2016-01-15 09:30:06 -0500 received badge  Student (source)
2015-06-25 15:20:56 -0500 received badge  Famous Question (source)
2015-06-02 03:29:02 -0500 received badge  Notable Question (source)
2015-04-22 07:05:10 -0500 received badge  Popular Question (source)
2015-04-12 18:08:17 -0500 asked a question rospy tf waitForTransform not waiting

I keep getting lookup extrapolation errors when trying to use tf, even when using listener.waitForTransform. For example I get:

Exception: Lookup would require extrapolation into the future. Requested time 1428875486.097693682 but the latest data is at time 1428875486.097676516, when looking up transform from frame [ugv0] to frame [image]

The difference in time is less than a millisecond, and even if my timeout duration is very long, I still get an extrapolation error. My code has:

tfl.waitForTransform('image',obj_name,timeStamp,rospy.Duration(10.0))

The tf call is in a callback on a topic that has data published to it at a very fast rate, approximately 360hz, and the relevant transforms are also all being published at ~360hz except for a static transform, which is at 10hz. I would attach the pdf of the view frames output, but I dont have enough points to attach files.

What is wrong?

2013-08-24 02:50:34 -0500 received badge  Famous Question (source)
2013-06-20 02:50:16 -0500 received badge  Notable Question (source)
2013-06-10 06:05:43 -0500 marked best answer How to pass arguments to python node

I would like pass arguments to a node like so:

rosrun my_package my_node.py myArg1 myArg2

Is this possible? How do I define my python function? Currently it is:

#!/usr/bin/env python
import roslib; roslib.load_manifest('my_package')
import rospy

def my_node(myArg1,myArg2)
...

but when I use the command line and run rosrun I get errors saying the my function takes two arguments and 0 were passed.

Using topics to pass in information seems over complicated and I don't want to use parameters because I don't need to make myArg1 and myArg2 available to any other nodes. Any help would be appreciated.

Edit: Running fuerte