common_objects.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
39 #include <tf/transform_listener.h>
40 
41 namespace
42 {
43 struct SharedStorage
44 {
45  SharedStorage()
46  {
47  }
48 
49  ~SharedStorage()
50  {
51  tf_.reset();
52  state_monitors_.clear();
53  model_loaders_.clear();
54  }
55 
56  boost::mutex lock_;
58  std::map<std::string, robot_model_loader::RobotModelLoaderPtr> model_loaders_;
59  std::map<std::string, planning_scene_monitor::CurrentStateMonitorPtr> state_monitors_;
60 };
61 
62 SharedStorage& getSharedStorage()
63 {
64 #if 0 // destruction of static storage interferes with static destruction in class_loader
65  // More specifically, class_loader's static variables might be already destroyed
66  // while being accessed again in the destructor of the class_loader-based kinematics plugin.
67  static SharedStorage storage;
68  return storage;
69 #else // thus avoid destruction at all (until class_loader is fixed)
70  static SharedStorage* storage = new SharedStorage;
71  return *storage;
72 #endif
73 }
74 }
75 
76 namespace moveit
77 {
78 namespace planning_interface
79 {
81 {
82  SharedStorage& s = getSharedStorage();
83  boost::mutex::scoped_lock slock(s.lock_);
84  if (!s.tf_)
85  s.tf_.reset(new tf::TransformListener());
86  return s.tf_;
87 }
88 
89 robot_model::RobotModelConstPtr getSharedRobotModel(const std::string& robot_description)
90 {
91  SharedStorage& s = getSharedStorage();
92  boost::mutex::scoped_lock slock(s.lock_);
93  if (s.model_loaders_.find(robot_description) != s.model_loaders_.end())
94  return s.model_loaders_[robot_description]->getModel();
95  else
96  {
97  robot_model_loader::RobotModelLoader::Options opt(robot_description);
98  opt.load_kinematics_solvers_ = true;
99  robot_model_loader::RobotModelLoaderPtr loader(new robot_model_loader::RobotModelLoader(opt));
100  s.model_loaders_[robot_description] = loader;
101  return loader->getModel();
102  }
103 }
104 
105 planning_scene_monitor::CurrentStateMonitorPtr getSharedStateMonitor(const robot_model::RobotModelConstPtr& kmodel,
107 {
108  return getSharedStateMonitor(kmodel, tf, ros::NodeHandle());
109 }
110 
111 planning_scene_monitor::CurrentStateMonitorPtr getSharedStateMonitor(const robot_model::RobotModelConstPtr& kmodel,
113  ros::NodeHandle nh)
114 {
115  SharedStorage& s = getSharedStorage();
116  boost::mutex::scoped_lock slock(s.lock_);
117  if (s.state_monitors_.find(kmodel->getName()) != s.state_monitors_.end())
118  return s.state_monitors_[kmodel->getName()];
119  else
120  {
121  planning_scene_monitor::CurrentStateMonitorPtr monitor(
122  new planning_scene_monitor::CurrentStateMonitor(kmodel, tf, nh));
123  s.state_monitors_[kmodel->getName()] = monitor;
124  return monitor;
125  }
126 }
127 
128 } // namespace planning_interface
129 } // namespace moveit
boost::shared_ptr< tf::Transformer > getSharedTF()
XmlRpcServer s
planning_scene_monitor::CurrentStateMonitorPtr getSharedStateMonitor(const robot_model::RobotModelConstPtr &kmodel, const boost::shared_ptr< tf::Transformer > &tf)
getSharedStateMonitor is a simpler version of getSharedStateMonitor(const robot_model::RobotModelCons...
robot_model::RobotModelConstPtr getSharedRobotModel(const std::string &robot_description)


planning_interface
Author(s): Ioan Sucan
autogenerated on Sat Apr 21 2018 02:56:02