scene.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 
34 
36 #include <exotica_core/scene.h>
37 #include <exotica_core/server.h>
38 #include <exotica_core/setup.h>
39 
40 #include <exotica_core/attach_link_initializer.h>
41 #include <exotica_core/box_shape_initializer.h>
42 #include <exotica_core/collision_scene_initializer.h>
43 #include <exotica_core/cylinder_shape_initializer.h>
44 #include <exotica_core/link_initializer.h>
45 #include <exotica_core/mesh_shape_initializer.h>
46 #include <exotica_core/octree_shape_initializer.h>
47 #include <exotica_core/shape_initializer.h>
48 #include <exotica_core/sphere_shape_initializer.h>
49 #include <exotica_core/trajectory_initializer.h>
50 
51 #include <moveit/version.h>
52 
53 namespace exotica
54 {
55 Scene::Scene() = default;
56 
57 Scene::Scene(const std::string& name) : request_needs_updating_(false)
58 {
60 }
61 
62 Scene::~Scene() = default;
63 
64 const std::string& Scene::GetName() const
65 {
66  return object_name_;
67 }
68 
69 void Scene::Instantiate(const SceneInitializer& init)
70 {
71  Object::InstantiateObject(SceneInitializer(init));
72  this->parameters_ = init;
74 
75  // Load robot model and set up kinematics (KinematicTree)
76  robot_model::RobotModelPtr model;
77  if (init.URDF == "" || init.SRDF == "")
78  {
79  Server::Instance()->GetModel(init.RobotDescription, model);
80  }
81  else
82  {
83  Server::Instance()->GetModel(init.URDF, model, init.URDF, init.SRDF);
84  }
85  kinematica_.Instantiate(init.JointGroup, model, object_name_);
86  ps_.reset(new planning_scene::PlanningScene(model));
87 
88  // Write URDF/SRDF to ROS param server
89  if (Server::IsRos() && init.SetRobotDescriptionRosParams && init.URDF != "" && init.SRDF != "")
90  {
91  if (debug_) HIGHLIGHT_NAMED(object_name_, "Setting robot_description and robot_description_semantic from URDF and SRDF initializers");
92  const std::string urdf_string = PathExists(init.URDF) ? LoadFile(init.URDF) : init.URDF;
93  const std::string srdf_string = PathExists(init.SRDF) ? LoadFile(init.SRDF) : init.SRDF;
94  Server::SetParam("/robot_description", urdf_string);
95  Server::SetParam("/robot_description_semantic", srdf_string);
96  }
97 
98  // Set up debug topics if running in ROS mode
99  if (Server::IsRos())
100  {
101  ps_pub_ = Server::Advertise<moveit_msgs::PlanningScene>(object_name_ + (object_name_ == "" ? "" : "/") + "PlanningScene", 1, true);
102  proxy_pub_ = Server::Advertise<visualization_msgs::Marker>(object_name_ + (object_name_ == "" ? "" : "/") + "CollisionProxies", 1, true);
103  if (debug_)
104  HIGHLIGHT_NAMED(object_name_, "Running in debug mode, planning scene will be published to '" << Server::Instance()->GetName() << "/" << object_name_ << "/PlanningScene'");
105  }
106 
107  // Note: Using the LoadScene initializer does not support custom offsets/poses, assumes Identity transform to world_frame
108  if (init.LoadScene != "")
109  {
110  std::vector<std::string> files = ParseList(init.LoadScene, ';');
111  for (const std::string& file : files) LoadSceneFile(file, Eigen::Isometry3d::Identity(), false);
112  }
113 
114  // Add custom links
115  for (const exotica::Initializer& linkInit : init.Links)
116  {
117  LinkInitializer link(linkInit);
118 
119  shapes::ShapePtr link_shape = nullptr;
120  Eigen::Vector4d link_color = Eigen::Vector4d::Zero();
121  if (link.Shape.size() == 1)
122  {
123  ShapeInitializer shape(link.Shape[0]);
124  link_color = shape.Color;
125 
126  if (shape.Type == "Box")
127  {
128  BoxShapeInitializer box(link.Shape[0]);
129  std::cout << "BOX: " << box.Dimensions.transpose() << std::endl;
130  link_shape.reset(new shapes::Box(box.Dimensions.x(), box.Dimensions.y(), box.Dimensions.z()));
131  }
132  else if (shape.Type == "Cylinder")
133  {
134  CylinderShapeInitializer cylinder(link.Shape[0]);
135  link_shape.reset(new shapes::Cylinder(cylinder.Radius, cylinder.Length));
136  }
137  else if (shape.Type == "Mesh")
138  {
139  MeshShapeInitializer mesh(link.Shape[0]);
140  // TODO: This will not support textures.
141  link_shape.reset(shapes::createMeshFromResource(ParsePath(mesh.MeshFilePath), mesh.Scale));
142  }
143  else if (shape.Type == "Octree")
144  {
145  OctreeShapeInitializer octree(link.Shape[0]);
146  link_shape = LoadOctreeAsShape(ParsePath(octree.OctreeFilePath));
147  }
148  else if (shape.Type == "Sphere")
149  {
150  SphereShapeInitializer sphere(link.Shape[0]);
151  link_shape.reset(new shapes::Sphere(sphere.Radius));
152  }
153  else
154  {
155  ThrowPretty("Unrecognized ShapeType: " << shape.Type);
156  }
157  }
158  else if (link.Shape.size() > 1)
159  {
160  ThrowPretty("Only one Shape per Link allowed, given: " << link.Shape.size());
161  }
162 
163  AddObject(link.Name, GetFrame(link.Transform), link.Parent, link_shape, KDL::RigidBodyInertia(link.Mass, GetFrame(link.CenterOfMass).p), link_color, false); // false since CollisionScene is not yet setup
164  }
165 
166  // Check list of robot links to exclude from CollisionScene
167  if (init.RobotLinksToExcludeFromCollisionScene.size() > 0)
168  {
169  for (const auto& link : init.RobotLinksToExcludeFromCollisionScene)
170  {
172  if (debug_) HIGHLIGHT_NAMED("RobotLinksToExcludeFromCollisionScene", link);
173  }
174  }
175 
176  // Check list of world links to exclude from CollisionScene
177  if (init.WorldLinksToExcludeFromCollisionScene.size() > 0)
178  {
179  for (const auto& link : init.WorldLinksToExcludeFromCollisionScene)
180  {
182  if (debug_) HIGHLIGHT_NAMED("WorldLinksToExcludeFromCollisionScene", link);
183  }
184  }
185 
186  // Initialize CollisionScene
187  force_collision_ = init.AlwaysUpdateCollisionScene;
188  if (!init.DoNotInstantiateCollisionScene)
189  {
190  if (init.CollisionScene.size() == 0)
191  {
192  // Not set ==> Default to CollisionSceneFCLLatest for backwards compatibility.
193  collision_scene_ = Setup::CreateCollisionScene("CollisionSceneFCLLatest"); // NB: This is an implicit run-time dependency and thus dangerous! But we don't want to break existing configs...
194  }
195  else if (init.CollisionScene.size() == 1)
196  {
198  }
199  else
200  {
201  // Only one dynamics solver per scene is allowed, i.e., throw if more than one provided:
202  ThrowPretty("Only one CollisionScene per scene allowed - " << init.CollisionScene.size() << " provided");
203  }
204 
205  collision_scene_->debug_ = this->debug_; // Backwards compatibility - TODO: Remove
206  // collision_scene_->ns_ = ns_ + "/" + collision_scene_->GetObjectName();
207  collision_scene_->Setup(); // TODO: Trigger from Initializer
208  collision_scene_->AssignScene(shared_from_this());
209  collision_scene_->SetAlwaysExternallyUpdatedCollisionScene(force_collision_);
210  }
211 
213  UpdateInternalFrames(false);
214 
215  // Attach links
216  for (const exotica::Initializer& linkInit : init.AttachLinks)
217  {
218  AttachLinkInitializer link(linkInit);
219  if (link.Local)
220  {
221  AttachObjectLocal(link.Name, link.Parent, GetFrame(link.Transform));
222  }
223  else
224  {
225  AttachObject(link.Name, link.Parent);
226  }
227  }
228 
229  // Set up allowed collision matrix (i.e., collision pairs that are filtered/ignored)
231  std::vector<std::string> acm_names;
232  ps_->getAllowedCollisionMatrix().getAllEntryNames(acm_names);
233  for (auto& name1 : acm_names)
234  {
235  for (auto& name2 : acm_names)
236  {
237  collision_detection::AllowedCollision::Type type = collision_detection::AllowedCollision::Type::ALWAYS;
238  ps_->getAllowedCollisionMatrix().getAllowedCollision(name1, name2, type);
239  if (type == collision_detection::AllowedCollision::Type::ALWAYS)
240  {
241  acm.setEntry(name1, name2);
242  }
243  }
244  }
245  if (collision_scene_ != nullptr) collision_scene_->SetACM(acm);
246 
247  // Set up trajectory generators
248  for (const exotica::Initializer& it : init.Trajectories)
249  {
250  TrajectoryInitializer trajInit(it);
251  if (trajInit.File != "")
252  {
253  AddTrajectoryFromFile(trajInit.Link, trajInit.File);
254  }
255  else
256  {
257  AddTrajectory(trajInit.Link, trajInit.Trajectory);
258  }
259  }
260 
261  // Set up DynamicsSolver (requires a fully initialised scene)
262  if (init.DynamicsSolver.size() > 0)
263  {
264  // Only one dynamics solver per scene is allowed, i.e., throw if more than one provided:
265  if (init.DynamicsSolver.size() > 1) ThrowPretty("Only one DynamicsSolver per scene allowed - " << init.DynamicsSolver.size() << " provided");
266 
267  // Create dynamics solver
268  dynamics_solver_ = Setup::CreateDynamicsSolver(init.DynamicsSolver.at(0));
269  dynamics_solver_->AssignScene(shared_from_this());
270  dynamics_solver_->ns_ = ns_ + "/" + dynamics_solver_->GetObjectName();
271 
272  num_positions_ = dynamics_solver_->get_num_positions();
273  num_velocities_ = dynamics_solver_->get_num_velocities();
274  num_controls_ = dynamics_solver_->get_num_controls();
275  num_state_ = dynamics_solver_->get_num_state();
276  num_state_derivative_ = dynamics_solver_->get_num_state_derivative();
277  }
278  else
279  {
281  num_velocities_ = 0;
282  num_controls_ = 0;
285  }
286 
287  // Check if the system has a floating-base, and if so, if it contains a quaternion.
288  // Will need to trigger special logic below to handle this (w.r.t. normalisation).
290 
291  // Set or override position, velocity, and acceleration limits
292  if (init.JointPositionLimitsLower.rows() > 0)
293  {
294  if (init.JointPositionLimitsLower.rows() != kinematica_.GetNumControlledJoints()) ThrowPretty("Size of JointPositionLimitsLower incorrect: Provided " << init.JointPositionLimitsLower.rows() << ", expected " << kinematica_.GetNumControlledJoints());
295  if (debug_) HIGHLIGHT_NAMED(object_name_, "Overriding lower position limits: " << init.JointPositionLimitsLower.transpose());
296  kinematica_.SetJointLimitsLower(init.JointPositionLimitsLower);
297  }
298  if (init.JointPositionLimitsUpper.rows() > 0)
299  {
300  if (init.JointPositionLimitsUpper.rows() != kinematica_.GetNumControlledJoints()) ThrowPretty("Size of JointPositionLimitsUpper incorrect: Provided " << init.JointPositionLimitsUpper.rows() << ", expected " << kinematica_.GetNumControlledJoints());
301  if (debug_) HIGHLIGHT_NAMED(object_name_, "Overriding upper position limits: " << init.JointPositionLimitsUpper.transpose());
302  kinematica_.SetJointLimitsUpper(init.JointPositionLimitsUpper);
303  }
304  if (init.JointVelocityLimits.rows() > 0)
305  {
306  if (init.JointVelocityLimits.rows() != kinematica_.GetNumControlledJoints()) ThrowPretty("Size of JointVelocityLimits incorrect: Provided " << init.JointVelocityLimits.rows() << ", expected " << kinematica_.GetNumControlledJoints());
307  if (debug_) HIGHLIGHT_NAMED(object_name_, "Overriding velocity limits: " << init.JointVelocityLimits.transpose());
308  kinematica_.SetJointVelocityLimits(init.JointVelocityLimits.cwiseAbs());
309  }
310  if (init.JointAccelerationLimits.rows() > 0)
311  {
312  if (init.JointAccelerationLimits.rows() != kinematica_.GetNumControlledJoints()) ThrowPretty("Size of JointAccelerationLimits incorrect: Provided " << init.JointAccelerationLimits.rows() << ", expected " << kinematica_.GetNumControlledJoints());
313  if (debug_) HIGHLIGHT_NAMED(object_name_, "Overriding acceleration limits: " << init.JointAccelerationLimits.transpose());
314  kinematica_.SetJointAccelerationLimits(init.JointAccelerationLimits.cwiseAbs());
315  }
316 
317  if (debug_) INFO_NAMED(object_name_, "Exotica Scene initialized");
318 }
319 
320 void Scene::RequestKinematics(KinematicsRequest& request, std::function<void(std::shared_ptr<KinematicResponse>)> callback)
321 {
322  kinematic_request_ = request;
323  kinematic_request_callback_ = callback;
326  request_needs_updating_ = false;
327 }
328 
330 {
331  for (auto& it : trajectory_generators_)
332  {
333  it.second.first.lock()->generated_offset = it.second.second->GetPosition(t);
334  }
335 }
336 
338 {
340  {
342  }
343 
346  if (force_collision_ && collision_scene_ != nullptr) collision_scene_->UpdateCollisionObjectTransforms();
347  if (debug_) PublishScene();
348 }
349 
351 {
352  std::map<std::string, double> modelState = GetModelStateMap();
353  for (const auto& joint : modelState)
354  {
355  try
356  {
357  ps_->getCurrentStateNonConst().setVariablePosition(joint.first, joint.second);
358  }
359  catch (const std::out_of_range& e)
360  {
361  HIGHLIGHT("Could not find Kinematica joint name in MoveIt: " + joint.first);
362  }
363  }
364 
365  // The floating base joint in MoveIt uses quaternion, while Kinematica uses
366  // RPY [but using rot_x, rot_y, and rot_z as joint names]. Thus, we need to
367  // fix the orientation of the virtual floating base by extracting the RPY
368  // values, converting them to quaternion, and then updating the planning
369  // scene.
371  {
372  KDL::Rotation rot = KDL::Rotation::RPY(modelState[kinematica_.GetRootJointName() + "/rot_x"], modelState[kinematica_.GetRootJointName() + "/rot_y"], modelState[kinematica_.GetRootJointName() + "/rot_z"]);
373  Eigen::Quaterniond quat(Eigen::Map<const Eigen::Matrix3d>(rot.data).transpose());
374  ps_->getCurrentStateNonConst().setVariablePosition(kinematica_.GetRootJointName() + "/rot_x", quat.x());
375  ps_->getCurrentStateNonConst().setVariablePosition(kinematica_.GetRootJointName() + "/rot_y", quat.y());
376  ps_->getCurrentStateNonConst().setVariablePosition(kinematica_.GetRootJointName() + "/rot_z", quat.z());
377  ps_->getCurrentStateNonConst().setVariablePosition(kinematica_.GetRootJointName() + "/rot_w", quat.w());
378  }
379 }
380 
382 {
383  if (Server::IsRos())
384  {
386  }
387 }
388 
389 void Scene::PublishProxies(const std::vector<CollisionProxy>& proxies)
390 {
391  if (Server::IsRos())
392  {
394  }
395 }
396 
397 visualization_msgs::Marker Scene::ProxyToMarker(const std::vector<CollisionProxy>& proxies, const std::string& frame)
398 {
399  visualization_msgs::Marker ret;
400  ret.header.frame_id = "exotica/" + frame;
401  ret.action = visualization_msgs::Marker::ADD;
402  ret.frame_locked = false;
403  ret.ns = "Proxies";
404  ret.color.a = 1.0;
405  ret.id = 0;
406  ret.type = visualization_msgs::Marker::LINE_LIST;
407  ret.points.resize(proxies.size() * 6);
408  ret.colors.resize(proxies.size() * 6);
409  ret.scale.x = 0.005;
410  ret.pose.orientation.w = 1.0;
411  double normalLength = 0.01;
412  std_msgs::ColorRGBA normal = GetColor(0.8, 0.8, 0.8);
413  std_msgs::ColorRGBA far = GetColor(0.5, 0.5, 0.5);
414  std_msgs::ColorRGBA colliding = GetColor(1, 0, 0);
415  for (int i = 0; i < proxies.size(); ++i)
416  {
417  KDL::Vector c1 = KDL::Vector(proxies[i].contact1(0), proxies[i].contact1(1), proxies[i].contact1(2));
418  KDL::Vector c2 = KDL::Vector(proxies[i].contact2(0), proxies[i].contact2(1), proxies[i].contact2(2));
419  KDL::Vector n1 = KDL::Vector(proxies[i].normal1(0), proxies[i].normal1(1), proxies[i].normal1(2));
420  KDL::Vector n2 = KDL::Vector(proxies[i].normal2(0), proxies[i].normal2(1), proxies[i].normal2(2));
421  tf::pointKDLToMsg(c1, ret.points[i * 6]);
422  tf::pointKDLToMsg(c2, ret.points[i * 6 + 1]);
423  tf::pointKDLToMsg(c1, ret.points[i * 6 + 2]);
424  tf::pointKDLToMsg(c1 + n1 * normalLength, ret.points[i * 6 + 3]);
425  tf::pointKDLToMsg(c2, ret.points[i * 6 + 4]);
426  tf::pointKDLToMsg(c2 + n2 * normalLength, ret.points[i * 6 + 5]);
427  ret.colors[i * 6] = ret.colors[i * 6 + 1] = proxies[i].distance > 0 ? far : colliding;
428  ret.colors[i * 6 + 2] = ret.colors[i * 6 + 3] = ret.colors[i * 6 + 4] = ret.colors[i * 6 + 5] = normal;
429  }
430  return ret;
431 }
432 
433 void Scene::UpdatePlanningScene(const moveit_msgs::PlanningScene& scene)
434 {
435  ps_->usePlanningSceneMsg(scene);
438 }
439 
440 void Scene::UpdatePlanningSceneWorld(const moveit_msgs::PlanningSceneWorldConstPtr& world)
441 {
442  ps_->processPlanningSceneWorldMsg(*world);
445 }
446 
448 {
449  if (collision_scene_ != nullptr) collision_scene_->UpdateCollisionObjects(kinematica_.GetCollisionTreeMap());
450 }
451 
453 {
454  if (collision_scene_ == nullptr) ThrowPretty("No CollisionScene initialized!");
455  return collision_scene_;
456 }
457 
458 std::shared_ptr<DynamicsSolver> Scene::GetDynamicsSolver() const
459 {
460  return dynamics_solver_;
461 }
462 
464 {
465  return kinematica_.GetRootFrameName();
466 }
467 
469 {
470  return kinematica_.GetRootJointName();
471 }
472 
473 moveit_msgs::PlanningScene Scene::GetPlanningSceneMsg()
474 {
475  // Update the joint positions in the PlanningScene from Kinematica - we do
476  // not do this on every Update() as it is only required when publishing
477  // the scene and would take unnecessary time otherwise.
479 
480  moveit_msgs::PlanningScene msg;
481  ps_->getPlanningSceneMsg(msg);
482 
483  // The robot link paddings and scales are applied in the CollisionScene
484  // and are not propagated back to the internal MoveIt PlanningScene. Here
485  // we set them in the message that is being returned.
486  msg.link_padding.clear();
487  msg.link_scale.clear();
488  for (auto robot_link : msg.robot_state.joint_state.name)
489  {
490  moveit_msgs::LinkPadding padding;
491  padding.link_name = robot_link;
492  padding.padding = (collision_scene_ != nullptr) ? collision_scene_->GetRobotLinkPadding() : 0.0;
493  msg.link_padding.push_back(padding);
494 
495  moveit_msgs::LinkScale scale;
496  scale.link_name = robot_link;
497  scale.scale = (collision_scene_ != nullptr) ? collision_scene_->GetRobotLinkScale() : 1.0;
498  msg.link_scale.push_back(scale);
499  }
500 
501  // As we cannot apply world link scalings in the message itself, we need to
502  // manually scale the objects.
503  // TODO(wxm): Recreate as updated poses won't be reflected (e.g. trajectories)
504  if (collision_scene_ != nullptr && (collision_scene_->GetWorldLinkScale() != 1.0 || collision_scene_->GetWorldLinkPadding() > 0.0))
505  {
506  for (auto it : msg.world.collision_objects)
507  {
508  // Primitives
509  for (auto primitive : it.primitives)
510  {
512  tmp->scaleAndPadd(collision_scene_->GetWorldLinkScale(), collision_scene_->GetWorldLinkPadding());
513  shapes::ShapeMsg tmp_msg;
514  shapes::constructMsgFromShape(const_cast<shapes::Shape*>(tmp.get()), tmp_msg);
515  primitive = boost::get<shape_msgs::SolidPrimitive>(tmp_msg);
516  }
517 
518  // Meshes
519  for (auto mesh : it.meshes)
520  {
522  tmp->scaleAndPadd(collision_scene_->GetWorldLinkScale(), collision_scene_->GetWorldLinkPadding());
523  shapes::ShapeMsg tmp_msg;
524  shapes::constructMsgFromShape(const_cast<shapes::Shape*>(tmp.get()), tmp_msg);
525  mesh = boost::get<shape_msgs::Mesh>(tmp_msg);
526  }
527 
528  // NB: Scaling and padding does not apply to planes
529  }
530  }
531 
532  return msg;
533 }
534 
536 {
537  return kinematica_;
538 }
539 
540 std::vector<std::string> Scene::GetControlledJointNames()
541 {
543 }
544 
545 std::vector<std::string> Scene::GetControlledLinkNames()
546 {
548 }
549 
550 std::vector<std::string> Scene::GetModelLinkNames()
551 {
553 }
554 
555 std::vector<std::string> Scene::GetModelJointNames()
556 {
558 }
559 
560 Eigen::VectorXd Scene::GetModelState()
561 {
562  return kinematica_.GetModelState();
563 }
564 
565 std::map<std::string, double> Scene::GetModelStateMap()
566 {
567  return kinematica_.GetModelStateMap();
568 }
569 
570 std::map<std::string, std::weak_ptr<KinematicElement>> Scene::GetTreeMap()
571 {
572  return kinematica_.GetTreeMap();
573 }
574 
575 void Scene::SetModelState(Eigen::VectorXdRefConst x, double t, bool update_traj)
576 {
578  {
580  }
581 
582  if (update_traj) UpdateTrajectoryGenerators(t);
583  // Update Kinematica internal state
585 
586  if (force_collision_ && collision_scene_ != nullptr) collision_scene_->UpdateCollisionObjectTransforms();
587  if (debug_) PublishScene();
588 }
589 
590 void Scene::SetModelState(const std::map<std::string, double>& x, double t, bool update_traj)
591 {
593  {
595  }
596 
597  if (update_traj) UpdateTrajectoryGenerators(t);
598  // Update Kinematica internal state
600 
601  if (force_collision_ && collision_scene_ != nullptr) collision_scene_->UpdateCollisionObjectTransforms();
602  if (debug_) PublishScene();
603 }
604 
605 Eigen::VectorXd Scene::GetControlledState()
606 {
608 }
609 
610 void Scene::LoadScene(const std::string& scene, const KDL::Frame& offset, bool update_collision_scene)
611 {
612  Eigen::Isometry3d tmp_offset;
613  tf::transformKDLToEigen(offset, tmp_offset);
614  LoadScene(scene, tmp_offset, update_collision_scene);
615 }
616 
617 void Scene::LoadScene(const std::string& scene, const Eigen::Isometry3d& offset, bool update_collision_scene)
618 {
619  std::stringstream ss(scene);
620  LoadSceneFromStringStream(ss, offset, update_collision_scene);
621 }
622 
623 void Scene::LoadSceneFile(const std::string& file_name, const KDL::Frame& offset, bool update_collision_scene)
624 {
625  Eigen::Isometry3d tmp_offset;
626  tf::transformKDLToEigen(offset, tmp_offset);
627  LoadSceneFile(file_name, tmp_offset, update_collision_scene);
628 }
629 
630 void Scene::LoadSceneFile(const std::string& file_name, const Eigen::Isometry3d& offset, bool update_collision_scene)
631 {
632  std::ifstream ss(ParsePath(file_name));
633  if (!ss.is_open()) ThrowPretty("Cant read file '" << ParsePath(file_name) << "'!");
634  LoadSceneFromStringStream(ss, offset, update_collision_scene);
635 }
636 
637 void Scene::LoadSceneFromStringStream(std::istream& in, const Eigen::Isometry3d& offset, bool update_collision_scene)
638 {
639 #if ROS_VERSION_MINIMUM(1, 14, 0) // if ROS version >= ROS_MELODIC
640  ps_->loadGeometryFromStream(in, offset);
641 #else
642  ps_->loadGeometryFromStream(in, Eigen::Affine3d(offset));
643 #endif
644 
646  if (update_collision_scene) UpdateInternalFrames();
647 }
648 
649 std::string Scene::GetScene()
650 {
651  std::stringstream ss;
652  ps_->saveGeometryToStream(ss);
653  // TODO: include all custom environment scene objects
654  return ss.str();
655 }
656 
658 {
659  ps_->removeAllCollisionObjects();
660  // TODO: remove all custom environment scene objects
662 }
663 
664 void Scene::UpdateInternalFrames(bool update_request)
665 {
666  for (auto& it : custom_links_)
667  {
668  Eigen::Isometry3d pose;
669  tf::transformKDLToEigen(it->segment.getFrameToTip(), pose);
670  std::string shape_resource_path = it->shape_resource_path;
671  Eigen::Vector3d scale = it->scale;
672  it = kinematica_.AddElement(it->segment.getName(), pose, it->parent_name, it->shape, it->segment.getInertia(), it->color, it->visual, it->is_controlled);
673  it->shape_resource_path = shape_resource_path;
674  it->scale = scale;
675  }
676 
677  auto trajectory_generators_copy = trajectory_generators_;
678  trajectory_generators_.clear();
679  for (auto& traj : trajectory_generators_copy)
680  {
681  AddTrajectory(traj.first, traj.second.second);
682  }
683 
684  for (auto& link : attached_objects_)
685  {
686  AttachObjectLocal(link.first, link.second.parent, link.second.pose);
687  }
688 
690 
691  if (update_request)
692  {
695  }
696 
698 
699  request_needs_updating_ = false;
700 }
701 
703 {
705 
706  // Add world objects
707  std::map<std::string, int> visual_map;
708  for (const auto& object : *ps_->getWorld())
709  {
710  if (object.second->shapes_.size())
711  {
712  // Use the first collision shape as the origin of the object
713  Eigen::Isometry3d obj_transform;
714  obj_transform.translation() = object.second->shape_poses_[0].translation();
715  obj_transform.linear() = object.second->shape_poses_[0].rotation();
716  std::shared_ptr<KinematicElement> element = kinematica_.AddEnvironmentElement(object.first, obj_transform);
717  std::vector<VisualElement> visuals;
718  for (int i = 0; i < object.second->shape_poses_.size(); ++i)
719  {
720  Eigen::Isometry3d shape_transform;
721  shape_transform.translation() = object.second->shape_poses_[i].translation();
722  shape_transform.linear() = object.second->shape_poses_[i].rotation();
723  Eigen::Isometry3d trans = obj_transform.inverse() * shape_transform;
724  VisualElement visual;
725  std::string name = object.first;
726  // Check for name duplicates after loading from scene files
727  const auto& it = visual_map.find(name);
728  if (it != visual_map.end())
729  {
730  it->second++;
731  name = name + "_" + std::to_string(it->second);
732  }
733  else
734  {
735  visual_map[name] = 0;
736  }
737  visual.name = name;
738  visual.shape = shapes::ShapePtr(object.second->shapes_[i]->clone());
739  tf::transformEigenToKDL(trans, visual.frame);
740  if (ps_->hasObjectColor(object.first))
741  {
742  auto color_msg = ps_->getObjectColor(object.first);
743  visual.color = Eigen::Vector4d(color_msg.r, color_msg.g, color_msg.b, color_msg.a);
744  kinematica_.AddEnvironmentElement(object.first + "_collision_" + std::to_string(i), trans, object.first, object.second->shapes_[i], KDL::RigidBodyInertia::Zero(), visual.color);
745  }
746  else
747  {
748  kinematica_.AddEnvironmentElement(object.first + "_collision_" + std::to_string(i), trans, object.first, object.second->shapes_[i]);
749  }
750  if (visual.shape) visuals.push_back(visual);
751  }
752  element->visual = visuals;
753  }
754  else
755  {
756  HIGHLIGHT("Object with no shapes ('" << object.first << "')");
757  }
758  }
759 
760  // Add robot collision objects
761  ps_->getCurrentStateNonConst().update(true);
762 #if MOVEIT_VERSION_MAJOR >= 1 && MOVEIT_VERSION_MINOR >= 1
763  const std::vector<const robot_model::LinkModel*>& links = ps_->getCollisionEnv()->getRobotModel()->getLinkModelsWithCollisionGeometry();
764 #else
765  const std::vector<const robot_model::LinkModel*>& links = ps_->getCollisionRobot()->getRobotModel()->getLinkModelsWithCollisionGeometry();
766 #endif
767 
768  int last_controlled_joint_id = -1;
769  std::string last_controlled_joint_name = "";
773  for (int i = 0; i < links.size(); ++i)
774  {
775  // Check whether link is excluded from collision checking
777  {
778  continue;
779  }
780 
781  Eigen::Isometry3d obj_transform;
782  obj_transform.translation() = ps_->getCurrentState().getGlobalLinkTransform(links[i]).translation();
783  obj_transform.linear() = ps_->getCurrentState().getGlobalLinkTransform(links[i]).rotation();
784 
785  int joint_id = GetKinematicTree().IsControlledLink(links[i]->getName());
786  if (joint_id != -1)
787  {
788  if (last_controlled_joint_id != joint_id)
789  {
790  last_controlled_joint_name = GetKinematicTree().GetControlledJointNames()[joint_id];
791  last_controlled_joint_id = joint_id;
792  }
793  }
794 
795  for (int j = 0; j < links[i]->getShapes().size(); ++j)
796  {
797  // // Workaround for issue #172
798  // // To disable collisions with visual tags, we define a sphere of radius 0 which we will ignore here
799  // // This is in contrast to IHMC's convention where a sphere of radius 0 in the SDF is a desired contact point
800  // if (links[i]->getShapes()[j]->type == shapes::ShapeType::SPHERE)
801  // if (static_cast<const shapes::Sphere*>(links[i]->getShapes()[j].get())->radius == 0.0)
802  // continue;
803 
804  Eigen::Affine3d collisionBodyTransform_affine = ps_->getCurrentState().getCollisionBodyTransform(links[i], j);
805  Eigen::Isometry3d collisionBodyTransform;
806  collisionBodyTransform.translation() = collisionBodyTransform_affine.translation();
807  collisionBodyTransform.linear() = collisionBodyTransform_affine.rotation();
808  Eigen::Isometry3d trans = obj_transform.inverse(Eigen::Isometry) * collisionBodyTransform;
809 
810  std::string collision_element_name = links[i]->getName() + "_collision_" + std::to_string(j);
811  std::shared_ptr<KinematicElement> element = kinematica_.AddElement(collision_element_name, trans, links[i]->getName(), links[i]->getShapes()[j]);
812  model_link_to_collision_element_map_[links[i]->getName()].push_back(element);
813 
814  // Set up mappings
815  model_link_to_collision_link_map_[links[i]->getName()].push_back(collision_element_name);
816 
817  if (last_controlled_joint_name != "")
818  {
819  controlled_joint_to_collision_link_map_[last_controlled_joint_name].push_back(collision_element_name);
820  }
821  }
822  }
823 
825 
827 }
828 
829 void Scene::AddObject(const std::string& name, const KDL::Frame& transform, const std::string& parent, shapes::ShapeConstPtr shape, const KDL::RigidBodyInertia& inertia, const Eigen::Vector4d& color, bool update_collision_scene)
830 {
831  if (kinematica_.DoesLinkWithNameExist(name)) ThrowPretty("Link '" << name << "' already exists in the scene!");
832  std::string parent_name = (parent == "") ? kinematica_.GetRootFrameName() : parent;
833  if (!kinematica_.DoesLinkWithNameExist(parent_name)) ThrowPretty("Can't find parent '" << parent_name << "'!");
834  Eigen::Isometry3d pose;
836  custom_links_.push_back(kinematica_.AddElement(name, pose, parent_name, shape, inertia, color));
837  if (update_collision_scene) UpdateCollisionObjects();
838 }
839 
840 void Scene::AddObject(const std::string& name, const KDL::Frame& transform, const std::string& parent, const std::string& shape_resource_path, const Eigen::Vector3d& scale, const KDL::RigidBodyInertia& inertia, const Eigen::Vector4d& color, bool update_collision_scene)
841 {
842  if (kinematica_.DoesLinkWithNameExist(name)) ThrowPretty("Link '" << name << "' already exists in the scene!");
843  std::string parent_name = (parent == "") ? kinematica_.GetRootFrameName() : parent;
844  if (!kinematica_.DoesLinkWithNameExist(parent_name)) ThrowPretty("Can't find parent '" << parent_name << "'!");
845  Eigen::Isometry3d pose;
847  custom_links_.push_back(kinematica_.AddElement(name, pose, parent_name, shape_resource_path, scale, inertia, color));
850  if (update_collision_scene) UpdateCollisionObjects();
851 }
852 
853 void Scene::AddObjectToEnvironment(const std::string& name, const KDL::Frame& transform, shapes::ShapeConstPtr shape, const Eigen::Vector4d& color, const bool update_collision_scene)
854 {
856  {
857  throw std::runtime_error("link '" + name + "' already exists in kinematic tree");
858  }
859  Eigen::Isometry3d pose;
861  ps_->getWorldNonConst()->addToObject(name, shape, pose);
862  ps_->setObjectColor(name, GetColor(color));
864  if (update_collision_scene) UpdateInternalFrames();
865 }
866 
867 void Scene::RemoveObject(const std::string& name)
868 {
869  auto it = std::begin(custom_links_);
870  while (it != std::end(custom_links_))
871  {
872  if ((*it)->segment.getName() == name)
873  {
874  custom_links_.erase(it);
877  return;
878  }
879  else
880  {
881  ++it;
882  }
883  }
884  ThrowPretty("Link " << name << " not removed as it cannot be found.");
885 }
886 
887 void Scene::AttachObject(const std::string& name, const std::string& parent)
888 {
889  kinematica_.ChangeParent(name, parent, KDL::Frame::Identity(), false);
891 }
892 
893 void Scene::AttachObjectLocal(const std::string& name, const std::string& parent, const KDL::Frame& pose)
894 {
895  kinematica_.ChangeParent(name, parent, pose, true);
896  attached_objects_[name] = AttachedObject(parent, pose);
897 }
898 
899 void Scene::AttachObjectLocal(const std::string& name, const std::string& parent, const Eigen::VectorXd& pose)
900 {
901  AttachObjectLocal(name, parent, GetFrame(pose));
902 }
903 
904 void Scene::DetachObject(const std::string& name)
905 {
906  if (!HasAttachedObject(name)) ThrowPretty("'" << name << "' is not attached to the robot!");
907  auto object = attached_objects_.find(name);
908  kinematica_.ChangeParent(name, "", KDL::Frame::Identity(), false);
909  attached_objects_.erase(object);
910 }
911 
912 bool Scene::HasAttachedObject(const std::string& name)
913 {
914  return attached_objects_.find(name) != attached_objects_.end();
915 }
916 
917 void Scene::AddTrajectoryFromFile(const std::string& link, const std::string& traj)
918 {
919  AddTrajectory(link, LoadFile(traj));
920 }
921 
922 void Scene::AddTrajectory(const std::string& link, const std::string& traj)
923 {
924  AddTrajectory(link, std::shared_ptr<Trajectory>(new Trajectory(traj)));
925 }
926 
927 void Scene::AddTrajectory(const std::string& link, std::shared_ptr<Trajectory> traj)
928 {
929  const auto& tree = kinematica_.GetTreeMap();
930  const auto& it = tree.find(link);
931  if (it == tree.end()) ThrowPretty("Can't find link '" << link << "'!");
932  if (traj->GetDuration() == 0.0) ThrowPretty("The trajectory is empty!");
933  trajectory_generators_[link] = std::pair<std::weak_ptr<KinematicElement>, std::shared_ptr<Trajectory>>(it->second, traj);
934  it->second.lock()->is_trajectory_generated = true;
935 }
936 
937 std::shared_ptr<Trajectory> Scene::GetTrajectory(const std::string& link)
938 {
939  const auto& it = trajectory_generators_.find(link);
940  if (it == trajectory_generators_.end()) ThrowPretty("No trajectory generator defined for link '" << link << "'!");
941  return it->second.second;
942 }
943 
944 void Scene::RemoveTrajectory(const std::string& link)
945 {
946  const auto& it = trajectory_generators_.find(link);
947  if (it == trajectory_generators_.end()) ThrowPretty("No trajectory generator defined for link '" << link << "'!");
948  it->second.first.lock()->is_trajectory_generated = false;
949  trajectory_generators_.erase(it);
950 }
951 
953 {
954  return num_positions_;
955 }
956 
958 {
959  return num_velocities_;
960 }
961 
963 {
964  return num_controls_;
965 }
966 
968 {
969  return num_state_;
970 }
971 
973 {
974  return num_state_derivative_;
975 }
976 
978 {
980 }
981 
982 } // namespace exotica
exotica::Scene::world_links_to_exclude_from_collision_scene_
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
exotica::Scene::robot_links_to_exclude_from_collision_scene_
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
exotica::KinematicTree::RequestFrames
std::shared_ptr< KinematicResponse > RequestFrames(const KinematicsRequest &request)
Definition: kinematic_tree.cpp:628
shapes::ShapeMsg
boost::variant< shape_msgs::SolidPrimitive, shape_msgs::Mesh, shape_msgs::Plane > ShapeMsg
exotica::Object::InstantiateObject
void InstantiateObject(const Initializer &init)
Definition: object.h:71
exotica::Scene::GetName
const std::string & GetName() const
Definition: scene.cpp:64
exotica::Object::type
virtual std::string type() const
Type Information wrapper: must be virtual so that it is polymorphic...
Definition: object.h:61
exotica::Scene::GetRootJointName
std::string GetRootJointName()
Definition: scene.cpp:468
exotica::KinematicTree::Update
void Update(Eigen::VectorXdRefConst x)
Definition: kinematic_tree.cpp:678
exotica::Scene::Update
void Update(Eigen::VectorXdRefConst x, double t=0)
Definition: scene.cpp:337
exotica::GetFrame
KDL::Frame GetFrame(Eigen::VectorXdRefConst val)
Definition: conversions.cpp:52
exotica::Scene::DetachObject
void DetachObject(const std::string &name)
Detaches an object and leaves it a at its current world location. This effectively attaches the objec...
Definition: scene.cpp:904
exotica::KinematicTree::GetRootFrameName
const std::string & GetRootFrameName() const
Definition: kinematic_tree.cpp:1299
exotica::Instantiable< SceneInitializer >::parameters_
SceneInitializer parameters_
Definition: property.h:139
exotica::Scene::GetDynamicsSolver
std::shared_ptr< DynamicsSolver > GetDynamicsSolver() const
Returns a pointer to the CollisionScene.
Definition: scene.cpp:458
exotica::Scene::num_controls_
int num_controls_
"nu"
Definition: scene.h:205
exotica::Scene::get_num_positions
int get_num_positions() const
Definition: scene.cpp:952
exotica::Scene::GetTrajectory
std::shared_ptr< Trajectory > GetTrajectory(const std::string &link)
Definition: scene.cpp:937
exotica::KinematicTree::DoesLinkWithNameExist
bool DoesLinkWithNameExist(std::string name) const
Checks whether a link with this name exists in any of the trees.
Definition: kinematic_tree.cpp:1461
tf::pointKDLToMsg
void pointKDLToMsg(const KDL::Vector &k, geometry_msgs::Point &m)
exotica::Scene::GetModelState
Eigen::VectorXd GetModelState()
Definition: scene.cpp:560
exotica::KinematicTree::IsControlledLink
int IsControlledLink(const std::string &link_name)
Definition: kinematic_tree.cpp:600
exotica::Scene::get_num_state_derivative
int get_num_state_derivative() const
Definition: scene.cpp:972
exotica::Scene::proxy_pub_
ros::Publisher proxy_pub_
Definition: scene.h:214
exotica::Scene::AttachObject
void AttachObject(const std::string &name, const std::string &parent)
Attaches existing object to a new parent. E.g. attaching a grasping target to the end-effector....
Definition: scene.cpp:887
exotica::Setup::CreateDynamicsSolver
static std::shared_ptr< exotica::DynamicsSolver > CreateDynamicsSolver(const std::string &type, bool prepend=true)
Definition: setup.h:68
exotica::AttachedObject
Definition: scene.h:53
exotica::Scene::controlled_joint_to_collision_link_map_
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
exotica::Scene::ps_pub_
ros::Publisher ps_pub_
Visual debug.
Definition: scene.h:213
exotica::KinematicTree::SetJointAccelerationLimits
void SetJointAccelerationLimits(Eigen::VectorXdRefConst acceleration_in)
Definition: kinematic_tree.cpp:1093
exotica::Scene::GetPlanningSceneMsg
moveit_msgs::PlanningScene GetPlanningSceneMsg()
Returns the current robot configuration and collision environment as a moveit_msgs::PlanningScene.
Definition: scene.cpp:473
exotica::Scene::UpdatePlanningScene
void UpdatePlanningScene(const moveit_msgs::PlanningScene &scene)
Update the collision scene from a moveit_msgs::PlanningScene.
Definition: scene.cpp:433
exotica::Scene::GetModelStateMap
std::map< std::string, double > GetModelStateMap()
Definition: scene.cpp:565
exotica::GetColor
std_msgs::ColorRGBA GetColor(double r, double g, double b, double a=1.0)
Definition: tools.h:69
exotica::VisualElement::name
EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::string name
Definition: kinematic_element.h:46
exotica::Scene::get_has_quaternion_floating_base
bool get_has_quaternion_floating_base() const
Definition: scene.cpp:977
exotica::Scene::AttachObjectLocal
void AttachObjectLocal(const std::string &name, const std::string &parent, const KDL::Frame &pose)
Attaches existing object to a new parent specifying an offset in the new parent local frame.
Definition: scene.cpp:893
planning_scene::PlanningScene
getName
ROSCONSOLE_CONSOLE_IMPL_DECL std::string getName(void *handle)
exotica::Scene::GetTreeMap
std::map< std::string, std::weak_ptr< KinematicElement > > GetTreeMap()
Definition: scene.cpp:570
mesh_operations.h
exotica::Scene::UpdateSceneFrames
void UpdateSceneFrames()
Updates exotica scene object frames from the MoveIt scene.
Definition: scene.cpp:702
exotica::KinematicTree::UpdateModel
void UpdateModel()
Definition: kinematic_tree.cpp:423
exotica::Scene::kinematic_request_
KinematicsRequest kinematic_request_
Definition: scene.h:240
exotica::KinematicTree::ChangeParent
void ChangeParent(const std::string &name, const std::string &parent, const KDL::Frame &pose, bool relative)
Definition: kinematic_tree.cpp:454
exotica::Server::Instance
static std::shared_ptr< Server > Instance()
Get the server.
Definition: server.h:65
INFO_NAMED
#define INFO_NAMED(name, x)
Definition: printable.h:64
shapes::Cylinder
exotica::KinematicTree::GetNumControlledJoints
int GetNumControlledJoints() const
Definition: kinematic_tree.cpp:91
shape_operations.h
exotica::Scene::collision_scene_
CollisionScenePtr collision_scene_
The collision scene.
Definition: scene.h:198
exotica::Scene::num_positions_
int num_positions_
"nq"
Definition: scene.h:203
exotica::Scene::GetModelLinkNames
std::vector< std::string > GetModelLinkNames()
Definition: scene.cpp:550
exotica::Scene::trajectory_generators_
std::map< std::string, std::pair< std::weak_ptr< KinematicElement >, std::shared_ptr< Trajectory > > > trajectory_generators_
Definition: scene.h:223
exotica::Object::object_name_
std::string object_name_
Definition: object.h:85
exotica::Scene::GetControlledLinkNames
std::vector< std::string > GetControlledLinkNames()
Definition: scene.cpp:545
exotica::Scene::model_link_to_collision_link_map_
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
exotica::KinematicTree::GetTreeMap
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetTreeMap() const
Definition: kinematic_tree.h:233
exotica::KinematicTree::HasModelLink
bool HasModelLink(const std::string &link) const
Definition: kinematic_tree.cpp:1436
generate_initializers.offset
int offset
Definition: generate_initializers.py:636
exotica::Scene::GetKinematicTree
exotica::KinematicTree & GetKinematicTree()
Definition: scene.cpp:535
shapes::Shape
transform
template Halfspace< double > transform(const Halfspace< double > &a, const Transform3< double > &tf)
exotica::Scene::num_state_
int num_state_
"nx"
Definition: scene.h:206
exotica::Scene::attached_objects_
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
exotica
Definition: collision_scene.h:46
exotica::FLOATING
@ FLOATING
Definition: kinematic_tree.h:52
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
exotica::Scene::GetCollisionScene
const CollisionScenePtr & GetCollisionScene() const
Returns a pointer to the CollisionScene.
Definition: scene.cpp:452
exotica::Scene::request_needs_updating_
bool request_needs_updating_
Definition: scene.h:243
exotica::KinematicTree::GetModelJointNames
const std::vector< std::string > & GetModelJointNames() const
Definition: kinematic_tree.h:181
exotica::Object::ns_
std::string ns_
Definition: object.h:84
exotica::Scene::kinematic_request_callback_
std::function< void(std::shared_ptr< KinematicResponse >)> kinematic_request_callback_
Definition: scene.h:242
exotica::Scene::UpdateInternalFrames
void UpdateInternalFrames(bool update_request=true)
Definition: scene.cpp:664
exotica::Scene::GetControlledState
Eigen::VectorXd GetControlledState()
Definition: scene.cpp:605
exotica::KinematicTree::GetCollisionTreeMap
const std::map< std::string, std::weak_ptr< KinematicElement > > & GetCollisionTreeMap() const
Definition: kinematic_tree.h:234
exotica::Scene::get_num_state
int get_num_state() const
Definition: scene.cpp:967
exotica::KinematicTree::GetModelLinkNames
const std::vector< std::string > & GetModelLinkNames() const
Definition: kinematic_tree.h:186
exotica::Scene::model_link_to_collision_element_map_
std::map< std::string, std::vector< std::shared_ptr< KinematicElement > > > model_link_to_collision_element_map_
Definition: scene.h:229
exotica::Scene::HasAttachedObject
bool HasAttachedObject(const std::string &name)
Definition: scene.cpp:912
exotica::KinematicTree::ResetModel
void ResetModel()
Definition: kinematic_tree.cpp:436
exotica::Scene::RemoveTrajectory
void RemoveTrajectory(const std::string &link)
Definition: scene.cpp:944
HIGHLIGHT_NAMED
#define HIGHLIGHT_NAMED(name, x)
Definition: printable.h:62
exotica::Scene::AddObjectToEnvironment
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)
Definition: scene.cpp:853
exotica::KinematicTree::GetRootJointName
const std::string & GetRootJointName() const
Definition: kinematic_tree.cpp:1304
shapes::ShapePtr
std::shared_ptr< Shape > ShapePtr
scene.h
exotica::Scene::RequestKinematics
void RequestKinematics(KinematicsRequest &request, std::function< void(std::shared_ptr< KinematicResponse >)> callback)
Definition: scene.cpp:320
shapes::Box
name
std::string name
exotica::LoadFile
std::string LoadFile(const std::string &path)
Definition: tools.cpp:189
shapes::Sphere
collision_detection::AllowedCollision::Type
Type
exotica::KinematicTree::SetJointLimitsLower
void SetJointLimitsLower(Eigen::VectorXdRefConst lower_in)
Definition: kinematic_tree.cpp:1035
Eigen::VectorXdRefConst
const typedef Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
Definition: conversions.h:53
HIGHLIGHT
#define HIGHLIGHT(x)
Definition: printable.h:61
exotica::KinematicTree::debug
bool debug
Definition: kinematic_tree.h:251
exotica::KinematicTree::AddEnvironmentElement
std::shared_ptr< KinematicElement > AddEnvironmentElement(const std::string &name, const Eigen::Isometry3d &transform, 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 std::vector< VisualElement > &visual={}, bool is_controlled=false)
Definition: kinematic_tree.cpp:502
exotica::Scene::num_velocities_
int num_velocities_
"nv"
Definition: scene.h:204
tf::transformEigenToKDL
void transformEigenToKDL(const Eigen::Affine3d &e, KDL::Frame &k)
exotica::Setup::CreateCollisionScene
static std::shared_ptr< exotica::CollisionScene > CreateCollisionScene(const std::string &type, bool prepend=true)
Definition: setup.h:67
exotica::Scene::GetScene
std::string GetScene()
Definition: scene.cpp:649
exotica::Scene::has_quaternion_floating_base_
bool has_quaternion_floating_base_
Whether the state includes a SE(3) floating base.
Definition: scene.h:185
exotica::Scene::UpdateTrajectoryGenerators
void UpdateTrajectoryGenerators(double t=0)
Definition: scene.cpp:329
exotica::Scene::CleanScene
void CleanScene()
Definition: scene.cpp:657
kdl_msg.h
exotica::Scene::Instantiate
virtual void Instantiate(const SceneInitializer &init)
Definition: scene.cpp:69
exotica::Scene::AddTrajectory
void AddTrajectory(const std::string &link, const std::string &traj)
Definition: scene.cpp:922
exotica::Scene::LoadSceneFromStringStream
void LoadSceneFromStringStream(std::istream &in, const Eigen::Isometry3d &offset, bool update_collision_scene)
Definition: scene.cpp:637
exotica::KinematicTree::GetControlledState
Eigen::VectorXd GetControlledState() const
Definition: kinematic_tree.cpp:1426
shapes::createMeshFromResource
Mesh * createMeshFromResource(const std::string &resource)
exotica::Scene::UpdateCollisionObjects
void UpdateCollisionObjects()
Definition: scene.cpp:447
exotica::Object::debug_
bool debug_
Definition: object.h:86
exotica::Scene::~Scene
virtual ~Scene()
exotica::Initializer
Definition: property.h:70
exotica::Trajectory
Definition: trajectory.h:40
exotica::KinematicTree::GetControlledLinkNames
const std::vector< std::string > & GetControlledLinkNames() const
Definition: kinematic_tree.h:176
exotica::Scene::ps_
planning_scene::PlanningScenePtr ps_
Internal MoveIt planning scene.
Definition: scene.h:210
exotica::Scene::GetControlledJointNames
std::vector< std::string > GetControlledJointNames()
Definition: scene.cpp:540
exotica::Scene::PublishScene
void PublishScene()
Definition: scene.cpp:381
exotica::ParsePath
std::string ParsePath(const std::string &path)
Definition: tools.cpp:150
exotica::AllowedCollisionMatrix::setEntry
void setEntry(const std::string &name1, const std::string &name2)
Definition: collision_scene.h:70
exotica::CollisionScenePtr
std::shared_ptr< CollisionScene > CollisionScenePtr
Definition: collision_scene.h:345
exotica::Scene::GetRootFrameName
std::string GetRootFrameName()
Definition: scene.cpp:463
exotica::KinematicTree::GetModelState
Eigen::VectorXd GetModelState() const
Definition: kinematic_tree.cpp:1309
exotica::VisualElement
Definition: kinematic_element.h:41
exotica::Scene::get_num_velocities
int get_num_velocities() const
Definition: scene.cpp:957
exotica::Scene::SetModelState
void SetModelState(Eigen::VectorXdRefConst x, double t=0, bool update_traj=true)
Definition: scene.cpp:575
exotica::KinematicTree
Definition: kinematic_tree.h:142
exotica::Server::SetParam
static void SetParam(const std::string &name, T &param)
Definition: server.h:110
exotica::Scene::get_num_controls
int get_num_controls() const
Definition: scene.cpp:962
shapes::constructMsgFromShape
bool constructMsgFromShape(const Shape *shape, ShapeMsg &shape_msg)
exotica::KinematicTree::GetModelBaseType
BaseType GetModelBaseType() const
Definition: kinematic_tree.cpp:1000
exotica::KinematicTree::GetModelStateMap
std::map< std::string, double > GetModelStateMap() const
Definition: kinematic_tree.cpp:1320
exotica::KinematicTree::GetControlledJointNames
const std::vector< std::string > & GetControlledJointNames() const
Definition: kinematic_tree.h:171
exotica::KinematicTree::SetJointVelocityLimits
void SetJointVelocityLimits(Eigen::VectorXdRefConst velocity_in)
Definition: kinematic_tree.cpp:1069
exotica::Scene::LoadSceneFile
void LoadSceneFile(const std::string &file_name, const Eigen::Isometry3d &offset=Eigen::Isometry3d::Identity(), bool update_collision_scene=true)
Definition: scene.cpp:630
exotica::Scene::GetModelJointNames
std::vector< std::string > GetModelJointNames()
Definition: scene.cpp:555
exotica::Scene::UpdateMoveItPlanningScene
void UpdateMoveItPlanningScene()
Updates the internal state of the MoveIt PlanningScene from Kinematica.
Definition: scene.cpp:350
exotica::Scene::PublishProxies
void PublishProxies(const std::vector< CollisionProxy > &proxies)
Definition: scene.cpp:389
setup.h
shapes::constructShapeFromMsg
Shape * constructShapeFromMsg(const shape_msgs::Mesh &shape_msg)
exotica::Scene::LoadScene
void LoadScene(const std::string &scene, const Eigen::Isometry3d &offset=Eigen::Isometry3d::Identity(), bool update_collision_scene=true)
Definition: scene.cpp:617
exotica::Scene::AddTrajectoryFromFile
void AddTrajectoryFromFile(const std::string &link, const std::string &traj)
Definition: scene.cpp:917
exotica::Scene::AddObject
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)
Definition: scene.cpp:829
ThrowPretty
#define ThrowPretty(m)
Definition: exception.h:36
tf::transformKDLToEigen
void transformKDLToEigen(const KDL::Frame &k, Eigen::Affine3d &e)
exotica::Scene::RemoveObject
void RemoveObject(const std::string &name)
Definition: scene.cpp:867
exotica::KinematicTree::AddElement
std::shared_ptr< KinematicElement > AddElement(const std::string &name, const Eigen::Isometry3d &transform, 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 std::vector< VisualElement > &visual={}, bool is_controlled=false)
Definition: kinematic_tree.cpp:537
exotica::Scene::ProxyToMarker
visualization_msgs::Marker ProxyToMarker(const std::vector< CollisionProxy > &proxies, const std::string &frame)
Definition: scene.cpp:397
exotica::LoadOctreeAsShape
std::shared_ptr< shapes::Shape > LoadOctreeAsShape(const std::string &file_path)
Definition: tools.cpp:131
exotica::KinematicsRequest
Definition: kinematic_tree.h:93
exotica::VisualElement::frame
KDL::Frame frame
Definition: kinematic_element.h:49
exotica::VisualElement::shape
shapes::ShapePtr shape
Definition: kinematic_element.h:47
init
void init(const M_string &remappings)
shapes::ShapeConstPtr
std::shared_ptr< const Shape > ShapeConstPtr
exotica::Scene::custom_links_
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
x
double x
exotica::Scene::num_state_derivative_
int num_state_derivative_
"ndx"
Definition: scene.h:207
eigen_kdl.h
exotica::PathExists
bool PathExists(const std::string &path)
Definition: tools.cpp:204
exotica::Scene::UpdatePlanningSceneWorld
void UpdatePlanningSceneWorld(const moveit_msgs::PlanningSceneWorldConstPtr &world)
Update the collision scene from a moveit_msgs::PlanningSceneWorld.
Definition: scene.cpp:440
exotica::KinematicTree::SetModelState
void SetModelState(Eigen::VectorXdRefConst x)
Definition: kinematic_tree.cpp:1385
server.h
exotica::Scene::Scene
Scene()
exotica::Scene::kinematic_solution_
std::shared_ptr< KinematicResponse > kinematic_solution_
Definition: scene.h:241
exotica::KinematicTree::GetNumModelJoints
int GetNumModelJoints() const
Definition: kinematic_tree.cpp:96
exotica::KinematicTree::Instantiate
void Instantiate(const std::string &joint_group, robot_model::RobotModelPtr model, const std::string &name)
Definition: kinematic_tree.cpp:101
exotica::Server::IsRos
static bool IsRos()
Definition: server.h:96
dynamics_solver.h
exotica::Scene::kinematica_
exotica::KinematicTree kinematica_
The kinematica tree.
Definition: scene.h:195
exotica::Scene::force_collision_
bool force_collision_
Definition: scene.h:225
t
geometry_msgs::TransformStamped t
exotica::KinematicTree::SetJointLimitsUpper
void SetJointLimitsUpper(Eigen::VectorXdRefConst upper_in)
Definition: kinematic_tree.cpp:1052
exotica::AllowedCollisionMatrix
The AllowedCollisionMatrix is a data structure containing links for which a detected collision does n...
Definition: collision_scene.h:54
exotica::Scene::dynamics_solver_
std::shared_ptr< DynamicsSolver > dynamics_solver_
The dynamics solver.
Definition: scene.h:201
exotica::ParseList
std::vector< std::string > ParseList(const std::string &value, char token=',')
Definition: conversions.h:337
exotica::VisualElement::color
Eigen::Vector4d color
Definition: kinematic_element.h:51


exotica_core
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Fri Aug 2 2024 08:43:02