ed
configure.cpp
Go to the documentation of this file.
1 #include <ros/console.h>
2 #include <ros/init.h>
3 #include <ros/node_handle.h>
4 #include <ros/service_client.h>
5 
6 #include <ed_msgs/Configure.h>
7 
11 
12 #include <tue/filesystem/path.h>
13 
14 // ----------------------------------------------------------------------------------------------------
15 
16 void usage()
17 {
18  std::cout << "Usage: configure CONFIG_FILE.yaml/json" << std::endl;
19 }
20 
21 // ----------------------------------------------------------------------------------------------------
22 
23 int main(int argc, char **argv)
24 {
26  ros::removeROSArgs(argc, argv, myargv);
27  if (myargv.size() != 2)
28  {
29  usage();
30  return 1;
31  }
32 
33  ros::init(argc, argv, "ed_configure");
34 
35  ros::NodeHandle nh;
36  ros::ServiceClient client = nh.serviceClient<ed_msgs::Configure>("ed/configure");
37 
38  tue::filesystem::Path config_file(myargv[1]);
39  if (!config_file.exists())
40  {
41  ROS_ERROR_STREAM("Could not configure ED: config file '" << config_file.string() << "' does not exist");
42  return 1;
43  }
44 
45  tue::config::ResolveConfig resolve_config;
46  resolve_config.env = true;
47  resolve_config.file = false;
48  resolve_config.rospkg = false;
50  if (!tue::config::loadFromYAMLFile(config_file.string(), config, resolve_config))
51  {
52  ROS_ERROR_STREAM("Could not configure ED: Error during parsing of the config file '" << config_file.string() << "' "<< std::endl << std::endl << config.error());
53  return 1;
54  }
55 
56  ed_msgs::Configure srv;
57  srv.request.request = config.toYAMLString();
58 
59  // We do this as late as possible, so as much time as possible has passed doing other stuff
60  // and we wait as less as possible.
61  client.waitForExistence();
62 
63  if (!client.call(srv))
64  {
65  ROS_ERROR_STREAM("Could not configure ED: Service call failed");
66  return 1;
67  }
68 
69  if (!srv.response.error_msg.empty())
70  {
71  ROS_ERROR_STREAM("Could not configure ED:\n\n" + srv.response.error_msg);
72  return 1;
73  }
74 
75  return 0;
76 }
tue::filesystem::Path
std::vector< std::string >
std::vector::size
T size(T... args)
resolve_config.h
tue::config::ResolveConfig::env
bool env
std::cout
tue::config::ReaderWriter
tue::config::loadFromYAMLFile
bool loadFromYAMLFile(const std::string &filename, ReaderWriter &config, const ResolveConfig &resolve_config=ResolveConfig::defaultConfig())
tue::config::ReaderWriter::toYAMLString
std::string toYAMLString() const
tue::config::ReaderWriter::error
const std::string & error() const
main
int main(int argc, char **argv)
Definition: configure.cpp:23
tue::config::ResolveConfig::rospkg
bool rospkg
client
ros::ServiceClient client
Definition: show_gui.cpp:6
yaml.h
tue::config::ResolveConfig::file
bool file
usage
void usage()
Definition: configure.cpp:16
configuration.h
path.h
std::endl
T endl(T... args)
tue::config::ResolveConfig
config
tue::config::ReaderWriter config