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
28
31
32#include <SemanticObjectRelations/SupportAnalysis/json.h>
33
35{
37 std::string prefix) :
39 {
40 // ICE
41
42 defineOptionalProperty<std::string>("ice.ShapesTopicName",
43 "ShapesTopic",
44 "Name of the topic on which shapes are reported.");
45
47 "ice.SemanticGraphName",
48 "Support",
49 "Name of the graph when reported to the SemanticGraphStorage topic.");
50 defineOptionalProperty<std::string>("ice.SemanticGraphTopicName",
51 "SemanticGraphTopic",
52 "Name of SemanticGraphStorage topic.");
53
54 defineOptionalProperty<std::string>("ice.RobotStateComponentName",
55 "RobotStateComponent",
56 "Name of the robot state component.");
57
58 defineOptionalProperty<std::string>("pc.PointCloudFrameName",
60 "Name of the frame of the point cloud coordinates. \n"
61 "Used to determine the gravity vector.");
62
63 defineOptionalProperty<std::string>("ice.DebugObserverName",
64 "DebugObserver",
65 "Name of the topic the DebugObserver listens to.");
66
67
68 // PARAMETERS
69
71 "GR.ContactMargin",
72 10.,
73 "Distance by which objects are increased for contact computation [mm].")
74 .setMin(0.);
75
77 "GR.VerticalSepPlaneAngleMax",
78 10.,
79 "Maximal angle [degree] between gravity and separating plane for \n"
80 "separating plane to be considered vertical.")
81 .setMin(0.);
82
84 "GR.VerticalSepPlaneAssumeSupport",
85 false,
86 "If true, edges are added if the separating plane is vertical.");
87
88
90 "UD.enabled", true, "Enable or disble uncertainty detection (UD).");
91
93 "UD.SupportAreaRatioMin",
94 0.7f,
95 "Minimal support area ratio of an object to consider it safe.")
96 .setMin(0.)
97 .setMax(1.);
98
99
100 // VISUALIZATION
101
103 *this, properties::defaults::visualizationLevelName, semrel::VisuLevel::DISABLED);
104 }
105
106 std::string
108 {
109 return "ShapesSupportRelations";
110 }
111
112 std::string
117
118 void
120 {
121 // Register offered topices and used proxies here.
122
123 usingTopicFromProperty("ice.ShapesTopicName");
124
125 offeringTopicFromProperty("ice.SemanticGraphTopicName");
126 getProperty(graphName, "ice.SemanticGraphName");
127
128 offeringTopicFromProperty("ice.DebugObserverName");
129 debugDrawer.offeringTopic(*this); // Calls this->offeringTopic().
130
131 // usingProxyFromProperty("ice.RobotStateComponentName"); // RobotStateComponent is not required.
132 getProperty(pointCloudFrameName, "pc.PointCloudFrameName");
133
134 supportAnalysis.setContactMargin(getProperty<float>("GR.ContactMargin"));
135 supportAnalysis.setVertSepPlaneAngleMax(getProperty<float>("GR.VerticalSepPlaneAngleMax"));
136 supportAnalysis.setVertSepPlaneAssumeSupport(
137 getProperty<bool>("GR.VerticalSepPlaneAssumeSupport"));
138
139 supportAnalysis.setUncertaintyDetectionEnabled(getProperty<bool>("UD.enabled"));
140 supportAnalysis.setSupportAreaRatioMin(getProperty<float>("UD.SupportAreaRatioMin"));
141 }
142
143 void
145 {
146 // Get topics and proxies here. Pass the *InterfacePrx type as template argument.
147 // Robot state component may not be available.
148 getProxyFromProperty(robotStateComponent, "ice.RobotStateComponentName", false, "", false);
149 getTopicFromProperty(graphTopic, "ice.SemanticGraphTopicName");
150
151 if (!robotStateComponent)
152 {
153 ARMARX_INFO << "RobotStateComponent is not available. Global gravity vector "
154 << gravityInGlobal.transpose() << " will be used.";
155 }
156
157 getTopicFromProperty(debugObserver, "ice.DebugObserverName");
158 debugDrawer.getTopic(*this); // Calls this->getTopic().
159
162 }
163
164 void
166 {
167 robotStateComponent = nullptr;
168 }
169
170 void
174
175 void
177 const data::ShapeList& objectsIce,
178 const Ice::Current&)
179 {
180 const semrel::ShapeList objects = semantic::fromIce(objectsIce);
181 const semrel::ShapeMap objectsMap = semrel::toShapeMap(objects);
182
183 std::set<semrel::ShapeID> safeObjectsIDs;
184 // Use the lowest object as safe object?
185
186 const data::Graph graph = extractSupportGraph(objectsMap, safeObjectsIDs);
187
188 std::stringstream graphName;
189 graphName << this->graphName << " (" << name << ")";
190 graphTopic->reportGraph(graphName.str(), graph);
191 }
192
193 data::Graph
194 ShapesSupportRelations::extractSupportGraph(const data::ShapeList& objectsIce,
195 const Ice::LongSeq& safeObjectIDsIce,
196 const Ice::Current&)
197 {
198 const semrel::ShapeList objects = semantic::fromIce(objectsIce);
199 const semrel::ShapeMap objectsMap = semrel::toShapeMap(objects);
200
201 std::set<semrel::ShapeID> safeObjectIDs;
202 for (long id : safeObjectIDsIce)
203 {
204 safeObjectIDs.insert(semrel::ShapeID{id});
205 }
206
207 const data::Graph ice = extractSupportGraph(objectsMap, safeObjectIDs);
208 return ice;
209 }
210
211 data::Graph
213 const std::set<semrel::ShapeID>& safeObjectIDs)
214 {
215 // Update gravity vector.
216 supportAnalysis.setGravityVector(getGravityFromRobotStateComponent());
217
218 // Perform support analysis.
219 const semrel::SupportGraph supportGraph =
220 supportAnalysis.performSupportAnalysis(objects, safeObjectIDs);
221 ARMARX_INFO << "Support Graph: " << supportGraph.str();
222
223 const data::Graph graphIce = semantic::toIce(supportGraph, objects);
224 return graphIce;
225 }
226
227 Eigen::Vector3f
228 ShapesSupportRelations::getGravityFromRobotStateComponent()
229 {
230 if (!robotStateComponent || pointCloudFrameName == armarx::GlobalFrame)
231 {
232 return gravityInGlobal;
233 }
234 else
235 {
237 robotStateComponent, "", {}, VirtualRobot::RobotIO::eStructure);
238
239 FramedDirection dir(gravityInGlobal, armarx::GlobalFrame, "");
240 dir.changeFrame(robot, pointCloudFrameName);
241 return dir.toEigen();
242 }
243 }
244
251
252
253
255} // namespace armarx::semantic
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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.
Brief description of class 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.
std::string getDefaultName() const override
Retrieve default name of component.
#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.