Last active
November 24, 2022 03:31
-
-
Save bechu/6222399 to your computer and use it in GitHub Desktop.
Get all topic and type from ROS in c++ !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ros/ros.h> | |
int main(int argc, char** argv) | |
{ | |
ros::init(argc, argv, "ros_something"); | |
ros::start(); | |
XmlRpc::XmlRpcValue params("ros_topic_list"); | |
XmlRpc::XmlRpcValue results; | |
XmlRpc::XmlRpcValue r; | |
if(ros::master::execute("getTopicTypes", params, results, r, false) == true) | |
{ | |
if(results.getType() == XmlRpc::XmlRpcValue::TypeArray) | |
{ | |
int32_t i = 2; | |
if(results[i].getType() == XmlRpc::XmlRpcValue::TypeArray) | |
{ | |
for (int32_t j = 0; j < results[i].size(); ++j) | |
{ | |
if(results[i][j].getType() == XmlRpc::XmlRpcValue::TypeArray) | |
{ | |
if(results[i][j].size() == 2) | |
{ | |
if(results[i][j][0].getType() == XmlRpc::XmlRpcValue::TypeString | |
&& results[i][j][1].getType() == XmlRpc::XmlRpcValue::TypeString) | |
{ | |
std::string topic = static_cast<std::string>(results[i][j][0]); | |
std::string type = static_cast<std::string>(results[i][j][1]); | |
std::cout<<"Topic : "<<topic<<" -> "<<type<<std::endl; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
ros::shutdown(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only get published topic