hebiros_services_gazebo.cpp
Go to the documentation of this file.
2 
3 #include "hebiros.h"
4 
6 
8 
9  services["hebiros/entry_list"] = HebirosNode::n_ptr->advertiseService(
10  "hebiros/entry_list", &HebirosServicesGazebo::entryList, this);
11 
12  services["hebiros/add_group_from_names"] = HebirosNode::n_ptr->advertiseService(
13  "hebiros/add_group_from_names", &HebirosServicesGazebo::addGroupFromNames, this);
14 
15  services["hebiros/add_group_from_urdf"] = HebirosNode::n_ptr->advertiseService(
16  "hebiros/add_group_from_urdf", &HebirosServicesGazebo::addGroupFromURDF, this);
17 
18  services["hebiros/add_model_from_urdf"] = HebirosNode::n_ptr->advertiseService(
19  "hebiros/add_model_from_urdf", &HebirosServicesGazebo::addModelFromURDF, this);
20 }
21 
22 void HebirosServicesGazebo::registerGroupServices(std::string group_name) {
23 
24  services["hebiros/"+group_name+"/size"] =
25  HebirosNode::n_ptr->advertiseService<SizeSrv::Request, SizeSrv::Response>(
26  "hebiros/"+group_name+"/size",
27  boost::bind(&HebirosServicesGazebo::size, this, _1, _2, group_name));
28 
29  services["hebiros/"+group_name+"/set_feedback_frequency"] =
30  HebirosNode::n_ptr->advertiseService<SetFeedbackFrequencySrv::Request,
31  SetFeedbackFrequencySrv::Response>(
32  "hebiros/"+group_name+"/set_feedback_frequency",
33  boost::bind(&HebirosServicesGazebo::setFeedbackFrequency, this, _1, _2, group_name));
34 
35  services["hebiros/"+group_name+"/set_command_lifetime"] =
36  HebirosNode::n_ptr->advertiseService<SetCommandLifetimeSrv::Request,
37  SetCommandLifetimeSrv::Response>(
38  "hebiros/"+group_name+"/set_command_lifetime",
39  boost::bind(&HebirosServicesGazebo::setCommandLifetime, this, _1, _2, group_name));
40 
41  services["hebiros/"+group_name+"/send_command_with_acknowledgement"] =
42  HebirosNode::n_ptr->advertiseService<SendCommandWithAcknowledgementSrv::Request,
43  SendCommandWithAcknowledgementSrv::Response>(
44  "hebiros/"+group_name+"/send_command_with_acknowledgement",
45  boost::bind(&HebirosServicesGazebo::sendCommandWithAcknowledgement, this, _1, _2, group_name));
46 }
47 
49  EntryListSrv::Request &req, EntryListSrv::Response &res) {
50 
51  return true;
52 }
53 
55  AddGroupFromNamesSrv::Request &req, AddGroupFromNamesSrv::Response &res,
56  std::map<std::string, std::string> joint_full_names) {
57 
58  auto& registry = HebirosGroupRegistry::Instance();
59 
60  if (registry.hasGroup(req.group_name)) {
61 
62  ROS_WARN("Group [%s] already exists", req.group_name.c_str());
63  return true;
64  }
65 
66  std::unique_ptr<HebirosGroupGazebo> group(new HebirosGroupGazebo());
67 
68  if (!HebirosServices::addGroup(req, res, joint_full_names, std::move(group))) {
69  return false;
70  }
71 
72  registerGroupServices(req.group_name);
78 
79  return true;
80 }
81 
83  AddGroupFromNamesSrv::Request &req, AddGroupFromNamesSrv::Response &res) {
84 
85  std::map<std::string, std::string> joint_full_names;
86 
87  return HebirosNode::services_gazebo.addGroup(req, res, joint_full_names);
88 }
89 
91  AddGroupFromURDFSrv::Request &req, AddGroupFromURDFSrv::Response &res) {
92 
93  std::string urdf_name("robot_description");
94  urdf::Model urdf_model;
95  if (!urdf_model.initParam(urdf_name))
96  {
97  ROS_WARN("Could not load robot_description");
98  return false;
99  }
100  else {
102  }
103 
104  std::set<std::string> joint_names;
105  std::set<std::string> family_names;
106  std::map<std::string, std::string> joint_full_names;
107 
108  HebirosServices::addJointChildren(joint_names, family_names, joint_full_names,
109  urdf_model.getRoot().get());
110 
111  AddGroupFromNamesSrv::Request names_req;
112  AddGroupFromNamesSrv::Response names_res;
113  names_req.group_name = req.group_name;
114  names_req.families.insert(names_req.families.end(), family_names.begin(), family_names.end());
115  names_req.names.insert(names_req.names.end(), joint_names.begin(), joint_names.end());
116 
117  return HebirosNode::services_gazebo.addGroup(names_req, names_res, joint_full_names);
118 }
119 
121  AddModelFromURDFSrv::Request &req, AddModelFromURDFSrv::Response &res) {
122 
123  return HebirosServices::addModelFromURDF(req, res);
124 }
125 
127  SizeSrv::Request &req, SizeSrv::Response &res, std::string group_name) {
128 
129  HebirosServices::size(req, res, group_name);
130 
131  return true;
132 }
133 
135  SetFeedbackFrequencySrv::Request &req, SetFeedbackFrequencySrv::Response &res,
136  std::string group_name) {
137 
139 
140  HebirosServices::setFeedbackFrequency(req, res, group_name);
141 
142  return true;
143 }
144 
146  SetCommandLifetimeSrv::Request &req, SetCommandLifetimeSrv::Response &res,
147  std::string group_name) {
148 
149  HebirosNode::clients.setCommandLifetime(req, group_name);
150 
151  HebirosServices::setCommandLifetime(req, res, group_name);
152 
153  return true;
154 }
155 
157  SendCommandWithAcknowledgementSrv::Request &req,
158  SendCommandWithAcknowledgementSrv::Response &res, std::string group_name) {
159 
160  std_srvs::Empty empty_srv;
161 
162  while(!HebirosNode::clients.acknowledge(empty_srv.request, group_name)) {
163  HebirosNode::publishers_gazebo.command(req.command, group_name);
164  }
165 
166  return true;
167 }
168 
169 
170 
void command(hebiros::CommandMsg command_msg, std::string group_name)
void registerGroupClients(std::string group_name)
bool addGroup(AddGroupFromNamesSrv::Request &req, AddGroupFromNamesSrv::Response &res, const std::map< std::string, std::string > &joint_full_names, std::unique_ptr< HebirosGroup > group_tmp)
static HebirosPublishersGazebo publishers_gazebo
Definition: hebiros.h:79
bool addModelFromURDF(AddModelFromURDFSrv::Request &req, AddModelFromURDFSrv::Response &res)
bool setCommandLifetime(SetCommandLifetimeSrv::Request &req, SetCommandLifetimeSrv::Response &res, std::string group_name)
bool sendCommandWithAcknowledgement(SendCommandWithAcknowledgementSrv::Request &req, SendCommandWithAcknowledgementSrv::Response &res, std::string group_name)
static HebirosSubscribersGazebo subscribers_gazebo
Definition: hebiros.h:81
bool addGroupFromNames(AddGroupFromNamesSrv::Request &req, AddGroupFromNamesSrv::Response &res)
bool setFeedbackFrequency(SetFeedbackFrequencySrv::Request &req, SetFeedbackFrequencySrv::Response &res, std::string group_name)
void addJointChildren(std::set< std::string > &names, std::set< std::string > &families, std::map< std::string, std::string > &full_names, const urdf::Link *link)
void registerGroupPublishers(std::string group_name)
bool addGroup(hebiros::AddGroupFromNamesSrv::Request &req)
bool size(SizeSrv::Request &req, SizeSrv::Response &res, std::string group_name)
bool addGroup(AddGroupFromNamesSrv::Request &req, AddGroupFromNamesSrv::Response &res, std::map< std::string, std::string > joint_full_names)
#define ROS_WARN(...)
static std::shared_ptr< ros::NodeHandle > n_ptr
Definition: hebiros.h:78
bool addModelFromURDF(AddModelFromURDFSrv::Request &req, AddModelFromURDFSrv::Response &res)
void registerGroupServices(std::string group_name)
bool entryList(EntryListSrv::Request &req, EntryListSrv::Response &res)
URDF_EXPORT bool initParam(const std::string &param)
bool setCommandLifetime(hebiros::SetCommandLifetimeSrv::Request &req, std::string group_name)
void registerGroupActions(std::string group_name)
static HebirosServicesGazebo services_gazebo
Definition: hebiros.h:83
bool setFeedbackFrequency(hebiros::SetFeedbackFrequencySrv::Request &req, std::string group_name)
void registerGroupSubscribers(std::string group_name)
bool size(SizeSrv::Request &req, SizeSrv::Response &res, std::string group_name)
static HebirosClients clients
Definition: hebiros.h:85
static std::map< std::string, ros::ServiceServer > services
static HebirosActions actions
Definition: hebiros.h:86
bool setCommandLifetime(SetCommandLifetimeSrv::Request &req, SetCommandLifetimeSrv::Response &res, std::string group_name)
bool addGroupFromURDF(AddGroupFromURDFSrv::Request &req, AddGroupFromURDFSrv::Response &res)
bool setFeedbackFrequency(SetFeedbackFrequencySrv::Request &req, SetFeedbackFrequencySrv::Response &res, std::string group_name)
bool addGroupFromURDF(AddGroupFromURDFSrv::Request &req, AddGroupFromURDFSrv::Response &res)


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:14