savitzky_golay.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 #################################################################
00004 ##\file
00005 #
00006 # \note
00007 # Copyright (c) 2013 \n
00008 # Fraunhofer Institute for Manufacturing Engineering
00009 # and Automation (IPA) \n\n
00010 #
00011 #################################################################
00012 #
00013 # \note
00014 # Project name: Care-O-bot Research
00015 # \note
00016 # ROS package name:
00017 #
00018 # \author
00019 # Author: Thiago de Freitas Oliveira Araujo,
00020 # email:thiago.de.freitas.oliveira.araujo@ipa.fhg.de
00021 # \author
00022 # Supervised by: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de
00023 #
00024 # \date Date of creation: April 2013
00025 #
00026 # \brief
00027 # Battery Characterization for the IPA robots
00028 #
00029 #################################################################
00030 #
00031 # Redistribution and use in source and binary forms, with or without
00032 # modification, are permitted provided that the following conditions are met:
00033 #
00034 # - Redistributions of source code must retain the above copyright
00035 # notice, this list of conditions and the following disclaimer. \n
00036 # - Redistributions in binary form must reproduce the above copyright
00037 # notice, this list of conditions and the following disclaimer in the
00038 # documentation and/or other materials provided with the distribution. \n
00039 # - Neither the name of the Fraunhofer Institute for Manufacturing
00040 # Engineering and Automation (IPA) nor the names of its
00041 # contributors may be used to endorse or promote products derived from
00042 # this software without specific prior written permission. \n
00043 #
00044 # This program is free software: you can redistribute it and/or modify
00045 # it under the terms of the GNU Lesser General Public License LGPL as
00046 # published by the Free Software Foundation, either version 3 of the
00047 # License, or (at your option) any later version.
00048 #
00049 # This program is distributed in the hope that it will be useful,
00050 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00051 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00052 # GNU Lesser General Public License LGPL for more details.
00053 #
00054 # You should have received a copy of the GNU Lesser General Public
00055 # License LGPL along with this program.
00056 # If not, see < http://www.gnu.org/licenses/>.
00057 #
00058 #################################################################
00059 import roslib; roslib.load_manifest('cob_relayboard')
00060 import rospy
00061 import time
00062 import csv
00063 from cob_relayboard.msg import EmergencyStopState
00064 from std_msgs.msg import Float64
00065 import savitzky
00066 import numpy as np
00067 from math import *
00068 from pr2_msgs.msg import PowerState
00069 
00070 class volts_filter():
00071     
00072     def __init__(self):
00073         self.volts = 0.
00074         self.wsize = 61
00075         self.filter_order = 3
00076         self.theta = rospy.get_param("~theta")
00077         self.off_y = rospy.get_param("~off_y")
00078         self.abcd = rospy.get_param("~abcd")
00079         self.maximum_time = rospy.get_param("~maximum_time")
00080         self.sg = savitzky.savitzky_golay(window_size=self.wsize, order=self.filter_order)
00081         size = 2*self.wsize+1
00082         self.volt_filt = 48000*np.ones(size)
00083         
00084         rospy.Subscriber("/power_board/voltage", Float64, self.callback)
00085         
00086         self.pub_power = rospy.Publisher('/power_state', PowerState)
00087         self.msg_power = PowerState()
00088         
00089     def callback(self, data):
00090     
00091         self.volts = data.data
00092         self.volts = self.volts*1000
00093         
00094         if(self.volts <= 44000):
00095             self.volts = 44000
00096             time_r = 0.
00097         elif(self.volts >= 48000):
00098             self.volts = 48000      
00099 
00100         self.process_voltage()
00101         
00102     def process_voltage(self):
00103 
00104         self.volt_filt = np.insert(self.volt_filt, 0, self.volts)
00105         self.volt_filt = np.delete(self.volt_filt, -1)
00106 
00107         vfilt = self.sg.filter(self.volt_filt)
00108 
00109         old_settings = np.seterr(all='raise')
00110 
00111         self.t_est = np.polyval(self.abcd, vfilt[self.wsize])
00112 
00113         self.t_est = vfilt[self.wsize]*sin(self.theta) + self.t_est*cos(self.theta)
00114         self.t_est = self.t_est + self.off_y
00115         
00116         if(self.t_est <0):
00117             self.t_est = 0
00118         
00119         self.msg_power.header.stamp = rospy.Time.now()
00120         self.msg_power.time_remaining.secs = self.t_est
00121         self.msg_power.prediction_method = '3rd_order_polynom'
00122         self.msg_power.relative_capacity = (self.t_est/self.maximum_time) * 100
00123         self.msg_power.AC_present = 0
00124         
00125         self.pub_power.publish(self.msg_power)
00126             
00127 if __name__ == '__main__':
00128     rospy.init_node('volt_filt')
00129     vf = volts_filter()
00130 
00131     while not rospy.is_shutdown():
00132     
00133         
00134         rospy.sleep(1.0)
00135 
00136 
00137 


cob_voltage_control
Author(s): Alexander Bubeck
autogenerated on Thu Aug 27 2015 12:45:45