Ignition Gazebo

API Reference

Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
20 #include <string>
21 #include <unordered_set>
22 #include <vector>
24 #include <ignition/math/Pose3.hh>
25 #include "ignition/gazebo/config.hh"
28 #include "ignition/gazebo/Export.hh"
29 #include "ignition/gazebo/Types.hh"
31 namespace ignition
32 {
33  namespace gazebo
34  {
35  // Inline bracket to help doxygen filtering.
37  //
42  math::Pose3d IGNITION_GAZEBO_VISIBLE worldPose(const Entity &_entity,
43  const EntityComponentManager &_ecm);
51  std::string IGNITION_GAZEBO_VISIBLE scopedName(const Entity &_entity,
52  const EntityComponentManager &_ecm, const std::string &_delim = "/",
53  bool _includePrefix = true);
78  std::unordered_set<Entity> IGNITION_GAZEBO_VISIBLE entitiesFromScopedName(
79  const std::string &_scopedName, const EntityComponentManager &_ecm,
80  Entity _relativeTo = kNullEntity,
81  const std::string &_delim = "::");
103  ComponentTypeId IGNITION_GAZEBO_VISIBLE entityTypeId(const Entity &_entity,
104  const EntityComponentManager &_ecm);
123  std::string IGNITION_GAZEBO_VISIBLE entityTypeStr(const Entity &_entity,
124  const EntityComponentManager &_ecm);
130  Entity IGNITION_GAZEBO_VISIBLE worldEntity(const Entity &_entity,
131  const EntityComponentManager &_ecm);
136  Entity IGNITION_GAZEBO_VISIBLE worldEntity(
137  const EntityComponentManager &_ecm);
144  std::string IGNITION_GAZEBO_VISIBLE removeParentScope(
145  const std::string &_name, const std::string &_delim);
155  std::string IGNITION_GAZEBO_VISIBLE asFullPath(const std::string &_uri,
156  const std::string &_filePath);
160  std::vector<std::string> IGNITION_GAZEBO_VISIBLE resourcePaths();
166  void IGNITION_GAZEBO_VISIBLE addResourcePaths(
167  const std::vector<std::string> &_paths = {});
174  ignition::gazebo::Entity IGNITION_GAZEBO_VISIBLE topLevelModel(
175  const Entity &_entity,
176  const EntityComponentManager &_ecm);
190  std::string IGNITION_GAZEBO_VISIBLE validTopic(
191  const std::vector<std::string> &_topics);
208  std::string IGNITION_GAZEBO_VISIBLE topicFromScopedName(
209  const Entity &_entity,
210  const EntityComponentManager &_ecm,
211  bool _excludeWorld = true);
221  template <class ComponentType>
223  Entity _entity, bool _enable = true)
224  {
225  bool changed{false};
227  auto exists = _ecm.Component<ComponentType>(_entity);
228  if (_enable && !exists)
229  {
230  _ecm.CreateComponent(_entity, ComponentType());
231  changed = true;
232  }
233  else if (!_enable && exists)
234  {
235  _ecm.RemoveComponent<ComponentType>(_entity);
236  changed = true;
237  }
238  return changed;
239  }
247  std::optional<math::Vector3d> IGNITION_GAZEBO_VISIBLE sphericalCoordinates(
248  Entity _entity, const EntityComponentManager &_ecm);
251  const std::string kResourcePathEnv{"IGN_GAZEBO_RESOURCE_PATH"};
255  const std::string kSdfPathEnv{"SDF_PATH"};
258  const std::string kServerConfigPathEnv{"IGN_GAZEBO_SERVER_CONFIG_PATH"};
262  const std::string kRenderPluginPathEnv{"IGN_GAZEBO_RENDER_ENGINE_PATH"};
264  }
265  }
266 }
267 #endif
std::string removeParentScope(const std::string &_name, const std::string &_delim)
Helper function to remove a parent scope from a given name. This removes the first name found before ...
std::string asFullPath(const std::string &_uri, const std::string &_filePath)
Combine a URI and a file path into a full path. If the URI is already a full path or contains a schem...
bool enableComponent(EntityComponentManager &_ecm, Entity _entity, bool _enable=true)
Helper function to "enable" a component (i.e. create it if it doesn&#39;t exist) or "disable" a component...
Definition: Util.hh:222
const ComponentTypeT * Component(const Entity _entity) const
Get a component assigned to an entity based on a component type.
std::string topicFromScopedName(const Entity &_entity, const EntityComponentManager &_ecm, bool _excludeWorld=true)
Helper function that returns a valid Ignition Transport topic consisting of the scoped name for the p...
std::vector< std::string > resourcePaths()
Get resource paths based on latest environment variables.
const std::string kRenderPluginPathEnv
Environment variable holding paths to custom rendering engine plugins.
Definition: Util.hh:262
std::unordered_set< Entity > entitiesFromScopedName(const std::string &_scopedName, const EntityComponentManager &_ecm, Entity _relativeTo=kNullEntity, const std::string &_delim="::")
Helper function to get an entity given its scoped name. The scope may start at any level by default...
ComponentTypeId entityTypeId(const Entity &_entity, const EntityComponentManager &_ecm)
Generally, each entity will be of some specific high-level type, such as World, Sensor, Collision, etc, and one type only. The entity type is usually marked by having some component that represents that type, such as components::Visual.
const std::string kServerConfigPathEnv
Environment variable holding server config paths.
Definition: Util.hh:258
ComponentTypeT * CreateComponent(const Entity _entity, const ComponentTypeT &_data)
Create a component of a particular type. This will copy the _data parameter.
STL class.
std::string entityTypeStr(const Entity &_entity, const EntityComponentManager &_ecm)
Generally, each entity will be of some specific high-level type, such as "world", "sensor"...
The EntityComponentManager constructs, deletes, and returns components and entities. A component can be of any class which inherits from components::BaseComponent.
Definition: EntityComponentManager.hh:66
Pose3< double > Pose3d
std::string scopedName(const Entity &_entity, const EntityComponentManager &_ecm, const std::string &_delim="/", bool _includePrefix=true)
Helper function to generate scoped name for an entity.
math::Pose3d worldPose(const Entity &_entity, const EntityComponentManager &_ecm)
Helper function to compute world pose of an entity.
uint64_t ComponentTypeId
A unique identifier for a component type. A component type must be derived from components::BaseCompo...
Definition: Types.hh:90
bool RemoveComponent(const Entity _entity, const ComponentKey &_key)
Remove a component from an entity based on a key.
const Entity kNullEntity
Indicates a non-existant or invalid Entity.
Definition: Entity.hh:62
STL class.
std::optional< math::Vector3d > sphericalCoordinates(Entity _entity, const EntityComponentManager &_ecm)
Get the spherical coordinates for an entity.
Entity worldEntity(const Entity &_entity, const EntityComponentManager &_ecm)
Get the world to which the given entity belongs.
std::string validTopic(const std::vector< std::string > &_topics)
Helper function to generate a valid transport topic, given a list of topics ordered by preference...
bool exists(const std::string &_path)
Entity topLevelModel(const Entity &_entity, const EntityComponentManager &_ecm)
Get the top level model of an entity.
const std::string kResourcePathEnv
Environment variable holding resource paths.
Definition: Util.hh:251
const std::string kSdfPathEnv
Environment variable used by SDFormat to find URIs inside <include>
Definition: Util.hh:255
This library is part of the Ignition Robotics project.
uint64_t Entity
An Entity identifies a single object in simulation such as a model, link, or light. At its core, an Entity is just an identifier.
Definition: Entity.hh:59
void addResourcePaths(const std::vector< std::string > &_paths={})
Add resource paths based on latest environment variables. This will update the SDF and Ignition envir...