KIFlyTo.cpp
Go to the documentation of this file.
00001 
00021 #include "KIFlyTo.h"
00022 #include "../DroneController.h"
00023 #include "../ControlNode.h"
00024 #include "../../HelperFunctions.h"
00025 
00026 
00027 KIFlyTo::KIFlyTo(DronePosition checkpointP, 
00028                 double stayTime,
00029                 double maxControlFactorP,
00030                 double initialReachedDistP,
00031                 double stayWithinDistP)
00032 {
00033         stayTimeMs = (int)(1000*stayTime);
00034         maxControlFactor = maxControlFactorP;
00035         initialReachedDist = initialReachedDistP;
00036         stayWithinDist = stayWithinDistP;
00037 
00038         checkpoint = checkpointP;
00039 
00040         reachedAtClock = -1;
00041         reached = false;
00042         
00043         targetSet = false;
00044 
00045         isCompleted = false;
00046 
00047         char buf[200];
00048         snprintf(buf,200,"goto %.2f %.2f %.2f %.2f", checkpointP.pos[0], checkpointP.pos[1], checkpointP.pos[2], checkpointP.yaw);
00049         command = buf;
00050 }
00051 
00052 
00053 KIFlyTo::~KIFlyTo(void)
00054 {
00055 }
00056 
00057 
00058 bool KIFlyTo::update(const tum_ardrone::filter_stateConstPtr statePtr)
00059 {
00060         if(!targetSet)
00061                 controller->setTarget(checkpoint);
00062         targetSet = true;
00063 
00064         // target reached?
00065         if(!isCompleted && reached && (getMS() - reachedAtClock) > stayTimeMs)
00066         {
00067                 printf("checkpoint done!\n");
00068                 isCompleted = true;
00069         }
00070         if(isCompleted)
00071         {
00072                 node->sendControlToDrone(controller->update(statePtr));
00073                 return true;
00074         }
00075 
00076 
00077         // get target dist:
00078         TooN::Vector<3> diffs = TooN::makeVector(
00079                         statePtr->x - checkpoint.pos[0],
00080                         statePtr->y - checkpoint.pos[1],
00081                         statePtr->z - checkpoint.pos[2]);
00082 
00083         double diffYaw = statePtr->yaw - checkpoint.yaw;
00084         double diffDistSquared = diffs[0] * diffs[0] + diffs[1] * diffs[1] + diffs[2] * diffs[2];
00085 
00086         // if not reached yet, need to get within small radius to count.
00087         if(!reached && diffDistSquared < initialReachedDist * initialReachedDist && diffYaw*diffYaw < 25)
00088         {
00089                 reached = true;
00090                 reachedAtClock = getMS();
00091                 printf("target reached initially!\n");
00092         }
00093 
00094         // if too far away again: revoke reached status...
00095         if(reached && (diffDistSquared > stayWithinDist * stayWithinDist || diffYaw*diffYaw > 25))
00096         {
00097                 reached = false;
00098                 printf("target lost again!\n");
00099         }
00100 
00101         // control!
00102         node->sendControlToDrone(controller->update(statePtr));
00103         return false;   // not done yet (!)
00104 }


tum_ardrone
Author(s):
autogenerated on Sat Jun 8 2019 20:27:23