hebiros_gazebo_group.cpp
Go to the documentation of this file.
1 #include <hebiros_gazebo_group.h>
3 
5  std::shared_ptr<ros::NodeHandle> n) {
6  this->name = name;
7 
8  ros::Time current_time = ros::Time::now();
9  this->start_time = current_time;
10  this->prev_time = current_time;
11  this->prev_feedback_time = current_time;
12 
13  this->command_sub = n->subscribe<CommandMsg>("hebiros_gazebo_plugin/command/"+name, 100,
14  boost::bind(&HebirosGazeboGroup::SubCommand, this, _1));
15 
16  this->acknowledge_srv =
17  n->advertiseService<std_srvs::Empty::Request, std_srvs::Empty::Response>(
18  "hebiros_gazebo_plugin/acknowledge/"+name, boost::bind(
19  &HebirosGazeboGroup::SrvAcknowledge, this, _1, _2));
20 
21  this->command_lifetime_srv =
22  n->advertiseService<SetCommandLifetimeSrv::Request, SetCommandLifetimeSrv::Response>(
23  "hebiros_gazebo_plugin/set_command_lifetime/"+name, boost::bind(
25 
27  n->advertiseService<SetFeedbackFrequencySrv::Request, SetFeedbackFrequencySrv::Response>(
28  "hebiros_gazebo_plugin/set_feedback_frequency/"+name, boost::bind(
30 }
31 
33 
34  if (this->check_acknowledgement) {
35  this->acknowledgement = true;
36  this->check_acknowledgement = false;
37  }
38 
39  if (!this->command_received) {
40  this->command_received = true;
41  }
42 
43  ros::Time current_time = ros::Time::now();
44  this->start_time = current_time;
45  this->prev_time = current_time;
46 
47  command_target = *data;
48 
49  for (int i = 0; i < data->name.size(); i++) {
50  std::string joint_name = data->name[i];
51 
52  if (joints.find(joint_name) != joints.end()) {
53  std::shared_ptr<HebirosGazeboJoint> hebiros_joint = joints[joint_name];
54  hebiros_joint->command_index = i;
55 
56  HebirosGazeboController::ChangeSettings(shared_from_this(),
57  hebiros_joint);
58  }
59  }
60 }
61 
62 //Service callback which acknowledges that a command has been received
63 bool HebirosGazeboGroup::SrvAcknowledge(std_srvs::Empty::Request &req,
64  std_srvs::Empty::Response &res) {
65 
66  this->check_acknowledgement = true;
67 
68  if (this->acknowledgement) {
69  this->check_acknowledgement = false;
70  this->acknowledgement = false;
71  return true;
72  }
73  else {
74  return false;
75  }
76 }
77 
78 bool HebirosGazeboGroup::SrvSetCommandLifetime(SetCommandLifetimeSrv::Request &req,
79  SetCommandLifetimeSrv::Response &res) {
80 
81  command_lifetime = req.command_lifetime;
82  return true;
83 }
84 
85 bool HebirosGazeboGroup::SrvSetFeedbackFrequency(SetFeedbackFrequencySrv::Request &req,
86  SetFeedbackFrequencySrv::Response &res) {
87 
88  feedback_frequency = req.feedback_frequency;
89  return true;
90 }
91 
92 
93 
94 
95 
96 
bool SrvSetCommandLifetime(SetCommandLifetimeSrv::Request &req, SetCommandLifetimeSrv::Response &res)
ros::ServiceServer feedback_frequency_srv
std::map< std::string, std::shared_ptr< HebirosGazeboJoint > > joints
bool SrvSetFeedbackFrequency(SetFeedbackFrequencySrv::Request &req, SetFeedbackFrequencySrv::Response &res)
void SubCommand(const boost::shared_ptr< CommandMsg const > data)
bool SrvAcknowledge(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
HebirosGazeboGroup(std::string name, std::shared_ptr< ros::NodeHandle > n)
static void ChangeSettings(std::shared_ptr< HebirosGazeboGroup > hebiros_group, std::shared_ptr< HebirosGazeboJoint > hebiros_joint)
static Time now()
ros::ServiceServer command_lifetime_srv
ros::ServiceServer acknowledge_srv
ros::Subscriber command_sub


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