MobileRob3D.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 
00026 
00033 
00034 
00038 
00039 
00040 #ifndef __MOB_ROB_3D_H_
00041 #define __MOB_ROB_3D_H_
00042 
00043 #ifdef MIP_HOST_APPLE
00044 #include <applePatch.h>
00045 #endif
00046 
00047 #include <stdlib.h>
00048 #include <string>
00049 #include <sstream>
00050 #include <vector>
00051 #include <assert.h>
00052 
00053 #include <CommonOptions.h>
00054 
00055 #include <baselib.h>
00056 #include <RangeSens.h>
00057 // #include <RangeSensmm.h>
00058 #include <MotionModule3D.h>
00059 #include <PositionDetector3D.h>
00060 #include <Imu3D.h>
00061 
00062 #include <Resource.h>
00063 #include <MIPMatrix.h>
00064 #include <Surface.h>
00065 
00066 
00067 namespace MipResources{
00069  /* @{ */
00070 
00074 class MobileRob3DOptions : public Options {
00075  public:
00076   IntOption* motionModule;
00077   IntOption* laser;
00078   IntOption* infrared;
00079   IntOption* sonar;
00080   IntOption* gps;
00081   IntOption* odoLoc;
00082   IntOption* imu;
00083   
00084   MobileRob3DOptions(){
00085 
00086    motionModule= createIntOption("mobileRob3DMotionModule",  "whether (1) or not (0) the motion module is onboard, default 1", 1);
00087    laser   = createIntOption("mobileRob3DLaser",  "whether (1) or not (0) the laser is onBoard, default 1", 1);
00088    infrared= createIntOption("mobileRob3DInfrared",  "whether (1) or not (0) the infrared is onboard, default 0", 0);
00089    sonar   = createIntOption("mobileRob3DSonar",  "whether (1) or not (0) the sonar is onboard, default 0", 0);
00090    gps     = createIntOption("mobileRob3DGps",  "whether (1) or not (0) the gps is onboard, default 0", 0);
00091    odoLoc =       createIntOption("mobileRobOdometryLocalization", "whether (1) or not (0) the localization is given by simple odometry", 1);
00092    imu     = createIntOption("mobileRob3DImu",  "whether (1) or not (0) the imu is onboard, default 0", 0);
00093    
00094    updateValues();
00095 
00096   }
00097 
00098   string getObjectName() const {
00099    return "MobileRob3DOptions";
00100   }
00101 };
00102 
00103 
00107 class MobileRob3DPar{
00108  private:
00109   int      _id;     
00110   Decimal  _lenght; 
00111   Decimal  _width;  
00112   Decimal  _height;  
00113   string  _name;   
00114   Decimal  _weelDiam;
00115 
00116  protected:
00121   void setId(int i){
00122    assert(i>0);
00123    _id=i;
00124   }
00129   void setLength(Decimal r){
00130    assert(r>0.0);
00131    _lenght=r;
00132   }
00137   void setWidth(Decimal r){
00138    assert(r>0.0);
00139    _width=r;
00140   }
00145   void setHeight(Decimal r){
00146    assert(r>0.0);
00147    _height=r;
00148   }
00149 
00151   void setName(string n){
00152    _name=n;
00153   }
00154  public:
00156   MobileRob3DPar (){
00157    _id  = 0;
00158    _lenght  = 0.0;
00159    _width  = 0.0;
00160    _height  = 0.0;
00161    _name  = string();
00162    _weelDiam  = 0.1; //10cm
00163   }
00164   
00166   MobileRob3DPar(const MobileRob3DPar &r){
00167    _id  = r._id;
00168    _lenght  = r._lenght;
00169    _width  = r._width;
00170    _height  = r._height;
00171    _name  = r._name;
00172    _weelDiam  = r._weelDiam;
00173   }
00174   
00176   MobileRob3DPar& operator=(const MobileRob3DPar& r){
00177    if (this != &r){
00178     _id  = r._id;
00179     _lenght  = r._lenght;
00180     _width  = r._width;
00181     _height  = r._height;
00182     _name  = r._name;
00183     _weelDiam = r._weelDiam;
00184    }
00185    return *this;
00186   }
00188   int id()
00189   {
00190    return _id;
00191   }
00193   Decimal lenght()
00194   {
00195    return _lenght;
00196   }
00198   Decimal width()
00199   {
00200    return _width;
00201   }
00203   Decimal height()
00204   {
00205    return _height;
00206   }
00208   string name()
00209   {
00210    return _name;
00211   }
00213   Decimal weelDiam()
00214   {
00215    return _weelDiam;
00216   }
00217 
00219   string print()
00220   {
00221    stringstream s;
00222    s << "name " << name() << endl
00223      << "id " << _id << endl 
00224      << "lenght " << _lenght << endl
00225      << "width " << _width << endl
00226      << "height " << _height << endl
00227      << "height " << _weelDiam << endl;
00228    return s.str();
00229   }
00230 };
00231 
00232 
00236 class MobileRob3DVar{
00237  protected:
00239   Pose3D  _pose;
00241   Pose3D  _goal;
00243   Position _goalVel;
00244  
00245  public:
00247   MobileRob3DVar (){}
00248   
00250   MobileRob3DVar(const MobileRob3DVar &v)
00251   {
00252    _goal  = v._goal;
00253    _goalVel = v._goalVel;
00254   }
00255   
00257   MobileRob3DVar& operator=(const MobileRob3DVar& v)
00258   {
00259    if (this != &v){
00260     _goal  = v._goal;
00261     _goalVel = v._goalVel;
00262    }
00263    return *this;
00264   }
00265   
00267   void setPose(Pose3D p)
00268   {
00269    _pose=p;
00270   }
00271   
00273   Pose3D pose()
00274   {
00275    return _pose;
00276   }
00277   
00279   void setGoal(Pose3D g)
00280   {
00281    _goal=g;
00282   }
00283   
00285   Pose3D goal()
00286   {
00287    return _goal;
00288   }
00289   
00291   void setGoalVel(Position gv)
00292   {
00293    _goalVel=gv;
00294   }
00295   
00297   Position getGoalVel()
00298   {
00299    return _goalVel;
00300   }
00301   
00303   string print()
00304   {
00305    stringstream s;
00306    s << "goal " << _goal.print() << ", goalVel " << _goalVel.print();
00307    return s.str();
00308   }
00309 };
00310 
00311 
00315 class MobileRob3D : public Resource{
00316  protected:
00317   MobileRob3DOptions options; 
00319   MobileRob3DPar  *_par;   
00320   MobileRob3DVar  *_var;  
00322   // onboard motion modules
00323   Unicycle3D    *_unicycle3D; 
00324   // onboard sensors and actuators
00325   RangeSens     *_rangeSens; 
00326 //  RangeSensmm     *_rangeSensmm; /**< abstract Robot range sensor */
00327   //RangeSens     *_infrared; /**< abstract Robot range sensor infrared*/
00328   //RangeSens     *_sonar; /**< abstract Robot range sensor sonar*/
00329   PositionDetector3D    *_positionDetector3D; 
00330   Imu      *_imu;   
00332   ScanTypes rangeSensorType; 
00334   bool unicycleActive;
00335   
00336   bool rangeSensActive;
00337   bool rangeSensmmActive;
00338   bool infraredActive;
00339   bool sonarActive;
00340   bool gpsActive;
00341   bool imuActive;
00342   
00343   bool useOdometryLocalization; 
00344   
00345  public:
00347   MobileRob3D(){}
00348   
00350   MobileRob3D(int argc, const char* argv[])
00351   {
00352           cout << "MobileRob3D constructor starting" << endl;
00353    unicycleActive  = false;
00354    
00355    //rangeSensActive = false;
00356    //rangeSensmmActive = false;
00357    //infraredActive = false;
00358    //sonarActive  = false;
00359    gpsActive  = false;
00360    imuActive  = false;
00361    
00362    if (options.odoLoc->getValue())
00363    {
00364     useOdometryLocalization = true;
00365    }
00366    else
00367    {
00368     useOdometryLocalization = false;
00369    }
00370 
00371    cout << "MobileRob3D constructor OK." << endl;
00372   }
00373   
00375   /*virtual TODO logging, anzi il logger รจ un task */
00376   
00378   virtual MobileRob3DPar* robPar()
00379   {
00380    return _par;
00381   }
00382   
00384   virtual MobileRob3DVar* robVar()
00385   {
00386    return _var;
00387   }
00388   
00389   
00390   /* ### ### ### Motion Module ### ### ### */
00392   virtual Unicycle3DPar* unicycle3DPar()
00393   {
00394    if (unicycleActive)
00395     return (Unicycle3DPar*) _unicycle3D->par();
00396    else
00397     return NULL;
00398   }
00399   
00400   
00402   virtual void velCmd(Decimal drive, Decimal turnrate)
00403   {
00404    if (unicycleActive)
00405    {
00406     _unicycle3D->velCmd(drive, turnrate);
00407    }
00408   }
00409   
00410   
00414   virtual void getVel(Decimal& drive, Decimal& turnrate)
00415   {
00416    if (unicycleActive)
00417     _unicycle3D->getVel(drive,turnrate);
00418   }
00419   
00420   
00422   virtual Pose3D getPose(void)
00423   {
00424    cout << "Start getPose" << endl;
00425    if (unicycleActive)
00426    {
00427     //cout << "2" << endl;
00428     if (useOdometryLocalization)
00429     {
00430      //cout << "A" << endl;
00431      return _unicycle3D->odometry();
00432     }
00433     else
00434     {
00435      //cout << "A1" << endl;
00436      return _var->pose();
00437     }
00438    }
00439    else
00440     return Pose3D(Position3D(0.0,0.0,0.0), Orientation3D(0.0,0.0,0.0));
00441   }
00442   
00443   
00445   virtual void setPose(Pose3D p)
00446   {
00447    if (unicycleActive){
00448     if (useOdometryLocalization)
00449      _unicycle3D->setOdometry(p);
00450     else
00451      return _var->setPose(p);
00452    }
00453   }
00454   
00455   
00457   virtual void getOdometry(MIPMatrix &RobStat, Decimal *ENCtime)
00458   {
00459           cout << "MobileRob3D::getOdometry()" << endl;
00460    _unicycle3D->odometryDiff(RobStat, ENCtime);
00461    return;
00462   }
00463 
00464   /* ### ### gps ### ### */
00465   virtual bool getGPSMeasures(Position3D &pos, Decimal *MeasTime)
00466   {
00467       cout << "MobileRob3D::getGPSMeasures()." << "\n";
00468       return(_positionDetector3D->getGPSMeasure(pos, MeasTime));
00469   }
00470 
00471   virtual bool getRefGPSMeasures(Position3D &pos, Decimal *MeasTime)
00472   {
00473       return(_positionDetector3D->getRefGPSMeasure(pos, MeasTime));
00474   }
00475 
00476   virtual bool getIMUMeasures(Acceleration3D &acc, Acceleration3D &gyro, Orientation3D &magn, Decimal *MeasTime)
00477   {
00478       cout << "MobileRob3D::getIMUMeasures()." << "\n";
00479       return(_imu->getIMUMeasure(acc, gyro, magn, MeasTime));
00480   }
00481   
00482   /* ### ### MobileRob ### ### */
00484   void setGoal(Pose3D g)
00485   {
00486    _var->setGoal(g);
00487   }
00488   
00489   
00491   Pose3D goal()
00492   {
00493    return _var->goal();
00494   }
00495   
00496   
00498   void setGoalVel(Position gv)
00499   {
00500    _var->setGoalVel(gv);
00501   }
00502   
00503   
00505   Position goalVel()
00506   {
00507    return _var->getGoalVel();
00508   }
00509 };
00510 
00511  /* @} */
00512  
00513 };// end namespace MipResources{
00514 
00515 
00516 #endif
00517 
00518 
00519 
00520 
00521 

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