ObjectCostmapStorage.cpp
Go to the documentation of this file.
2
3#include "util.h"
4
5#include <optional>
6#include <utility>
7#include <vector>
8
9#include <Eigen/Geometry>
10
14
16
18{
19
20 void
22 {
23 if (objectCostmaps_.find(cachedObjectCostmap.objectClassID.getClassID().str()) ==
24 objectCostmaps_.end())
25 {
26 objectCostmaps_.emplace(cachedObjectCostmap.objectClassID.getClassID().str(),
27 std::vector<CachedObjectCostmap>{});
28 }
29 objectCostmaps_[cachedObjectCostmap.objectClassID.getClassID().str()].emplace_back(
30 std::move(cachedObjectCostmap));
31 }
32
33 std::optional<armarx::navigation::algorithms::Costmap>
35 Eigen::Matrix4f objectGlobalPose,
36 JointValuesT jointValues)
37 {
38
39 if (objectCostmaps_.find(objectID.getClassID().str()) == objectCostmaps_.end())
40 {
41 return std::nullopt;
42 }
43
44 const auto global_T_object_desired_3d = objectGlobalPose;
45 Eigen::Vector3f eDesired =
46 global_T_object_desired_3d.block<3, 3>(0, 0).eulerAngles(0, 1, 2); // roll-pitch-yaw
47
48 for (const auto& cachedObjectCostmap : objectCostmaps_.at(objectID.getClassID().str()))
49 {
50 // check joint values
51 if (not jointValuesMatch(cachedObjectCostmap.jointValues, jointValues))
52 {
53 ARMARX_VERBOSE << "Skipping cached costmap because of different joint values";
54 continue;
55 }
56
57 const auto global_T_object_stored = cachedObjectCostmap.global_T_object;
58 Eigen::Vector3f eStored =
59 global_T_object_stored.block<3, 3>(0, 0).eulerAngles(0, 1, 2); // roll-pitch-yaw
60
61 // check if the stored costmap matches the desired one in terms of rotation
62 float rollDiff = std::abs(eDesired.x() - eStored.x());
63 float pitchDiff = std::abs(eDesired.y() - eStored.y());
64 float yawDiff = eDesired.z() - eStored.z();
65
66 if (rollDiff < 1e-3 && pitchDiff < 1e-3)
67 {
68
69 const Eigen::Vector2f global_P_object_desired =
70 Eigen::Isometry3f{global_T_object_desired_3d}.translation().head<2>();
71 const Eigen::Vector2f global_P_object_stored =
72 Eigen::Isometry3f{global_T_object_stored}.translation().head<2>();
73
74 ARMARX_INFO << deactivateSpam(10, "ObjectCostmapStorage::FoundCostmap")
75 << "Found cached costmap for objectID: " << objectID.str()
76 << " with rollDiff: " << rollDiff << ", pitchDiff: " << pitchDiff
77 << ", yawDiff: " << yawDiff;
78
79 Eigen::Isometry2f global_T_object_desired =
80 Eigen::Translation2f{global_P_object_desired} *
81 Eigen::Rotation2Df{eDesired.z()};
82 Eigen::Isometry2f global_T_object_stored =
83 Eigen::Translation2f{global_P_object_stored} * Eigen::Rotation2Df{eStored.z()};
84
85
86 Eigen::Isometry2f global_T_costmap = cachedObjectCostmap.costmap.origin();
87 Eigen::Isometry2f costmap_T_object =
88 global_T_costmap.inverse() * global_T_object_stored;
89 Eigen::Isometry2f global_T_costmap_new =
90 global_T_object_desired * costmap_T_object.inverse();
91
92 // copy costmap and update pose
93 algorithms::Costmap adaptedCostmap{cachedObjectCostmap.costmap};
94 adaptedCostmap.setOrigin(global_T_costmap_new);
95
96 return adaptedCostmap;
97 }
98
99 ARMARX_DEBUG << "Cached costmap for objectID: " << objectID.str()
100 << " does not match desired rotation. rollDiff: " << rollDiff
101 << ", pitchDiff: " << pitchDiff << ", yawDiff: " << yawDiff;
102 }
103
105 << "No matching cached costmap found for objectID: " << objectID.str();
106 return std::nullopt;
107 }
108
109 void
111 {
114 if (noSpam)
115 {
116 const auto duration = armarx::core::time::DateTime::Now() - t1;
118 {
120 }
121 else
122 {
123 return;
124 }
125 }
126
127 ARMARX_INFO << "Stored object costmaps:";
128 for (const auto& [classID, costmaps] : objectCostmaps_)
129 {
130 ARMARX_INFO << "- ClassID: " << classID
131 << ", number of cached costmaps: " << costmaps.size();
132 }
133 }
134} // namespace armarx::navigation::components::adaptive_distance_to_obstacle_costmap_provider
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
ObjectID getClassID() const
Return just the class ID without an intance name.
Definition ObjectID.cpp:71
std::string str() const
Return "dataset/className" or "dataset/className/instanceName".
Definition ObjectID.cpp:60
Represents a point in time.
Definition DateTime.h:25
static DateTime Now()
Definition DateTime.cpp:51
static Duration Hours(std::int64_t hours)
Constructs a duration in hours.
Definition Duration.cpp:120
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition Duration.cpp:72
void setOrigin(const core::Pose2D &globalPose)
Definition Costmap.h:177
std::optional< armarx::navigation::algorithms::Costmap > getTransformedCostmap(armarx::ObjectID objectID, Eigen::Matrix4f objectGlobalPose, JointValuesT jointValues)
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
bool jointValuesMatch(const JointValuesT &a, const JointValuesT &b, float tolerance)
Definition util.cpp:32