51 const armarx::SimulatorInterfacePrx& simulator,
53 config_(config), simulator_(simulator)
55 createCollisionWalls();
61 deleteLocalObjectCopies();
67 ARMARX_CHECK(!config_.objectSets.empty()) <<
"No object set configured.";
69 for (uint i = 0; i < config_.amountObjects; ++i)
72 const size_t objectSetIndex = i % config_.objectSets.size();
73 const ObjectSet& objectSet = config_.objectSets[objectSetIndex];
77 const boost::uniform_int<uint> uniform(0, objectSet.
objects.size() - 1);
78 const size_t objectIndex = uniform(rnd_);
82 std::string objectName =
"obj_" + std::to_string(i);
88 objectName = newID.
str();
90 std::unique_ptr<SimulatedObject>
object = makeObject(objectName, objectSource);
91 object->setLocalPose(randomObjectPose(i));
92 object->addToSimulator(simulator_);
93 object->updatePoseToSimulator(simulator_);
94 localObjectCopies_.push_back(std::move(
object));
101 if (config_.autoResetInvalidObjects)
103 resetInvalidObjects();
110 ClutteredSceneGenerator::createCollisionWalls()
113 const float wallHeight = 1000;
114 frontWall_ = VirtualRobot::Obstacle::createBox(config_.
boxW, 1, wallHeight);
115 backWall_ = VirtualRobot::Obstacle::createBox(config_.
boxW, 1, wallHeight);
116 leftWall_ = VirtualRobot::Obstacle::createBox(1, config_.
boxH, wallHeight);
117 rightWall_ = VirtualRobot::Obstacle::createBox(1, config_.
boxH, wallHeight);
119 const float wallZ = config_.
boxZ + config_.
boxD + wallHeight / 2;
120 frontWall_->setGlobalPose(simox::math::pose(
121 Eigen::Vector3f{config_.
boxX, config_.
boxY - config_.
boxH / 2.0f, wallZ}));
122 backWall_->setGlobalPose(simox::math::pose(
123 Eigen::Vector3f{config_.
boxX, config_.
boxY + config_.
boxH / 2.0f, wallZ}));
124 leftWall_->setGlobalPose(simox::math::pose(
125 Eigen::Vector3f{config_.
boxX - config_.
boxW / 2.0f, config_.
boxY, wallZ}));
126 rightWall_->setGlobalPose(simox::math::pose(
127 Eigen::Vector3f{config_.
boxX + config_.
boxW / 2.0f, config_.
boxY, wallZ}));
129 walls_.reset(
new VirtualRobot::SceneObjectSet(
"walls"));
130 walls_->addSceneObject(frontWall_);
131 walls_->addSceneObject(backWall_);
132 walls_->addSceneObject(leftWall_);
133 walls_->addSceneObject(rightWall_);
137 ClutteredSceneGenerator::randomObjectPose(uint heightIndex)
140 boost::uniform_real<float> objectPositionDistX(config_.minObjectX, config_.maxObjectX);
141 boost::uniform_real<float> objectPositionDistY(config_.minObjectY, config_.maxObjectY);
142 boost::uniform_real<float> objectAngleDist(0, 2 *
M_PI);
145 float x = objectPositionDistX(rnd_);
146 float y = objectPositionDistY(rnd_);
147 float z = config_.minObjectZ +
static_cast<float>(heightIndex) * config_.objectSpacingZ;
148 float angle = objectAngleDist(rnd_);
150 Eigen::AngleAxisf rotation(
angle, Eigen::Vector3f::UnitZ());
156 ClutteredSceneGenerator::deleteLocalObjectCopies()
158 localObjectCopies_.clear();
161 std::unique_ptr<SimulatedObject>
162 ClutteredSceneGenerator::makeObject(
const std::string& name,
const ObjectSource& objectSource)
164 switch (objectSource.type)
167 return std::make_unique<SimulatedObjectAsObject>(name, objectSource);
169 return std::make_unique<SimulatedObjectAsRobot>(name, objectSource);
172 ARMARX_INFO << __FUNCTION__ <<
" Unknown SimulationObjectType: TO DO: Implement";
175 ARMARX_ERROR << __FUNCTION__ <<
" - unknown object type for " << name;
181 ClutteredSceneGenerator::updateLocalObjectCopies()
183 for (
const auto&
object : localObjectCopies_)
185 object->updatePoseFromSimulator(simulator_);
190 ClutteredSceneGenerator::dropObjects()
193 for (uint k = 0; k < config_.fallingSteps; ++k)
201 ClutteredSceneGenerator::resetInvalidObjects()
203 VirtualRobot::CollisionCheckerPtr col =
204 VirtualRobot::CollisionChecker::getGlobalCollisionChecker();
205 bool anyRespawn =
false;
208 for (uint i = 0; i < config_.maxResetTries; ++i)
210 updateLocalObjectCopies();
218 for (
const auto&
object : localObjectCopies_)
221 bool collision =
object->checkCollision(col, walls_);
223 float z =
object->getLocalPose()->position->z;
224 bool isObjectOutsideOfTable = z < config_.minObjectZOtherwiseReset;
227 if (collision || isObjectOutsideOfTable)
230 object->setLocalPose(randomObjectPose(heightIndex));
231 object->updatePoseToSimulator(simulator_);
254 ClutteredSceneGenerator::config_ = conf;
257 const SimulatorInterfacePrx&
266 ClutteredSceneGenerator::simulator_ = sim;