MotionModule3D.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 
00037 
00038 
00039 
00040 
00041 
00042 #ifndef __MOTION_MODULE3D_H_
00043 #define __MOTION_MODULE3D_H_
00044 
00045 #ifdef MIP_HOST_APPLE
00046 #include <applePatch.h>
00047 #endif
00048 
00049 #include <stdlib.h>
00050 #include <string>
00051 #include <sstream>
00052 #include <vector>
00053 #include <assert.h>
00054 
00055 #include <baselib.h>
00056 #include <Resource.h>
00057 
00058 
00059 
00060 namespace MipResources
00061 {
00062 
00064  /* @{ */
00065 
00066 
00067 
00073 class MotionModule3DPar
00074 {
00075  private:
00076  protected:
00077   string _name;     
00079 
00080   void setName(string n)
00081   {
00082    _name=n;
00083   }
00084  public:
00086   MotionModule3DPar ()
00087   {
00088    _name  = string("");
00089   }  
00090   
00092   MotionModule3DPar(const MotionModule3DPar &p)
00093   {
00094    _name  = p._name;
00095   }
00096   
00098   MotionModule3DPar& operator=(const MotionModule3DPar& p)
00099   {
00100    if (this != &p)
00101    {
00102     _name  = p._name;
00103    }
00104    return *this;
00105   }
00106   
00108   string name()
00109   {
00110    return _name;
00111   }
00112   
00114   virtual string print()
00115   {
00116    stringstream s;
00117    s << "name" << name() << endl;
00118    return s.str();
00119   }
00120 };
00121 
00122 
00128 class MotionModule3DVar
00129 { 
00130  private:
00131  protected:
00132   Pose3D _odometry;
00134  public:
00136   MotionModule3DVar ()
00137   {
00138    _odometry = Pose3D();
00139   }
00140   
00142   MotionModule3DVar(const MotionModule3DVar &v)
00143   {
00144    _odometry = v._odometry;
00145   }
00146   
00148   MotionModule3DVar& operator=(const MotionModule3DVar& v)
00149   {
00150    if (this != &v)
00151    {
00152     _odometry = v._odometry;
00153    }
00154    return *this;
00155   }
00156   
00158   Pose3D odometry(void)
00159   {
00160           cout << "MotionModule3DVar::odometry()" << endl;
00161    cout << _odometry.print() << "\n";
00162    return _odometry;
00163   }
00164   
00166   void setOdometry(Pose3D value)
00167   {
00168           cout << "MotionModule3DVar::setOdometry()" << value.print()<< endl;
00169    _odometry = value;
00170    return;
00171   }
00172   
00174   virtual string print()
00175   {
00176    stringstream s;
00177    s << "odometry      " << _odometry.print() << endl;
00178    return s.str();
00179   }
00180 };
00181 
00182 
00183 
00191 class MotionModule3D : public Resource
00192 {
00193  protected:
00194   MotionModule3DPar *_par;
00195   MotionModule3DVar *_var;
00196   bool on; 
00197  public:
00199   MotionModule3D()
00200   {
00201    on = false; 
00202   };
00203   
00205   virtual ResourcePlate getPlate() const =0;
00206   
00208   virtual Pose3D odometry()
00209   {
00210    cout << "MotionModule3D::odometry()" << endl;
00211    /*TODO check if correct*/
00212    assert(on);
00213    return _var->odometry();
00214   }
00215   
00217   virtual void setOdometry(Pose3D p)
00218   {
00219      cout << "MotionModule3D::setOdometry()" << endl;
00220    assert(on);
00221    _var->setOdometry(p);
00222    p.print();
00223   }
00224   
00226   virtual string name()
00227   {
00228    assert(on);
00229    return _par->name();
00230   }
00231   
00233 /*  virtual void setName(string n){
00234    assert(on);
00235    _par->setName(n);
00236   }*/
00237   
00239   virtual MotionModule3DPar* par(void)
00240   {
00241    assert(on);
00242    return _par;
00243   }
00244 };
00245 
00246 
00253 class Unicycle3DPar : public MotionModule3DPar{
00254   Decimal _maxDrive;    
00255   Decimal _maxTurnRate; 
00257  protected:
00260   void setMaxDrive(Decimal m){
00261    assert(m>0.0);
00262    _maxDrive=m;
00263   }
00266   void setMaxTurnRate(Decimal m){
00267    assert(m>0.0);
00268    _maxTurnRate=m;
00269   }
00270  public:
00272   Unicycle3DPar():MotionModule3DPar(){
00273    _maxDrive = 0.0;
00274    _maxTurnRate = 0.0;
00275   }  
00277   Unicycle3DPar(const Unicycle3DPar &p):MotionModule3DPar(p){
00278    _maxDrive = p._maxDrive;
00279    _maxTurnRate = p._maxTurnRate;
00280   }
00282   Unicycle3DPar& operator=(const Unicycle3DPar& p){
00283    if (this != &p){
00284     _name = p._name;
00285     _maxDrive = p._maxDrive;
00286     _maxTurnRate = p._maxTurnRate;
00287    }
00288    return *this;
00289   }
00290   
00292   Decimal maxDrive(void){
00293    return _maxDrive;
00294   }
00296   Decimal maxTurnRate(void){
00297    return _maxTurnRate;
00298   }
00300   virtual string print(){
00301    stringstream s;
00302    s << "name     " << name() << endl
00303     << "max drive   " << _maxDrive << endl
00304     << "max turn-rate " << _maxTurnRate << endl;
00305    return s.str();
00306   }
00307 };
00308 
00309 
00316 class Unicycle3DVar : public MotionModule3DVar{
00317  private:
00318   Decimal _linVel;  
00319   Decimal _angVel;  
00321   Pose3D _oldOdometry; 
00322 
00323  protected:
00324 
00325  public:
00327   Unicycle3DVar ():MotionModule3DVar(){
00328    _linVel  = 0.0;
00329    _angVel  = 0.0;
00330   }
00332   Unicycle3DVar(const Unicycle3DVar &v):MotionModule3DVar(v){
00333    _linVel  = v._linVel;
00334    _angVel  = v._angVel;
00335   }
00337   Unicycle3DVar& operator=(const Unicycle3DVar& v){
00338    if (this != &v){
00339     _odometry = v._odometry;
00340     _linVel  = v._linVel;
00341     _angVel  = v._angVel;
00342    }
00343    return *this;
00344   }
00345   
00347   Decimal linVel(void){
00348    return _linVel;
00349   }
00350   // TODO da verificarne la correttezza
00352   Position3D vel(void){
00353    return Position3D(cos(odometry().ori().pitch().dCast2Pi())*cos(odometry().ori().yaw().dCast2Pi()), -sin(odometry().ori().yaw().dCast2Pi()), sin(odometry().ori().pitch().dCast2Pi())*cos(odometry().ori().yaw().dCast2Pi()))*_linVel;
00354   }
00356   Decimal angVel(void){
00357    return _angVel;
00358   }
00359   
00361   void setLinVel(Decimal value){
00362    _linVel = value;
00363   }
00365   void setAngVel(Decimal value){
00366    _angVel = value;
00367    return;
00368   }
00369   
00371   void setOldOdometry(Pose3D value){
00372    _oldOdometry = value;
00373    cout << "Unicycle3DVar::setOldOdometry" << value.print() << endl;
00374    return;
00375   }
00376   
00378   Pose3D odometryDiff(MIPMatrix &RobStat)
00379   {
00380           Pose3D tmp;
00381    Decimal d_x, d_y;
00382    
00383    cout << "Unicycle3DVar::odometryDiff(_odometry)" << _odometry.print() << endl;
00384    cout << "Unicycle3DVar::odometryDiff(_oldOdometry)" << _oldOdometry.print() << endl;
00385    tmp.operator=(_odometry.operator-(_oldOdometry));
00386           cout << "Unicycle3DVar::odometryDiff(_odometry - _oldOdometry)" << tmp.print() << endl;
00387    d_x = tmp.pos().x();
00388    d_y = tmp.pos().y();
00389    
00390    RobStat.SetMIPMatrixVal(4,1,sqrt(d_x*d_x + d_y*d_y));//Robot linear displacement during the last time slice
00391    RobStat.SetMIPMatrixVal(5,1,tmp.ori().yaw().dCast2Pi());//Robot angular displacement during the last time slice
00392    
00393    return _odometry - _oldOdometry;
00394   }
00395 
00397   virtual string print(){
00398    stringstream s;
00399    s << "odometry      " << odometry().print() << endl
00400     << "linear speed  " << _linVel << " m/sec"<< endl
00401     << "angular speed " << _angVel << " rad/sec" << endl;
00402    return s.str();
00403   }
00404 };
00411 class Unicycle3D : public MotionModule3D
00412 {
00413   
00414  protected:
00415   
00416   Unicycle3DPar* _uniPar;
00417   Unicycle3DVar* _uniVar;
00418  
00419  public:
00420   
00422   virtual void odometryDiff(MIPMatrix &RobStat, Decimal *ENCTime)
00423   {
00424           cout << "Unicycle3D::odometryDiff()" << endl;
00425    assert(on);
00426    updateOdometry(RobStat, ENCTime);//Update robot status components X,Y,Theta
00427    _uniVar->odometryDiff(RobStat);  //Update robot status: Components (d_x,d_th)=(linear displacement, angular displacement) 
00428                                     //occurred during the last time slice.
00429    return;
00430   }
00431   
00433   virtual void updateOdometry(MIPMatrix &RobStat, Decimal *ENCTime)=0;
00434   
00436   virtual ResourcePlate getPlate() const =0;
00437   
00441   virtual void velCmd(Decimal drive, Decimal turnrate)=0;
00442   
00446   virtual void getVel(Decimal& drive, Decimal& turnrate)=0;
00447 };
00448 
00449 
00453 class FlightModulePar : public MotionModule3DPar{
00454   Decimal _maxXVel;      
00455   Decimal _maxYVel;      
00456   Decimal _maxZVel;      
00457   Decimal _maxRollVel;   
00458   Decimal _maxPitchVel;  
00459   Decimal _maxYawVel;    
00461  protected:
00464   void setMaxXVel(Decimal m){
00465    assert(m>0.0);
00466    _maxXVel=m;
00467   }
00470   void setMaxYVel(Decimal m){
00471    assert(m>0.0);
00472    _maxYVel=m;
00473   }
00476   void setMaxZVel(Decimal m){
00477    assert(m>0.0);
00478    _maxZVel=m;
00479   }
00482   void setMaxRollVel(Decimal m){
00483    assert(m>0.0);
00484    _maxRollVel=m;
00485   }
00488   void setMaxPitchVel(Decimal m){
00489    assert(m>0.0);
00490    _maxPitchVel=m;
00491   }
00494   void setMaxYawVel(Decimal m){
00495    assert(m>0.0);
00496    _maxYawVel=m;
00497   }
00498  public:
00500   FlightModulePar():MotionModule3DPar(){
00501    _maxXVel = 0.0;
00502    _maxYVel = 0.0;
00503    _maxZVel = 0.0;
00504    _maxRollVel = 0.0;
00505    _maxPitchVel = 0.0;
00506    _maxYawVel = 0.0;
00507   }  
00509   FlightModulePar(const FlightModulePar &p):MotionModule3DPar(p){
00510    _maxXVel   = p._maxXVel;
00511    _maxYVel   = p._maxYVel;
00512    _maxZVel   = p._maxZVel;
00513    _maxRollVel  = p._maxRollVel;
00514    _maxPitchVel = p._maxPitchVel;
00515    _maxYawVel  = p._maxYawVel;
00516   }
00518   FlightModulePar& operator=(const FlightModulePar& p){
00519    if (this != &p){
00520     _name = p._name;
00521    _maxXVel   = p._maxXVel;
00522    _maxYVel   = p._maxYVel;
00523    _maxZVel   = p._maxZVel;
00524    _maxRollVel  = p._maxRollVel;
00525    _maxPitchVel = p._maxPitchVel;
00526    _maxYawVel  = p._maxYawVel;
00527    }
00528    return *this;
00529   }
00530   
00532   Decimal maxXVel(void){
00533    return _maxXVel;
00534   }
00536   Decimal maxYVel(void){
00537    return _maxYVel;
00538   }
00540   Decimal maxZVel(void){
00541    return _maxZVel;
00542   }
00544   Decimal maxRollRate(void){
00545    return _maxRollVel;
00546   }
00548   Decimal maxPitchRate(void){
00549    return _maxPitchVel;
00550   }
00552   Decimal maxYawRate(void){
00553    return _maxYawVel;
00554   }
00556   virtual string print(){
00557    stringstream s;
00558    s << "name     " << name() << endl
00559     << "max x vel   " << _maxXVel << endl
00560     << "max y vel   " << _maxYVel << endl
00561     << "max z vel   " << _maxZVel << endl
00562     << "max roll vel  " << _maxRollVel << endl
00563     << "max pitch vel " << _maxPitchVel << endl
00564     << "max yaw vel  " << _maxYawVel << endl;
00565    return s.str();
00566   }
00567 };
00568 
00572 class FlightModuleVar : public MotionModule3DVar{
00573  private:
00574   Decimal _linVel;  
00575   Decimal _angVel;  
00576  protected:
00577 
00578  public:
00580   FlightModuleVar ():MotionModule3DVar(){
00581    _linVel  = 0.0;
00582    _angVel  = 0.0;
00583   }
00585   FlightModuleVar(const FlightModuleVar &v):MotionModule3DVar(v){
00586    _linVel  = v._linVel;
00587    _angVel  = v._angVel;
00588   }
00590   FlightModuleVar& operator=(const FlightModuleVar& v){
00591    if (this != &v){
00592     _odometry = v._odometry;
00593     _linVel  = v._linVel;
00594     _angVel  = v._angVel;
00595    }
00596    return *this;
00597   }
00598   
00600   Decimal linVel(void){
00601    return _linVel;
00602   }
00603   // TODO da verificarne la correttezza
00605   Position3D vel(void){
00606    return Position3D(cos(odometry().ori().pitch().dCast2Pi())*cos(odometry().ori().yaw().dCast2Pi()), -sin(odometry().ori().yaw().dCast2Pi()), sin(odometry().ori().pitch().dCast2Pi())*cos(odometry().ori().yaw().dCast2Pi()))*_linVel;
00607   }
00609   Decimal angVel(void){
00610    return _angVel;
00611   }
00612   
00614   void setLinVel(Decimal value){
00615    _linVel = value;
00616   }
00618   void setAngVel(Decimal value){
00619    _angVel = value;
00620   }
00621   
00623   virtual string print(){
00624    stringstream s;
00625    s << "odometry      " << odometry().print() << endl
00626     << "linear speed  " << _linVel << " m/sec"<< endl
00627     << "angular speed " << _angVel << " rad/sec" << endl;
00628    return s.str();
00629   }
00630 };
00631 
00635 class FlightModule : public MotionModule3D{
00636  protected:
00637  public:
00639   FlightModule(){
00640    on = false; 
00641   };
00643   virtual ResourcePlate getPlate() const =0;
00644   
00647   virtual void velLinCmd(Position3D cmd)=0;
00648   
00651   virtual void velAngCmd(Position3D cmd)=0;
00652   
00655   virtual void velCmd(Position3D lcmd, Position3D acmd)=0;
00656   
00660   virtual void getVel(Position3D& linVel, Position3D& angVel)=0;
00661   
00662   
00664   virtual Pose3D odometry(){
00665    assert(on);
00666    return _var->odometry();
00667   }
00668   
00670   virtual void setOdometry(Pose3D p){
00671    assert(on);
00672    _var->setOdometry(p);
00673   }
00674   
00675 //  /** \brief get parameters  */
00676 /*  virtual FlightModulePar* par(void){
00677    assert(on);
00678    return _par;
00679   }*/
00680 };
00681 
00682  /* @} */
00683  
00684 };// end namespace MipResources{
00685 
00686 #endif
00687 
00688 
00689 
00690 
00691 
00692 

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