power_monitor.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2009, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
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
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Willow Garage nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 #ifndef POWER_MONITOR_POWER_MONITOR_H
00036 #define POWER_MONITOR_POWER_MONITOR_H
00037 
00038 #include <stdlib.h>
00039 #include <boost/thread/mutex.hpp>
00040 
00041 #include "ros/ros.h"
00042 #include "dynamic_reconfigure/server.h"
00043 
00044 #include "pr2_msgs/BatteryServer2.h"
00045 #include "pr2_msgs/PowerBoardState.h"
00046 #include "pr2_msgs/PowerState.h"
00047 
00048 #include "power_monitor/PowerMonitorConfig.h"
00049 
00050 #include "power_state_estimator.h"
00051 
00052 namespace power_monitor {
00053 
00059 class PowerMonitor
00060 {
00061 public:
00062     PowerMonitor();
00063 
00064     bool setActiveEstimator(PowerStateEstimator::Type estimator_type);
00065 
00066     void batteryServerUpdate(const boost::shared_ptr<const pr2_msgs::BatteryServer2>& battery_server);
00067     void powerNodeUpdate(const boost::shared_ptr<const pr2_msgs::PowerBoardState>& power_board_state);
00068     void configCallback(power_monitor::PowerMonitorConfig& config, uint32_t level);
00069 
00070 private:
00071     void addEstimator(PowerStateEstimator* estimator);
00072 
00073     PowerObservation extractObservation();
00074 
00075     void onPublishTimer(const ros::TimerEvent& e);
00076 
00077     void publishPowerState();
00078 
00079     std::string masterStateToString(int8_t master_state) const;
00080 
00081     ros::Time getLastBatteryUpdate() const;
00082 
00083 private:
00084     dynamic_reconfigure::Server<power_monitor::PowerMonitorConfig> config_server_;
00085 
00086     boost::mutex update_mutex_;
00087     boost::mutex publish_mutex_;
00088 
00089     int8_t master_state_;
00090     std::map<int, boost::shared_ptr<const pr2_msgs::BatteryServer2> > battery_servers_;
00091 
00092     std::map<std::string,               PowerStateEstimator::Type>               estimator_types_;
00093     std::map<PowerStateEstimator::Type, boost::shared_ptr<PowerStateEstimator> > estimators_;
00094 
00095     boost::shared_ptr<PowerStateEstimator> active_estimator_;
00096 
00097     ros::Timer      power_state_pub_timer_;
00098     ros::Publisher  power_state_pub_;
00099     ros::Subscriber battery_server_sub_;
00100     ros::Subscriber power_node_sub_;
00101 
00102     PowerObservation observation_;
00103 
00104     double battery_update_timeout_;
00105 };
00106 
00107 }
00108 
00109 #endif /* POWER_MONITOR_POWER_MONITOR_H */


power_monitor
Author(s): Tim Field, Curt Meyers
autogenerated on Tue Apr 22 2014 19:35:04