RemKhepServerROSController.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 
00031 
00032 #ifndef __REM_KHEP_SRV_ROS_CTRL_H_
00033 #define __REM_KHEP_SRV_ROS_CTRL_H_
00034 
00035 // MIP headers
00036 #include <CommonOptions.h>
00037 #include <Option.h>
00038 #include "RemKhepServerROS.h"
00039 
00040 #ifdef ROS_ELECTRIC
00041  // ROS 
00042  #include <geometry_msgs/Twist.h>
00043  #include <nav_msgs/Odometry.h>
00044  #include <ros/ros.h>
00045  #include <tf/transform_broadcaster.h>
00046  // ROS GAZEBO
00047  #include <gazebo/Simulator.hh>
00048  #include <gazebo/Global.hh>
00049  #include <gazebo/Controller.hh>
00050  #include <gazebo/ControllerFactory.hh>
00051  #include <gazebo/Model.hh>
00052 
00053  // Custom Callback Queue
00054  #include <ros/callback_queue.h>
00055  #include <ros/advertise_options.h>
00056 #endif
00057 // Boost
00058 #include <boost/thread.hpp>
00059 
00060 // Define macros
00061 #define SAMPLE_TIME_USEC 30000
00062 #define WAIT_TIME_USEC 1000
00063  
00064 #define KHS_COMM_DEBUG 0
00065 #define KHS_TIME_DEBUG 0
00066 #define KHS_EXECUTE_DEBUG 0
00067 
00068 namespace gazebo{
00069 class Joint;
00070 class Entity;
00071 
00072 class remKhepSrvROSController : public gazebo::Controller{
00073  public:
00074   remKhepSrvROSController(Entity *parent);
00075   virtual ~remKhepSrvROSController();
00076   
00077  protected:
00078   virtual void LoadChild(XMLConfigNode *node);
00079   void SaveChild(std::string &prefix, std::ostream &stream);
00080   virtual void InitChild();
00081   void ResetChild();
00082   virtual void UpdateChild();
00083   virtual void FiniChild();
00084   
00085  private:
00086   // Methods
00087   void write_position_data();
00088   void publish_odometry();
00089   
00090   // Variables
00091   Model *parent_;
00092   ParamT<float>*    wheelSepP;
00093   ParamT<float>*    wheelDiamP;
00094   ParamT<float>*    torqueP;
00095   ParamT<bool>*     enableMotors;
00096   ParamT<int>*      debugLevel;
00097   ParamT<int>*     urg04lxActive;
00098   ParamT<string>*    intMethodOdo;
00099   ParamT<string>*    laserTopicName;
00100   ParamT<string>*    topicName;
00101   ParamT<string>*    nodeName;
00102   ParamT<string>*    commType;
00103   ParamT<Decimal>*   encodRes;
00104   float         wheelSpeed[2];
00105 
00106   // Name of the actual robot
00107 //   string _nameRobot;
00108   KheperaServerROSPars* _khPars;
00109   
00110   // Simulation time of the last update
00111 //   Time          prevUpdateTime;
00112   
00113   // Timer to avoid too often request of data
00114   Time         _execTimer;
00115   
00116   // Pointer to the remote khepera server
00117   KheperaServerROS*   _remKhepSrvROS;
00118   
00119   // Bool to check if the current iteration is the first one or not
00120   bool          _firstRun;
00121   // Boolean to check if an ack message is received (for the starting connection)
00122   bool          _connected;
00123   // Integer to select which command is given at this time step
00124   int          _actCmd;
00125   // Boolean to set if enables the motors
00126   bool         _enableMotors;
00127   // Integer to store actual debugLevel
00128   int          _debugLevel;
00129   
00130   Joint *joints[2];
00131   PhysicsEngine     *physicsEngine;
00132   ParamT<std::string>  *leftJointNameP;
00133   ParamT<std::string>  *rightJointNameP;
00134   
00135   // Diameter of the wheel
00136   Decimal wd;
00137   // Separation between wheels
00138   Decimal ws;
00139   // Distance performed by a wheel in the last step
00140   double d1;
00141   double d2;
00142   double dr;
00143   double da;
00144   // Time step from the last time update
00145   Time stepTime;
00146   
00147   // ROS STUFF
00148 //   ros::NodeHandle* rosnode_;
00149   ros::Publisher  pub_;
00150   ros::Subscriber sub_;
00151 //   nav_msgs::Odometry odom_;
00152   std::string tf_prefix_;
00153   
00154   boost::mutex lock;
00155   
00156   ParamT<std::string> *robotNamespaceP;
00157   std::string robotNamespace;
00158   
00159 //   ParamT<std::string> *topicNameP;
00160 //   std::string topicName;
00161   std::string topicNameOdom;
00162   
00163   // Custom Callback Queue
00164   ros::CallbackQueue queue_;
00165   boost::thread* callback_queue_thread_;
00166   tf::TransformBroadcaster br;
00167 
00168   void QueueThread();
00169   
00170   // DiffDrive stuff
00171   void cmdVelCallback(const geometry_msgs::Twist::ConstPtr& cmd_msg);
00172   
00173   Decimal _xVel;
00174   Decimal _omega;
00175   bool alive_;
00176  };
00177  
00178 }
00179 
00180 #endif
00181 

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