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