yaml_menu_handler.cpp
Go to the documentation of this file.
2 #include <fstream>
3 
4 using namespace jsk_interactive_marker;
5 YamlMenuHandler::YamlMenuHandler(ros::NodeHandle* node_ptr, std::string file_name) {
6  _node_ptr = node_ptr;
7  initMenu(file_name);
8 }
9 
10 bool YamlMenuHandler::initMenu(std::string file_name) {
11  YAML::Node doc;
12 #ifdef USE_OLD_YAML
13  std::ifstream fin(file_name.c_str());
14  ROS_INFO("opening yaml file %s", file_name.c_str());
15  if (!fin.good()){
16  ROS_INFO("Unable to open yaml file %s", file_name.c_str());
17  return false;
18  }
19  YAML::Parser parser(fin);
20  if (!parser) {
21  ROS_INFO("Unable to create YAML parser for marker_set");
22  return false;
23  }
24  parser.GetNextDocument(doc);
25 #else
26  // yaml-cpp is greater than 0.5.0
27  ROS_INFO("opening yaml file with new yaml-cpp %s", file_name.c_str());
28  if ( !(access(file_name.c_str(), F_OK) != -1)) {
29  ROS_INFO("file not exists :%s", file_name.c_str());
30  return false;
31  }
32  doc = YAML::LoadFile(file_name);
33 #endif
34  for (int i=0; i<doc.size() ;i++) {
35  std::string text, topic_name;
36  const YAML::Node& single_menu = doc[i];
37 #ifdef USE_OLD_YAML
38  single_menu["text"] >> text;
39  single_menu["topic"] >> topic_name;
40 #else
41  text = single_menu["text"].as<std::string>();
42  topic_name = single_menu["topic"].as<std::string>();
43 #endif
44  ROS_INFO("Regist %s, %s", text.c_str(), topic_name.c_str());
45  _publisher_map[topic_name] = _node_ptr->advertise<std_msgs::String>(topic_name, 1);
46  _menu_handler.insert(text, boost::bind(&YamlMenuHandler::pubTopic, this, _1, topic_name));
47  }
48 }
49 
50 void YamlMenuHandler::pubTopic(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, std::string topic_name) {
51  std_msgs::String text_msg;
52  text_msg.data = feedback->marker_name;
53  if (_publisher_map.find(topic_name)==_publisher_map.end()) {
54  return;
55  }
56  else {
57  _publisher_map[topic_name].publish(text_msg);
58  }
59 }
60 
62  _menu_handler.apply(*server_ptr, name);
63 }
YamlMenuHandler(ros::NodeHandle *node_ptr, std::string file_name)
text
interactive_markers::MenuHandler _menu_handler
bool apply(InteractiveMarkerServer &server, const std::string &marker_name)
#define ROS_INFO(...)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
doc
std::map< std::string, ros::Publisher > _publisher_map
EntryHandle insert(const std::string &title, const FeedbackCallback &feedback_cb)
void applyMenu(interactive_markers::InteractiveMarkerServer *server_ptr, std::string name)
void pubTopic(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, std::string topic_name)


jsk_interactive_marker
Author(s): furuta
autogenerated on Sat Mar 20 2021 03:03:33