Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

KoduAgent.cc

Go to the documentation of this file.
00001 // INCLUDES
00002 // tekkodu
00003 #include "Kodu/KoduPage.h"
00004 #include "Kodu/General/GeneralFncs.h"
00005 #include "Kodu/PerceptualTasks/PerceptualTaskBase.h"
00006 #include "Kodu/Primitives/PerceptionSearch.h"
00007 
00008 #include "Kodu/KoduAgent.h"
00009 
00010 // tekkotsu
00011 #include "DualCoding/ShapeTypes.h"
00012 #include "Shared/get_time.h"
00013 #include "Shared/mathutils.h"
00014 using namespace DualCoding;
00015 
00016 namespace Kodu {
00017 
00018     KoduAgent::KoduAgent()
00019       : gripperObject(),
00020         agentIsExecutingManipAction(false),
00021         agentWantsToDropObject(false),
00022         agentWantsToGrabObject(false),
00023         targetObjectIsInGripper(false),
00024         agentIsExecutingMotionAction(false),
00025         currMotionCmd(),
00026         distanceTravelled(0.0f),
00027         agentWantsToGiveObject(false),
00028         giveTargetObject(),
00029         agentIsReceiving(false),
00030         agentReceivingFrom(0),
00031         gotGiveReady(false),
00032         gotGiveInformation(false),
00033         giveAngleToTurn(0.0),
00034         giveObjType(""),
00035         pages(),
00036         currPageIndex(0),
00037         newReqdPage(0),
00038         ptasks(),
00039         scoreQueue(),
00040         stringToSpeak(""),
00041         playQueue(),
00042         agentGazePoints()
00043     {
00044         // generate the gaze points
00045         generateGazePoints();
00046     }
00047 
00048     KoduAgent::~KoduAgent() {
00049         GeneralFncs::destroyAllPtrsInQueue(ptasks);
00050         GeneralFncs::destroyAllPtrsInVector(pages);
00051         stringToSpeak.clear();
00052     }
00053 
00054     KoduAgent& KoduAgent::operator=(const KoduAgent& kAgent) {
00055         if (this != &kAgent) {
00056             gripperObject = kAgent.gripperObject;
00057             agentIsExecutingManipAction = kAgent.agentIsExecutingManipAction;
00058             agentWantsToDropObject = kAgent.agentWantsToDropObject;
00059             agentWantsToGrabObject = kAgent.agentWantsToGrabObject;
00060             targetObjectIsInGripper = kAgent.targetObjectIsInGripper;
00061             agentIsExecutingMotionAction = kAgent.agentIsExecutingMotionAction;
00062             currMotionCmd = kAgent.currMotionCmd;
00063             distanceTravelled = kAgent.distanceTravelled;
00064             pages = kAgent.pages;
00065             currPageIndex = kAgent.currPageIndex;
00066             newReqdPage = kAgent.newReqdPage;
00067             ptasks = kAgent.ptasks;
00068             scoreQueue = kAgent.scoreQueue;
00069             stringToSpeak = kAgent.stringToSpeak;
00070             playQueue = kAgent.playQueue;
00071             agentGazePoints = kAgent.agentGazePoints;
00072         }
00073         return *this;
00074     }
00075 
00076     /// ================================ Static initializations ================================ ///
00077     const float KoduAgent::kLocalizationDistanceThreshold = 1000.0f;
00078 
00079     /// ================================ Gaze functions ================================ ///
00080     void KoduAgent::generateGazePoints() {
00081         // SA: the search area (in degrees)--(from -SA/2 to SA/2)
00082         const float kSearchArea = mathutils::deg2rad(50.0f);  // was 200 degrees
00083         const float kAngleIncrement = mathutils::deg2rad(50.0f);   // was 25 degrees from Troi
00084         // the search radius
00085         float radius = 750.0f;
00086         // the beginning angle
00087         float currAngle = -1.0f * kSearchArea / 2.0f;
00088         // loop until all the search points have been generated
00089         while (currAngle <= (kSearchArea / 2.0f)) {
00090             agentGazePoints.push_back(
00091                 Point(
00092                     cos(currAngle) * radius,  // x-value
00093                     sin(currAngle) * radius,  // y-value
00094                     0.0f,                     // z-value
00095                     DualCoding::egocentric    // point is relative to agent body
00096                 ));
00097             currAngle += kAngleIncrement; // increment the current angle after generating each point
00098         }
00099     }
00100 
00101     const std::vector<Point>& KoduAgent::getGazePoints() const {
00102         return agentGazePoints;
00103     }
00104 
00105     /// ================================ Grasper functions ================================ ///
00106     bool KoduAgent::isExecutingManipAction() const {
00107         return agentIsExecutingManipAction;
00108     }
00109 
00110     bool KoduAgent::isHoldingAnObject() const {
00111         return targetObjectIsInGripper;
00112     }
00113 
00114     void KoduAgent::manipulationComplete() {
00115         // check the type of manipulation completed
00116         if (agentWantsToDropObject) {
00117             setWantsToDropObjectFlag(false);    // the robot no longer "wants to drop an object"
00118             setTargetInGripperFlag(false);      // the object is no longer in the gripper
00119         }
00120         // else, it must be the grab action
00121         else {
00122             setWantsToGrabObjectFlag(false);    // the robot no longer "wants to grab an object"
00123             setTargetInGripperFlag();           // (implicit true) object is in the gripper
00124         }
00125         setIsExecutingManipActionFlag(false);   // the manipulation action is no longer executing
00126     }
00127 
00128     void KoduAgent::setIsExecutingManipActionFlag(bool bval) {
00129         agentIsExecutingManipAction = bval;
00130     }
00131 
00132     void KoduAgent::setTargetInGripperFlag(bool bval) {
00133         targetObjectIsInGripper = bval;
00134     }
00135 
00136     void KoduAgent::setWantsToDropObjectFlag(bool bval) {
00137         agentWantsToDropObject = bval;
00138     }
00139 
00140     void KoduAgent::setWantsToGrabObjectFlag(bool bval) {
00141         agentWantsToGrabObject = bval;
00142     }
00143 
00144     void KoduAgent::signalDropActionStart() {
00145         setIsExecutingManipActionFlag();    // states the robot is executing a manipulation action
00146         setWantsToDropObjectFlag();         // the robot wants to drop an object
00147     }
00148 
00149     void KoduAgent::signalGrabActionStart() {
00150         setIsExecutingManipActionFlag();    // states the robot is executing a manipulation action
00151         setWantsToGrabObjectFlag();         // the robot wants to grab an object
00152     }
00153 
00154     void KoduAgent::signalGiveActionStart() {
00155         setIsExecutingManipActionFlag();
00156         setIsExecutingMotionActionFlag();
00157         setWantsToGiveObjectFlag();
00158     }
00159 
00160     bool KoduAgent::wantsToDropObject() const {
00161         return agentWantsToDropObject;
00162     }
00163 
00164     bool KoduAgent::wantsToGrabObject() const {
00165         return agentWantsToGrabObject;
00166     }
00167 
00168     /// ================================ Motion functions ================================ ///
00169     bool KoduAgent::bodyIsInMotion() const {
00170         return VRmixin::isWalkingFlag;
00171     }
00172 
00173     bool KoduAgent::isExecutingMotionAction() const {
00174         return agentIsExecutingMotionAction;
00175     }
00176 
00177     bool KoduAgent::needsToLocalize() const {
00178         return (distanceTravelled >= kLocalizationDistanceThreshold);
00179     }
00180 
00181     void KoduAgent::motionComplete() {
00182       // make sure the current motion command is invalid
00183       currMotionCmd = MotionCommand();
00184       setIsExecutingMotionActionFlag(false);
00185     }
00186 
00187     void KoduAgent::signalMotionActionStart() {
00188         setIsExecutingMotionActionFlag();
00189     }
00190 
00191     void KoduAgent::setIsExecutingMotionActionFlag(bool bval) {
00192         agentIsExecutingMotionAction = bval;
00193     }
00194 
00195     void KoduAgent::setMotionCommand(const MotionCommand& kCmd) {
00196         currMotionCmd = kCmd;
00197     }
00198 
00199     /// ================================ Give functions =================================== ///
00200     void KoduAgent::setWantsToGiveObjectFlag(bool bval) {
00201         agentWantsToGiveObject = bval;
00202     }
00203 
00204     void KoduAgent::setIsReceiving(bool bval) {
00205         agentIsReceiving = bval;
00206         setIsExecutingManipActionFlag(bval);
00207         setIsExecutingMotionActionFlag(bval);
00208 
00209     }
00210 
00211     bool KoduAgent::wantsToGiveObject() const {
00212         return agentWantsToGiveObject;
00213     }
00214 
00215 
00216     /// ================================ Scoring functions ================================ ///
00217     bool KoduAgent::hasNewScoreChanges() const {
00218         return (!scoreQueue.empty());
00219     }
00220 
00221     /// ================================ Page functions ================================ ///
00222     KoduPage* KoduAgent::getCurrentPage() const {
00223         return pages[currPageIndex];
00224     }
00225 
00226     KoduPage* KoduAgent::getPage(unsigned int pageNumber) const {
00227         return getPageInPos(pageNumber - 1);
00228     }
00229 
00230     KoduPage* KoduAgent::getPageInPos(unsigned int pageIndex) const {
00231         if (pageIndex < pages.size()) {
00232             return pages[pageIndex];
00233         } else {
00234             std::cout << "Page index \"" << pageIndex << "\" is out of bounds!\nReturning NULL...\n";
00235             return NULL;
00236         }
00237     }
00238 
00239     bool KoduAgent::hasNewPageNumber() const {
00240         return (newReqdPage > 0);
00241     }
00242 
00243     /// ================================ Speech functions ================================ ///
00244     bool KoduAgent::hasTextToSay() const {
00245         return (!stringToSpeak.empty());
00246     }
00247 
00248     /// ================================ Sound functions ================================ ///
00249     bool KoduAgent::hasSoundsToPlay() const {
00250         return (!playQueue.empty());
00251     }
00252 }

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