##

Population.hh
Go to the documentation of this file.
/*
* Copyright (C) 2014 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_PHYSICS_POPULATION_HH_
#define GAZEBO_PHYSICS_POPULATION_HH_
#include <string>
#include <vector>
#include <ignition/math/Pose3.hh>
#include <ignition/math/Vector3.hh>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <sdf/sdf.hh>
#include "gazebo/common/Console.hh"
#include "gazebo/physics/World.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace physics
{
class PopulationPrivate;
class GZ_PHYSICS_VISIBLE PopulationParams
{
public: ignition::math::Vector3d size;
public: int rows;
public: int cols;
public: ignition::math::Vector3d step;
public: ignition::math::Pose3d pose;
public: double radius;
public: double length;
public: std::string modelName;
public: std::string modelSdf;
public: int modelCount;
public: std::string distribution;
public: std::string region;
};
class GZ_PHYSICS_VISIBLE Population
{
public: Population(sdf::ElementPtr _sdf, boost::shared_ptr<World> _world);
public: virtual ~Population();
public: bool PopulateAll();
private: bool PopulateOne(const sdf::ElementPtr _population);
private: template<typename T> bool ValueFromSdf(
const sdf::ElementPtr &_sdfElement, const std::string &_element,
T &_value)
{
if (_sdfElement->HasElement(_element))
{
_value = _sdfElement->Get<T>(_element);
return true;
}
gzerr << "Unable to find <" << _element << "> inside the population tag"
<< std::endl;
return false;
}
private: bool ElementFromSdf(const sdf::ElementPtr &_sdfElement,
const std::string &_element, sdf::ElementPtr &_value);
private: bool ParseSdf(sdf::ElementPtr _population,
PopulationParams &_params);
private: void CreatePosesBoxRandom(const PopulationParams &_populParams,
std::vector<ignition::math::Vector3d> &_poses);
private: void CreatePosesBoxUniform(const PopulationParams &_populParams,
std::vector<ignition::math::Vector3d> &_poses);
private: void CreatePosesBoxGrid(const PopulationParams &_populParams,
std::vector<ignition::math::Vector3d> &_poses);
private: void CreatePosesBoxLinearX(const PopulationParams &_populParams,
std::vector<ignition::math::Vector3d> &_poses);
private: void CreatePosesBoxLinearY(const PopulationParams &_populParams,
std::vector<ignition::math::Vector3d> &_poses);
private: void CreatePosesBoxLinearZ(const PopulationParams &_populParams,
std::vector<ignition::math::Vector3d> &_poses);
private: void CreatePosesCylinderRandom(
const PopulationParams &_populParams,
std::vector<ignition::math::Vector3d> &_poses);
private: void CreatePosesCylinderUniform(
const PopulationParams &_populParams,
std::vector<ignition::math::Vector3d> &_poses);
private: boost::scoped_ptr<PopulationPrivate> dataPtr;
};
}
}
#endif
gazebo::physics::PopulationParams::length
double length
Length of the cylinder containing the models.
Definition: Population.hh:63
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::physics::PopulationParams::cols
int cols
Number of columns used when models are distributed as a grid.
Definition: Population.hh:51
gazebo::physics::PopulationParams::modelCount
int modelCount
Number of models to spawn.
Definition: Population.hh:72
World.hh
gazebo::physics::PopulationParams::step
ignition::math::Vector3d step
Distance between models when they are distributed as a grid.
Definition: Population.hh:54
gazebo::physics::PopulationParams::distribution
std::string distribution
Object distribution. E.g.: random, grid.
Definition: Population.hh:75
Console.hh
system.hh
gazebo::physics::Population::~Population
virtual ~Population()
Destructor.
gazebo::physics::Population::Population
Population(sdf::ElementPtr _sdf, boost::shared_ptr< World > _world)
Constructor.
gazebo::physics::PopulationParams::modelSdf
std::string modelSdf
Contains the sdf representation of the model.
Definition: Population.hh:69
gazebo::physics::PopulationParams::modelName
std::string modelName
Name of the model.
Definition: Population.hh:66
gzerr
#define gzerr
Output an error message.
Definition: Console.hh:50
gazebo::physics::PopulationParams
Stores all the posible parameters that define a population.
Definition: Population.hh:42
gazebo::physics::PopulationParams::radius
double radius
Radius of the cylinder's base containing the models.
Definition: Population.hh:60
gazebo::physics::PopulationParams::size
ignition::math::Vector3d size
The three side lengths of the box.
Definition: Population.hh:45
gazebo::physics::Population
Class that automatically populates an environment with multiple objects based on several parameters t...
Definition: Population.hh:85
gazebo::physics::PopulationParams::region
std::string region
Type region in which the objects will be spawned. E.g.: box.
Definition: Population.hh:78
gazebo::physics::PopulationParams::rows
int rows
Number of rows used when models are distributed as a grid.
Definition: Population.hh:48
gazebo::physics::PopulationParams::pose
ignition::math::Pose3d pose
The reference frame of the population's region.
Definition: Population.hh:57
gazebo::physics::Population::PopulateAll
bool PopulateAll()
Generate and spawn multiple populations into the world.