KorebotROS.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 __KOREBOT_ROS_H_
00034 #define __KOREBOT_ROS_H_
00035 
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include <math.h>
00040 #include <iostream>
00041 #include <fstream>
00042 
00043 #include <baselib.h>
00044 #include "MotionModule.h"
00045 #include <includeROS.h>
00046 
00047 namespace MipResources{
00049  /* @{ */
00050  
00051 
00056 class KorebotROSPar : public DiffDrivePar{
00057  private:
00058   // Robot name
00059   string     _korebotName;
00060   
00061   // Maximum wheel turn rate
00062   Decimal     _maxWheelTurnRate;
00063   
00064   // Diameter of the left wheel
00065   Decimal     _leftDiam;
00066   
00067   // Diameter of the right wheel
00068   Decimal     _rightDiam;
00069   
00070   // Separation between the wheels
00071   Decimal     _axelTrack;
00072   
00073   // Encoder resolution
00074   Decimal     _encoderResol;
00075   
00076   // Pointer to left joint
00077   GAZEBO_JOINT_PTR _leftJoint;
00078   
00079   // Pointer to right joint
00080   GAZEBO_JOINT_PTR _rightJoint;
00081   
00082   // Left ratio, defined as (M_PI*leftDiameter)/(encoderResolution)
00083   Decimal     _leftRatio;
00084   
00085   // Right ratio, defined as (M_PI*rightDiameter)/(encoderResolution)
00086   Decimal     _rightRatio;
00087   
00088   // Integration method for odometer
00089   string     _intOdoMeth;
00090   
00091  public:
00093   KorebotROSPar();
00094   
00096   KorebotROSPar(const string &kn, const Decimal &mwtr, const Decimal &ld, const Decimal &rd, const Decimal &at, const Decimal &er, GAZEBO_JOINT_PTR lj, GAZEBO_JOINT_PTR rj, const string &intOdoMeth);
00097   
00099   KorebotROSPar(GAZEBO_JOINT_PTR lj, GAZEBO_JOINT_PTR rj, const string &intOdoMeth);
00100   
00102   KorebotROSPar(const string &kn, const Decimal &mwtr, const Decimal &ld, const Decimal &rd, const Decimal &at, const Decimal &er, const string &intOdoMeth);
00103   
00105   ~KorebotROSPar(){
00106   }
00107   
00110   string  _providedName();
00111   
00114   Decimal _providedMaxWheelTurnRate(void);
00115   
00118   Decimal _providedLeftDiam(void);
00119   
00122   Decimal _providedRightDiam(void);
00123   
00126   Decimal _providedAxelTrack(void);
00127   
00130   Decimal _providedEncoderResol(void);
00131   
00134   GAZEBO_JOINT_PTR getLeftJoint();
00135   
00138   GAZEBO_JOINT_PTR getRightJoint();
00139   
00142   Decimal getLeftRatio() const;
00143   
00146   Decimal getRightRatio() const;
00147   
00150   string getIntOdoMeth() const;
00151   
00154   string print();
00155 };
00156 
00163 class KorebotROSVar : public DiffDriveVar{
00164  private:
00165   
00166  public:
00168   KorebotROSVar();
00169   
00172   virtual string getName(void){
00173    return "MotionKorebotROS";
00174   }
00175 };
00176 
00177 
00184 class KorebotROS : protected DiffDrive{
00185  private:
00186   static const ResourcePlate _plate = MM_KORROS_RES; 
00187   
00188   // Time of the last encoder measurement
00189   GAZEBO_COMMON_NAMESPACE::Time* _lastTime;
00190   Decimal    _odomPose[3];
00191   Decimal    _odomVel[3];
00192   
00193   // Pulses from encoders
00194   long int   _lastLeftPulses;
00195   long int   _lastRightPulses;
00196   
00197   // Actual velocities on left and right wheels 
00198   Decimal    _actLeftWheelSpeed;
00199   Decimal    _actRightWheelSpeed;
00200   
00201   // Previous computed velocities: needed for Tustin Integration
00202   Decimal    _prevLeftWheelSpeed;
00203   Decimal    _prevRightWheelSpeed;
00204   
00205   // Actual linear and angular speed
00206   Decimal    _linearSpeed;
00207   Decimal    _angularSpeed;
00208   
00209   // Check if it is the first step or not
00210   bool      _firstStep;
00211   
00212   GAZEBO_COMMON_NAMESPACE::Time _actIntTime;
00213   GAZEBO_COMMON_NAMESPACE::Time _lastIntTime;
00214   Decimal    _elapsedTimeROS;
00215   
00216   // Private methods:
00217   void _updateIntTime();
00218  protected:
00219   /* PROMEMO from more abstract classes */
00220   /* UnicyclePar *_par; */
00221   /* UnicycleVar *_var; */
00222   /* DiffDrivePar *_ddPar; */
00223   /* DiffDriveVar *_ddVar; */
00224   KorebotROSPar *_korePar; 
00225   KorebotROSVar *_koreVar; 
00227   // The variables count the left and right pulses emulating the incremental encoders
00228   long int _leftPulses;
00229   long int _rightPulses;
00230   
00231  public:
00235   KorebotROS(int argc, const char* argv[],KorebotROSPar* krp);
00236   
00238   ~KorebotROS();
00239   
00241   ResourcePlate getPlate() const {
00242    return _plate;
00243   }
00244 
00248   void setWheelCommands(Decimal leftAngVel, Decimal rightAngVel);
00249   
00254   DiffDriveEncoderReading getEncoders();
00255   
00257   void resetEncoders();
00258   
00267   bool setStateKorebotROS(MotionModuleState correctedState, bool setPastTimeStamp=false, Time pastTimeStamp=Time());
00268   
00270   void _localizationStepKorebotROS();
00271   
00273   MotionModuleTState _providedLocStepKorebotROS();
00274   
00276   void _initOdometerKorebotROS();
00277   
00280   void _computeVelocities(DiffDriveEncoderReading &currReading);
00281   
00283   void _intVelocities();
00284   
00286   void _setWheelCommandsKorebotROS();
00287   
00288   void _providedLocSetKorebotROS(MotionModuleState state);
00289   
00292   MotionModuleTState getStateKorebotROS();
00293   
00297   MotionModuleTState getState(Time ts);
00298   
00308   bool setStateKorebotROS(MotionModuleState correctedState, MotionModuleState &finalState, bool setPastTimeStamp=false, Time pastTimeStamp=Time());
00309   
00315   void setCommandsKorebotROS(const Decimal &drive, const Decimal &turnrate, bool scaled=true);
00316   
00323   void setCommandsKorebotROS(const Decimal &drive, const Decimal &turnrate, MotionModuleTState &finalTState, bool scaled=true);
00324   
00335   void setCommandsAndTStateKorebotROS(MotionModuleState correctedState, const Decimal &drive, const Decimal &turnrate, MotionModuleTState &finalTState, bool scaled=true, bool setPastTimeStamp=false, Time pastTimeStamp=Time());
00336   
00340   void _providedSetCommandsKorebotROS(const Decimal &drive, const Decimal &turnrate);
00341   
00342 };
00343  
00344  
00345  /* @} */
00346  
00347 };// end namespace MipResources
00348 
00349 #endif
00350 
00351 
00352 
00353 
00354 

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