HummingBirdUav.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00032 
00033 #ifndef __HUMMING_BIRD_UAV_H__
00034 #define __HUMMING_BIRD_UAV_H__
00035 
00036 #ifdef MIP_HOST_APPLE
00037 #include <applePatch.h>
00038 #endif
00039 
00040 #ifdef USE_ROS
00041  #ifdef FOUND_ROS_LIBS
00042   #include <ros/ros.h>
00043   #include <std_msgs/String.h>
00044   #include <std_msgs/Float32.h>
00045   #include <std_msgs/Float32MultiArray.h>
00046   #include <ros/callback_queue.h>
00047  #endif
00048 #endif
00049 
00050 #include "HummingBirdUavComm.h"
00051 #include "HBstructs.h"
00052 
00053 #include <Uav.h>
00054  
00055 namespace MipResources {
00057  /* @{ */
00058  
00059  class HummingBirdUavOptions : public Options {
00060  public:
00061  StringOption *port_name;
00062  IntOption  *max_input;
00063  IntOption  *fdata_send_rate;
00064  IntOption  *read_rate;
00065  IntOption  *send_rate;
00066  
00067  IntOption   *ctrlin_send_rate;
00068  IntOption   *ctrlfl_send_rate;
00069  
00070  IntOption   *h_sonar_rate;
00071  IntOption   *h_sonar_p_gain;
00072  IntOption   *h_sonar_i_gain;
00073  IntOption   *h_sonar_d_gain;
00074  DecimalOption *height_ref;
00075 
00076  StringOption *log_path;
00077  StringOption *log_name;
00078  BoolOption   *make_log;
00079   BoolOption   *use_ros;
00080   BoolOption   *use_test;
00081  
00082  StringOption *ros_gains_sender_name;
00083 
00084  string getObjectName() const {
00085   return "HummingBirdUavOptions";
00086  }
00087 
00088  HummingBirdUavOptions() {
00089   MIP_DEBUG(5,"HummingBird Options constructor");
00090 
00091   port_name  = createStringOption("hbUavPortName" ,
00092    "Name of com port, default \"/dev/ttyUSB0\".",
00093    "/dev/ttyUSB0");
00094 
00096   max_input  = createIntOption("hbUavMaxInput",
00097    "Maximum remote input in [-2047,+2047], default 500.",
00098    500);
00099 
00100   fdata_send_rate  = createIntOption("hbUavFdataSendRate",
00101    "Rate of data transmission (1000/sendRate Hz) from quadrotor to pc, default 20.",20);
00102   read_rate  = createIntOption("hbUavReadRate",
00103    "Rate of data reading loop (1000/readRate Hz), default 20.",20);
00104   send_rate  = createIntOption("hbUavSendRate",
00105    "Rate of data sending to the quadrotor (1000/sendRate Hz), default 30.",30);
00106 
00107   height_ref = createDecimalOption("hbUavHReference",
00108    "Initial height reference for controller, default 1.5.",1.5);
00109 
00110   h_sonar_rate = createIntOption("hbUavhSonarRate",
00111    "Rate for sonar height controller (1000/rate Hz), default 40.", 40);
00112   h_sonar_p_gain = createIntOption("hbUavhSonarPGain",
00113    "Proportional gain in pid height controller", 200);
00114   h_sonar_i_gain = createIntOption("hbUavhSonarIGain",
00115    "Integral gain in pid height controller",0);
00116   h_sonar_d_gain = createIntOption("hbUavhSonarDGain", 
00117    "Derivative gain in pid height controller", 220);
00118 
00119   log_path = createStringOption("hbUavlogPath",
00120    "Path to save log. Default: current directory.", "./");
00121 
00122   ros_gains_sender_name = createStringOption("hbGainsRosTopicName",
00123    "Name of ros topic for sending gains.", "quad_sendGains");
00124 
00125   time_t rawtime;
00126   struct tm * timeinfo;
00127   char buffer [80];
00128   time ( &rawtime );
00129   timeinfo = localtime ( &rawtime );
00130   strftime(buffer,80,"%Y-%m-%d_%H-%M_HBdata",timeinfo);
00131 
00132   log_name = createStringOption("hbUavlogName",
00133    "Name for log file. Default: date_hour_HBdata.", buffer);
00134 
00135   make_log  = createBoolOption("hbUavmakeLog",
00136    "Whether on not register log. Deafult: true.", false);
00137     use_ros   = createBoolOption("hbUavUseRos",
00138    "Whether on not use ROS. Deafult: false." , false);
00139     use_test  = createBoolOption("hbUavUseTest",
00140    "Whether on not use test version. Deafult: true.", false);
00141 
00142   updateValues();
00143  }
00144 };
00145  
00149  class HummingBirdUavPar : public UavPar{
00150   private:
00151   public:
00152  };
00153  
00157  class HummingBirdUavVar : public UavVar{
00158   private:
00159   public:
00160  };
00161  
00166  class HummingBirdUav : public Uav{
00167   private:
00168    static const ResourcePlate _plate = UAV_HUBI_RES;   
00169    HummingBirdUavComm* _com;
00170    HummingBirdUavVar * _HBvar;
00171 
00172    Thread    _dataThread;
00173    Thread    _ctrlThread;
00174 
00175    EnhancedMutEx _comMutex;  
00176    EnhancedMutEx _ctrlMutex;  
00177 
00178    Time mutexTimeoutWrite;
00179    Time mutexTimeoutRead;
00180 
00181    HummingBirdUavOptions options;
00182 
00183    LABROB_CTRL_INPUT ctrl_input;
00184    bool ctrl_input_update;
00185 
00186    static const Decimal  angle2hubi;   
00187    static const Decimal  hubi2angle;   
00188    static const Decimal  hubi2angleVel;  
00189       
00190    static const int  thrust2hubi = 4095; 
00191    static const Decimal  hubi2thrust;  
00192    ofstream    _logFile;
00193    int         _numrow;
00194    
00195    //ROS FOR HEIGHT
00196    #ifdef USE_ROS
00197     #ifdef FOUND_ROS_LIBS
00198      std_msgs::Float32MultiArray *posDataRos;
00199      ros::NodeHandle *handleRos;
00200      ros::Publisher *chatter_pub;
00201      
00202      //ROS FOR CTRL GAINS
00203      std_msgs::Float32MultiArray *posGainsRos;
00204      ros::NodeHandle *handleGainsRos;
00205      ros::Publisher *chatterGainsPub;
00206      
00207      ros::NodeHandle *handleGainsRos_subscriber;
00208      ros::CallbackQueue queueCallbackGainsRos;
00209      ros::Subscriber subsGainsRos;   // maybe removed (?)
00210      
00211      void receiveNewGains(const std_msgs::Float32MultiArray::ConstPtr& msg);
00212     #endif
00213    #endif
00214 
00215   public:
00216    void dataLoop();
00217    void ctrlLoop();
00218    void doClean(){}
00219 
00220    void startCtrlLoop(){ _ctrlThread.startWork();  }
00221    void stopCtrlLoop() { _ctrlThread.stopWork();  }
00222    void startDataLoop(){ _dataThread.startWork();  }
00223    void stopDataLoop() {_dataThread.stopWork();   }
00224    
00225    /* two mandatory wrappers for mutex */
00226    bool askExclusiveAccess(Time timeout){
00227     return _comMutex.askExclusiveAccess(timeout);
00228    }
00229    void leaveExclusiveAccess(){
00230     _comMutex.leaveExclusiveAccess();
00231    }
00232 
00233    /* two mandatory wrappers for mutex */
00234    bool ctrlAskExclusiveAccess(Time timeout){
00235     return _ctrlMutex.askExclusiveAccess(timeout);
00236    }
00237    void ctrlLeaveExclusiveAccess(){
00238     _ctrlMutex.leaveExclusiveAccess();
00239    }
00240 
00242    HummingBirdUav(int argc, const char** argv);
00243 
00245    ~HummingBirdUav();
00246 
00248    ResourcePlate getPlate() const {
00249     return _plate;
00250    }
00251 
00254    Position3D getPosition(Time& t) {
00255     t = _HBvar->time();
00256     return _HBvar->position();
00257    }
00258 
00261    Orientation3D getAttitude(Time& t) {
00262     t = _HBvar->time();
00263     return _HBvar->attitude();
00264    }
00265 
00267    HummingBirdUavComm* getCom() {
00268     return _com;
00269    }
00270 
00275    bool setStatus(Orientation3D& pDes, Decimal& tDes);
00276 
00280    bool setThrust(Decimal tDes);
00281       
00286    bool setControllersGains(Decimal height_pid_des[3]);
00287 
00291    bool setFiltersGains(Decimal sonar_h_filt_des[2]);
00292 
00296    bool setYaw(Angle yaw){}
00297 
00302    bool setPose(Pose3D& pDes, short ctrlIn);
00303 
00307    bool setAttitude(Orientation3D& oDes);
00308 
00311    bool setPosition( Position3D p, 
00312             Velocity3D v    = Velocity3D(0.0,0.0,0.0),
00313             Acceleration3D a  = Acceleration3D(0.0,0.0,0.0));
00314 
00316    bool setVelocity(Velocity3D p,Acceleration3D a){}
00317 
00319    bool setAcceleration(Acceleration3D p){}
00320 
00323    bool readPosition(){}
00324 
00327    bool readVelocity(){};
00328 
00331    bool readAttitude(){}
00332 
00333    // Luca Ricci mod. //
00334    bool readAllData(){};
00335    // ************** //
00336  };
00337 }; // end of namespace MipResources
00338 
00339 #endif
00340 
00341 /* @} */

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6