ed
probe_client.cpp
Go to the documentation of this file.
2 
3 // ROS services
4 #include <ed_msgs/Configure.h>
5 #include "tue_serialization/BinaryService.h"
6 
7 #include <ros/node_handle.h>
8 
10 
11 namespace ed
12 {
13 
14 // ----------------------------------------------------------------------------------------------------
15 
16 ProbeClient::ProbeClient() : nh_(nullptr)
17 {
18 }
19 
20 // ----------------------------------------------------------------------------------------------------
21 
23 {
24  delete nh_;
25 }
26 
27 // ----------------------------------------------------------------------------------------------------
28 
29 void ProbeClient::launchProbe(const std::string& probe_name, const std::string& lib)
30 {
31  if (!ros::isInitialized())
32  {
33  ros::M_string remapping_args;
34  ros::init(remapping_args, "ed_probe_client_" + probe_name);
35  }
36 
37  nh_ = new ros::NodeHandle();
38  ros::ServiceClient client = nh_->serviceClient<ed_msgs::Configure>("ed/configure");
39  client.waitForExistence();
40 
41  ed_msgs::Configure srv;
42 
43  double freq = 1000; // default
45 
46  config.writeArray("plugins");
47  {
49  {
50  config.setValue("name", probe_name);
51  config.setValue("lib", lib);
52  config.setValue("frequency", freq);
53  }
55  }
56  config.endArray();
57 
58  srv.request.request = config.toYAMLString();
59 
60  std::cout << "Sending request to launch probe using configuration: " << srv.request.request << std::endl;
61 
63 
64  if (client.call(srv))
65  {
66  error = srv.response.error_msg;
67  }
68  else
69  {
70  error = "Failed to call service '/ed/configure'";
71  }
72 
73  if (!error.empty())
74  {
75  std::cout << "[ed::ProbeClient] ERROR: " + error << std::endl;
76  }
77  else
78  {
79  // Initialize connection with the probe
80  probe_name_ = probe_name;
81  srv_probe_ = nh_->serviceClient<tue_serialization::BinaryService>("ed/probe/" + probe_name_);
82  srv_probe_.waitForExistence();
83  }
84 }
85 
86 // ----------------------------------------------------------------------------------------------------
87 
89 {
90 
91 }
92 
93 // ----------------------------------------------------------------------------------------------------
94 
96 {
97  if (!srv_probe_.exists())
98  {
99  std::cout << "Service does not exist" << std::endl;
100  return false;
101  }
102 
103  tue_serialization::BinaryService srv;
104  tue::serialization::convert(req, srv.request.bin.data);
105 
106  if (srv_probe_.call(srv))
107  {
108  tue::serialization::convert(srv.response.bin.data, res);
109  return true;
110  }
111  else
112  {
113  std::cout << "Service call failed" << std::endl;
114  return false;
115  }
116 }
117 
118 }
std::string
tue::config::ReaderWriter::endArrayItem
bool endArrayItem()
ed::ProbeClient::nh_
ros::NodeHandle * nh_
Definition: probe_client.h:32
tue::config::ReaderWriter::writeArray
bool writeArray(const std::string &name)
tue::config::ReaderWriter::addArrayItem
bool addArrayItem()
std::cout
tue::config::ReaderWriter
tue::serialization::convert
void convert(Archive &a, std::vector< unsigned char > &data)
tue::config::ReaderWriter::toYAMLString
std::string toYAMLString() const
ed::log::error
std::ostream & error()
Definition: logging.cpp:74
ed::ProbeClient::launchProbe
void launchProbe(const std::string &probe_name, const std::string &lib)
Definition: probe_client.cpp:29
ed::ProbeClient::probe_name_
std::string probe_name_
Definition: probe_client.h:34
client
ros::ServiceClient client
Definition: show_gui.cpp:6
ed::ProbeClient::ProbeClient
ProbeClient()
Definition: probe_client.cpp:16
ed::ProbeClient::srv_probe_
ros::ServiceClient srv_probe_
Definition: probe_client.h:36
tue::config::ReaderWriter::endArray
bool endArray()
probe_client.h
tue::config::ReaderWriter::setValue
void setValue(const std::string &name, const T &value)
std::endl
T endl(T... args)
ed::ProbeClient::~ProbeClient
virtual ~ProbeClient()
Definition: probe_client.cpp:22
ed::ProbeClient::process
bool process(tue::serialization::Archive &req, tue::serialization::Archive &res)
Definition: probe_client.cpp:95
ed
Definition: convex_hull.h:8
conversions.h
tue::serialization::Archive
ed::ProbeClient::configure
void configure(tue::Configuration config)
Definition: probe_client.cpp:88
config
tue::config::ReaderWriter config