gazebo_ros_wheel_slip.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #include <gazebo/physics/World.hh>
18 #include <gazebo/physics/Model.hh>
19 #include <sdf/sdf.hh>
20 
22 
23 namespace gazebo
24 {
25 
26 // Register this plugin with the simulator
27 GZ_REGISTER_MODEL_PLUGIN(GazeboRosWheelSlip)
28 
31 {
32 }
33 
36 {
37  // Custom Callback Queue
38  this->queue_.clear();
39  this->queue_.disable();
40 
41  delete this->dyn_srv_;
42 
43  this->rosnode_->shutdown();
44  delete this->rosnode_;
45 }
46 
49  gazebo_plugins::WheelSlipConfig &config, uint32_t /*level*/)
50 {
51  if (config.slip_compliance_unitless_lateral >= 0)
52  {
53  ROS_INFO_NAMED("wheel_slip", "Reconfigure request for the gazebo ros wheel_slip: %s. New lateral slip compliance: %.3e",
54  this->GetParentModel()->GetScopedName().c_str(),
55  config.slip_compliance_unitless_lateral);
56  this->SetSlipComplianceLateral(config.slip_compliance_unitless_lateral);
57  }
58  if (config.slip_compliance_unitless_longitudinal >= 0)
59  {
60  ROS_INFO_NAMED("wheel_slip", "Reconfigure request for the gazebo ros wheel_slip: %s. New longitudinal slip compliance: %.3e",
61  this->GetParentModel()->GetScopedName().c_str(),
62  config.slip_compliance_unitless_longitudinal);
63  this->SetSlipComplianceLongitudinal(config.slip_compliance_unitless_longitudinal);
64  }
65 }
66 
68 // Load the controller
69 void GazeboRosWheelSlip::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
70 {
71  // Load the plugin
72  WheelSlipPlugin::Load(_parent, _sdf);
73 
74  if (_sdf->HasElement("robotNamespace"))
75  {
76  this->robotNamespace_ = _sdf->Get<std::string>("robotNamespace") + "/";
77  }
78  if (this->robotNamespace_.empty() ||
79  this->robotNamespace_ == "/" ||
80  this->robotNamespace_ == "//")
81  {
82  this->robotNamespace_ = "wheel_slip/";
83  }
84  this->robotNamespace_ = _parent->GetName() + "/" + this->robotNamespace_;
85 
86  // Init ROS
87  if (!ros::isInitialized())
88  {
89  ROS_FATAL_STREAM_NAMED("wheel_slip", "Not loading plugin since ROS hasn't been "
90  << "properly initialized. Try starting gazebo with ros plugin:\n"
91  << " gazebo -s libgazebo_ros_api_plugin.so\n");
92  return;
93  }
94 
95  this->rosnode_ = new ros::NodeHandle(this->robotNamespace_);
96 
97  // set up dynamic reconfigure
98  dyn_srv_ =
99  new dynamic_reconfigure::Server<gazebo_plugins::WheelSlipConfig>
100  (*this->rosnode_);
101  dynamic_reconfigure::Server<gazebo_plugins::WheelSlipConfig>
102  ::CallbackType f =
103  boost::bind(&GazeboRosWheelSlip::configCallback, this, _1, _2);
104  dyn_srv_->setCallback(f);
105 
106  // Custom Callback Queue
107  this->callbackQueueThread_ =
108  boost::thread(boost::bind(&GazeboRosWheelSlip::QueueThread, this));
109 }
110 
113 {
114  static const double timeout = 0.01;
115 
116  while (this->rosnode_->ok())
117  {
118  this->queue_.callAvailable(ros::WallDuration(timeout));
119  }
120 }
121 }
virtual void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
Load the plugin.
#define ROS_INFO_NAMED(name,...)
f
ROSCPP_DECL bool isInitialized()
ros::NodeHandle * rosnode_
pointer to ros node
void configCallback(gazebo_plugins::WheelSlipConfig &config, uint32_t level)
GZ_REGISTER_MODEL_PLUGIN(GazeboRosF3D)
#define ROS_FATAL_STREAM_NAMED(name, args)
std::string robotNamespace_
for setting ROS name space
virtual ~GazeboRosWheelSlip()
Destructor.
void QueueThread()
Custom callback queue thread.
dynamic_reconfigure::Server< gazebo_plugins::WheelSlipConfig > * dyn_srv_
Dynamic reconfigure server.
bool ok() const


gazebo_plugins
Author(s): John Hsu
autogenerated on Wed Aug 24 2022 02:47:52