|
From: <tf...@us...> - 2008-03-28 22:18:41
|
Revision: 65
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=65&view=rev
Author: tfoote
Date: 2008-03-28 15:18:45 -0700 (Fri, 28 Mar 2008)
Log Message:
-----------
monitorBatteries now publishes to the ParamServer. and watchBatteries now prints to screen.
Modified Paths:
--------------
pkg/trunk/IBPSBatteryInterface/src/IBPSBatteryInterface/monitorBatteries.py
Added Paths:
-----------
pkg/trunk/IBPSBatteryInterface/nodes/watchBatteries
pkg/trunk/IBPSBatteryInterface/src/IBPSBatteryInterface/watchBatteries.py
Added: pkg/trunk/IBPSBatteryInterface/nodes/watchBatteries
===================================================================
--- pkg/trunk/IBPSBatteryInterface/nodes/watchBatteries (rev 0)
+++ pkg/trunk/IBPSBatteryInterface/nodes/watchBatteries 2008-03-28 22:18:45 UTC (rev 65)
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+PKG = 'IBPSBatteryInterface'
+MODULE = 'IBPSBatteryInterface.watchBatteries' #this is the module that will be invoked by python
+
+######################################################
+# BOILERPLATE: Should not have to modify anything
+# below except for very last line
+######################################################
+# Bootstrap ourselves into latest rospy install
+import sys, os
+BOOTSTRAP_VERSION = "0.1"
+
+# Read in ROS_ROOT
+if not os.environ.has_key('ROS_ROOT'):
+ print """\nCannot run ROS: ROS_ROOT is not set.\nPlease set the ROS_ROOT environment variable to the
+location of your ROS install.\n"""
+ sys.exit(-1)
+rosRoot = os.environ['ROS_ROOT']
+
+# Read in the rospy directory location from the 'rospack latest rospy' command
+rospackLatest = os.popen(os.path.join(rosRoot,'rospack')+' latest rospy', 'r')
+rospyDir = rospackLatest.read()
+rospackLatest.close()
+if rospyDir is None or not os.path.isdir(rospyDir.strip()):
+ print "\nERROR: Cannot locate rospy installation.\n"
+ sys.exit(-1)
+
+# Run launcher bootstrapper
+sys.path.append(os.path.join(rospyDir.strip(),'scripts'))
+import launcher
+
+manifestFile = launcher.getManifestFile(sys.argv[0], PKG)
+launcher.init(BOOTSTRAP_VERSION)
+launchCommand, launchArgs, launchEnv = \
+ launcher.getLaunchCommands(manifestFile, MODULE)
+launcher.ready(launchCommand, launchArgs, launchEnv, BOOTSTRAP_VERSION)
+
+######################################################
+# END BOILERPLATE:
+# You may wish to modify the exec command below to
+# customize the behavior of your node, e.g.:
+# * env['FOO'] = bar
+# * launchArgs.append('--test')
+######################################################
+
+os.execvpe(launchCommand, launchArgs, launchEnv)
Property changes on: pkg/trunk/IBPSBatteryInterface/nodes/watchBatteries
___________________________________________________________________
Name: svn:executable
+ *
Modified: pkg/trunk/IBPSBatteryInterface/src/IBPSBatteryInterface/monitorBatteries.py
===================================================================
--- pkg/trunk/IBPSBatteryInterface/src/IBPSBatteryInterface/monitorBatteries.py 2008-03-28 21:17:51 UTC (rev 64)
+++ pkg/trunk/IBPSBatteryInterface/src/IBPSBatteryInterface/monitorBatteries.py 2008-03-28 22:18:45 UTC (rev 65)
@@ -150,8 +150,13 @@
for message in control.latest_system_messages:
print message
+ def updateParamServer(self, master):
+ master.setParam('IBPS.current', (self.controllers[0].total_current(),self.controllers[1].total_current(),self.controllers[2].total_current(),self.controllers[3].total_current()))
+ master.setParam('IBPS.voltage', (self.controllers[0].average_voltage(),self.controllers[1].average_voltage(),self.controllers[2].average_voltage(),self.controllers[3].average_voltage()))
+ master.setParam('IBPS.time_remaining', (self.controllers[0].time_remaining,self.controllers[1].time_remaining,self.controllers[2].time_remaining,self.controllers[3].time_remaining))
+ master.setParam('IBPS.average_charge', (self.controllers[0].average_charge,self.controllers[1].average_charge,self.controllers[2].average_charge,self.controllers[3].average_charge))
+
-
def setupPorts():
os.system('stty 19200 </dev/ttyUSB0')
@@ -358,8 +363,7 @@
if time.time() - last_time > increment:
last_time = last_time + increment
myPow.print_remaining()
-
-
+ myPow.updateParamServer(master)
if __name__ == '__main__':
try:
Added: pkg/trunk/IBPSBatteryInterface/src/IBPSBatteryInterface/watchBatteries.py
===================================================================
--- pkg/trunk/IBPSBatteryInterface/src/IBPSBatteryInterface/watchBatteries.py (rev 0)
+++ pkg/trunk/IBPSBatteryInterface/src/IBPSBatteryInterface/watchBatteries.py 2008-03-28 22:18:45 UTC (rev 65)
@@ -0,0 +1,111 @@
+# Software License Agreement (BSD License)
+#
+# Copyright (c) 2008, Willow Garage, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided
+# with the distribution.
+# * Neither the name of the Willow Garage nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+"""
+viewGraph
+
+To run, invoke nodes/viewGraph
+"""
+
+import os, sys, getopt, traceback, logging
+import rospy
+import time
+
+
+NAME = 'watchBatteries'
+
+def usage(stdout, progname):
+ print >>stdout, """%s [-h] [-s SERVER_ADDRESS] [-p SERVER_PORT]
+
+"""%progname+rospy.USAGE_ENV
+
+def viewGraphMain(argv, stdout, env):
+ # default arguments
+ server = "http://localhost"
+ server_port = rospy.DEFAULT_TEST_PORT
+
+ #check arguments for a help flag
+ optlist, args = getopt.getopt(argv[1:], "h?p:s:", ["help","port=","server=","test"])
+ for o, a in optlist:
+ if o in ("-h","-?","--help"):
+ usage(stdout, argv[0])
+ return
+ elif o in ("--test"):
+ server_port = rospy.DEFAULT_TEST_PORT
+ elif o in ("-p", "--port"):
+ server_port = a
+ elif o in ("-s", "--server"):
+ server = a
+
+
+ serverUri = '%s:%s/'%(server,server_port)
+ print "Looking for server at %s"%serverUri
+ os.environ[rospy.ROS_MASTER_URI] = serverUri
+ os.environ[rospy.ROS_NODE] = "watchBatteries"
+ os.environ[rospy.ROS_PORT] = str(0) # any
+
+
+ master = rospy.getMaster()
+ rospy.ready()
+
+ while 1:
+ print "-------------------------------------------------------------------"
+ print "Getting IBPS params from Parameter Server"
+ print "-------------------------------------------------------------------"
+ status_code, statusMessage, current = master.getParam('IBPS.current')
+ print "Current"
+ print current
+ status_code, statusMessage, voltage = master.getParam('IBPS.voltage')
+ print "Voltage"
+ print voltage
+ status_code, statusMessage, time_remaining = master.getParam('IBPS.time_remaining')
+ print "Time Remaining (minutes)"
+ print time_remaining
+ status_code, statusMessage, average_charge = master.getParam('IBPS.average_charge')
+ print "Average Charge"
+ print average_charge
+
+ time.sleep(1.0)
+
+if __name__ == '__main__':
+ try:
+ viewGraphMain(sys.argv, sys.stdout, os.environ)
+ except Exception, e:
+ traceback.print_exc()
+ #attempt to log, may fail if logger is not properly initialized
+ logger = logging.getLogger(NAME)
+ logger.error(str(e)+"\n"+traceback.format_exc())
+ print "Exception is causing %s exit, check log for details"%NAME
+
+ print "exiting"
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|