diff_drive_plugin.h
Go to the documentation of this file.
00001 /*
00002  * A differential drive plugin for the segbot. Based on the diffdrive plugin 
00003  * developed for the erratic robot (see copyright notice below). The original
00004  * plugin can be found in the ROS package gazebo_erratic_plugins
00005  *
00006  * Copyright (c) 2010, Daniel Hewlett, Antons Rebguns
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions are met:
00011  *      * Redistributions of source code must retain the above copyright
00012  *      notice, this list of conditions and the following disclaimer.
00013  *      * Redistributions in binary form must reproduce the above copyright
00014  *      notice, this list of conditions and the following disclaimer in the
00015  *      documentation and/or other materials provided with the distribution.
00016  *      * Neither the name of the <organization> nor the
00017  *      names of its contributors may be used to endorse or promote products
00018  *      derived from this software without specific prior written permission.
00019  *
00020  *  THIS SOFTWARE IS PROVIDED BY Antons Rebguns <email> ''AS IS'' AND ANY
00021  *  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  *  DISCLAIMED. IN NO EVENT SHALL Antons Rebguns <email> BE LIABLE FOR ANY
00024  *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00027  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  **/
00032 
00033 #ifndef DIFFDRIVE_PLUGIN_HH
00034 #define DIFFDRIVE_PLUGIN_HH
00035 
00036 #include <map>
00037 
00038 #include <common/common.hh>
00039 #include <physics/physics.hh>
00040 
00041 // ROS
00042 #include <ros/ros.h>
00043 #include <tf/transform_broadcaster.h>
00044 #include <tf/transform_listener.h>
00045 #include <geometry_msgs/Twist.h>
00046 #include <nav_msgs/Odometry.h>
00047 #include <nav_msgs/OccupancyGrid.h>
00048 
00049 // Custom Callback Queue
00050 #include <ros/callback_queue.h>
00051 #include <ros/advertise_options.h>
00052 
00053 // Boost
00054 #include <boost/thread.hpp>
00055 #include <boost/bind.hpp>
00056 
00057 namespace gazebo {
00058 
00059   class Joint;
00060   class Entity;
00061 
00062   class DiffDrivePlugin : public ModelPlugin {
00063 
00064     public:
00065       DiffDrivePlugin();
00066       ~DiffDrivePlugin();
00067       void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf);
00068 
00069     protected:
00070       virtual void UpdateChild();
00071       virtual void FiniChild();
00072 
00073     private:
00074       void publishOdometry(double step_time);
00075       void getWheelVelocities();
00076 
00077       physics::WorldPtr world;
00078       physics::ModelPtr parent;
00079       event::ConnectionPtr updateConnection;
00080 
00081       std::string leftJointName;
00082       std::string rightJointName;
00083 
00084       double wheelSeparation;
00085       double wheelDiameter;
00086       double torque;
00087       double wheelSpeed[2];
00088       math::Pose last_odom_pose_;
00089       double last_angular_vel_;
00090 
00091       physics::JointPtr joints[2];
00092       physics::PhysicsEnginePtr physicsEngine;
00093 
00094       // ROS STUFF
00095       ros::NodeHandle* rosnode_;
00096       ros::Publisher pub_;
00097       ros::Subscriber sub_;
00098       tf::TransformBroadcaster *transform_broadcaster_;
00099       nav_msgs::Odometry odom_;
00100       std::string tf_prefix_;
00101 
00102       boost::mutex lock;
00103 
00104       std::string robotNamespace;
00105       std::string topicName;
00106       bool useSimpleModel;
00107 
00108       // Custom Callback Queue
00109       ros::CallbackQueue queue_;
00110       boost::thread callback_queue_thread_;
00111       void QueueThread();
00112 
00113       // DiffDrive stuff
00114       void cmdVelCallback(const geometry_msgs::Twist::ConstPtr& cmd_msg);
00115 
00116       double x_;
00117       double rot_;
00118       bool alive_;
00119 
00120       // Update Rate
00121       double updateRate;
00122       double update_period_;
00123       common::Time last_update_time_;
00124 
00125 
00126   };
00127 
00128 }
00129 
00130 #endif
00131 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends


segbot_gazebo_plugins
Author(s): Piyush Khandelwal
autogenerated on Mon Aug 5 2013 12:10:02