example_set_gains_node.cpp
Go to the documentation of this file.
1 #include "ros/ros.h"
2 #include "sensor_msgs/JointState.h"
3 #include "hebiros/AddGroupFromNamesSrv.h"
4 #include "hebiros/SendCommandWithAcknowledgementSrv.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_set_gains_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 create a group
19  ros::ServiceClient add_group_client = n.serviceClient<AddGroupFromNamesSrv>(
20  "/hebiros/add_group_from_names");
21 
22  //Create a client which uses the service to send a command and determine
23  //whether it has been received
24  ros::ServiceClient send_command_client = n.serviceClient<SendCommandWithAcknowledgementSrv>(
25  "/hebiros/"+group_name+"/send_command_with_acknowledgement");
26 
27  AddGroupFromNamesSrv add_group_srv;
28 
29  //Construct a group using 3 known modules
30  add_group_srv.request.group_name = group_name;
31  add_group_srv.request.names = {"base", "shoulder", "elbow"};
32  add_group_srv.request.families = {"HEBI"};
33  //Call the add_group_from_names service to create a group until it succeeds
34  //Specific topics and services will now be available under this group's namespace
35  while(!add_group_client.call(add_group_srv)) {}
36 
37  //Construct a CommandMsg to command the modules
38  //In addition to joint states, various settings such as pid gains may be set
39  CommandMsg command_msg;
40  std::vector<std::string> names = {"HEBI/base", "HEBI/shoulder", "HEBI/elbow"};
41 
42  command_msg.name = names;
43  command_msg.settings.name = names;
44  //Set each of the modules to not save settings after reboot (default behavior)
45  command_msg.settings.save_current_settings = {false, false, false};
46  command_msg.settings.position_gains.name = names;
47  command_msg.settings.velocity_gains.name = names;
48  command_msg.settings.effort_gains.name = names;
49  //For each module, set p, i, d gains for position, velocity, effort
50  command_msg.settings.position_gains.kp = {1, 2, 1};
51  command_msg.settings.position_gains.ki = {0.1, 0.2, 0.2};
52  command_msg.settings.position_gains.kd = {0.005, 0.001, 0.001};
53  command_msg.settings.velocity_gains.kp = {0.1, 0.2, 0.1};
54  command_msg.settings.velocity_gains.ki = {0.01, 0.02, 0.02};
55  command_msg.settings.velocity_gains.kd = {0.005, 0.001, 0.001};
56  command_msg.settings.effort_gains.kp = {0.001, 0.002, 0.001};
57  command_msg.settings.effort_gains.ki = {0.001, 0.002, 0.001};
58  command_msg.settings.effort_gains.kd = {0.005, 0.001, 0.001};
59 
60  SendCommandWithAcknowledgementSrv send_command_srv;
61  send_command_srv.request.command = command_msg;
62 
63  //Send the command and check for acknowledgement
64  //It is also possible to publish the command over a topic without acknowledgement
65  if (send_command_client.call(send_command_srv)) {
66  std::cout << "The gains were changed successfully" << std::endl;
67  }
68  else {
69  std::cout << "The gains were not changed" << std::endl;
70  }
71 
72  return 0;
73 }
74 
75 
76 
77 
78 
79 
80 
81 
82 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
int main(int argc, char **argv)
int n
Definition: key_read.py:85
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)


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