ROSAriacKitTrayPlugin.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-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 <string>
19 
20 #include <osrf_gear/KitTray.h>
21 
22 #include "ROSAriacKitTrayPlugin.hh"
23 
24 using namespace gazebo;
26 
29 {
30 }
31 
34 {
35  event::Events::DisconnectWorldUpdateBegin(this->updateConnection);
36  this->parentSensor.reset();
37  this->world.reset();
38 }
39 
41 void KitTrayPlugin::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
42 {
43 
44  SideContactPlugin::Load(_model, _sdf);
45  this->trayID = this->parentLink->GetScopedName();
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, unable to load plugin. "
51  << "Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
52  return;
53  }
54 
55  this->rosNode = new ros::NodeHandle("");
56  this->currentKitPub = this->rosNode->advertise<osrf_gear::KitTray>(
57  "/ariac/trays", 1000);
58 }
59 
61 void KitTrayPlugin::OnUpdate(const common::UpdateInfo &/*_info*/)
62 {
63  if (!this->newMsg)
64  {
65  return;
66  }
67 
68  auto prevNumberContactingModels = this->contactingModels.size();
70  if (prevNumberContactingModels != this->contactingModels.size()) {
71  gzdbg << this->parentLink->GetScopedName() << ": number of contacting models: " \
72  << this->contactingModels.size() << "\n";
73  }
75  this->PublishKitMsg();
76 }
77 
80 {
81  this->currentKit.objects.clear();
82  auto trayPose = this->parentLink->GetWorldPose().Ign();
83  for (auto model : this->contactingModels) {
84  if (model) {
85  ariac::KitObject object;
86 
87  // Determine the object type
88  object.type = ariac::DetermineModelType(model->GetName());
89 
90  // Determine the pose of the object in the frame of the tray
91  math::Pose objectPose = model->GetWorldPose();
92  ignition::math::Matrix4d transMat(trayPose);
93  ignition::math::Matrix4d objectPoseMat(objectPose.Ign());
94  object.pose = (transMat.Inverse() * objectPoseMat).Pose();
95 
96  this->currentKit.objects.push_back(object);
97  }
98  }
99 }
100 
103 {
104  // Publish current kit
105  osrf_gear::KitTray kitTrayMsg;
106  kitTrayMsg.tray.data = this->trayID;
107  for (const auto &obj : this->currentKit.objects)
108  {
109  osrf_gear::KitObject msgObj;
110  msgObj.type = obj.type;
111  msgObj.pose.position.x = obj.pose.pos.x;
112  msgObj.pose.position.y = obj.pose.pos.y;
113  msgObj.pose.position.z = obj.pose.pos.z;
114  msgObj.pose.orientation.x = obj.pose.rot.x;
115  msgObj.pose.orientation.y = obj.pose.rot.y;
116  msgObj.pose.orientation.z = obj.pose.rot.z;
117  msgObj.pose.orientation.w = obj.pose.rot.w;
118 
119  // Add the object to the kit.
120  kitTrayMsg.kit.objects.push_back(msgObj);
121  }
122  this->currentKitPub.publish(kitTrayMsg);
123 }
std::vector< KitObject > objects
A kit is composed of multiple objects.
Definition: ARIAC.hh:287
physics::WorldPtr world
Pointer to the world.
bool newMsg
Flag for new contacts message.
void publish(const boost::shared_ptr< M > &message) const
virtual void CalculateContactingModels()
Determine which models are in contact with the side of the parent link.
A plugin for a contact sensor on a kit tray.
ROSCPP_DECL bool isInitialized()
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load the sensor plugin.
ros::Publisher currentKitPub
Publisher for the kit state.
std::string type
Object type.
Definition: ARIAC.hh:258
std::set< physics::ModelPtr > contactingModels
Set of pointers to models that have collisions with the parent link&#39;s side.
void PublishKitMsg()
Publish the Kit ROS message.
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load the model plugin.
Class to store information about each object contained in a kit.
Definition: ARIAC.hh:241
void OnUpdate(const common::UpdateInfo &_info)
Callback that receives the world update event.
A plugin for a model with a contact sensor that only monitors collisions on one of its sides...
#define ROS_FATAL_STREAM(args)
sensors::ContactSensorPtr parentSensor
Pointer to the contact sensor.
virtual ~KitTrayPlugin()
Destructor.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
event::ConnectionPtr updateConnection
Pointer to the update event connection.
physics::LinkPtr parentLink
Pointer to the sensor&#39;s parent&#39;s link.
std::string trayID
ID of tray.
physics::ModelPtr model
Pointer to the model.
TrayID_t DetermineModelType(const std::string &modelName)
Determine the type of a gazebo model from its name.
Definition: ARIAC.hh:222
ros::NodeHandle * rosNode
ROS node handle.
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
void ProcessContactingModels()
Update the kit based on which models are in contact.
ariac::Kit currentKit
Kit which is currently on the tray.


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