Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
WaypointList.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_WaypointList_h_ 00003 #define INCLUDED_WaypointList_h_ 00004 00005 #include <vector> 00006 00007 //! Holds information about each waypoint, see WaypointEngine for overview 00008 struct Waypoint { 00009 public: 00010 00011 //! defines different ways to interpret the position values 00012 enum posType_t { 00013 POSTYPE_EGOCENTRIC, //!< #x and #y are relative to current heading - so x is forward and y is strafe 00014 POSTYPE_OFFSET, //!< #x and #y are oriented with the coordinates, but relative to current location (delta x and delta y) 00015 POSTYPE_ABSOLUTE //!< #x and #y are a specific coordinate location 00016 }; 00017 00018 //! constructor 00019 Waypoint() 00020 : x(0), y(0), angle(0), arc(), speed(), turnSpeed(), posType(), angleIsRelative(), trackPath() 00021 {} 00022 00023 //! constructor 00024 Waypoint(float xc, float yc, Waypoint::posType_t pos_rel, float ac, bool ang_rel, float spd, bool track, float turn) 00025 : x(xc), y(yc), angle(ac), arc(0), speed(spd), turnSpeed(turn), posType(pos_rel), angleIsRelative(ang_rel), trackPath(track) 00026 {} 00027 00028 //!< If @a next is a relative waypoint (offset or egocentric), it is added to this instance's location; otherwise if @a next is absolute, this is set to @a next 00029 /*! The Waypoint::angle field is used to store the headings */ 00030 void apply(const Waypoint& next, float eps[]); 00031 00032 float x; //!< the displacement along x (millimeters), subject to #posType 00033 float y; //!< the displacement along y (millimeters), subject to #posType 00034 float angle; //!< either the angle relative to path to maintain, or the heading to maintain, see #angleIsRelative 00035 float arc; //!< angle of sector of arc to use to get to waypoint (0 means straight line) 00036 float speed; //!< speed (in millimeters per second) 00037 float turnSpeed; //!< maximum speed to correct heading (in radians per second) 00038 posType_t posType; //!< lets us know how to interpret the #x and #y values 00039 bool angleIsRelative; //!< if true, #angle is interpreted as relative to the path; otherwise, interpreted as an absolute heading to maintain 00040 bool trackPath; //!< if true, if off course, will attempt to get back on path at the ideal location; if false, simply heads directly for waypoint from whereever it is 00041 }; 00042 00043 class WaypointList : public std::vector<Waypoint> { 00044 public: 00045 WaypointList() {} 00046 00047 static const float defaultTurnSpeed; 00048 00049 //!@name Adding Waypoints 00050 00051 //! adds a waypoint to the end of the list, allows you to specify turtle-style instructions 00052 /*! <img src="Waypoint_Ego.png"> 00053 * @param forward distance forward to move (negative to move backward of course) 00054 * @param left distance to the left to move (negative to move right of course) 00055 * @param angle angle of attack to use on the path 00056 * @param angleIsRelative controls interpretation of @a angle; true means angle specifies an offset from the bearing of the target waypoint, false means maintain an absolute heading 00057 * @param speed is the speed to move at; millimeters per second 00058 * @param turnSpeed is the speed to turn; radians per second */ 00059 void addEgocentricWaypoint(float forward, float left, float angle, bool angleIsRelative, float fwdSpeed, float turnSpeed=-1.f) { 00060 push_back(Waypoint(forward,left,Waypoint::POSTYPE_EGOCENTRIC,angle,angleIsRelative,fwdSpeed,false,turnSpeed>=0?turnSpeed:defaultTurnSpeed)); 00061 } 00062 //! adds a waypoint to the end of the list, allows you to set locations relative to the location of the previous waypoint (or starting position) 00063 /*! <img src="Waypoint_Off.png"> 00064 * @param x distance delta along x axis of the waypoint 00065 * @param y distance delta along y axis of the waypoint 00066 * @param angle angle of attack to use on the path 00067 * @param angleIsRelative controls interpretation of @a angle; true means angle specifies an offset from the bearing of the target waypoint, false means maintain an absolute heading 00068 * @param speed is the speed to move at; millimeters per second 00069 * @param turnSpeed is the speed to turn; radians per second */ 00070 void addOffsetWaypoint(float x, float y, float angle, bool angleIsRelative, float fwdSpeed, float turnSpeed=-1.f) { 00071 push_back(Waypoint(x,y,Waypoint::POSTYPE_OFFSET,angle,angleIsRelative,fwdSpeed,false,turnSpeed>=0?turnSpeed:defaultTurnSpeed)); 00072 } 00073 //! adds a waypoint to the end of the list, allows you to set locations relative to the world coordinate frame 00074 /*! <img src="Waypoint_Abs.png"> 00075 * @param x position along x axis of the waypoint 00076 * @param y position along y axis of the waypoint 00077 * @param angle angle of attack to use on the path 00078 * @param angleIsRelative controls interpretation of @a angle; true means angle specifies an offset from the bearing of the target waypoint, false means maintain an absolute heading 00079 * @param fwdSpeed is the speed to move at; millimeters per second 00080 * @param turnSpeed is the speed to turn; radians per second */ 00081 void addAbsoluteWaypoint(float x, float y, float angle, bool angleIsRelative, float fwdSpeed, float turnSpeed=-1.f) { 00082 push_back(Waypoint(x,y,Waypoint::POSTYPE_ABSOLUTE,angle,angleIsRelative,fwdSpeed,false,turnSpeed>=0?turnSpeed:defaultTurnSpeed)); 00083 } 00084 00085 //! adds a waypoint to the end of the list, using an arcing path to get there, allows you to specify turtle-style instructions to specify the focus of the arc 00086 /*! <img src="Waypoint_Ego.png"> 00087 * If you would rather specify the ending point and then "bow" the path, try addEgocentricWaypoint() followed by setting the Waypoint::arc field directly 00088 * @param forward distance in front of the center of the circle of the arc 00089 * @param left distance to the left of the center of the circle of the arc 00090 * @param angle angle of attack to use on the path 00091 * @param angleIsRelative controls interpretation of @a angle; true means angle specifies an offset from the bearing of the target waypoint, false means maintain an absolute heading 00092 * @param speed is the speed to move at; millimeters per second 00093 * @param arc is the number of radians the arc fills; arcs near 0 (or multiples of 360) may cause numeric instability */ 00094 void addEgocentricArc(float forward, float left, float angle, bool angleIsRelative, float speed, float arc) { 00095 addEgocentricWaypoint(forward,left,angle,angleIsRelative,speed); 00096 fixArc(arc); 00097 } 00098 //! adds a waypoint to the end of the list, using an arcing path to get there, allows you to specify locations relative to previous waypoint to specify the focus of the arc 00099 /*! <img src="Waypoint_Off.png"> 00100 * If you would rather specify the ending point and then "bow" the path, try addOffsetWaypoint() followed by setting the Waypoint::arc field directly 00101 * @param x distance delta along x of the center of the circle of the arc 00102 * @param y distance delta along y of the center of the circle of the arc 00103 * @param angle angle of attack to use on the path 00104 * @param angleIsRelative controls interpretation of @a angle; true means angle specifies an offset from the bearing of the target waypoint, false means maintain an absolute heading 00105 * @param speed is the speed to move at; millimeters per second 00106 * @param arc is the number of radians the arc fills; arcs near 0 (or multiples of 360) may cause numeric instability */ 00107 void addOffsetArc(float x, float y, float angle, bool angleIsRelative, float speed, float arc) { 00108 addOffsetWaypoint(x,y,angle,angleIsRelative,speed); 00109 fixArc(arc); 00110 } 00111 //! adds a waypoint to the end of the list, using an arcing path to get there, allows you to specify absolute locations to specify the focus of the arc 00112 /*! <img src="Waypoint_Abs.png"> 00113 * If you would rather specify the ending point and then "bow" the path, try addAbsoluteWaypoint() followed by setting the Waypoint::arc field directly 00114 * @param x position along x of the center of the circle of the arc 00115 * @param y position along y of the center of the circle of the arc 00116 * @param angle angle of attack to use on the path 00117 * @param angleIsRelative controls interpretation of @a angle; true means angle specifies an offset from the bearing of the target waypoint, false means maintain an absolute heading 00118 * @param speed is the speed to move at; millimeters per second 00119 * @param arc is the number of radians the arc fills; arcs near 0 (or multiples of 360) may cause numeric instability */ 00120 void addAbsoluteArc(float x, float y, float angle, bool angleIsRelative, float speed, float arc) { 00121 addAbsoluteWaypoint(x,y,angle,angleIsRelative,speed); 00122 fixArc(arc); 00123 } 00124 00125 protected: 00126 //! assumes start at the origin, applies each waypoint through @a it and returns result as an absolute position (angle field stores heading) 00127 Waypoint calcAbsoluteCoords(const_iterator it); 00128 00129 //! assumes the last waypoint is actually center of circle, adjusts it to be the endpoint of following @a arc radians around that circle instead 00130 void fixArc(float arc); 00131 }; 00132 00133 #endif |
Tekkotsu v5.1CVS |
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3 |