00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef ARACTIONTRIANGLEDRIVETO
00027 #define ARACTIONTRIANGLEDRIVETO
00028
00029 #include "ariaTypedefs.h"
00030 #include "ArAction.h"
00031 #include "ArLineFinder.h"
00032
00034
00069 class ArActionTriangleDriveTo : public ArAction
00070 {
00071 public:
00073 AREXPORT ArActionTriangleDriveTo(const char *name = "triangleDriveTo",
00074 double finalDistFromVertex = 400,
00075 double approachDistFromVertex = 1000,
00076 double speed = 200,
00077 double closeDist = 100,
00078 double acquireTurnSpeed = 30);
00080 AREXPORT virtual ~ArActionTriangleDriveTo();
00082 void setAcquire(bool acquire = false) { myAcquire = acquire; }
00084 bool getAcquire(void) { return myAcquire; }
00086 void setFinalDistFromVertex(double dist) { myFinalDistFromVertex = dist; }
00088 double getFinalDistFromVertex(void) { return myFinalDistFromVertex; }
00090 void setTriangleParams(double line1Length = 254,
00091 double angleBetween = 135,
00092 double line2Length = 254)
00093 { myLine1Length = line1Length; myAngleBetween = angleBetween; myLine2Length = line2Length; }
00094 AREXPORT void setParameters(double finalDistFromVertex = 400,
00095 double approachDistFromVertex = 1000,
00096 double speed = 200,
00097 double closeDist = 100,
00098 double acquireTurnSpeed = 30);
00099
00101 bool getAdjustVertex(void) { return myAdjustVertex; }
00103 void setAdjustVertex(bool adjustVertex) { myAdjustVertex = adjustVertex; }
00105 void setVertexOffset(int localXOffset, int localYOffset, double thOffset)
00106 { myLocalXOffset = localXOffset; myLocalYOffset = localYOffset;
00107 myThOffset = thOffset; }
00108
00110 bool getGotoVertex(void) { return myGotoVertex; }
00112 void setGotoVertex(bool gotoVertex)
00113 { myGotoVertex = gotoVertex; }
00115 void setIgnoreTriangleDist(double dist = 250,
00116 bool useIgnoreInGotoVertexMode = false)
00117 { myIgnoreTriangleDist = dist;
00118 myUseIgnoreInGoto = useIgnoreInGotoVertexMode; }
00120 double getIgnoreTriangleDist(void) { return myIgnoreTriangleDist; }
00122 bool getUseIgnoreInGOtoVertexMode(void) { return myUseIgnoreInGoto; }
00124 void setVertexUnseenStopMSecs(int vertexUnseenStopMSecs = 4000)
00125 { myVertexUnseenStopMSecs = vertexUnseenStopMSecs; }
00127 int getVertexUnseenStopMSecs(void) { return myVertexUnseenStopMSecs; }
00129 void setMaxDistBetweenLinePoints(int maxDistBetweenLinePoints = 0)
00130 { myMaxDistBetweenLinePoints = maxDistBetweenLinePoints; }
00132 void setMaxLateralDist(int maxLateralDist = 0)
00133 { myMaxLateralDist = maxLateralDist; }
00134 enum State {
00135 STATE_INACTIVE,
00136 STATE_ACQUIRE,
00137 STATE_SEARCHING,
00138 STATE_GOTO_APPROACH,
00139 STATE_ALIGN_APPROACH,
00140 STATE_GOTO_VERTEX,
00141 STATE_GOTO_FINAL,
00142 STATE_ALIGN_FINAL,
00143 STATE_SUCCEEDED,
00144 STATE_FAILED
00145 };
00146 State getState(void) { return myState; }
00148 AREXPORT void setLineFinder(ArLineFinder *lineFinder);
00150 AREXPORT ArLineFinder *getLineFinder(void) { return myLineFinder; }
00151
00153 void setLogging(bool logging) { myPrinting = logging; }
00155 bool setLogging(void) { return myPrinting; }
00156 AREXPORT virtual void activate(void);
00157 AREXPORT virtual void deactivate(void);
00158 AREXPORT virtual void setRobot(ArRobot *robot);
00159 AREXPORT virtual ArActionDesired *fire(ArActionDesired currentDesired);
00160 AREXPORT virtual ArActionDesired *getDesired(void) { return &myDesired; }
00161 #ifndef SWIG
00162 AREXPORT virtual const ArActionDesired *getDesired(void) const
00163 { return &myDesired; }
00164 #endif
00165
00170 class Data
00171 {
00172 public:
00173 Data()
00174 { myFinalSet = false; myApproachSet = false; myLinesAndVertexSet = false; }
00175 ~Data() {}
00176 void setLinesAndVertex(std::map<int, ArLineFinderSegment *> *lines,
00177 ArPose vertex)
00178 {
00179 myLines.clear();
00180 std::map<int, ArLineFinderSegment *>::iterator it;
00181 for (it = lines->begin(); it != lines->end(); it++)
00182 {
00183 myLines.push_front(*(*it).second);
00184 }
00185 myVertex = vertex;
00186 myLinesAndVertexSet = true;
00187 }
00188 void setFinal(ArPose final) { myFinalSet = true; myFinal = final; }
00189 void setApproach(ArPose approach)
00190 { myApproachSet = true; myApproach = approach; }
00191 bool myLinesAndVertexSet;
00192 std::list<ArLineSegment> myLines;
00193 ArPose myVertex;
00194 bool myFinalSet;
00195 ArPose myFinal;
00196 bool myApproachSet;
00197 ArPose myApproach;
00198 };
00202 void setSaveData(bool saveData) { mySaveData = saveData; }
00206 bool getSaveData(void) { return mySaveData; }
00207 #ifndef SWIG
00208
00211 Data *getData(void);
00212 #endif // SWIG
00213 protected:
00214
00215 AREXPORT void findTriangle(bool initial, bool goStraight = false);
00216
00217 AREXPORT ArPose findPoseFromVertex(double distFromVertex);
00218
00219 ArPose myVertex;
00220
00221 ArRangeDevice *myLaser;
00222 ArMutex myDataMutex;
00223 bool mySaveData;
00224 Data *myData;
00225 std::map<int, ArLineFinderSegment *> *myLines;
00226 unsigned int myGotLinesCounter;
00227 bool myVertexSeen;
00228 bool myPrinting;
00229 ArTime myVertexSeenLast;
00230 State myState;
00231 bool myAcquire;
00232 double myFinalDistFromVertex;
00233 double myApproachDistFromVertex;
00234 double mySpeed;
00235 double myCloseDist;
00236 double myAcquireTurnSpeed;
00237 bool myTwoStageApproach;
00238 double myLine1Length;
00239 double myAngleBetween;
00240 double myLine2Length;
00241 int myVertexUnseenStopMSecs;
00242 ArActionDesired myDesired;
00243 ArLineFinder *myLineFinder;
00244 bool myOwnLineFinder;
00245 bool myAdjustVertex;
00246 bool myGotoVertex;
00247 int myLocalXOffset;
00248 int myLocalYOffset;
00249 double myThOffset;
00250 double myIgnoreTriangleDist;
00251 bool myUseIgnoreInGoto;
00252 int myMaxDistBetweenLinePoints;
00253 int myMaxLateralDist;
00254 };
00255
00256 #endif // ARACTIONTRIANGLEDRIVETO