Go to the documentation of this file.00001
00024 #include "Predictor.h"
00025 #include "../HelperFunctions.h"
00026
00027 const TooN::SE3<double> Predictor::droneToBottom = TooN::SE3<double>(TooN::SO3<double>(TooN::makeVector(3.14159265,0,0)),TooN::makeVector(0,0,0));
00028 const TooN::SE3<double> Predictor::bottomToDrone = Predictor::droneToBottom.inverse();
00029
00030 const TooN::SE3<double> Predictor::droneToFront = TooN::SE3<double>(TooN::SO3<double>(TooN::makeVector(3.14159265/2,0,0)),TooN::makeVector(0,0.025,-0.2));
00031 const TooN::SE3<double> Predictor::frontToDrone = Predictor::droneToFront.inverse();
00032
00033 const TooN::SE3<double> Predictor::droneToFrontNT = TooN::SE3<double>(TooN::SO3<double>(TooN::makeVector(3.14159265/2,0,0)),TooN::makeVector(0,0,0));
00034 const TooN::SE3<double> Predictor::frontToDroneNT = Predictor::droneToFrontNT.inverse();
00035
00036
00037
00038 Predictor::Predictor(std::string basePath)
00039 {
00040
00041 setPosRPY(0,0,0,0,0,0);
00042 lastAddedDronetime = 0;
00043 }
00044
00045
00046 Predictor::~Predictor(void)
00047 {
00048 }
00049
00050 void Predictor::calcCombinedTransformations()
00051 {
00052 globalToFront = droneToFront * globaltoDrone;
00053 globalToBottom = droneToBottom * globaltoDrone;
00054 frontToGlobal = globalToFront.inverse();
00055 bottmoToGlobal = globalToBottom.inverse();
00056 }
00057
00058
00059
00060 void Predictor::setPosRPY(double newX, double newY, double newZ, double newRoll, double newPitch, double newYaw)
00061 {
00062
00063 x = newX; y = newY; z = newZ;
00064 roll = newRoll; pitch = newPitch; yaw = newYaw;
00065
00066
00067 droneToGlobal.get_translation()[0] = x;
00068 droneToGlobal.get_translation()[1] = y;
00069 droneToGlobal.get_translation()[2] = z;
00070 droneToGlobal.get_rotation() = rpy2rod(roll,pitch,yaw);
00071
00072 globaltoDrone = droneToGlobal.inverse();
00073
00074
00075 calcCombinedTransformations();
00076 }
00077
00078
00079 void Predictor::setPosSE3_globalToDrone(TooN::SE3<double> newGlobaltoDrone)
00080 {
00081
00082 globaltoDrone = newGlobaltoDrone;
00083 droneToGlobal = globaltoDrone.inverse();
00084
00085
00086 x = droneToGlobal.get_translation()[0];
00087 y = droneToGlobal.get_translation()[1];
00088 z = droneToGlobal.get_translation()[2];
00089 rod2rpy(droneToGlobal.get_rotation(),&roll,&pitch,&yaw);
00090
00091
00092 calcCombinedTransformations();
00093 }
00094 void Predictor::setPosSE3_droneToGlobal(TooN::SE3<double> newDroneToGlobal)
00095 {
00096 droneToGlobal = newDroneToGlobal;
00097 globaltoDrone = droneToGlobal.inverse();
00098
00099 x = droneToGlobal.get_translation()[0];
00100 y = droneToGlobal.get_translation()[1];
00101 z = droneToGlobal.get_translation()[2];
00102
00103 rod2rpy(droneToGlobal.get_rotation(),&roll,&pitch,&yaw);
00104
00105 calcCombinedTransformations();
00106 }
00107
00108
00109
00110
00111 void Predictor::predictOneStep(ardrone_autonomy::Navdata* nfo)
00112 {
00113 double timespan = nfo->tm - lastAddedDronetime;
00114 lastAddedDronetime = nfo->tm;
00115 if(timespan > 50000 || timespan < 1)
00116 timespan = std::max(0.0,std::min(5000.0,timespan));
00117
00118
00119
00120 double dxDrone = nfo->vx * timespan / 1000000000;
00121 double dyDrone = nfo->vy * timespan / 1000000000;
00122
00123 double yawRad = (nfo->rotZ/1000.0) * 3.1415/180.0;
00124 x += sin(yawRad)*dxDrone+cos(yawRad)*dyDrone;
00125 y += cos(yawRad)*dxDrone-sin(yawRad)*dyDrone;
00126
00127 double alt = (nfo->altd*0.001) / sqrt(1.0 + (tan(nfo->rotX * 3.14159268 / 180)*tan(nfo->rotX * 3.14159268 / 180)) \
00128 + (tan(nfo->rotY * 3.14159268 / 180)*tan(nfo->rotY * 3.14159268 / 180)) );
00129
00130
00131 if (! std::isfinite(alt))
00132 alt = nfo->altd * 0.001;
00133
00134
00135 if(abs(z - alt) > 0.12)
00136 {
00137 if(std::abs(z - alt) > abs(zCorruptedJump))
00138 zCorruptedJump = z - alt;
00139 zCorrupted = true;
00140 }
00141
00142 z = alt;
00143
00144
00145 roll = nfo->rotX/1000.0;
00146 pitch = nfo->rotY/1000.0;
00147 yaw = nfo->rotZ/1000.0;
00148
00149 }
00150 void Predictor::resetPos()
00151 {
00152 zCorrupted = false;
00153 zCorruptedJump = 0;
00154 setPosRPY(0,0,0,0,0,0);
00155 }