object_controller_plugin.h
Go to the documentation of this file.
00001 /*
00002  * A generic object controller plugin. 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 OBJECT_CONTROLLER_PLUGIN_HH
00034 #define OBJECT_CONTROLLER_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 #include <segbot_gazebo_plugins/UpdatePluginState.h>
00049 
00050 // Custom Callback Queue
00051 #include <ros/callback_queue.h>
00052 #include <ros/advertise_options.h>
00053 
00054 // Boost
00055 #include <boost/thread.hpp>
00056 #include <boost/bind.hpp>
00057 
00058 namespace gazebo
00059 {
00060 class Joint;
00061 class Entity;
00062 
00063 class ObjectControllerPlugin : public ModelPlugin
00064 {
00065   public: ObjectControllerPlugin();
00066   public: ~ObjectControllerPlugin();
00067   public: void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf);
00068   protected: virtual void UpdateChild();
00069   protected: virtual void FiniChild();
00070 
00071 private:
00072   void writePositionData(double step_time);
00073   void publishOdometry(double step_time);
00074   void getWheelVelocities();
00075 
00076   physics::WorldPtr world;
00077   physics::ModelPtr parent;
00078   event::ConnectionPtr updateConnection;
00079 
00080   math::Pose last_odom_pose_;
00081 
00082   // ROS STUFF
00083   ros::NodeHandle* rosnode_;
00084   ros::Publisher pub_, pub2_;
00085   ros::Subscriber sub_, sub2_;
00086   tf::TransformBroadcaster *transform_broadcaster_;
00087   nav_msgs::Odometry odom_;
00088   std::string tf_prefix_;
00089   ros::ServiceServer update_state_service_server_;
00090 
00091   boost::mutex lock;
00092   boost::mutex state_lock_;
00093 
00094   bool pause_;
00095 
00096   double timeout_period_;
00097   common::Time time_of_last_message_;
00098 
00099   std::string modelNamespace;
00100   std::string topicName;
00101 
00102   // Custom Callback Queue
00103   ros::CallbackQueue queue_;
00104   boost::thread callback_queue_thread_;
00105   void QueueThread();
00106 
00107   // DiffDrive stuff
00108   void cmdVelCallback(const geometry_msgs::Twist::ConstPtr& cmd_msg);
00109   bool updateState(segbot_gazebo_plugins::UpdatePluginState::Request &req,
00110     segbot_gazebo_plugins::UpdatePluginState::Response &resp);
00111 
00112   double x_;
00113   double y_;
00114   double rot_;
00115   bool alive_;
00116 
00117   // Update Rate
00118   double updateRate;
00119   double update_period_;
00120   common::Time last_update_time_;
00121 
00122   // Simple map stuff
00123   std::string mapTopic;
00124   std::string globalFrame;
00125   double modelRadius;
00126   double modelPadding;
00127   double circumscribed_model_distance_;
00128   nav_msgs::OccupancyGrid map_;
00129   bool map_available_;
00130   void getSimpleMap(const nav_msgs::OccupancyGrid::ConstPtr& map);
00131 
00132 };
00133 
00134 }
00135 
00136 #endif
00137 
 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