util.cpp
Go to the documentation of this file.
1/**
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package Navigation::ArmarXObjects::util
17 * @author Fabian Reister ( fabian dot reister at kit dot edu )
18 * @author Christian R. G. Dreher ( c dot dreher at kit dot edu )
19 * @date 2021
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24#include "util.h"
25
26#include <cmath>
27#include <string>
28
29#include <Eigen/Geometry>
30
31#include <VirtualRobot/CollisionDetection/CollisionModel.h>
32#include <VirtualRobot/SceneObject.h>
33#include <VirtualRobot/SceneObjectSet.h>
34#include <VirtualRobot/VirtualRobot.h>
35#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
36
38
42
44{
45
46 VirtualRobot::SceneObjectSetPtr
48 const OccupancyGridHelper::Params& params)
49 {
50 const OccupancyGridHelper ocHelper(occupancyGrid, params);
51 const auto obstacles = ocHelper.obstacles();
52
53 const float boxSize = occupancyGrid.resolution;
54 const float resolution = occupancyGrid.resolution;
55
56 VirtualRobot::SceneObjectSetPtr sceneObjects(new VirtualRobot::SceneObjectSet);
57
59 << "Only occupancy grid in global frame supported.";
60
61 VirtualRobot::CoinVisualizationFactory factory;
62
63 const Eigen::Isometry3f& world_T_map = occupancyGrid.pose;
64
65 for (int x = 0; x < obstacles.rows(); x++)
66 {
67 for (int y = 0; y < obstacles.cols(); y++)
68 {
69 if (obstacles(x, y))
70 {
71 const Eigen::Vector3f pos{
72 static_cast<float>(x * resolution), static_cast<float>(y * resolution), 0};
73
74 Eigen::Isometry3f map_T_obj = Eigen::Isometry3f::Identity();
75 map_T_obj.translation() = pos;
76
77 Eigen::Isometry3f world_T_obj = world_T_map * map_T_obj;
78
79 auto cube = factory.createBox(boxSize, boxSize, boxSize);
80
81 VirtualRobot::CollisionModelPtr collisionModel(
82 new VirtualRobot::CollisionModel(cube));
83
84 VirtualRobot::SceneObjectPtr sceneObject(new VirtualRobot::SceneObject(
85 "box_" + std::to_string(sceneObjects->getSize()), cube, collisionModel));
86 sceneObject->setGlobalPose(world_T_obj.matrix());
87
88 sceneObjects->addSceneObject(sceneObject);
89 }
90 }
91 }
92
93 return sceneObjects;
94 }
95
96 Eigen::Matrix4f
97 getRobotPoseAtXOrientedTowardsY(const Eigen::Vector3f& x, const Eigen::Vector3f& y)
98 {
99 const auto goalPosition = Eigen::Affine3f{Eigen::Translation3f{x}};
100 const auto lookPosition = Eigen::Affine3f{Eigen::Translation3f{y}};
101 const Eigen::Vector3f direction = lookPosition.translation() - goalPosition.translation();
102 const auto dot = direction.x() * 0 + direction.y() * 1;
103 const auto det = direction.x() * 1 - direction.y() * 0;
104 const auto angle = -atan2(det, dot);
105 const Eigen::Affine3f rot{Eigen::AngleAxisf{angle, Eigen::Vector3f::UnitZ()}};
106 const auto pose = (goalPosition * rot).matrix();
107 return pose;
108 }
109} // namespace armarx::navigation::util
detail::OccupancyGridHelperParams Params
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
This file is part of ArmarX.
Definition geometry.cpp:13
Eigen::Matrix4f getRobotPoseAtXOrientedTowardsY(const Eigen::Vector3f &x, const Eigen::Vector3f &y)
Definition util.cpp:97
VirtualRobot::SceneObjectSetPtr asSceneObjects(const armem::vision::OccupancyGrid &occupancyGrid, const OccupancyGridHelper::Params &params)
Definition util.cpp:47
This file offers overloads of toIce() and fromIce() functions for STL container types.
double angle(const Point &a, const Point &b, const Point &c)
Definition point.hpp:109
double dot(const Point &x, const Point &y)
Definition point.hpp:57