gazebo_ros_kobuki.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Yujin Robot.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Yujin Robot nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00036 #ifndef GAZEBO_ROS_KOBUKI_H
00037 #define GAZEBO_ROS_KOBUKI_H
00038 
00039 #include <cmath>
00040 #include <cstring>
00041 #include <string>
00042 #include <boost/bind.hpp>
00043 #include <boost/thread.hpp>
00044 #include <boost/shared_ptr.hpp>
00045 #include <gazebo/gazebo.hh>
00046 #include <gazebo/common/common.hh>
00047 #include <gazebo/common/Time.hh>
00048 #include <gazebo/math/gzmath.hh>
00049 #include <gazebo/physics/physics.hh>
00050 #include <gazebo/sensors/sensors.hh>
00051 #include <gazebo_plugins/gazebo_ros_utils.h>
00052 #include <ros/ros.h>
00053 #include <std_msgs/Empty.h>
00054 #include <std_msgs/Float64.h>
00055 #include <sensor_msgs/Imu.h>
00056 #include <sensor_msgs/JointState.h>
00057 #include <nav_msgs/Odometry.h>
00058 #include <geometry_msgs/Twist.h>
00059 #include <geometry_msgs/TransformStamped.h>
00060 #include <tf/transform_broadcaster.h>
00061 #include <tf/LinearMath/Quaternion.h>
00062 #include <kobuki_msgs/MotorPower.h>
00063 #include <kobuki_msgs/CliffEvent.h>
00064 #include <kobuki_msgs/BumperEvent.h>
00065 
00066 namespace gazebo
00067 {
00068 
00069 enum {LEFT= 0, RIGHT=1};
00070 
00071 class GazeboRosKobuki : public ModelPlugin
00072 {
00073 public:
00075   GazeboRosKobuki();
00077   ~GazeboRosKobuki();
00079   void Load(physics::ModelPtr parent, sdf::ElementPtr sdf);
00081   void OnUpdate();
00082 
00083 private:
00084   /*
00085    * Methods
00086    */
00088   void cmdVelCB(const geometry_msgs::TwistConstPtr &msg);
00090   void motorPowerCB(const kobuki_msgs::MotorPowerPtr &msg);
00092   void resetOdomCB(const std_msgs::EmptyConstPtr &msg);
00094   void spin();
00095   //  void OnContact(const std::string &name, const physics::Contact &contact); necessary?
00096 
00097   
00098   // internal functions for load
00099   void prepareMotorPower();
00100   bool prepareJointState();
00101   void preparePublishTf();
00102   bool prepareWheelAndTorque();
00103   void prepareOdom();
00104   bool prepareVelocityCommand();
00105   bool prepareCliffSensor();
00106   bool prepareBumper();
00107   bool prepareIMU();
00108   void setupRosApi(std::string& model_name);
00109 
00110   // internal functions for update
00111   void updateJointState();
00112   void updateOdometry(common::Time& step_time);
00113   void updateIMU();
00114   void propagateVelocityCommands();
00115   void updateCliffSensor();
00116   void updateBumper();
00117 
00118 
00119   /*
00120    *  Parameters
00121    */
00123   ros::NodeHandle nh_, nh_priv_;
00125   std::string node_name_;
00126 
00128   std::string tf_prefix_;
00130 //  boost::shared_ptr<boost::thread> ros_spinner_thread_; necessary?
00132   bool shutdown_requested_;
00134   physics::ModelPtr model_;
00136   GazeboRosPtr gazebo_ros_;
00137   sdf::ElementPtr sdf_;
00139   physics::WorldPtr world_;
00141   event::ConnectionPtr update_connection_;
00143   common::Time prev_update_time_;
00145   ros::Subscriber motor_power_sub_;
00147   bool motors_enabled_;
00149   physics::JointPtr joints_[2];
00151   std::string left_wheel_joint_name_;
00153   std::string right_wheel_joint_name_;
00155   ros::Publisher joint_state_pub_;
00157   sensor_msgs::JointState joint_state_;
00159   ros::Subscriber cmd_vel_sub_;
00161   common::Time last_cmd_vel_time_;
00163   double cmd_vel_timeout_;
00165   double wheel_speed_cmd_[2];
00167   double torque_;
00169   double wheel_sep_;
00171   double wheel_diam_;
00173   double odom_pose_[3];
00175   double odom_vel_[3];
00177   double *pose_cov_[36];
00179   double *twist_cov_[36];
00181   ros::Publisher odom_pub_;
00183   nav_msgs::Odometry odom_;
00185   bool publish_tf_;
00187   tf::TransformBroadcaster tf_broadcaster_;
00189   geometry_msgs::TransformStamped odom_tf_;
00191   sensors::RaySensorPtr cliff_sensor_left_;
00193   sensors::RaySensorPtr cliff_sensor_center_;
00195   sensors::RaySensorPtr cliff_sensor_right_;
00197   ros::Publisher cliff_event_pub_;
00199   kobuki_msgs::CliffEvent cliff_event_;
00201   bool cliff_detected_left_;
00203   bool cliff_detected_center_;
00205   bool cliff_detected_right_;
00207   float cliff_detection_threshold_;
00209   int floot_dist_;
00211   sensors::ContactSensorPtr bumper_;
00213   ros::Publisher bumper_event_pub_;
00215   kobuki_msgs::BumperEvent bumper_event_;
00217   bool bumper_left_was_pressed_;
00219   bool bumper_center_was_pressed_;
00221   bool bumper_right_was_pressed_;
00223   bool bumper_left_is_pressed_;
00225   bool bumper_center_is_pressed_;
00227   bool bumper_right_is_pressed_;
00229   sensors::ImuSensorPtr imu_;
00231   math::Vector3 vel_angular_;
00233   ros::Publisher imu_pub_;
00235   sensor_msgs::Imu imu_msg_;
00237   ros::Subscriber odom_reset_sub_;
00238 
00239 
00240 
00241 };
00242 
00243 } // namespace gazebo
00244 
00245 #endif /* GAZEBO_ROS_KOBUKI_H */


kobuki_gazebo_plugins
Author(s): Marcus Liebhardt
autogenerated on Thu Jun 6 2019 19:42:48