ShapesSupportRelations.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 VisionX::ArmarXObjects::ShapesSupportRelations
17 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18 * @date 2019
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
26
29
30#include <SemanticObjectRelations/SupportAnalysis/json.h>
31
33{
35 std::string prefix) :
37 {
38 // ICE
39
40 defineOptionalProperty<std::string>("ice.ShapesTopicName",
41 "ShapesTopic",
42 "Name of the topic on which shapes are reported.");
43
45 "ice.SemanticGraphName",
46 "Support",
47 "Name of the graph when reported to the SemanticGraphStorage topic.");
48 defineOptionalProperty<std::string>("ice.SemanticGraphTopicName",
49 "SemanticGraphTopic",
50 "Name of SemanticGraphStorage topic.");
51
52 defineOptionalProperty<std::string>("ice.RobotStateComponentName",
53 "RobotStateComponent",
54 "Name of the robot state component.");
55
56 defineOptionalProperty<std::string>("pc.PointCloudFrameName",
58 "Name of the frame of the point cloud coordinates. \n"
59 "Used to determine the gravity vector.");
60
61 defineOptionalProperty<std::string>("ice.DebugObserverName",
62 "DebugObserver",
63 "Name of the topic the DebugObserver listens to.");
64
65
66 // PARAMETERS
67
69 "GR.ContactMargin",
70 10.,
71 "Distance by which objects are increased for contact computation [mm].")
72 .setMin(0.);
73
75 "GR.VerticalSepPlaneAngleMax",
76 10.,
77 "Maximal angle [degree] between gravity and separating plane for \n"
78 "separating plane to be considered vertical.")
79 .setMin(0.);
80
82 "GR.VerticalSepPlaneAssumeSupport",
83 false,
84 "If true, edges are added if the separating plane is vertical.");
85
86
88 "UD.enabled", true, "Enable or disble uncertainty detection (UD).");
89
91 "UD.SupportAreaRatioMin",
92 0.7f,
93 "Minimal support area ratio of an object to consider it safe.")
94 .setMin(0.)
95 .setMax(1.);
96
97
98 // VISUALIZATION
99
101 *this, properties::defaults::visualizationLevelName, semrel::VisuLevel::DISABLED);
102 }
103
104 std::string
106 {
107 return "ShapesSupportRelations";
108 }
109
110 void
112 {
113 // Register offered topices and used proxies here.
114
115 usingTopicFromProperty("ice.ShapesTopicName");
116
117 offeringTopicFromProperty("ice.SemanticGraphTopicName");
118 getProperty(graphName, "ice.SemanticGraphName");
119
120 offeringTopicFromProperty("ice.DebugObserverName");
121 debugDrawer.offeringTopic(*this); // Calls this->offeringTopic().
122
123 // usingProxyFromProperty("ice.RobotStateComponentName"); // RobotStateComponent is not required.
124 getProperty(pointCloudFrameName, "pc.PointCloudFrameName");
125
126 supportAnalysis.setContactMargin(getProperty<float>("GR.ContactMargin"));
127 supportAnalysis.setVertSepPlaneAngleMax(getProperty<float>("GR.VerticalSepPlaneAngleMax"));
128 supportAnalysis.setVertSepPlaneAssumeSupport(
129 getProperty<bool>("GR.VerticalSepPlaneAssumeSupport"));
130
131 supportAnalysis.setUncertaintyDetectionEnabled(getProperty<bool>("UD.enabled"));
132 supportAnalysis.setSupportAreaRatioMin(getProperty<float>("UD.SupportAreaRatioMin"));
133 }
134
135 void
137 {
138 // Get topics and proxies here. Pass the *InterfacePrx type as template argument.
139 // Robot state component may not be available.
140 getProxyFromProperty(robotStateComponent, "ice.RobotStateComponentName", false, "", false);
141 getTopicFromProperty(graphTopic, "ice.SemanticGraphTopicName");
142
143 if (!robotStateComponent)
144 {
145 ARMARX_INFO << "RobotStateComponent is not available. Global gravity vector "
146 << gravityInGlobal.transpose() << " will be used.";
147 }
148
149 getTopicFromProperty(debugObserver, "ice.DebugObserverName");
150 debugDrawer.getTopic(*this); // Calls this->getTopic().
151
154 }
155
156 void
158 {
159 robotStateComponent = nullptr;
160 }
161
162 void
166
167 void
169 const data::ShapeList& objectsIce,
170 const Ice::Current&)
171 {
172 const semrel::ShapeList objects = semantic::fromIce(objectsIce);
173 const semrel::ShapeMap objectsMap = semrel::toShapeMap(objects);
174
175 std::set<semrel::ShapeID> safeObjectsIDs;
176 // Use the lowest object as safe object?
177
178 const data::Graph graph = extractSupportGraph(objectsMap, safeObjectsIDs);
179
180 std::stringstream graphName;
181 graphName << this->graphName << " (" << name << ")";
182 graphTopic->reportGraph(graphName.str(), graph);
183 }
184
185 data::Graph
186 ShapesSupportRelations::extractSupportGraph(const data::ShapeList& objectsIce,
187 const Ice::LongSeq& safeObjectIDsIce,
188 const Ice::Current&)
189 {
190 const semrel::ShapeList objects = semantic::fromIce(objectsIce);
191 const semrel::ShapeMap objectsMap = semrel::toShapeMap(objects);
192
193 std::set<semrel::ShapeID> safeObjectIDs;
194 for (long id : safeObjectIDsIce)
195 {
196 safeObjectIDs.insert(semrel::ShapeID{id});
197 }
198
199 const data::Graph ice = extractSupportGraph(objectsMap, safeObjectIDs);
200 return ice;
201 }
202
203 data::Graph
205 const std::set<semrel::ShapeID>& safeObjectIDs)
206 {
207 // Update gravity vector.
208 supportAnalysis.setGravityVector(getGravityFromRobotStateComponent());
209
210 // Perform support analysis.
211 const semrel::SupportGraph supportGraph =
212 supportAnalysis.performSupportAnalysis(objects, safeObjectIDs);
213 ARMARX_INFO << "Support Graph: " << supportGraph.str();
214
215 const data::Graph graphIce = semantic::toIce(supportGraph, objects);
216 return graphIce;
217 }
218
219 Eigen::Vector3f
220 ShapesSupportRelations::getGravityFromRobotStateComponent()
221 {
222 if (!robotStateComponent || pointCloudFrameName == armarx::GlobalFrame)
223 {
224 return gravityInGlobal;
225 }
226 else
227 {
229 robotStateComponent, "", {}, VirtualRobot::RobotIO::eStructure);
230
231 FramedDirection dir(gravityInGlobal, armarx::GlobalFrame, "");
232 dir.changeFrame(robot, pointCloudFrameName);
233 return dir.toEigen();
234 }
235 }
236
243
244
245} // namespace armarx::semantic
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
Definition Component.h:221
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
void usingTopicFromProperty(const std::string &propertyName, bool orderedPublishing=false)
Use a topic whose name is specified by the given property.
ProxyType getProxyFromProperty(const std::string &propertyName, bool addToDependencies=false, const std::string &endpoints="", bool throwOnProxyError=true)
Get a proxy whose name is specified by the given property.
Definition Component.h:242
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
std::string getName() const
Retrieve name of object.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
Property definitions of ShapesSupportRelations.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportShapes(const std::string &name, const data::ShapeList &objects, const Ice::Current &) override
Topic/pipeline: Extract the support graph for objects and publish it to the graph topic.
data::Graph extractSupportGraph(const data::ShapeList &objects, const Ice::LongSeq &safeObjectIDs, const Ice::Current &=Ice::emptyCurrent) override
Service: Extract the support graph for objects and return it.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
void defineVisualizationLevel(armarx::ComponentPropertyDefinitions &defs, const std::string &propertyName=defaults::visualizationLevelName, semrel::VisuLevel defaultLevel=semrel::VisuLevel::RESULT, const std::string &description=defaults::visualizationLevelDescription)
void setMinimumVisuLevel(armarx::PropertyUser &defs, const std::string &propertyName=defaults::visualizationLevelName)
void setArmarXHooksAsImplementation(const DebugDrawerInterfacePrx &debugDrawer, const std::string &logTag="SemanticObjectRelations")
Definition hooks.cpp:7
semrel::AttributedGraph fromIce(const semantic::data::Graph &graph)
data::Graph toIce(const semrel::AttributedGraph &input)
Definition graph.cpp:15
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.