Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

KoduActionMotion.h

Go to the documentation of this file.
00001 #ifndef KODU_ACTION_MOTION_H_
00002 #define KODU_ACTION_MOTION_H_
00003 
00004 // INCLUDES
00005 // c++
00006 #include <cmath>
00007 
00008 // tekkotsu
00009 #include "DualCoding/BaseData.h"
00010 #include "DualCoding/DualCoding.h"
00011 #include "DualCoding/ShapeRoot.h"
00012 
00013 // tekkodu
00014 #include "Kodu/Primitives/KoduAction.h"
00015 #include "Kodu/Primitives/PerceptionSearch.h"
00016 #include "Kodu/Generators/KoduGenerators.h"
00017 #include "Kodu/Keepers/ObjectKeeper.h"
00018 
00019 namespace Kodu {
00020 
00021     class MotionCommand {
00022     public:
00023         //! Constructor #1
00024         MotionCommand();
00025 
00026         //! Constructor #2
00027         MotionCommand(const ShapeRoot& kTarget, float fwdSpeed, float trnSpeed);
00028 
00029         //! Constructor #3
00030         MotionCommand(float fwdDist, float trnAngle, float fwdSpeed, float trnSpeed);
00031 
00032         //! Constructor #4
00033         MotionCommand(const ShapeRoot& kTarget, float fwdDist, float trnAngle,
00034             float fwdSpeed, float trnSpeed);
00035         //! Constructor #5
00036         MotionCommand(float fwdDist, float trnAngle, float fwdSpeed, float trnSpeed, bool driven);
00037 
00038         //! Copy Constructor
00039         MotionCommand(const MotionCommand&);
00040 
00041         //! Destructor
00042         ~MotionCommand();
00043 
00044         //! Assignment operator
00045         MotionCommand& operator=(const MotionCommand&);
00046 
00047         //! Equals operator
00048         bool operator==(const MotionCommand&);
00049 
00050         //! Not equals operator
00051         bool operator!=(const MotionCommand&);
00052 
00053         //! Returns the forward speed
00054         float getForwardSpeed() const;
00055 
00056         //! Returns the turning speed
00057         float getTurnSpeed() const;
00058 
00059         //! Returns the distance to travel in the x-direction
00060         float getDistanceToTravel() const;
00061 
00062         //! Returns the angle to turn (in degrees)
00063         float getTurningAngle() const;
00064 
00065         //! True if this is a feasible motion command
00066         bool isValid() const;
00067 
00068         //! Returns if the shape reference is valid or not
00069         bool targetObjectIsValid() const;
00070   
00071         bool isDriven() const;
00072 
00073         //! Returns the target object (if available)
00074         const ShapeRoot& getTargetObject() const;
00075 
00076         friend class KoduActionMotion;
00077         friend std::ostream& operator<<(std::ostream &os, const MotionCommand &cmd);
00078 
00079     private:
00080         ShapeRoot targetObject;
00081         float dx;           //!< How far the robot should move forward (units: mm)
00082         float da;           //!< How much the robot should turn (units: rads)
00083         float forwardSpeed; //!< How fast the robot should move forward (units: mm/s)
00084         float turnSpeed;    //!< How fast the robot should turn (units: rads/s)
00085         bool cmdDriven;
00086     };
00087 
00088     std::ostream& operator<<(std::ostream &os, const MotionCommand &cmd);
00089 
00090     //! Kodu Action Motion (derived from Kodu Action)
00091     class KoduActionMotion : public KoduAction {
00092     public:
00093         //! The different types of move and turn movements
00094         enum MotionType_t {
00095             MT_MOVE_WANDER          = 1L << 0,
00096             MT_MOVE_FORWARD         = 1L << 1,
00097             MT_MOVE_TOWARDS         = 1L << 2,
00098             MT_EMPTY_MOTION_TYPE    = 1L << 3,  // place holder
00099             MT_TURN_DIRECTION       = 1L << 4,
00100             MT_TURN_LEFT            = 1L << 5,
00101             MT_TURN_RIGHT           = 1L << 6,
00102             MT_MOVE_GAMEPAD         = 1L << 7
00103         };
00104 
00105         //! Helps set the speed of a particular motion type
00106         enum MotionRate_t {
00107             MR_NORMAL               = 1L << 0,
00108             MR_QUICKLY              = 1L << 1,
00109             MR_SLOWLY               = 1L << 2
00110         };
00111 
00112         //! Constructor #1
00113         KoduActionMotion(MotionType_t type, MotionRate_t rate, unsigned int motionMagCount);
00114 
00115         //! Constructor #2
00116         KoduActionMotion(Direction_t direction, MotionRate_t rate, unsigned int motionMagCount);
00117 
00118         //! Copy constructor
00119         KoduActionMotion(const KoduActionMotion& kAction);
00120 
00121         //! Destructor
00122         ~KoduActionMotion();
00123 
00124         //! Assignment operator
00125         KoduActionMotion& operator=(const KoduActionMotion& kAction);
00126 
00127         //! Returns the motion command
00128         const MotionCommand getMotionCommand();
00129 
00130         //! Returns the motion type
00131         MotionType_t getMotionType() const;
00132 
00133         //! Returns true if the motion type (action) is "move"
00134         bool motionTypeIsMove() const;
00135 
00136         //! Returns true if the motion type (action) is "turn"
00137         bool motionTypeIsTurn() const;
00138 
00139         //! Used to reinitialize certain variables (e.g. when switching to another page)
00140         virtual void reinitialize();
00141 
00142     private:
00143         //! States what type of movement the robot will do
00144         MotionType_t motionType;
00145 
00146         //! Used to generate constant or random angle values
00147         NumericGenerator angleGen;
00148 
00149         //! Used to generate constant or random distance values
00150         NumericGenerator distGen;
00151 
00152         //! The direction the robot wants to face (north, west, etc.)
00153         Direction_t directionToFace;
00154     };
00155 }
00156 
00157 #endif // KODU_ACTION_MOTION_H_

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