gazebo_ros_power_monitor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef PR2_GAZEBO_PLUGINS_ROS_POWER_MONITOR_H
31 #define PR2_GAZEBO_PLUGINS_ROS_POWER_MONITOR_H
32 
33 #include <map>
34 #include <vector>
35 #include <boost/thread/mutex.hpp>
36 
37 #include <gazebo/physics/World.hh>
38 #include <gazebo/physics/Model.hh>
39 #include <gazebo/physics/physics.hh>
40 #include <gazebo/common/Time.hh>
41 #include <gazebo/common/Plugin.hh>
42 
43 #include <ros/ros.h>
44 #include <ros/advertise_options.h>
45 #include <ros/callback_queue.h>
46 #include <pr2_msgs/PowerState.h>
47 #include <pr2_gazebo_plugins/PlugCommand.h>
48 
49 namespace gazebo {
50 
51 class GazeboRosPowerMonitor : public ModelPlugin
52 {
53 public:
55  virtual ~GazeboRosPowerMonitor();
56 
57 protected:
58  // Inherited from Controller
59  void Load( physics::ModelPtr _parent, sdf::ElementPtr _sdf );
60  virtual void UpdateChild();
61 
62 private:
63  virtual void LoadThread();
64  virtual void ConnectCb();
65  virtual void DisconnectCb();
66  virtual void QueueThread();
67  void SetPlug(const pr2_gazebo_plugins::PlugCommandConstPtr& plug_msg);
68 
69 private:
70  // parameters
72  std::string robot_namespace_;
74  std::string power_state_topic_;
82  double charge_rate_;
87 
88  // ros
92  boost::thread deferred_load_thread_;
93  boost::thread callback_queue_thread_;
96 
97  // gazebo
98  event::ConnectionPtr update_connection_;
99  physics::WorldPtr world_;
100  sdf::ElementPtr sdf_;
101 
102  // internal variables
104  double last_time_;
106  double charge_;
108  double voltage_;
110  pr2_msgs::PowerState power_state_;
112  boost::mutex lock_;
113 };
114 
115 }
116 
117 #endif
gazebo::GazeboRosPowerMonitor::SetPlug
void SetPlug(const pr2_gazebo_plugins::PlugCommandConstPtr &plug_msg)
Definition: gazebo_ros_power_monitor.cpp:247
gazebo::GazeboRosPowerMonitor::ConnectCb
virtual void ConnectCb()
Definition: gazebo_ros_power_monitor.cpp:170
ros::Publisher
gazebo::GazeboRosPowerMonitor::charge_voltage_
double charge_voltage_
charge voltage when plugged in (V)
Definition: gazebo_ros_power_monitor.h:86
gazebo::GazeboRosPowerMonitor::full_capacity_
double full_capacity_
full capacity of battery (Ah)
Definition: gazebo_ros_power_monitor.h:78
gazebo::GazeboRosPowerMonitor::Load
void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
Definition: gazebo_ros_power_monitor.cpp:57
gazebo
gazebo::GazeboRosPowerMonitor::last_time_
double last_time_
latest time on callback is called
Definition: gazebo_ros_power_monitor.h:104
gazebo::GazeboRosPowerMonitor::update_connection_
event::ConnectionPtr update_connection_
Definition: gazebo_ros_power_monitor.h:98
gazebo::GazeboRosPowerMonitor::sdf_
sdf::ElementPtr sdf_
Definition: gazebo_ros_power_monitor.h:100
ros.h
gazebo::GazeboRosPowerMonitor::voltage_
double voltage_
voltage (V)
Definition: gazebo_ros_power_monitor.h:108
gazebo::GazeboRosPowerMonitor::queue_
ros::CallbackQueue queue_
Definition: gazebo_ros_power_monitor.h:94
gazebo::GazeboRosPowerMonitor::robot_namespace_
std::string robot_namespace_
namespace of robot in ROS system
Definition: gazebo_ros_power_monitor.h:72
gazebo::GazeboRosPowerMonitor::power_state_pub_
ros::Publisher power_state_pub_
Definition: gazebo_ros_power_monitor.h:90
gazebo::GazeboRosPowerMonitor::rosnode_
ros::NodeHandle * rosnode_
Definition: gazebo_ros_power_monitor.h:89
gazebo::GazeboRosPowerMonitor::~GazeboRosPowerMonitor
virtual ~GazeboRosPowerMonitor()
Definition: gazebo_ros_power_monitor.cpp:47
ros::CallbackQueue
gazebo::GazeboRosPowerMonitor::discharge_rate_
double discharge_rate_
discharge rate when not plugged in (W)
Definition: gazebo_ros_power_monitor.h:80
gazebo::GazeboRosPowerMonitor::QueueThread
virtual void QueueThread()
Definition: gazebo_ros_power_monitor.cpp:180
gazebo::GazeboRosPowerMonitor::power_state_rate_
double power_state_rate_
rate to broadcast power state message
Definition: gazebo_ros_power_monitor.h:76
gazebo::GazeboRosPowerMonitor::connect_count_
int connect_count_
Definition: gazebo_ros_power_monitor.h:95
gazebo::GazeboRosPowerMonitor::GazeboRosPowerMonitor
GazeboRosPowerMonitor()
Definition: gazebo_ros_power_monitor.cpp:44
callback_queue.h
gazebo::GazeboRosPowerMonitor::DisconnectCb
virtual void DisconnectCb()
Definition: gazebo_ros_power_monitor.cpp:175
gazebo::GazeboRosPowerMonitor::LoadThread
virtual void LoadThread()
Definition: gazebo_ros_power_monitor.cpp:69
gazebo::GazeboRosPowerMonitor::lock_
boost::mutex lock_
lock access to fields that are used in message callbacks
Definition: gazebo_ros_power_monitor.h:112
advertise_options.h
gazebo::GazeboRosPowerMonitor::world_
physics::WorldPtr world_
Definition: gazebo_ros_power_monitor.h:99
gazebo::GazeboRosPowerMonitor::UpdateChild
virtual void UpdateChild()
Definition: gazebo_ros_power_monitor.cpp:189
gazebo::GazeboRosPowerMonitor::plugged_in_sub_
ros::Subscriber plugged_in_sub_
Definition: gazebo_ros_power_monitor.h:91
gazebo::GazeboRosPowerMonitor
Definition: gazebo_ros_power_monitor.h:51
gazebo::GazeboRosPowerMonitor::charge_
double charge_
charge state (Ah)
Definition: gazebo_ros_power_monitor.h:106
gazebo::GazeboRosPowerMonitor::deferred_load_thread_
boost::thread deferred_load_thread_
Definition: gazebo_ros_power_monitor.h:92
gazebo::GazeboRosPowerMonitor::discharge_voltage_
double discharge_voltage_
discharge voltage when plugged in (V)
Definition: gazebo_ros_power_monitor.h:84
gazebo::GazeboRosPowerMonitor::charge_rate_
double charge_rate_
charge rate (W)
Definition: gazebo_ros_power_monitor.h:82
gazebo::GazeboRosPowerMonitor::power_state_topic_
std::string power_state_topic_
name of published topic
Definition: gazebo_ros_power_monitor.h:74
gazebo::GazeboRosPowerMonitor::callback_queue_thread_
boost::thread callback_queue_thread_
Definition: gazebo_ros_power_monitor.h:93
gazebo::GazeboRosPowerMonitor::power_state_
pr2_msgs::PowerState power_state_
published messages
Definition: gazebo_ros_power_monitor.h:110
ros::NodeHandle
ros::Subscriber


pr2_gazebo_plugins
Author(s): John Hsu
autogenerated on Sun Apr 17 2022 02:26:35