scene.h
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 #ifndef EXOTICA_CORE_SCENE_H_
31 #define EXOTICA_CORE_SCENE_H_
32 
33 #include <fstream>
34 #include <functional>
35 #include <iostream>
36 #include <string>
37 
40 #include <moveit_msgs/PlanningScene.h>
41 
44 #include <exotica_core/object.h>
45 #include <exotica_core/property.h>
48 
49 #include <exotica_core/scene_initializer.h>
50 
51 namespace exotica
52 {
54 {
55  AttachedObject() = default;
56  AttachedObject(std::string _parent) : parent(_parent) {}
57  AttachedObject(std::string _parent, KDL::Frame _pose) : parent(_parent), pose(_pose) {}
58  std::string parent = "";
60 };
61 
62 #ifndef EXOTICA_CORE_DYNAMICS_SOLVER_H_
63 template <typename T, int NX, int NU>
66 #endif
67 
69 class Scene : public Object, Uncopyable, public Instantiable<SceneInitializer>, public std::enable_shared_from_this<Scene>
70 {
71 public:
72  Scene(const std::string& name);
73  Scene();
74  virtual ~Scene();
75  virtual void Instantiate(const SceneInitializer& init);
76  void RequestKinematics(KinematicsRequest& request, std::function<void(std::shared_ptr<KinematicResponse>)> callback);
77  const std::string& GetName() const; // Deprecated - use GetObjectName
78  void Update(Eigen::VectorXdRefConst x, double t = 0);
79 
81  const CollisionScenePtr& GetCollisionScene() const;
82 
84  std::shared_ptr<DynamicsSolver> GetDynamicsSolver() const;
85 
86  std::string GetRootFrameName();
87  std::string GetRootJointName();
88 
89  exotica::KinematicTree& GetKinematicTree();
90  std::vector<std::string> GetControlledJointNames();
91  std::vector<std::string> GetModelJointNames();
92  std::vector<std::string> GetControlledLinkNames();
93  std::vector<std::string> GetModelLinkNames();
94  Eigen::VectorXd GetControlledState();
95  Eigen::VectorXd GetModelState();
96  std::map<std::string, double> GetModelStateMap();
97  std::map<std::string, std::weak_ptr<KinematicElement>> GetTreeMap();
98  void SetModelState(Eigen::VectorXdRefConst x, double t = 0, bool update_traj = true);
99  void SetModelState(const std::map<std::string, double>& x, double t = 0, bool update_traj = true);
100 
101  void AddTrajectoryFromFile(const std::string& link, const std::string& traj);
102  void AddTrajectory(const std::string& link, const std::string& traj);
103  void AddTrajectory(const std::string& link, std::shared_ptr<Trajectory> traj);
104  std::shared_ptr<Trajectory> GetTrajectory(const std::string& link);
105  void RemoveTrajectory(const std::string& link);
106 
108  void UpdateSceneFrames();
114  void AttachObject(const std::string& name, const std::string& parent);
121  void AttachObjectLocal(const std::string& name, const std::string& parent, const KDL::Frame& pose);
122  void AttachObjectLocal(const std::string& name, const std::string& parent, const Eigen::VectorXd& pose);
127  void DetachObject(const std::string& name);
128  bool HasAttachedObject(const std::string& name);
129 
130  void AddObject(const std::string& name, const KDL::Frame& transform = KDL::Frame(), const std::string& parent = "", shapes::ShapeConstPtr shape = shapes::ShapeConstPtr(nullptr), const KDL::RigidBodyInertia& inertia = KDL::RigidBodyInertia::Zero(), const Eigen::Vector4d& color = Eigen::Vector4d(0.5, 0.5, 0.5, 1.0), const bool update_collision_scene = true);
131 
132  void AddObject(const std::string& name, const KDL::Frame& transform = KDL::Frame(), const std::string& parent = "", const std::string& shape_resource_path = "", const Eigen::Vector3d& scale = Eigen::Vector3d::Ones(), const KDL::RigidBodyInertia& inertia = KDL::RigidBodyInertia::Zero(), const Eigen::Vector4d& color = Eigen::Vector4d(0.5, 0.5, 0.5, 1.0), const bool update_collision_scene = true);
133 
134  void AddObjectToEnvironment(const std::string& name, const KDL::Frame& transform = KDL::Frame(), shapes::ShapeConstPtr shape = nullptr, const Eigen::Vector4d& color = Eigen::Vector4d(0.5, 0.5, 0.5, 1.0), const bool update_collision_scene = true);
135 
136  void RemoveObject(const std::string& name);
137 
140  void UpdatePlanningSceneWorld(const moveit_msgs::PlanningSceneWorldConstPtr& world);
141 
144  void UpdatePlanningScene(const moveit_msgs::PlanningScene& scene);
145 
148  moveit_msgs::PlanningScene GetPlanningSceneMsg();
149 
150  void UpdateCollisionObjects();
151  void UpdateTrajectoryGenerators(double t = 0);
152 
153  void PublishScene();
154  void PublishProxies(const std::vector<CollisionProxy>& proxies);
155  visualization_msgs::Marker ProxyToMarker(const std::vector<CollisionProxy>& proxies, const std::string& frame);
156  void LoadScene(const std::string& scene, const Eigen::Isometry3d& offset = Eigen::Isometry3d::Identity(), bool update_collision_scene = true);
157  void LoadScene(const std::string& scene, const KDL::Frame& offset = KDL::Frame(), bool update_collision_scene = true);
158  void LoadSceneFile(const std::string& file_name, const Eigen::Isometry3d& offset = Eigen::Isometry3d::Identity(), bool update_collision_scene = true);
159  void LoadSceneFile(const std::string& file_name, const KDL::Frame& offset = KDL::Frame(), bool update_collision_scene = true);
160  std::string GetScene();
161  void CleanScene();
162 
165  bool AlwaysUpdatesCollisionScene() const { return force_collision_; }
168  const std::map<std::string, std::vector<std::string>>& GetModelLinkToCollisionLinkMap() const { return model_link_to_collision_link_map_; };
171  const std::map<std::string, std::vector<std::shared_ptr<KinematicElement>>>& GetModelLinkToCollisionElementMap() const { return model_link_to_collision_element_map_; };
174  const std::map<std::string, std::vector<std::string>>& GetControlledJointToCollisionLinkMap() const { return controlled_joint_to_collision_link_map_; };
176  const std::set<std::string>& get_world_links_to_exclude_from_collision_scene() const { return world_links_to_exclude_from_collision_scene_; }
177  int get_num_positions() const;
178  int get_num_velocities() const;
179  int get_num_controls() const;
180  int get_num_state() const;
181  int get_num_state_derivative() const;
182  bool get_has_quaternion_floating_base() const;
183 
184 private:
185  bool has_quaternion_floating_base_ = false;
186 
187  void UpdateInternalFrames(bool update_request = true);
188 
190  void UpdateMoveItPlanningScene();
191 
192  void LoadSceneFromStringStream(std::istream& in, const Eigen::Isometry3d& offset, bool update_collision_scene);
193 
196 
199 
201  std::shared_ptr<DynamicsSolver> dynamics_solver_ = std::shared_ptr<DynamicsSolver>(nullptr);
202 
203  int num_positions_ = 0;
204  int num_velocities_ = 0;
205  int num_controls_ = 0;
206  int num_state_ = 0;
207  int num_state_derivative_ = 0;
208 
210  planning_scene::PlanningScenePtr ps_;
211 
215 
218  std::map<std::string, AttachedObject> attached_objects_;
219 
221  std::vector<std::shared_ptr<KinematicElement>> custom_links_;
222 
223  std::map<std::string, std::pair<std::weak_ptr<KinematicElement>, std::shared_ptr<Trajectory>>> trajectory_generators_;
224 
226 
228  std::map<std::string, std::vector<std::string>> model_link_to_collision_link_map_;
229  std::map<std::string, std::vector<std::shared_ptr<KinematicElement>>> model_link_to_collision_element_map_;
230 
232  std::map<std::string, std::vector<std::string>> controlled_joint_to_collision_link_map_;
233 
236 
239 
241  std::shared_ptr<KinematicResponse> kinematic_solution_;
242  std::function<void(std::shared_ptr<KinematicResponse>)> kinematic_request_callback_;
244 };
245 
246 typedef std::shared_ptr<Scene> ScenePtr;
247 } // namespace exotica
248 
249 #endif // EXOTICA_CORE_SCENE_H_
planning_scene::PlanningScenePtr ps_
Internal MoveIt planning scene.
Definition: scene.h:210
KDL::Frame pose
Definition: scene.h:59
const std::set< std::string > & get_world_links_to_exclude_from_collision_scene() const
Returns world links that are to be excluded from collision checking.
Definition: scene.h:176
const std::map< std::string, std::vector< std::string > > & GetControlledJointToCollisionLinkMap() const
Returns a map between controlled robot joint names and associated collision link names. Here we consider all fixed links between controlled links as belonging to the previous controlled joint (as if the collision links had been fused).
Definition: scene.h:174
AttachedObject(std::string _parent)
Definition: scene.h:56
std::vector< std::shared_ptr< KinematicElement > > custom_links_
List of frames/links added on top of robot links and scene objects defined in the MoveIt scene...
Definition: scene.h:221
std::shared_ptr< Scene > ScenePtr
Definition: scene.h:246
bool AlwaysUpdatesCollisionScene() const
Whether the collision scene transforms get updated on every scene update.
Definition: scene.h:165
exotica::KinematicTree kinematica_
The kinematica tree.
Definition: scene.h:195
std::set< std::string > robot_links_to_exclude_from_collision_scene_
List of robot links to be excluded from the collision scene.
Definition: scene.h:235
std::shared_ptr< KinematicResponse > kinematic_solution_
Definition: scene.h:241
std::set< std::string > world_links_to_exclude_from_collision_scene_
List of world links to be excluded from the collision scene.
Definition: scene.h:238
bool force_collision_
Definition: scene.h:225
ros::Publisher proxy_pub_
Definition: scene.h:214
The class of EXOTica Scene.
Definition: scene.h:69
static RigidBodyInertia Zero()
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
Definition: conversions.h:52
std::map< std::string, std::vector< std::string > > controlled_joint_to_collision_link_map_
Mapping between controlled joint name and collision links.
Definition: scene.h:232
ros::Publisher ps_pub_
Visual debug.
Definition: scene.h:213
KinematicsRequest kinematic_request_
Definition: scene.h:240
CollisionScenePtr collision_scene_
The collision scene.
Definition: scene.h:198
std::string parent
Definition: scene.h:58
AttachedObject(std::string _parent, KDL::Frame _pose)
Definition: scene.h:57
std::map< std::string, AttachedObject > attached_objects_
List of attached objects These objects will be reattached if the scene gets reloaded.
Definition: scene.h:218
std::shared_ptr< CollisionScene > CollisionScenePtr
const std::map< std::string, std::vector< std::shared_ptr< KinematicElement > > > & GetModelLinkToCollisionElementMap() const
Returns a map between a model link name and the KinematicElement of associated collision links...
Definition: scene.h:171
std::map< std::string, std::pair< std::weak_ptr< KinematicElement >, std::shared_ptr< Trajectory > > > trajectory_generators_
Definition: scene.h:223
std::map< std::string, std::vector< std::string > > model_link_to_collision_link_map_
Mapping between model link names and collision links.
Definition: scene.h:228
AbstractDynamicsSolver< double, Eigen::Dynamic, Eigen::Dynamic > DynamicsSolver
bool request_needs_updating_
Definition: scene.h:243
const std::map< std::string, std::vector< std::string > > & GetModelLinkToCollisionLinkMap() const
Returns a map between a model link name and the names of associated collision links.
Definition: scene.h:168
double x
std::map< std::string, std::vector< std::shared_ptr< KinematicElement > > > model_link_to_collision_element_map_
Definition: scene.h:229
std::shared_ptr< const Shape > ShapeConstPtr


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