ROSVacuumGripperPlugin.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 
18 #include <memory>
19 #include <string>
20 #include <ros/ros.h>
21 #include <sdf/sdf.hh>
23 #include "osrf_gear/VacuumGripperControl.h"
24 #include "osrf_gear/VacuumGripperState.h"
25 
26 namespace gazebo
27 {
31  {
33  public: std::unique_ptr<ros::NodeHandle> rosnode;
34 
37 
40  };
41 }
42 
43 using namespace gazebo;
44 
46 
51 {
52 }
53 
56 {
57  this->dataPtr->rosnode->shutdown();
58 }
59 
61 void ROSVacuumGripperPlugin::Load(physics::ModelPtr _parent,
62  sdf::ElementPtr _sdf)
63 {
64  // Make sure the ROS node for Gazebo has already been initialized
65  if (!ros::isInitialized())
66  {
67  ROS_FATAL_STREAM("A ROS node for Gazebo has not been initialized,"
68  << "unable to load plugin. Load the Gazebo system plugin "
69  << "'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
70  return;
71  }
72 
73  // Load SDF parameters.
74  std::string robotNamespace = "";
75  if (_sdf->HasElement("robot_namespace"))
76  {
77  robotNamespace = _sdf->GetElement(
78  "robot_namespace")->Get<std::string>() + "/";
79  }
80 
81  std::string controlTopic = "gripper/control";
82  if (_sdf->HasElement("control_topic"))
83  controlTopic = _sdf->Get<std::string>("control_topic");
84 
85  std::string stateTopic = "gripper/state";
86  if (_sdf->HasElement("state_topic"))
87  stateTopic = _sdf->Get<std::string>("state_topic");
88 
89  VacuumGripperPlugin::Load(_parent, _sdf);
90 
91  this->dataPtr->rosnode.reset(new ros::NodeHandle(robotNamespace));
92 
93  // Service for controlling the gripper.
94  this->dataPtr->controlService =
95  this->dataPtr->rosnode->advertiseService(controlTopic,
97 
98  // Message used for publishing the state of the gripper.
99  this->dataPtr->statePub = this->dataPtr->rosnode->advertise<
100  osrf_gear::VacuumGripperState>(stateTopic, 1000);
101 }
102 
105 {
107 }
108 
110  osrf_gear::VacuumGripperControl::Request &_req,
111  osrf_gear::VacuumGripperControl::Response &_res)
112 {
113  if (_req.enable)
114  this->Enable();
115  else
116  this->Disable();
117 
118  _res.success = true;
119  return _res.success;
120 }
121 
124 {
125  osrf_gear::VacuumGripperState msg;
126  msg.attached = this->Attached();
127  msg.enabled = this->Enabled();
128  this->dataPtr->statePub.publish(msg);
129 }
msg
virtual ~ROSVacuumGripperPlugin()
Destructor.
ros::ServiceServer controlService
Receives service calls to control the gripper.
std::unique_ptr< ROSVacuumGripperPluginPrivate > dataPtr
virtual void Reset()
Documentation inherited.
ROSCPP_DECL bool isInitialized()
virtual void Publish() const
Overwrite this method for sending periodic updates with the gripper state.
ROS interface for the VacuumGripperPlugin plugin.
bool Attached() const
True if the gripper is attached to another model.
void Disable()
Disable the suction.
#define ROS_FATAL_STREAM(args)
bool OnGripperControl(osrf_gear::VacuumGripperControl::Request &_req, osrf_gear::VacuumGripperControl::Response &_res)
Receives messages on the gripper&#39;s topic.
void Enable()
Enable the suction.
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
bool Enabled() const
Whether the suction of the gripper has been enabled.
virtual void Reset()
Documentation inherited.
ros::Publisher statePub
Publishes the state of the gripper.
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
std::unique_ptr< ros::NodeHandle > rosnode
ROS node handle.
virtual void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)


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