00001
00002 #ifndef _SHAPE_SPACE_PLANNER_XYTHETA_H_
00003 #define _SHAPE_SPACE_PLANNER_XYTHETA_H_
00004
00005 #include "Motion/Kinematics.h"
00006
00007 #include "Planners/RRT/ShapeSpacePlannerBase.h"
00008
00009 class ShapeSpacePlannerXYTheta;
00010
00011
00012
00013 class RRTNodeXYTheta : public RRTNodeBase {
00014 public:
00015
00016 typedef std::pair<std::pair<float,float>,AngTwoPi> NodeValue_t;
00017 typedef GenericRRTBase::PlannerResult<2> PlannerResult;
00018 NodeValue_t q;
00019
00020
00021 RRTNodeXYTheta(const NodeValue_t &_q, unsigned int _parent) : RRTNodeBase(_parent), q(_q) {};
00022
00023 class CollisionChecker : public ShapeSpaceCollisionCheckerBase<2> {
00024 public:
00025 CollisionChecker(DualCoding::ShapeSpace & shs,
00026 const DualCoding::Shape<DualCoding::PolygonData> &_worldBounds,
00027 float _inflation) :
00028 ShapeSpaceCollisionCheckerBase<2>(shs, _worldBounds, _inflation) {}
00029
00030 virtual bool collides(const NodeValue_t &qnew, PlannerResult* result=NULL) const;
00031 };
00032
00033 static const unsigned int maxInterpolations = 10;
00034 static const AngSignPi turnLimit;
00035
00036 virtual float distance(const NodeValue_t &target);
00037 static void generateSample(const NodeValue_t &lower, const NodeValue_t &upper, NodeValue_t &sample);
00038 static Interp_t interpolate(const NodeValue_t &start, const NodeValue_t &target, const NodeValue_t &interp,
00039 bool truncate, CollisionChecker *cc, NodeValue_t &reached, bool fromOtherTree);
00040 static Interp_t smoothInterpolate(const NodeValue_t &start, const NodeValue_t &target, const NodeValue_t &interp, CollisionChecker *cc);
00041 static bool goodAngle(const NodeValue_t &q1, const NodeValue_t &qnew);
00042
00043 virtual std::string toString() const;
00044 };
00045
00046
00047
00048
00049 class ShapeSpacePlannerXYTheta : public GenericRRT<RRTNodeXYTheta, 2> {
00050 public:
00051 typedef RRTNodeXYTheta NodeType_t;
00052 typedef NodeType_t::NodeValue_t NodeValue_t;
00053 typedef GenericRRTBase::PlannerResult<2> PlannerResult;
00054
00055 ShapeSpacePlannerXYTheta(DualCoding::ShapeSpace &shs,
00056 const DualCoding::Shape<DualCoding::PolygonData> &worldBounds = Shape<PolygonData>(),
00057 float inflation = 0);
00058
00059 virtual ~ShapeSpacePlannerXYTheta() {}
00060
00061 float targetHeading;
00062
00063 virtual void initialize(const NodeValue_t &start, std::vector<NodeType_t> &treeStartResult,
00064 const NodeValue_t &end, std::vector<NodeType_t> &treeEndResult);
00065 virtual void buildPath(const std::vector<NodeType_t> *treeStart, const std::vector<NodeType_t> *treeEnd,
00066 std::vector<NodeValue_t> &path);
00067
00068 using GenericRRT<NodeType_t, 2>::planPath;
00069 PlannerResult
00070 planPath(const Point &start,
00071 const Point &end,
00072 const AngTwoPi &initialHeading,
00073 const AngTwoPi &targetHeading,
00074 unsigned int _maxIterations=4000,
00075 std::vector<NodeValue_t> *pathResult=NULL,
00076 std::vector<NodeType_t> *treeStartResult=NULL,
00077 std::vector<NodeType_t> *treeEndResult=NULL);
00078
00079 static void plotPath(const std::vector<NodeValue_t> &path,
00080 Shape<GraphicsData> &graphics,
00081 rgb color = rgb(0,0,255));
00082
00083 static void plotTree(const std::vector<NodeType_t> &tree,
00084 Shape<GraphicsData> &graphics,
00085 rgb color = rgb(0,0,255));
00086 };
00087
00088 #endif