00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 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 the Willow Garage, Inc. 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 00030 #ifndef PR2_GAZEBO_PLUGINS_ROS_POWER_MONITOR_H 00031 #define PR2_GAZEBO_PLUGINS_ROS_POWER_MONITOR_H 00032 00033 #include <map> 00034 #include <vector> 00035 #include <boost/thread/mutex.hpp> 00036 00037 #include <gazebo/physics/World.hh> 00038 #include <gazebo/physics/Model.hh> 00039 #include <gazebo/physics/physics.hh> 00040 #include <gazebo/common/Time.hh> 00041 #include <gazebo/common/Plugin.hh> 00042 00043 #include <ros/ros.h> 00044 #include <pr2_msgs/PowerState.h> 00045 #include <pr2_gazebo_plugins/PlugCommand.h> 00046 00047 namespace gazebo { 00048 00049 class GazeboRosPowerMonitor : public ModelPlugin 00050 { 00051 public: 00052 GazeboRosPowerMonitor(); 00053 virtual ~GazeboRosPowerMonitor(); 00054 00055 protected: 00056 // Inherited from Controller 00057 void Load( physics::ModelPtr _parent, sdf::ElementPtr _sdf ); 00058 virtual void InitChild(); 00059 virtual void UpdateChild(); 00060 00061 private: 00063 void SetPlug(const pr2_gazebo_plugins::PlugCommandConstPtr& plug_msg); 00064 00065 private: 00066 gazebo::physics::ModelPtr parent_model_; 00067 double curr_time_; 00068 double last_time_; 00069 00070 //ParamT<std::string>* robot_namespace_param_; 00071 //ParamT<std::string>* power_state_topic_param_; 00072 std::string robot_namespace_; 00073 std::string power_state_topic_; 00074 00075 ros::NodeHandle* rosnode_; 00076 ros::Subscriber plugged_in_sub_; 00077 ros::Publisher power_state_pub_; 00078 00080 boost::mutex lock_; 00081 00082 pr2_msgs::PowerState power_state_; 00083 00085 //ParamT<double>* power_state_rate_param_; 00086 double power_state_rate_; 00087 00089 00091 //ParamT<double>* full_capacity_param_; 00092 double full_capacity_; 00093 00095 //ParamT<double>* charge_rate_param_; 00096 00098 //ParamT<double>* discharge_rate_param_; 00099 double discharge_rate_; 00100 00102 //ParamT<double>* charge_voltage_param_; 00103 double charge_voltage_; 00104 00106 //ParamT<double>* discharge_voltage_param_; 00107 double discharge_voltage_; 00108 00110 double charge_; 00111 00113 double charge_rate_; 00114 00116 double voltage_; 00117 00118 // Pointer to the model 00119 private: physics::WorldPtr world; 00120 00121 // Pointer to the update event connection 00122 private: event::ConnectionPtr updateConnection; 00123 00124 // subscribe to world stats 00125 private: transport::NodePtr node; 00126 private: transport::SubscriberPtr statsSub; 00127 private: common::Time simTime; 00128 00129 }; 00130 00131 } 00132 00133 #endif