37 #define TCP_POSE_CHANNEL "TCPPose"
38 #define TCP_TRANS_VELOCITIES_CHANNEL "TCPVelocities"
49 usingTopic(getProperty<std::string>(
"GraspCandidatesTopicName").getValue());
50 offeringTopic(getProperty<std::string>(
"ConfigTopicName").getValue());
56 configTopic = getTopic<GraspCandidateProviderInterfacePrx>(
57 getProperty<std::string>(
"ConfigTopicName").getValue());
58 graspCandidateWriter.connect(memoryNameSystem());
70 const std::string& providerName,
71 const GraspCandidatePtr& candidate)
73 if (filter->providerName !=
"*" && filter->providerName != providerName)
77 if (filter->minimumSuccessProbability > candidate->graspSuccessProbability)
81 if (filter->approach != AnyApproach &&
82 (candidate->executionHints == 0 || filter->approach != candidate->executionHints->approach))
86 if (filter->preshape != AnyAperture &&
87 (candidate->executionHints == 0 || filter->preshape != candidate->executionHints->preshape))
91 if (filter->objectType != objpose::AnyObject && filter->objectType != candidate->objectType)
103 case objpose::AnyObject:
105 case objpose::KnownObject:
106 return "KnownObject";
107 case objpose::UnknownObject:
108 return "UnknownObject";
115 GraspCandidateObserver::handleProviderUpdate(
const std::string& providerName,
int candidateCount)
117 if (updateCounters.count(providerName) == 0)
119 updateCounters[providerName] = 0;
121 updateCounters[providerName]++;
122 if (providers.count(providerName) == 0)
124 providers[providerName] =
new ProviderInfo();
127 if (!existsChannel(providerName))
129 offerChannel(providerName,
"Channel of " + providerName);
131 offerOrUpdateDataField(providerName,
133 Variant(updateCounters[providerName]),
134 "Counter that increases for each update");
135 offerOrUpdateDataField(
136 providerName,
"candidateCount",
Variant(candidateCount),
"Number of provided candiates");
141 const GraspCandidateSeq& candidates,
144 std::unique_lock lock(dataMutex);
145 this->candidates[providerName] = candidates;
146 graspCandidateWriter.commitGraspCandidateSeq(
148 handleProviderUpdate(providerName, candidates.size());
153 const BimanualGraspCandidateSeq& candidates,
156 std::unique_lock lock(dataMutex);
157 this->bimanualCandidates[providerName] = candidates;
158 handleProviderUpdate(providerName, candidates.size());
163 const ProviderInfoPtr& info,
166 std::unique_lock lock(dataMutex);
167 providers[providerName] = info;
168 if (updateCounters.count(providerName) == 0)
170 updateCounters[providerName] = 0;
174 if (!existsChannel(providerName))
176 offerChannel(providerName,
"Channel of " + providerName);
178 offerOrUpdateDataField(providerName,
"objectType", ObjectTypeToString(info->objectType),
"");
184 std::unique_lock lock(dataMutex);
189 GraspCandidateObserver::getAvailableProviderNames(
const Ice::Current&)
191 std::unique_lock lock(dataMutex);
192 return getAvailableProviderNames();
198 std::unique_lock lock(dataMutex);
199 checkHasProvider(providerName);
200 return providers[providerName];
206 std::unique_lock lock(dataMutex);
207 return hasProvider(providerName);
213 std::unique_lock lock(dataMutex);
214 GraspCandidateSeq
all;
215 for (
const auto& pair : candidates)
217 all.insert(
all.end(), pair.second.begin(), pair.second.end());
224 const Ice::Current&
c)
226 return getCandidatesByProviders(Ice::StringSeq{providerName});
231 const Ice::Current&
c)
233 std::unique_lock lock(dataMutex);
234 GraspCandidateSeq
all;
235 for (
const auto& pr : providerNames)
237 const auto it = candidates.find(pr);
238 if (it != candidates.end())
240 all.insert(
all.end(), it->second.begin(), it->second.end());
250 std::unique_lock lock(dataMutex);
251 GraspCandidateSeq matching;
252 for (
const auto& pair : candidates)
254 for (
const grasping::GraspCandidatePtr& candidate : pair.second)
256 if (FilterMatches(filter, pair.first, candidate))
258 matching.push_back(candidate);
269 std::unique_lock lock(dataMutex);
270 checkHasProvider(providerName);
271 return updateCounters[providerName];
277 std::unique_lock lock(dataMutex);
278 return updateCounters;
286 std::unique_lock lock(dataMutex);
287 if (providers.count(providerName) == 0)
291 configTopic->setServiceConfig(providerName, config);
299 std::unique_lock lock(selectedCandidatesMutex);
300 selectedCandidates = candidates;
306 std::unique_lock lock(selectedCandidatesMutex);
307 return selectedCandidates;
310 BimanualGraspCandidateSeq
313 std::unique_lock lock(dataMutex);
314 BimanualGraspCandidateSeq
all;
315 for (
const auto& pair : bimanualCandidates)
317 all.insert(
all.end(), pair.second.begin(), pair.second.end());
324 const grasping::BimanualGraspCandidateSeq& candidates,
327 std::unique_lock lock(selectedCandidatesMutex);
328 selectedBimanualCandidates = candidates;
331 BimanualGraspCandidateSeq
334 std::unique_lock lock(selectedCandidatesMutex);
335 return selectedBimanualCandidates;
342 std::unique_lock lock(dataMutex);
344 if (candidates.count(providerName))
346 candidates[providerName].clear();
353 return providers.count(providerName) > 0;
357 GraspCandidateObserver::checkHasProvider(
const std::string& providerName)
359 if (!hasProvider(providerName))
361 throw LocalException(
"Unknown provider name '")
362 << providerName <<
"'. Available providers: " << getAvailableProviderNames();
367 GraspCandidateObserver::getAvailableProviderNames()
370 for (
const auto& pair : providers)
372 names.push_back(pair.first);