27 #include <VirtualRobot/CollisionDetection/CollisionChecker.h>
28 #include <VirtualRobot/Robot.h>
29 #include <VirtualRobot/SceneObjectSet.h>
45 const VirtualRobot::SceneObjectSetPtr& obstacles,
48 const std::string& robotCollisonModelName) :
52 parameters(parameters),
53 robotCollisionModelName(robotCollisonModelName)
57 ARMARX_CHECK(robot->hasRobotNode(robotCollisionModelName));
68 Costmap costmap(grid, parameters, sceneBounds);
71 << costmap.
getGrid().cols() <<
")";
72 fillGridCosts(costmap);
75 initializeMask(costmap);
82 CostmapBuilder::initializeMask(
Costmap& costmap)
84 costmap.mask = costmap.grid.array() > 0.F;
86 ARMARX_VERBOSE <<
"Initializing mask: Fraction of valid elements: "
87 << costmap.mask->cast<
float>().sum() / costmap.mask->size();
99 size_t c_x = (sceneBounds.
max.x() - sceneBounds.
min.x()) / parameters.
cellSize + 1;
100 size_t c_y = (sceneBounds.
max.y() - sceneBounds.
min.y()) / parameters.
cellSize + 1;
105 Eigen::MatrixXf grid(c_x, c_y);
114 const VirtualRobot::CollisionModelPtr& robotCollisionModel)
124 collisionRobot->setGlobalPose(globalPose.matrix());
127 const float distanceNonArticulated =
128 VirtualRobot::CollisionChecker::getGlobalCollisionChecker()->calculateDistance(
129 robotCollisionModel, obstacles);
133 for(
const auto& articulatedObject : articulatedObjects)
135 for(
const auto& colModel : articulatedObject->getCollisionModels())
137 const float distanceArticulated = VirtualRobot::CollisionChecker::getGlobalCollisionChecker()->calculateDistance(robotCollisionModel, colModel);
138 distanceArticulatedMin =
std::min(distanceArticulated, distanceArticulatedMin);
142 return std::min(distanceNonArticulated, distanceArticulatedMin);
190 CostmapBuilder::fillGridCosts(Costmap& costmap)
194 VirtualRobot::CollisionModelPtr robotCollisionModel;
196 const std::size_t c_x = costmap.grid.rows();
197 const std::size_t c_y = costmap.grid.cols();
199 robot->setUpdateVisualization(
false);
201 #pragma omp parallel for schedule(static) private(collisionRobot, \
202 robotCollisionModel) default(shared)
203 for (
unsigned int x = 0; x < c_x; x++)
206 if (collisionRobot ==
nullptr)
213 robot->clone(
"collision_robot_" +
std::to_string(omp_get_thread_num()));
216 collisionRobot->setPrimitiveApproximationModel({
"navigation"},
false);
218 collisionRobot->setUpdateVisualization(
false);
223 ARMARX_CHECK(collisionRobot->hasRobotNode(robotCollisionModelName));
226 const auto collisionRobotNode =
227 collisionRobot->getRobotNode(robotCollisionModelName);
230 robotCollisionModel = collisionRobotNode->getCollisionModel();
231 ARMARX_CHECK(robotCollisionModel) <<
"Collision model not available. "
232 "Make sure that you load the robot correctly!";
238 for (
unsigned int y = 0; y < c_y; y++)
243 costmap.grid(x, y) = computeCost(position, collisionRobot, robotCollisionModel);