Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

GripperVisualMonitorTask.cc

Go to the documentation of this file.
00001 // INCLUDES
00002 // tekkotsu
00003 #include "Kodu/KoduWorld.h"
00004 //#include "Kodu/PosOrientState.h"
00005 #include "Kodu/PerceptualTasks/PerceptualTaskBase.h"
00006 #include "Kodu/PerceptualTasks/GripperVisualMonitorTask.h"
00007 
00008 namespace Kodu {
00009     
00010     /**
00011      * ASSUMPTION:
00012      * - grabbed object's radius is greater than or equal to 1/2 the distance from the inside of
00013      *   the gripper to the gripper's fingers.
00014     **/
00015     float const MatchesObjectTagInGripper::kMaxAprTagCentroidVariance = 30.0f;
00016 
00017     unsigned int VisualGripperMonitorTask::idCount = 70000;
00018     
00019     bool MatchesObjectTagInGripper::operator()(const DualCoding::ShapeRoot& kShape) const {
00020         if (kShape->getType() != DualCoding::aprilTagDataType)
00021             return false;
00022         std::cout << "diff in centroids = ";
00023         float diff = (kShape->getCentroid() - aprTagCentroid).xyNorm();
00024         std::cout << diff << "mm; ";
00025         // for debugging
00026         bool match = ShapeRootTypeConst(kShape, DualCoding::AprilTagData)->getTagID() == aprTagId;
00027         std::cout << "april tag ids " << (match ? "" : "do not") << " match\n";
00028         return (diff < kMaxAprTagCentroidVariance && match);
00029     }
00030 
00031     bool VisualGripperMonitorTask::canExecute(const KoduWorld& kWorldState) {
00032         // return (kWorldState.thisAgent.isHoldingAnObject() && kWorldState.thisAgent.isWalking());
00033         return (kWorldState.thisAgent.isHoldingAnObject() && kWorldState.thisAgent.bodyIsInMotion()
00034             && kWorldState.thisAgent.isExecutingMotionAction());
00035     }
00036 
00037     void VisualGripperMonitorTask::examineTaskResults() {
00038         std::cout << "Examining visual gripper monitor results...\n";
00039         // search for the gripper object's April Tag in the local shape space
00040         DualCoding::Shape<DualCoding::AprilTagData> objectTag
00041             = DualCoding::find_if<DualCoding::AprilTagData>(DualCoding::VRmixin::localShS,taskPred);
00042 
00043         std::cout << "objectTag reference valid? ";
00044         // if the tag was found, log the agent's current state
00045         if (objectTag.isValid()) {
00046             float orient = DualCoding::VRmixin::theAgent->getOrientation();
00047             lastSuccessfulState = PosOrientState(DualCoding::VRmixin::theAgent->getCentroid(), orient);
00048             std::cout << "yes, it is. state logged at: " << lastSuccessfulState.position
00049                 << " w/ orient = " << lastSuccessfulState.orientation << std::endl;
00050         } else {
00051             std::cout << "no, reporting failure. last successful state: pos = "
00052                 << lastSuccessfulState.position << "; orient = " << lastSuccessfulState.orientation
00053                 << std::endl;
00054             taskStatus = TS_FAILURE;
00055         }
00056     }
00057 
00058     const DualCoding::ShapeRoot& VisualGripperMonitorTask::getGripperObject() const {
00059         return objInGripper;
00060     }
00061 
00062     const PosOrientState& VisualGripperMonitorTask::getLastSuccessfulState() const {
00063         return lastSuccessfulState;
00064     }
00065 
00066     const DualCoding::MapBuilderRequest& VisualGripperMonitorTask::getMapBuilderRequest() {
00067         NEW_SHAPE(tagApproxPosition, DualCoding::PointData,
00068             new DualCoding::PointData(DualCoding::VRmixin::localShS, taskPred.aprTagCentroid));
00069         mapreq = DualCoding::MapBuilderRequest(DualCoding::MapBuilderRequest::localMap);
00070         mapreq.searchArea = tagApproxPosition;
00071         mapreq.setAprilTagFamily();
00072         return mapreq;
00073     }
00074 
00075     const DualCoding::Point& VisualGripperMonitorTask::getTagCentroid() const {
00076         return taskPred.aprTagCentroid;
00077     }
00078 
00079     int VisualGripperMonitorTask::getTagId() const {
00080         return taskPred.aprTagId;
00081     }
00082 
00083     void VisualGripperMonitorTask::relocateTagCentroid(const DualCoding::Point& kNewLocation) {
00084         taskPred.aprTagCentroid = kNewLocation;
00085     }
00086 
00087     bool VisualGripperMonitorTask::taskIsComplete(const KoduWorld& kWorldState) {
00088         if (taskStatus != TS_IN_PROGRESS)
00089             return true;
00090 
00091         if (!kWorldState.thisAgent.isHoldingAnObject()) {
00092             taskStatus = TS_COMPLETE;
00093             return true;
00094         }
00095         return false;
00096     }
00097 }

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