Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diagnostics rate not periodic while logging pixhawk cpu usage #1190

Open
SiddharthPatel45 opened this issue Mar 4, 2019 · 2 comments
Open
Labels

Comments

@SiddharthPatel45
Copy link

Hi guys,

I am trying to log pixhawk CPU usage using the rostopic /diagnostics. But even though it says it publishes at 1Hz, when I subscribe to this topics to extract the CPU usage, most of the messages received by the subscriber in the node does not contain that much info, and I get the error segmentation fault (core dumped). I checked the vector length and see that it receives full message only sporadically. There is not relation in between the timestamps I receive, so I have to use a workaround like:

#include <ros/ros.h>
#include <diagnostic_msgs/DiagnosticArray.h>
#include <std_msgs/Float32.h>

ros::Publisher pixhawk_cpu_usage_pub;
ros::Subscriber pixhawk_diagnostics_sub;
std_msgs::Float32 pub_msg;

void diagnostics_cb(const diagnostic_msgs::DiagnosticArray::ConstPtr& msg) {
    if (msg->status.size() >= 4) {
        // std::cout << msg->status[3].values[3].key.c_str() << std::endl;
        pub_msg.data = atof(msg->status[3].values[3].value.c_str());
        pixhawk_cpu_usage_pub.publish(pub_msg);
    }
}

int main(int argc, char** argv){
    ros::init(argc, argv, "pixhawkCPUpub");
    ros::NodeHandle nh;
    pixhawk_diagnostics_sub = nh.subscribe("/diagnostics", 1, diagnostics_cb);
    pixhawk_cpu_usage_pub = nh.advertise<std_msgs::Float32>("/pixhawk_cpu_usage", 10);
    ros::spin();
}

But when I use rostopic echo /diagnostics I can see all the content. Can someone explain why part of the message is not published regularly or is there something I am missing. thanks. It is not something critical but as I am logging I just want to know if there is a consistent way to log this parameter.

Thanks

MAVROS version and platform

Mavros: ?0.29.0?
ROS: ?Kinetic?
Ubuntu: ?16.04?

@vooon
Copy link
Member

vooon commented Mar 4, 2019

/diagnostics are used by all nodes that wants to emit diag data. So some nodes may publish different amount of diag entries. That is similar to how /tf works.
You should not rely on indexes, they may change. You should walk and compare names.

@vooon vooon added the question label Mar 4, 2019
@SiddharthPatel45
Copy link
Author

ok, got it. thanks
So there is actually no specific time time on which they will publish data. I will do as you suggested
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants