example_01_lookup_node.cpp
Go to the documentation of this file.
1 #include "ros/ros.h"
2 #include "hebiros/EntryListSrv.h"
3 #include "hebiros/AddGroupFromNamesSrv.h"
4 #include "hebiros/SizeSrv.h"
5 
6 using namespace hebiros;
7 
8 
9 int main(int argc, char **argv) {
10 
11  //Initialize ROS node
12  ros::init(argc, argv, "example_01_lookup_node");
14  ros::Rate loop_rate(200);
15 
16  std::string group_name = "my_group";
17 
18  //Create a client which uses the service to see the entry list of modules
19  ros::ServiceClient entry_list_client = n.serviceClient<EntryListSrv>(
20  "/hebiros/entry_list");
21 
22  //Create a client which uses the service to create a group
23  ros::ServiceClient add_group_client = n.serviceClient<AddGroupFromNamesSrv>(
24  "/hebiros/add_group_from_names");
25 
26  //Create a client which uses the service to find the size of a group
27  ros::ServiceClient size_client = n.serviceClient<SizeSrv>(
28  "/hebiros/"+group_name+"/size");
29 
30  EntryListSrv entry_list_srv;
31  AddGroupFromNamesSrv add_group_srv;
32  SizeSrv size_srv;
33 
34  //Call the entry_list service, displaying each module on the network
35  //entry_list_srv.response.entry_list will now be populated with those modules
36  entry_list_client.call(entry_list_srv);
37 
38  //Construct a group using 3 known modules
39  add_group_srv.request.group_name = group_name;
40  add_group_srv.request.names = {"base", "shoulder", "elbow"};
41  add_group_srv.request.families = {"HEBI"};
42  //Call the add_group_from_urdf service to create a group until it succeeds
43  //Specific topics and services will now be available under this group's namespace
44  while(!add_group_client.call(add_group_srv)) {}
45 
46  //Call the size service for the newly created group
47  size_client.call(size_srv);
48  ROS_INFO("%s has been created and has size %d", group_name.c_str(), size_srv.response.size);
49 
50  //Spin
51  //The group will exist until the node is shutdown
52  while(ros::ok()) {
53  ros::spinOnce();
54  loop_rate.sleep();
55  }
56 
57  return 0;
58 }
59 
60 
61 
62 
63 
64 
65 
66 
67 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
bool sleep()
ROSCPP_DECL void spinOnce()


hebiros_basic_examples
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:13:38