Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

VisualBumpDetectionTask.cc

Go to the documentation of this file.
00001 // INCLUDES
00002 // c++
00003 #include <iostream>
00004 
00005 // tekkodu
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 // tekkotsu
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         // this task can execute if:
00024         // 1) the agent is near the matching object
00025         // 2) the agent is not walking
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         // create an AprilTagData shape
00033         NEW_SHAPEROOTVEC(aprilTags, DualCoding::subset(DualCoding::VRmixin::localShS,
00034             IsShapeOfType(DualCoding::aprilTagDataType)));
00035         // check if the shape is valid (if it is then the task was successful)
00036         if (!aprilTags.empty()) {
00037             std::cout << "found the tag!\n";
00038             // confirm the agent saw the object
00039             condition->setVisualBumpDetection(true);
00040             // tell the interpreter that it can evaluate the condition again
00041             condition->setAgentCanUsePrimitive(true);
00042 
00043             // check if there is not a relationship between the target object and the april tag seen,
00044             // add the relationship in the map
00045             int shapeId = condition->getTargetObject().getId();
00046             if (!wState->shapeTagPairExists(shapeId)) {
00047                 // find the april tag belonging to the bumped target object
00048                 Point targetLoc = condition->getTargetObject()->getCentroid();
00049                 targetLoc.applyTransform(VRmixin::mapBuilder->worldToLocalMatrix, egocentric);
00050                 
00051                 // store the relationship between the target object and the marker
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             // state the task is complete
00060             taskStatus = TS_COMPLETE;
00061         }
00062         // else the task was not successful
00063         else {
00064             std::cout << "nothing.\n";
00065             condition->setVisualBumpDetection(false);
00066             // state the task is a failure
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         // create the mapbuilder request
00089         mapreq = DualCoding::MapBuilderRequest(DualCoding::MapBuilderRequest::localMap);
00090         mapreq.setAprilTagFamily();
00091         mapreq.searchArea = gazePolygon;
00092         return mapreq;
00093     }
00094 }

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3