setup.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018, University of Edinburgh
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 #include <type_traits>
31 
33 #include <exotica_core/scene.h>
34 #include <exotica_core/server.h>
35 #include <exotica_core/setup.h>
36 #include <exotica_core/tools.h>
37 
38 namespace exotica
39 {
41 
43 {
46 }
47 
49 {
50  HIGHLIGHT("Registered solvers:");
51  std::vector<std::string> solvers = Instance()->solvers_.getDeclaredClasses();
52  for (const std::string& s : solvers)
53  {
54  HIGHLIGHT(" '" << s << "'");
55  }
56  HIGHLIGHT("Registered problems:");
57  std::vector<std::string> problems = Instance()->problems_.GetDeclaredClasses();
58  for (const std::string& s : problems)
59  {
60  HIGHLIGHT(" '" << s << "'");
61  }
62  HIGHLIGHT("Registered task maps:");
63  std::vector<std::string> maps = Instance()->maps_.getDeclaredClasses();
64  for (const std::string& s : maps)
65  {
66  HIGHLIGHT(" '" << s << "'");
67  }
68  HIGHLIGHT("Registered collision scenes:");
69  std::vector<std::string> scenes = Instance()->collision_scenes_.getDeclaredClasses();
70  for (const std::string& s : scenes)
71  {
72  HIGHLIGHT(" '" << s << "'");
73  }
74  HIGHLIGHT("Registered dynamics solvers:");
75  std::vector<std::string> dynamics_solvers = Instance()->dynamics_solvers_.getDeclaredClasses();
76  for (const std::string& s : dynamics_solvers)
77  {
78  HIGHLIGHT(" '" << s << "'");
79  }
80 }
81 
82 void AppendInitializer(std::shared_ptr<InstantiableBase> it, std::vector<Initializer>& ret)
83 {
84  std::vector<Initializer> temps = it->GetAllTemplates();
85  for (Initializer& i : temps)
86  {
87  bool found = false;
88  for (Initializer& j : ret)
89  {
90  if (i.GetName() == j.GetName())
91  {
92  found = true;
93  break;
94  }
95  }
96  if (!found)
97  {
98  ret.push_back(i);
99  }
100  }
101 }
102 
103 std::vector<Initializer> Setup::GetInitializers()
104 {
105  std::vector<Initializer> ret = Scene().GetAllTemplates();
106  std::vector<std::string> solvers = Instance()->solvers_.getDeclaredClasses();
107  for (const std::string& s : solvers)
108  {
109  try
110  {
111  AppendInitializer(std::static_pointer_cast<InstantiableBase>(CreateSolver(s, false)), ret);
112  }
113  catch (std::exception& e)
114  {
115  WARNING_NAMED("Setup::GetInitializers", "Solver '" << s << "' not built. Won't be able to instantiate.");
116  continue;
117  }
118  }
119  std::vector<std::string> maps = Instance()->maps_.getDeclaredClasses();
120  for (const std::string& s : maps)
121  {
122  try
123  {
124  AppendInitializer(std::static_pointer_cast<InstantiableBase>(CreateMap(s, false)), ret);
125  }
126  catch (std::exception& e)
127  {
128  WARNING_NAMED("Setup::GetInitializers", "TaskMap '" << s << "' not built. Won't be able to instantiate.");
129  continue;
130  }
131  }
132  std::vector<std::string> collision_scenes = Instance()->collision_scenes_.getDeclaredClasses();
133  for (const std::string& s : collision_scenes)
134  {
135  try
136  {
137  AppendInitializer(std::static_pointer_cast<InstantiableBase>(CreateCollisionScene(s, false)), ret);
138  }
139  catch (std::exception& e)
140  {
141  WARNING_NAMED("Setup::GetInitializers", "CollisionScene '" << s << "' not built. Won't be able to instantiate.");
142  continue;
143  }
144  }
145  std::vector<std::string> dynamics_solvers = Instance()->dynamics_solvers_.getDeclaredClasses();
146  for (const std::string& s : dynamics_solvers)
147  {
148  try
149  {
150  AppendInitializer(std::static_pointer_cast<InstantiableBase>(CreateDynamicsSolver(s, false)), ret);
151  }
152  catch (std::exception& e)
153  {
154  WARNING_NAMED("Setup::GetInitializers", "DynamicsSolver '" << s << "' not built. Won't be able to instantiate.");
155  continue;
156  }
157  }
158  return ret;
159 }
160 
161 std::vector<std::string> Setup::GetSolvers() { return Instance()->solvers_.getDeclaredClasses(); }
162 std::vector<std::string> Setup::GetProblems() { return Instance()->problems_.GetDeclaredClasses(); }
163 std::vector<std::string> Setup::GetMaps() { return Instance()->maps_.getDeclaredClasses(); }
164 std::vector<std::string> Setup::GetCollisionScenes() { return Instance()->collision_scenes_.getDeclaredClasses(); }
165 std::vector<std::string> Setup::GetDynamicsSolvers() { return Instance()->dynamics_solvers_.getDeclaredClasses(); }
166 Setup::Setup() : solvers_("exotica_core", "exotica::MotionSolver"),
167  maps_("exotica_core", "exotica::TaskMap"),
169  collision_scenes_("exotica_core", "exotica::CollisionScene"),
170  dynamics_solvers_("exotica_core", "exotica::DynamicsSolver")
171 {
172 }
173 } // namespace exotica
static std::vector< std::string > GetDynamicsSolvers()
Definition: setup.cpp:165
#define HIGHLIGHT(x)
Definition: printable.h:61
static std::shared_ptr< exotica::CollisionScene > CreateCollisionScene(const std::string &type, bool prepend=true)
Definition: setup.h:66
PlanningProblemFac problems_
Definition: setup.h:137
#define WARNING_NAMED(name, x)
Definition: printable.h:63
void AppendInitializer(std::shared_ptr< InstantiableBase > it, std::vector< Initializer > &ret)
Definition: setup.cpp:82
XmlRpcServer s
static std::shared_ptr< exotica::MotionSolver > CreateSolver(const std::string &type, bool prepend=true)
Definition: setup.h:63
static void Destroy()
Definition: server.cpp:57
std::vector< Initializer > GetAllTemplates() const override
Definition: property.h:126
pluginlib::ClassLoader< exotica::TaskMap > maps_
Definition: setup.h:134
pluginlib::ClassLoader< exotica::DynamicsSolver > dynamics_solvers_
Definition: setup.h:136
static std::shared_ptr< Setup > singleton_initialiser_
Definition: setup.h:121
static std::vector< Initializer > GetInitializers()
Definition: setup.cpp:103
static void Destroy()
Definition: setup.cpp:42
static std::vector< std::string > GetCollisionScenes()
Definition: setup.cpp:164
std::shared_ptr< Setup > SetupPtr
Definition: setup.h:140
static void PrintSupportedClasses()
Definition: setup.cpp:48
The class of EXOTica Scene.
Definition: scene.h:69
static std::shared_ptr< exotica::DynamicsSolver > CreateDynamicsSolver(const std::string &type, bool prepend=true)
Definition: setup.h:67
static std::vector< std::string > GetProblems()
Definition: setup.cpp:162
pluginlib::ClassLoader< exotica::MotionSolver > solvers_
Definition: setup.h:133
static std::vector< std::string > GetMaps()
Definition: setup.cpp:163
static std::vector< std::string > GetSolvers()
Definition: setup.cpp:161
pluginlib::ClassLoader< exotica::CollisionScene > collision_scenes_
Definition: setup.h:135
static std::shared_ptr< Setup > Instance()
Definition: setup.h:54
static std::shared_ptr< exotica::TaskMap > CreateMap(const std::string &type, bool prepend=true)
Definition: setup.h:64


exotica_core
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Sat Apr 10 2021 02:34:49