VisualBumpDetectionTask.cc
Go to the documentation of this file.00001
00002
00003 #include <iostream>
00004
00005
00006 #include "Kodu/KoduWorld.h"
00007 #include "Kodu/PerceptualTasks/PerceptualTaskBase.h"
00008 #include "Kodu/PerceptualTasks/VisualBumpDetectionTask.h"
00009 #include "Kodu/Primitives/KoduConditionBump.h"
00010
00011
00012 #include "DualCoding/AprilTagData.h"
00013 #include "DualCoding/Point.h"
00014 #include "DualCoding/ShapeAprilTag.h"
00015 #include "DualCoding/ShapeFuns.h"
00016 #include "DualCoding/ShapeRoot.h"
00017
00018 namespace Kodu {
00019
00020 unsigned int VisualBumpDetectionTask::idCount = 10000;
00021
00022 bool VisualBumpDetectionTask::canExecute(const KoduWorld& kWorldState) {
00023
00024
00025
00026 return ((condition->agentIsNearMatchingObject(kWorldState.thisAgent.gripperObject))
00027 && (!kWorldState.thisAgent.isExecutingMotionAction()));
00028 }
00029
00030 void VisualBumpDetectionTask::examineTaskResults() {
00031 std::cout << "Examining visual bump detection results...";
00032
00033 NEW_SHAPEROOTVEC(aprilTags, DualCoding::subset(DualCoding::VRmixin::localShS,
00034 IsShapeOfType(DualCoding::aprilTagDataType)));
00035
00036 if (!aprilTags.empty()) {
00037 std::cout << "found the tag!\n";
00038
00039 condition->setVisualBumpDetection(true);
00040
00041 condition->setAgentCanUsePrimitive(true);
00042
00043
00044
00045 int shapeId = condition->getTargetObject().getId();
00046 if (!wState->shapeTagPairExists(shapeId)) {
00047
00048 Point targetLoc = condition->getTargetObject()->getCentroid();
00049 targetLoc.applyTransform(VRmixin::mapBuilder->worldToLocalMatrix, egocentric);
00050
00051
00052 ShapeRoot bumpedObjectTag = getClosestObjectToPoint(aprilTags, targetLoc);
00053 int tagId = ShapeRootTypeConst(bumpedObjectTag, AprilTagData)->getTagID();
00054 wState->pairShapeWithTag(shapeId, tagId);
00055
00056 std::cout << "added pair { " << shapeId << ", " << tagId << " } to the shape-tag map\n";
00057 }
00058
00059
00060 taskStatus = TS_COMPLETE;
00061 }
00062
00063 else {
00064 std::cout << "nothing.\n";
00065 condition->setVisualBumpDetection(false);
00066
00067 taskStatus = TS_FAILURE;
00068 }
00069 }
00070
00071 const DualCoding::MapBuilderRequest& VisualBumpDetectionTask::getMapBuilderRequest() {
00072 const float kSearchRadius = 300.0f;
00073 const float kSideAngle = mathutils::deg2rad(10.0f);
00074
00075 std::vector<DualCoding::Point> searchPoints;
00076 searchPoints.push_back(DualCoding::Point(cos(kSideAngle) * kSearchRadius,
00077 sin(kSideAngle) * kSearchRadius,
00078 0.0f, DualCoding::egocentric));
00079
00080 searchPoints.push_back(DualCoding::Point(cos(-1.0f * kSideAngle) * kSearchRadius,
00081 sin(-1.0f * kSideAngle) * kSearchRadius,
00082 0.0f, DualCoding::egocentric));
00083
00084 searchPoints.push_back(DualCoding::Point(kSearchRadius, 0.0f, 0.0f, DualCoding::egocentric));
00085
00086 NEW_SHAPE(gazePolygon, DualCoding::PolygonData,
00087 new PolygonData(DualCoding::VRmixin::localShS, searchPoints, false));
00088
00089 mapreq = DualCoding::MapBuilderRequest(DualCoding::MapBuilderRequest::localMap);
00090 mapreq.setAprilTagFamily();
00091 mapreq.searchArea = gazePolygon;
00092 return mapreq;
00093 }
00094 }