ROSConveyorBeltPlugin.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 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 "ROSConveyorBeltPlugin.hh"
18 
19 #include <string>
20 
21 using namespace gazebo;
22 
24 
27 {
28 }
29 
32 {
33  this->rosnode_->shutdown();
34 }
35 
37 void ROSConveyorBeltPlugin::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
38 {
39  // load parameters
40  this->robotNamespace_ = "";
41  if (_sdf->HasElement("robot_namespace"))
42  {
43  this->robotNamespace_ = _sdf->GetElement(
44  "robot_namespace")->Get<std::string>() + "/";
45  }
46 
47  // Make sure the ROS node for Gazebo has already been initialized
48  if (!ros::isInitialized())
49  {
50  ROS_FATAL_STREAM("A ROS node for Gazebo has not been initialized,"
51  << "unable to load plugin. Load the Gazebo system plugin "
52  << "'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
53  return;
54  }
55 
56  std::string topic = "conveyor/control";
57  if (_sdf->HasElement("topic"))
58  topic = _sdf->Get<std::string>("topic");
59 
60  ConveyorBeltPlugin::Load(_parent, _sdf);
61 
62  this->rosnode_ = new ros::NodeHandle(this->robotNamespace_);
63 
64  this->controlService_ = this->rosnode_->advertiseService(topic,
66 }
67 
70  osrf_gear::ConveyorBeltControl::Request &_req,
71  osrf_gear::ConveyorBeltControl::Response &_res)
72 {
73  gzdbg << "Control command received\n";
74  this->SetVelocity(_req.state.velocity);
75  _res.success = true;
76  return true;
77 }
ROSCPP_DECL bool isInitialized()
bool OnControlCommand(osrf_gear::ConveyorBeltControl::Request &_req, osrf_gear::ConveyorBeltControl::Response &_res)
Receives requests on the conveyor belt&#39;s topic.
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::NodeHandle * rosnode_
ros node handle
void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
Load the plugin.
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load the model plugin.
#define ROS_FATAL_STREAM(args)
std::string robotNamespace_
for setting ROS name space
ros::ServiceServer controlService_
Receives service calls to control the conveyor belt.
ROS implementation of the ConveyorBeltPlugin plugin.
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
virtual ~ROSConveyorBeltPlugin()
Destructor.
void SetVelocity(double velocity)
Set the state of the conveyor belt.


osrf_gear
Author(s):
autogenerated on Wed Sep 7 2016 03:48:12