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

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