Uav.h
Go to the documentation of this file.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
00033
00034 #ifndef __UAV_H_
00035 #define __UAV_H_
00036
00037 #ifdef MIP_HOST_APPLE
00038 #include <applePatch.h>
00039 #endif
00040
00041 #include <stdlib.h>
00042 #include <string>
00043 #include <sstream>
00044 #include <vector>
00045 #include <assert.h>
00046
00047 #include <CommonOptions.h>
00048
00049 #include <baselib.h>
00050 #include <RangeSens.h>
00051 #include <MotionModule3D.h>
00052 #include <PositionDetector3D.h>
00053
00054 #include <Resource.h>
00055
00056 namespace MipResources {
00057
00061
00063
00064
00068 enum UavModes{
00069 UAV_FREE_MODE,
00070 UAV_POSITION_MODE,
00071 UAV_VELOCITY_MODE,
00072 UAV_ACCELERATION_MODE,
00073 UAV_MODE_NUM,
00074 };
00075
00078 static const char* UavModesNames[UAV_MODE_NUM] = {
00079 "FreeMode",
00080 "PositionMode",
00081 "VelocityMode",
00082 "AccelerationMode"
00083 };
00084
00088 class UavOptions : public Options {
00089 public:
00090 IntOption* gps;
00091 UavOptions(){
00092 gps = createIntOption("uavGps", "whether (1) or not (0) the gps is onboard, default 0", 0);
00093 updateValues();
00094 }
00095
00096 string getObjectName() const {
00097 return "UavOptions";
00098 }
00099 };
00100
00101
00105 class UavPar{
00106 private:
00107 int _id;
00108 Decimal _lenght;
00109 Decimal _width;
00110 Decimal _height;
00111 string _name;
00113 protected:
00116 void setId(int i){
00117 assert(i>0);
00118 _id = i;
00119 }
00120
00123 void setLength(Decimal r){
00124 assert(r > 0.0);
00125 _lenght = r;
00126 }
00127
00130 void setWidth(Decimal r){
00131 assert(r>0.0);
00132 _width=r;
00133 }
00134
00137 void setHeight(Decimal r){
00138 assert(r>0.0);
00139 _height=r;
00140 }
00141
00143 void setName(string n){
00144 _name=n;
00145 }
00146
00147 public:
00149 UavPar (){
00150 _id = 0;
00151 _lenght = 0.0;
00152 _width = 0.0;
00153 _height = 0.0;
00154 _name = string();
00155 }
00156
00158 UavPar(const UavPar &r){
00159 _id = r._id;
00160 _lenght = r._lenght;
00161 _width = r._width;
00162 _height = r._height;
00163 _name = r._name;
00164 }
00165
00167 UavPar& operator=(const UavPar& r){
00168 if (this != &r){
00169 _id = r._id;
00170 _lenght = r._lenght;
00171 _width = r._width;
00172 _height = r._height;
00173 _name = r._name;
00174 }
00175 return *this;
00176 }
00178 int id(){
00179 return _id;
00180 }
00182 Decimal lenght(){
00183 return _lenght;
00184 }
00186 Decimal width(){
00187 return _width;
00188 }
00190 Decimal height(){
00191 return _height;
00192 }
00194 string name(){
00195 return _name;
00196 }
00198 string print(){
00199 stringstream s;
00200 s << "name " << name() << endl
00201 << "id " << _id << endl
00202 << "lenght " << _lenght << endl
00203 << "width " << _width << endl
00204 << "height " << _height << endl;
00205 return s.str();
00206 }
00207 };
00208
00209
00213 class UavVar{
00214
00215 protected:
00216 Position3D _position;
00217 Orientation3D _attitude;
00218 Velocity3D _velocity;
00219 Position3D _omega;
00220 Position3D _localVelocity;
00221 Position3D _localOmega;
00222 Time _lastTime;
00223 Time _lastTimeQuad;
00224
00226 Acceleration3D _accel;
00227 bool ptammInitProxy;
00228
00229
00230
00231 pthread_mutex_t _varMutex;
00232
00233 int remCtrl;
00234 public:
00235 Position3D desPosi;
00236 Velocity3D desVel;
00237 Acceleration3D desAcc;
00238 Orientation3D desAtt;
00239 Decimal desThr;
00240 Angle desYaw;
00241
00242 UavModes controlMode;
00243
00245 UavVar ();
00246
00249 Time time();
00250
00251
00252
00253
00254 inline void setPtammInitProxy(bool value){ptammInitProxy = value;};
00255 inline bool getPtammInitProxy(){return ptammInitProxy;};
00256
00259 Time quadTime();
00260
00263 Position3D position();
00264
00267 Orientation3D attitude();
00268
00271 Velocity3D velocity();
00272
00274
00275
00276 Acceleration3D acceleration();
00277
00278
00281 Position3D omega();
00282
00285 Position3D localOmega();
00286
00289 Position3D localVelocity();
00290
00292 void setPositionVal(Decimal x, Decimal y, Decimal z);
00293
00295 void setPositionVal(Position3D &p);
00296
00298 void setAttitudeVal(Decimal roll, Decimal pitch, Decimal yaw);
00299
00301 void setVelocityVal(Decimal x, Decimal y, Decimal z);
00302
00304 void setOmegaVal(Decimal x, Decimal y, Decimal z);
00305
00307 void setLocalVelocityVal(Decimal x, Decimal y, Decimal z);
00308
00310 void setLocalOmegaVal(Decimal x, Decimal y, Decimal z);
00311
00314 void setTime(Time newTime);
00315
00316
00317
00318
00319
00322 void setTimeQuad(Time newTime);
00323
00326 void setRemoteControlled(int newStatus);
00327
00329 int getRemoteControlled();
00330
00331 };
00332
00333
00337 class Uav : public Resource{
00338 protected:
00339 UavOptions options;
00341 UavPar *_par;
00342 UavVar *_var;
00344 PositionDetector3D *_gps;
00346 bool gpsActive;
00347
00348 public:
00350 Uav(){
00351 }
00352
00354 Uav(int argc, const char* argv[]){
00355 gpsActive = false;
00356 }
00357
00359
00360
00362 virtual UavPar* getPar() {
00363 return _par;
00364 }
00365
00367 virtual UavVar* getVar(){
00368 return _var;
00369 }
00370
00375 virtual bool setStatus(Orientation3D& oDes, Decimal& tdes) = 0;
00376
00380 virtual bool setThrust(Decimal tdes) = 0;
00381
00385 virtual bool setYaw(Angle yaw) = 0;
00386
00391 virtual bool setPose(Pose3D& pDes, short ctrlIn = 0) = 0;
00392
00396 virtual bool setAttitude(Orientation3D& oDes) = 0;
00397
00399 virtual bool setPosition(Position3D p,Velocity3D v = Velocity3D(0.0,0.0,0.0),Acceleration3D a = Acceleration3D(0.0,0.0,0.0)) = 0;
00400
00402 virtual bool setVelocity(Velocity3D p,Acceleration3D a = Acceleration3D(0.0,0.0,0.0)) = 0;
00403
00405 virtual bool setAcceleration(Acceleration3D p) = 0;
00406
00408 virtual bool readPosition() = 0;
00409
00411 virtual bool readVelocity() = 0;
00412
00414 virtual bool readAttitude() = 0;
00415
00416
00418 virtual bool readAllData() = 0;
00419
00420 };
00421
00422 };
00423
00424 #endif
00425
00426
00427
00428
00429
00430