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 }
jsk_interactive_marker::YamlMenuHandler::initMenu
bool initMenu(std::string file)
Definition: yaml_menu_handler.cpp:10
jsk_interactive_marker::YamlMenuHandler::_publisher_map
std::map< std::string, ros::Publisher > _publisher_map
Definition: yaml_menu_handler.h:16
interactive_markers::MenuHandler::apply
bool apply(InteractiveMarkerServer &server, const std::string &marker_name)
jsk_interactive_marker::YamlMenuHandler::pubTopic
void pubTopic(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, std::string topic_name)
Definition: yaml_menu_handler.cpp:50
jsk_interactive_marker::YamlMenuHandler::_node_ptr
ros::NodeHandle * _node_ptr
Definition: yaml_menu_handler.h:14
doc
doc
jsk_interactive_marker::YamlMenuHandler::applyMenu
void applyMenu(interactive_markers::InteractiveMarkerServer *server_ptr, std::string name)
Definition: yaml_menu_handler.cpp:61
parser
jsk_interactive_marker
Definition: camera_info_publisher.h:48
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
text
text
_1
boost::arg< 1 > _1
interactive_markers::InteractiveMarkerServer
yaml_menu_handler.h
interactive_markers::MenuHandler::insert
EntryHandle insert(const std::string &title, const FeedbackCallback &feedback_cb)
jsk_interactive_marker::YamlMenuHandler::_menu_handler
interactive_markers::MenuHandler _menu_handler
Definition: yaml_menu_handler.h:15
ROS_INFO
#define ROS_INFO(...)
ros::NodeHandle
jsk_interactive_marker::YamlMenuHandler::YamlMenuHandler
YamlMenuHandler(ros::NodeHandle *node_ptr, std::string file_name)
Definition: yaml_menu_handler.cpp:5


jsk_interactive_marker
Author(s): furuta
autogenerated on Fri Aug 2 2024 08:50:24