Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

KoduConditionBump.cc

Go to the documentation of this file.
00001 // Kodu Library
00002 #include "Kodu/KoduWorld.h"
00003 #include "Kodu/Primitives/KoduConditionBump.h"
00004 #include "Kodu/General/GeneralMacros.h"
00005 
00006 namespace Kodu {
00007 
00008     const float KoduConditionBump::kMaxDistanceAwayToSenseBump = 100.0f; // millimeters
00009     
00010     bool KoduConditionBump::evaluate(const KoduWorld& kWorldState) {
00011         // check the following:
00012         // 1) the agent visually detected the bump,
00013         // 2) the referenced object (the object the bump condition will react to) is valid
00014         // 3) the agent has not moved anywhere (translated the body in the x-direction)
00015         //    (3) assumes that the agent's centroid measurement is correct.
00016         static float const kMaxDistAgentCanMoveAway = 20.0f;
00017         bool rv = (visuallyDetectedBump && refdObject.isValid()
00018             && distanceFromAgentToPoint(agentLastPosAfterDetection) <= kMaxDistAgentCanMoveAway);
00019         
00020         // if the not modifier is enabled, negate the value of the return value (rv)
00021         if (notModifierEnabled)
00022             rv = !rv;
00023 
00024         // 
00025         if ((ObjectKeeper::isValid = rv) == true)
00026             ObjectKeeper::tempObject = refdObject;
00027 
00028         return rv;
00029     }
00030 
00031     bool KoduConditionBump::agentIsNearMatchingObject(const DualCoding::ShapeRoot& kExcludedShape) {
00032         DualCoding::ShapeRoot obj;
00033         // get the closest object that matches what this condition is searching for
00034         obj = getClosestObjectMatching(objColor, objType, searchLocation, kExcludedShape);
00035         // If there is one valid remaining and it is within some distance to the agent,
00036         // then the robot will react to that object
00037         std::cout << "Bump condition:  closesObj=" << obj << "  dist="
00038                   << (obj.isValid() ? distanceInBetweenAgentAndObject(obj) : -1.0f) << " ... ";
00039         if (obj.isValid() && (distanceInBetweenAgentAndObject(obj) <= kMaxDistanceAwayToSenseBump)) {
00040             std::cout << "yes!\n";
00041             refdObject = obj;
00042             return true;
00043         } else {
00044             std::cout << "no bump.\n";
00045             refdObject = ObjectKeeper::invalidObject;
00046             return false;
00047         }
00048     }
00049 
00050     void KoduConditionBump::setVisualBumpDetection(bool bval) {
00051         visuallyDetectedBump = bval;
00052         // check if the agent visually detected the bump
00053         if (visuallyDetectedBump) {
00054             // if it did, note the last position the robot was at when it visually detected the object
00055             agentLastPosAfterDetection = DualCoding::VRmixin::theAgent->getCentroid();
00056             ObjectKeeper::tempObject = refdObject;
00057         }
00058     }
00059 
00060     const std::string& KoduConditionBump::getObjectColor() const {
00061         return objColor;
00062     }
00063 
00064     const std::string& KoduConditionBump::getObjectType() const {
00065         return objType;
00066     }
00067 
00068     const DualCoding::ShapeRoot KoduConditionBump::getTargetObject() {
00069         return refdObject;
00070     }
00071 
00072     bool KoduConditionBump::isSameTypeAs(const KoduPrimitive* kPrimitive) {
00073         return (dynamic_cast<const KoduConditionBump*>(kPrimitive) != NULL);
00074     }
00075 
00076     void KoduConditionBump::reinitialize() {
00077         KoduCondition::reinitialize();
00078     }
00079     
00080     void KoduConditionBump::printAttrs() const {
00081         KoduCondition::printAttrs();
00082         // not enabled?
00083         PRINT_ATTRS("Not enabled", notModifierEnabled);
00084         // object color and type
00085         std::cout << "Object color and type: " << objColor << " " << objType << std::endl;
00086         // search region
00087         /*
00088         std::cout << "Search region:";
00089         if (searchRegion == SRG_UNRESTRICTED) {
00090             std::cout << " unrestricted\n";
00091         } else {
00092             if (searchRegion & SRG_TO_LEFT) {
00093                 std::cout << " to_left";
00094             } else if (searchRegion & SRG_TO_RIGHT) {
00095                 std::cout << " to_right";
00096             }
00097 
00098             if (searchRegion & SRG_IN_FRONT) {
00099                 std::cout << " in_front";
00100             } else if (searchRegion & SRG_BEHIND) {
00101                 std::cout << " behind";
00102             }
00103             std::cout << std::endl;
00104         }
00105         */
00106         // referenced object...
00107     }
00108 }

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