VisualLocalizationTask.cc
Go to the documentation of this file.00001
00002
00003 #include <iostream>
00004 #include <vector>
00005
00006
00007 #include "Kodu/KoduWorld.h"
00008 #include "Kodu/PerceptualTasks/PerceptualTaskBase.h"
00009 #include "Kodu/PerceptualTasks/VisualLocalizationTask.h"
00010 #include "Kodu/Primitives/PerceptionSearch.h"
00011
00012
00013 #include "Crew/MapBuilderRequest.h"
00014 #include "DualCoding/PolygonData.h"
00015 #include "DualCoding/VRmixin.h"
00016
00017 namespace Kodu {
00018
00019 unsigned int VisualLocalizationTask::idCount = 50000;
00020 const int VisualLocalizationTask::kMinStarsRequiredToLocalize = 2;
00021
00022 bool VisualLocalizationTask::canExecute(const KoduWorld& kWorldState) {
00023 return (!kWorldState.thisAgent.isExecutingMotionAction() && (localizationPoints.size() >= 2));
00024 }
00025
00026 const DualCoding::PilotRequest VisualLocalizationTask::getPilotRequest() {
00027 std::cout << "[Visual Localization Task]\n";
00028
00029 PilotRequest pilotreq;
00030 DualCoding::MapBuilderRequest* mreq = new DualCoding::MapBuilderRequest(DualCoding::MapBuilderRequest::localMap);
00031 mreq->removePts = false;
00032
00033 if (!localizationPoints.empty()) {
00034
00035 std::vector<DualCoding::Point> starLocs;
00036 starLocs.reserve(localizationPoints.size());
00037 std::cout << "creating the localization point vector for " << localizationPoints.size()
00038 << " points.\n";
00039
00040
00041 int numbOfStarsInVector = 0;
00042
00043 for (std::map<int, DualCoding::Point>::iterator it = localizationPoints.begin();
00044 it != localizationPoints.end(); ++it)
00045 {
00046 AngSignPi dtheta = bearingFromAgentToPoint(it->second);
00047 dtheta += AngSignPi(M_PI / 2.0f);
00048 if (dtheta > 0.0f) {
00049 std::cout << "adding tag #" << it->first << " @ " << it->second << " to vector.\n";
00050 NEW_SHAPE(star, DualCoding::AprilTagData,
00051 new DualCoding::AprilTagData(DualCoding::VRmixin::worldShS,
00052 AprilTags::TagDetection(it->first), DualCoding::Point(it->second)));
00053 DualCoding::Point starCen(star->getCentroid());
00054
00055 starLocs.push_back(starCen);
00056 starLocs.push_back(DualCoding::Point(starCen.coordX() - 200.0f, starCen.coordY(),
00057 starCen.coordZ(), starCen.getRefFrameType()));
00058
00059
00060 if ((++numbOfStarsInVector) == maxStarsRequested) break;
00061 }
00062 }
00063 if (numbOfStarsInVector < maxStarsRequested) {
00064 std::cout << "VisualLocalizationTask: WARNING---you requested " << maxStarsRequested
00065 << " stars, but there were only " << numbOfStarsInVector << " 'visible'.\n";
00066 }
00067
00068 std::cout << "generating localization polygon\n";
00069 NEW_SHAPE(localizePolygon, DualCoding::PolygonData,
00070 new DualCoding::PolygonData(DualCoding::VRmixin::localShS, starLocs, false));
00071 localizePolygon->setObstacle(false);
00072 localizePolygon->setViewable(true);
00073
00074 std::cout << "creating mapbuilder request\n";
00075 mreq->setAprilTagFamily();
00076 mreq->searchArea = localizePolygon;
00077 }
00078
00079
00080 else {
00081 std::cout << "THIS SHOULD HAVE NEVER EXECUTED!!! WHAT'S HAPPENING!!!\n";
00082 taskStatus = TS_FAILURE;
00083 return pilotreq;
00084 }
00085
00086
00087 std::cout << "creating pilot request\n";
00088 pilotreq = DualCoding::PilotRequest(DualCoding::PilotTypes::localize);
00089 pilotreq.landmarkExtractor = mreq;
00090
00091
00092 taskStatus = TS_COMPLETE;
00093 std::cout << "done!\n";
00094 return pilotreq;
00095 }
00096 }