Exotica
setup.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018-2020, University of Edinburgh, University of Oxford
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_CORE_SETUP_H_
31 #define EXOTICA_CORE_SETUP_H_
32 
33 #include <memory>
34 #include <vector>
35 
37 #include <exotica_core/factory.h>
39 #include <exotica_core/object.h>
41 #include <exotica_core/property.h>
42 
43 #include <pluginlib/class_loader.h>
44 
45 namespace exotica
46 {
47 class Setup : public Object, Uncopyable
48 {
49 public:
50  ~Setup() noexcept
51  {
52  }
53 
54  static std::shared_ptr<Setup> Instance()
55  {
58  }
59 
60  static void Destroy();
61 
62  static void PrintSupportedClasses();
63  static std::shared_ptr<exotica::MotionSolver> CreateSolver(const std::string& type, bool prepend = true) { return ToStdPtr(Instance()->solvers_.createInstance((prepend ? "exotica/" : "") + type)); }
64  static std::shared_ptr<exotica::TaskMap> CreateMap(const std::string& type, bool prepend = true) { return ToStdPtr(Instance()->maps_.createInstance((prepend ? "exotica/" : "") + type)); }
65  static std::shared_ptr<exotica::PlanningProblem> CreateProblem(const std::string& type, bool prepend = true) { return Instance()->problems_.CreateInstance((prepend ? "exotica/" : "") + type); }
66  static std::shared_ptr<exotica::CollisionScene> CreateCollisionScene(const std::string& type, bool prepend = true) { return ToStdPtr(Instance()->collision_scenes_.createInstance((prepend ? "exotica/" : "") + type)); }
67  static std::shared_ptr<exotica::DynamicsSolver> CreateDynamicsSolver(const std::string& type, bool prepend = true) { return ToStdPtr(Instance()->dynamics_solvers_.createInstance((prepend ? "exotica/" : "") + type)); }
68  static std::vector<std::string> GetSolvers();
69  static std::vector<std::string> GetProblems();
70  static std::vector<std::string> GetMaps();
71  static std::vector<std::string> GetCollisionScenes();
72  static std::vector<std::string> GetDynamicsSolvers();
73  static std::vector<Initializer> GetInitializers();
74 
75  static std::shared_ptr<exotica::MotionSolver> CreateSolver(const Initializer& init)
76  {
77  std::shared_ptr<exotica::MotionSolver> ret = ToStdPtr(Instance()->solvers_.createInstance(init.GetName()));
78  ret->InstantiateInternal(init);
79  return ret;
80  }
81  static std::shared_ptr<exotica::PlanningProblem> CreateProblem(const Initializer& init)
82  {
83  std::shared_ptr<exotica::PlanningProblem> ret = Instance()->problems_.CreateInstance(init.GetName());
84  ret->InstantiateInternal(init);
85  return ret;
86  }
87 
98  {
99  exotica::ScenePtr ret = std::make_shared<exotica::Scene>();
100  ret->InstantiateInternal(init);
101  return ret;
102  }
103 
104  static std::shared_ptr<exotica::DynamicsSolver> CreateDynamicsSolver(const Initializer& init)
105  {
106  auto ret = ToStdPtr(Instance()->dynamics_solvers_.createInstance(init.GetName()));
107  ret->InstantiateInternal(init);
108  return ret;
109  }
110 
111  static std::shared_ptr<exotica::CollisionScene> CreateCollisionScene(const Initializer& init)
112  {
113  auto ret = ToStdPtr(Instance()->collision_scenes_.createInstance(init.GetName()));
114  ret->InstantiateInternal(init);
115  return ret;
116  }
117 
118 private:
120  Setup();
121  static std::shared_ptr<Setup> singleton_initialiser_;
122  // Make sure the singleton does not get copied
123  Setup(Setup const&) = delete;
124  void operator=(Setup const&) = delete;
125 
126  static std::shared_ptr<exotica::TaskMap> CreateMap(const Initializer& init)
127  {
128  std::shared_ptr<exotica::TaskMap> ret = ToStdPtr(Instance()->maps_.createInstance(init.GetName()));
129  ret->InstantiateInternal(init);
130  return ret;
131  }
132 
133  pluginlib::ClassLoader<exotica::MotionSolver> solvers_;
134  pluginlib::ClassLoader<exotica::TaskMap> maps_;
135  pluginlib::ClassLoader<exotica::CollisionScene> collision_scenes_;
136  pluginlib::ClassLoader<exotica::DynamicsSolver> dynamics_solvers_;
138 };
139 
140 typedef std::shared_ptr<Setup> SetupPtr;
141 } // namespace exotica
142 
143 #endif // EXOTICA_CORE_SETUP_H_
exotica::Setup::solvers_
pluginlib::ClassLoader< exotica::MotionSolver > solvers_
Definition: setup.h:133
exotica::Object::type
virtual std::string type() const
Type Information wrapper: must be virtual so that it is polymorphic...
Definition: object.h:61
ToStdPtr
std::shared_ptr< T > ToStdPtr(const boost::shared_ptr< T > &p)
Definition: tools.h:148
exotica::Setup::CreateMap
static std::shared_ptr< exotica::TaskMap > CreateMap(const Initializer &init)
Definition: setup.h:126
exotica::Setup::GetProblems
static std::vector< std::string > GetProblems()
exotica::Setup::collision_scenes_
pluginlib::ClassLoader< exotica::CollisionScene > collision_scenes_
Definition: setup.h:135
exotica::Setup::GetSolvers
static std::vector< std::string > GetSolvers()
exotica::Uncopyable
Definition: uncopyable.h:35
factory.h
planning_problem.h
exotica::Setup::GetDynamicsSolvers
static std::vector< std::string > GetDynamicsSolvers()
exotica::Setup::CreateDynamicsSolver
static std::shared_ptr< exotica::DynamicsSolver > CreateDynamicsSolver(const std::string &type, bool prepend=true)
Definition: setup.h:67
property.h
exotica::Setup::~Setup
~Setup() noexcept
Definition: setup.h:50
exotica::Setup::operator=
void operator=(Setup const &)=delete
exotica::Setup::CreateProblem
static std::shared_ptr< exotica::PlanningProblem > CreateProblem(const Initializer &init)
Definition: setup.h:81
exotica::Factory< PlanningProblem >
exotica
Definition: cartpole_dynamics_solver.h:38
exotica::SetupPtr
std::shared_ptr< Setup > SetupPtr
Definition: setup.h:140
exotica::Setup::GetInitializers
static std::vector< Initializer > GetInitializers()
exotica::Setup::GetMaps
static std::vector< std::string > GetMaps()
exotica::Setup::CreateDynamicsSolver
static std::shared_ptr< exotica::DynamicsSolver > CreateDynamicsSolver(const Initializer &init)
Definition: setup.h:104
exotica::Setup::CreateProblem
static std::shared_ptr< exotica::PlanningProblem > CreateProblem(const std::string &type, bool prepend=true)
Definition: setup.h:65
exotica::ScenePtr
std::shared_ptr< Scene > ScenePtr
Definition: scene.h:246
exotica::Setup::PrintSupportedClasses
static void PrintSupportedClasses()
exotica::Setup
Definition: setup.h:47
exotica::Object
Definition: object.h:44
exotica::Setup::CreateScene
static exotica::ScenePtr CreateScene(const Initializer &init)
CreateScene instantiate a scene from an initialiser The returned scene is independent of the internal...
Definition: setup.h:97
exotica::Setup::maps_
pluginlib::ClassLoader< exotica::TaskMap > maps_
Definition: setup.h:134
exotica::Setup::CreateCollisionScene
static std::shared_ptr< exotica::CollisionScene > CreateCollisionScene(const std::string &type, bool prepend=true)
Definition: setup.h:66
exotica::Setup::singleton_initialiser_
static std::shared_ptr< Setup > singleton_initialiser_
Definition: setup.h:121
exotica::Setup::CreateCollisionScene
static std::shared_ptr< exotica::CollisionScene > CreateCollisionScene(const Initializer &init)
Definition: setup.h:111
exotica::Initializer
Definition: property.h:70
exotica::Setup::Setup
Setup()
exotica::Setup::CreateSolver
static std::shared_ptr< exotica::MotionSolver > CreateSolver(const Initializer &init)
Definition: setup.h:75
exotica::Setup::dynamics_solvers_
pluginlib::ClassLoader< exotica::DynamicsSolver > dynamics_solvers_
Definition: setup.h:136
exotica::Setup::Instance
static std::shared_ptr< Setup > Instance()
Definition: setup.h:54
exotica::Setup::CreateMap
static std::shared_ptr< exotica::TaskMap > CreateMap(const std::string &type, bool prepend=true)
Definition: setup.h:64
motion_solver.h
exotica::Setup::problems_
PlanningProblemFac problems_
Definition: setup.h:137
exotica::Initializer::GetName
const std::string & GetName() const
exotica::Setup::CreateSolver
static std::shared_ptr< exotica::MotionSolver > CreateSolver(const std::string &type, bool prepend=true)
Definition: setup.h:63
exotica::Setup::PlanningProblem
friend PlanningProblem
Definition: setup.h:119
dynamics_solver.h
exotica::Setup::GetCollisionScenes
static std::vector< std::string > GetCollisionScenes()
exotica::Setup::Destroy
static void Destroy()
object.h