47 std::ifstream ConfigFile(path.c_str(),std::ifstream::in);
49 ROS_ERROR_STREAM(
"Unable to locate " << path <<
". Please make sure the launch file is correct and start again");
52 std::vector<char> buffer((std::istreambuf_iterator<char>(ConfigFile)), std::istreambuf_iterator<char>());
53 buffer.push_back(
'\0');
55 rapidxml::xml_document<> doc;
56 doc.parse<0>(&buffer[0]);
59 rapidxml::xml_node<> *root_node = doc.first_node(
"root");
60 for (rapidxml::xml_node<> *state_node = root_node->first_node(
"state"); state_node; state_node = state_node->next_sibling()) {
61 const PosePtr &goal_camera_pose_ptr =
parsePose(state_node,
"goal_camera_pose");
62 const PosePtr &goal_robot_pose_ptr =
parsePose(state_node,
"goal_robot_pose");
64 rapidxml::xml_node<> *goal_ptu_position_node = state_node->first_node(
"goal_ptu_position");
65 int goal_ptu_position_pan = boost::lexical_cast<
int>((goal_ptu_position_node->first_attribute(
"pan")->value()));
66 int goal_ptu_position_tilt = boost::lexical_cast<
int>((goal_ptu_position_node->first_attribute(
"tilt")->value()));
68 int deactivated_object_normals_count = 0;
69 if (state_node->first_node(
"deactivated_object_normals_count") !=
nullptr) {
70 deactivated_object_normals_count = boost::lexical_cast<
int>((state_node->first_node(
"deactivated_object_normals_count")->first_attribute(
"count")->value()));
74 ptu_tuple_ptr_vecotr_ptr->push_back(
PtuTuplePtr(
new PtuTuple(goal_ptu_position_pan, goal_ptu_position_tilt, goal_camera_pose_ptr, deactivated_object_normals_count)));
85 rapidxml::xml_node<> *pose_node = node->first_node(poseName);
87 rapidxml::xml_node<> *position_node = pose_node->first_node(
"position");
88 pose_ptr->position.x = boost::lexical_cast<
double>((position_node->first_attribute(
"x")->value()));
89 pose_ptr->position.y = boost::lexical_cast<
double>((position_node->first_attribute(
"y")->value()));
90 pose_ptr->position.z = boost::lexical_cast<
double>((position_node->first_attribute(
"z")->value()));
92 rapidxml::xml_node<> *orientation_node = pose_node->first_node(
"orientation");
93 pose_ptr->orientation.x = boost::lexical_cast<
double>((orientation_node->first_attribute(
"x")->value()));
94 pose_ptr->orientation.y = boost::lexical_cast<
double>((orientation_node->first_attribute(
"y")->value()));
95 pose_ptr->orientation.z = boost::lexical_cast<
double>((orientation_node->first_attribute(
"z")->value()));
96 pose_ptr->orientation.w = boost::lexical_cast<
double>((orientation_node->first_attribute(
"w")->value()));
113 for (
const asr_msgs::AsrTypeAndId &searchedObjectType : searchedObjectTypesAndIds) {
114 searchedObjectTypes.push_back(searchedObjectType.type);
117 ROS_INFO(
"Same searched object types -> nothing to update");
119 ROS_INFO(
"Different searched object types -> update");
126 ROS_ERROR(
"Service call to setInitialRobotState was not successful");
131 ROS_ERROR(
"Service call to setPointCloudInNBV was not successful");
158 asr_world_model::GetViewportList getViewportServiceCall;
159 getViewportServiceCall.request.object_type =
"all";
161 viewports = getViewportServiceCall.response.viewport_list;
167 std::vector<asr_msgs::AsrViewport> viewports;
169 ROS_INFO_STREAM(
"Got viewports from world_model: " << viewports.size());
171 for (
const asr_msgs::AsrViewport &viewport : viewports) {
173 for (
const PtuTuplePtr &ptuTuplePtr : *robotStatePtr->getPtuTuplePtrVecPtr()) {
174 if (
poseHelperPtr->checkViewCenterPointsAreApproxEquale(viewport.pose, *ptuTuplePtr->getCameraPosePtr())) {
175 ptuTuplePtr->addAlreadySearchedObjectTypes(viewport.object_type_name_list);
185 ROS_ERROR(
"Service call to setInitialRobotState was not successful");
190 ROS_ERROR(
"Service call to setPointCloudInNBV was not successful");
195 for (
const asr_msgs::AsrTypeAndId &searchedObjectType : searchedObjectTypesAndIds) {
196 searchedObjectTypes.push_back(searchedObjectType.type);
215 asr_next_best_view::RateViewports rateViewports;
216 rateViewports.request.current_pose =
poseHelperPtr->getCurrentCameraPose();
217 rateViewports.request.object_type_name_list = searchedObjectTypes;
218 rateViewports.request.use_object_type_to_rate =
false;
223 ROS_DEBUG_STREAM(
"Initial number of poses to explore: " << orginalNumberOfPoses);
226 for (
const PtuTuplePtr &ptuTuplePtr : *robotStatePtr->getPtuTuplePtrVecPtr()) {
227 rateViewports.request.viewports.push_back(*ptuTuplePtr->getCameraPosePtr());
232 ptuTuplePtr->getTilt(),
233 ptuTuplePtr->getCameraPosePtr(),
234 ptuTuplePtr->getDeactivatedObjectNormalsCount(),
235 ptuTuplePtr->getAlreadySearchedObjectTypes())));
237 robotStatesToReorder->push_back(robotStatePtrCopy);
241 ROS_DEBUG_STREAM(
"Number of poses to explore with only one PTU config per each: " << robotStatesToReorder->size());
244 ROS_ERROR(
"Service call to rateViewportsServiceClient was not successful");
248 const std::vector<asr_next_best_view::RatedViewport> &ratedViewports = rateViewports.response.sortedRatedViewports;
250 ROS_ASSERT_MSG(ratedViewports.size() == robotStatesToReorder->size(),
251 "The number of returned viewports from RateViewports were not equale, expect: %zu actual: %zu",
252 robotStatesToReorder->size(), ratedViewports.size());
254 int numberOfPosesWhereRatingIsNot0 = 0;
257 for (
unsigned int currentIndex = 0; currentIndex < ratedViewports.size(); ++currentIndex) {
258 const asr_next_best_view::RatedViewport ¤tRatedViewport = ratedViewports[currentIndex];
260 *(*robotStatesToReorder)[currentRatedViewport.oldIdx]->getTopPtuTuplePtr()->getCameraPosePtr(),
262 "The Pose of currentRatedViewport does not fit to my Pose at oldIdx, for currentIndexOfCurrentRatedViewport: %u currentRatedViewport.oldIndex: %u",
263 currentIndex, currentRatedViewport.oldIdx);
265 const RobotStatePtr &robotStatePtrToInsert = (*robotStatesToReorder)[currentRatedViewport.oldIdx];
267 if (currentRatedViewport.rating != 0.0) {
268 ++numberOfPosesWhereRatingIsNot0;
272 copyPtuTuplePtrVecPtr->push_back(
PtuTuplePtr(
new PtuTuple(robotStatePtrToInsert->getTopPtuTuplePtr()->getPan(),
273 robotStatePtrToInsert->getTopPtuTuplePtr()->getTilt(),
274 robotStatePtrToInsert->getTopPtuTuplePtr()->getCameraPosePtr(),
275 robotStatePtrToInsert->getTopPtuTuplePtr()->getDeactivatedObjectNormalsCount(),
276 robotStatePtrToInsert->getTopPtuTuplePtr()->getAlreadySearchedObjectTypes())));
278 robotStatePtrToInsertCopy->getTopPtuTuplePtr()->setRatedViewport(currentRatedViewport);
285 robotStatePtrToInsertCopy->getTopPtuTuplePtr()->addAlreadySearchedObjectTypes(alreadySearchedObjectTypesForFirstRun);
286 reorderedRobotStates->push_back(robotStatePtrToInsertCopy);
288 robotStatePtrToInsert->getTopPtuTuplePtr()->addAlreadySearchedObjectTypes(currentRatedViewport.object_type_name_list);
289 robotStatePtrToInsert->getTopPtuTuplePtr()->setRatedViewport(asr_next_best_view::RatedViewport());
292 ROS_DEBUG_STREAM(
"numberOfPosesWhereRatingIsNot0: " << numberOfPosesWhereRatingIsNot0);
294 ROS_DEBUG_STREAM(
"Number of new poses to explore: " << reorderedRobotStates->size());
295 reorderedRobotStates->insert(reorderedRobotStates->end(), robotStatesToReorder->begin(), robotStatesToReorder->end());
296 ROS_DEBUG_STREAM(
"Number of all poses to explore: " << reorderedRobotStates->size());
298 ROS_DEBUG_STREAM(
"Check if some poses are not needed anymore, because they have no objects to search for");
300 ROS_DEBUG_STREAM(
"Number of poses to explore after filterPosesDependingOnAlreadyFoundObjectTypes: " << reorderedRobotStates->size());
302 ROS_DEBUG_STREAM(
"Concat poses again");
306 concatFilterIteration.
addFilter(concatApproxEqualePosesPtr);
309 posesToExplorePtr = reorderedRobotStates;
310 ROS_DEBUG_STREAM(
"Number of poses to explore after concate again: " << posesToExplorePtr->size());
313 int numberOfNewPoses =
static_cast<int>(posesToExplorePtr->size()) - orginalNumberOfPoses;
314 ROS_DEBUG_STREAM(
"Number of new poses after reorder: " << numberOfNewPoses);
323 concatFilterIterationForDeleteRedundant.
addFilter(deleteApproxEqualePosesPtr);
324 return concatFilterIterationForDeleteRedundant.
doIteration();
332 filterPosesDependingOnAlreadyFoundObjectTypes->updateSearchedObjectTypes(searchedObjectTypes);
333 doFilterIterationForFilterPosesDependingOnAlreadyFoundObjectTypes.
addFilter(filterPosesDependingOnAlreadyFoundObjectTypes);
334 return doFilterIterationForFilterPosesDependingOnAlreadyFoundObjectTypes.
doIteration();
338 asr_next_best_view::SetInitRobotState setInitRobotState;
339 setInitRobotState.request.robotState.pan =
currentPan;
340 setInitRobotState.request.robotState.tilt =
currentTilt;
342 geometry_msgs::Pose currentRobotPose =
poseHelperPtr->getCurrentRobotPose();
343 setInitRobotState.request.robotState.x = currentRobotPose.position.x;
344 setInitRobotState.request.robotState.y = currentRobotPose.position.y;
348 setInitRobotState.request.robotState.rotation = quat.
getAngle();
359 asr_next_best_view::SetAttributedPointCloud setAttributePointCloud;
362 ISM::TableHelperPtr table_helper = ISM::TableHelperPtr(
new ISM::TableHelper(
dbfilenameParam));
364 const std::vector<int> &setIds = table_helper->getSetIds();
365 for (
const int &setId : setIds) {
366 const ISM::ObjectSetPtr &objectSetPtr = table_helper->getRecordedObjectSet(setId);
367 for (
const ISM::ObjectPtr &
object : objectSetPtr->objects) {
368 bool shouldAdd =
false;
370 for (
const asr_msgs::AsrTypeAndId &searchedObjectTypeAndId : searchedObjectTypesAndIds) {
371 if (searchedObjectTypeAndId.type == object->type && searchedObjectTypeAndId.identifier == object->observedId) {
377 asr_msgs::AsrAttributedPoint pointCloudPoint;
378 pointCloudPoint.type =
object->type;
379 pointCloudPoint.identifier =
object->observedId;
380 pointCloudPoint.pose.position.x =
object->pose->point->eigen[0];
381 pointCloudPoint.pose.position.y =
object->pose->point->eigen[1];
382 pointCloudPoint.pose.position.z =
object->pose->point->eigen[2];
383 pointCloudPoint.pose.orientation.w =
object->pose->quat->eigen.w();
384 pointCloudPoint.pose.orientation.x =
object->pose->quat->eigen.x();
385 pointCloudPoint.pose.orientation.y =
object->pose->quat->eigen.y();
386 pointCloudPoint.pose.orientation.z =
object->pose->quat->eigen.z();
387 setAttributePointCloud.request.point_cloud.elements.push_back(pointCloudPoint);
393 success &= setAttributePointCloud.response.is_valid;
399 bool equale = searchecObjectTypes1.size() == searchecObjectTypes2.size();
403 std::sort(copySearchecObjectTypes1.begin(), copySearchecObjectTypes1.end());
404 std::sort(copySearchecObjectTypes2.begin(), copySearchecObjectTypes2.end());
405 equale = std::equal(copySearchecObjectTypes1.begin(), copySearchecObjectTypes1.begin() + copySearchecObjectTypes1.size(), copySearchecObjectTypes2.begin());
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
virtual bool getNextRobotState(const SearchedObjectTypesAndIds &searchedObjectTypesAndIds)
void filterSearchedObjectTypes(SearchedObjectTypes &searched_object_types_to_filter, const SearchedObjectTypes &filter_searched_object_types)
ros::ServiceClient setAttributedPointCloudServiceClient
bool arePosesFromDemonstrationLeft
tfScalar getAngle() const
SearchedObjectTypes lastSearchedObjectTypes
boost::shared_ptr< geometry_msgs::Pose > PosePtr
virtual bool resetHandler()
virtual bool backToInitial(const SearchedObjectTypesAndIds &searchedObjectTypesAndIds)
boost::shared_ptr< RobotStatePtrVec > RobotStatePtrVecPtr
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool setPointCloudInNBV(const SearchedObjectTypesAndIds &searchedObjectTypesAndIds)
std::string dbfilenameParam
PoseHelperPtr poseHelperPtr
ros::ServiceClient rateViewportsServiceClient
boost::shared_ptr< ConcatApproxEqualePoses > ConcatApproxEqualePosesPtr
void addFilter(const FilterBasicPtr &filter)
ros::Subscriber ptuDriverStateSubscriber
bool call(MReq &req, MRes &res)
std::vector< std::string > SearchedObjectTypes
ROSCPP_DECL const std::string & getName()
boost::shared_ptr< PtuTuple > PtuTuplePtr
void calculateRemainingPosesDistances()
std::vector< PtuTuplePtr > PtuTuplePtrVec
FilterPosesDependingOnAlreadyFoundObjectTypesPtr filterPosesDependingOnAlreadyFoundObjectTypesPtr
bool reorderPosesByNBV(const SearchedObjectTypes &searchedObjectTypes)
bool filterPosesDependingOnAlreadyFoundObjectTypes(const RobotStatePtrVecPtr &robotStates, const SearchedObjectTypes &searchedObjectTypes) const
bool deleteAllRedundantPoses(const RobotStatePtrVecPtr &robotStates) const
boost::shared_ptr< DoFilterIteration > DoFilterIterationPtr
virtual bool backToInitial(const SearchedObjectTypesAndIds &searchedObjectTypesAndIds)
bool checkSearchedObjectTypesAreEquale(const SearchedObjectTypes &searchecObjectTypes1, const SearchedObjectTypes &searchecObjectTypes2)
ros::ServiceClient setInitRobotStateServiceClient
std::vector< asr_msgs::AsrTypeAndId > SearchedObjectTypesAndIds
static void quaternionMsgToTF(const geometry_msgs::Quaternion &msg, Quaternion &bt)
#define ROS_ASSERT_MSG(cond,...)
ros::ServiceClient getViewportListServiceClient
bool setInitialRobotState()
bool reorderPosesByNBVParam
void ptuDriverStateCallback(const sensor_msgs::JointState::ConstPtr &ptuState)
RobotStatePtrVecPtr posesToExplorePtr
std::vector< RobotStatePtr > RobotStatePtrVec
PosePtr parsePose(const rapidxml::xml_node<> *node, const char *poseName) const
#define ROS_DEBUG_STREAM(args)
bool getViewportsFromWorldModel(std::vector< asr_msgs::AsrViewport > &viewports)
virtual bool resetHandler()
boost::shared_ptr< PtuTuplePtrVec > PtuTuplePtrVecPtr
virtual ~DirectSearchManager()
#define ROS_INFO_STREAM(args)
boost::shared_ptr< FilterPosesDependingOnAlreadyFoundObjectTypes > FilterPosesDependingOnAlreadyFoundObjectTypesPtr
bool getParam(const std::string &key, std::string &s) const
boost::shared_ptr< RobotState > RobotStatePtr
SearchedObjectTypes getSearchedObjectTypesFromAWithoutB(const SearchedObjectTypes &a, const SearchedObjectTypes &b)
#define ROS_ERROR_STREAM(args)
bool parsePosesToExploreFromXML(const std::string &path)
virtual bool getNextRobotState(const SearchedObjectTypesAndIds &searchedObjectTypesAndIds)
DoFilterIterationPtr doFilterIterationPtrForPosesDependingOnAlreadyFoundObjectTypes