8 const std::string &topic_name,
12 const std::string& datatype = msg->getDataType();
13 const std::string& definition = msg->getMessageDefinition();
21 static std::vector<uint8_t>
buffer;
22 static std::map<std::string,FlatMessage> flat_containers;
23 static std::map<std::string,RenamedValues> renamed_vectors;
29 buffer.resize( msg->size() );
39 printf(
"--------- %s ----------\n", topic_name.c_str() );
40 for (
auto it: renamed_values)
42 const std::string& key = it.first;
43 const Variant& value = it.second;
44 printf(
" %s = %f\n", key.c_str(), value.
convert<
double>() );
46 for (
auto it: flat_container.
name)
48 const std::string& key = it.first.toStdString();
49 const std::string& value = it.second;
50 printf(
" %s = %s\n", key.c_str(), value.c_str() );
56 int main(
int argc,
char** argv)
61 printf(
"Usage: rosbag_example list_of_topics_names\n");
65 ros::init(argc, argv,
"universal_subscriber");
67 std::set<std::string> topic_names;
69 for (
int i=1;
i< argc;
i++)
71 topic_names.insert( argv[
i] );
76 for (
const auto& topic_info: advertized_topics)
78 printf(
"advertized: %s\n", topic_info.name.c_str());
82 for (
const std::string& topic_name: topic_names)
85 for (
const auto& topic_info: advertized_topics)
87 if( topic_info.name == topic_name)
95 printf(
"This topic has not been published yet: %s\n", topic_name.c_str() );
103 std::vector<ros::Subscriber> subscribers;
105 for (
const std::string& topic_name: topic_names)
108 boost::function<void(const topic_tools::ShapeShifter::ConstPtr&) > callback;
113 subscribers.push_back( nh.
subscribe(topic_name, 10, callback) );
std::vector< std::pair< StringTreeLeaf, std::string > > name
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
RosIntrospection::Parser parser
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
void applyNameTransform(const std::string &msg_identifier, const FlatMessage &container, RenamedValues *renamed_value)
int main(int argc, char **argv)
std::vector< TopicInfo > V_TopicInfo
ROSCPP_DECL void spin(Spinner &spinner)
bool deserializeIntoFlatContainer(const std::string &msg_identifier, absl::Span< uint8_t > buffer, FlatMessage *flat_container_output, const uint32_t max_array_size) const
FlatMessage flat_container
std::vector< std::pair< std::string, Variant > > RenamedValues
ros::serialization::OStream stream(buffer.data(), buffer.size())
void topicCallback(const topic_tools::ShapeShifter::ConstPtr &msg, const std::string &topic_name, RosIntrospection::Parser &parser)
std::vector< uint8_t > buffer(ros::serialization::serializationLength(imu))
void registerMessageDefinition(const std::string &message_identifier, const ROSType &main_type, const std::string &definition)