|
From: <rob...@us...> - 2009-08-19 02:00:43
|
Revision: 22210
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=22210&view=rev
Author: rob_wheeler
Date: 2009-08-19 02:00:32 +0000 (Wed, 19 Aug 2009)
Log Message:
-----------
Bring taskman over from Scott's repository
Added Paths:
-----------
pkg/trunk/sandbox/web/taskman/
pkg/trunk/sandbox/web/taskman/CMakeLists.txt
pkg/trunk/sandbox/web/taskman/Makefile
pkg/trunk/sandbox/web/taskman/manifest.xml
pkg/trunk/sandbox/web/taskman/msg/
pkg/trunk/sandbox/web/taskman/msg/TaskStatus.msg
pkg/trunk/sandbox/web/taskman/src/
pkg/trunk/sandbox/web/taskman/src/taskman.py
pkg/trunk/sandbox/web/taskman/srv/
pkg/trunk/sandbox/web/taskman/srv/StartTask.srv
pkg/trunk/sandbox/web/taskman/srv/StatusUpdate.srv
pkg/trunk/sandbox/web/taskman/srv/StopTask.srv
pkg/trunk/sandbox/web/taskman/test/
pkg/trunk/sandbox/web/taskman/test/joystick.app
pkg/trunk/sandbox/web/taskman/test/pr2_core.app
pkg/trunk/sandbox/web/taskman/test/startTask.py
pkg/trunk/sandbox/web/taskman/test/stopTask.py
pkg/trunk/sandbox/web/taskman/test/talker.app
pkg/trunk/sandbox/web/taskman/test/talker1.app
pkg/trunk/sandbox/web/taskman/test/talker2.app
Added: pkg/trunk/sandbox/web/taskman/CMakeLists.txt
===================================================================
--- pkg/trunk/sandbox/web/taskman/CMakeLists.txt (rev 0)
+++ pkg/trunk/sandbox/web/taskman/CMakeLists.txt 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.4.6)
+include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
+rospack(taskman)
+genmsg()
+gensrv()
+
Added: pkg/trunk/sandbox/web/taskman/Makefile
===================================================================
--- pkg/trunk/sandbox/web/taskman/Makefile (rev 0)
+++ pkg/trunk/sandbox/web/taskman/Makefile 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1 @@
+include $(shell rospack find mk)/cmake.mk
Added: pkg/trunk/sandbox/web/taskman/manifest.xml
===================================================================
--- pkg/trunk/sandbox/web/taskman/manifest.xml (rev 0)
+++ pkg/trunk/sandbox/web/taskman/manifest.xml 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,11 @@
+<package>
+ <description>Task Manager</description>
+ <author>Scott Hassan</author>
+ <license>BSD</license>
+ <review status="na" notes=""/>
+ <url>http://pr.willowgarage.com/wiki/taskman</url>
+
+ <depend package="rospy"/>
+ <depend package="roslaunch"/>
+ <depend package="std_msgs"/>
+</package>
Added: pkg/trunk/sandbox/web/taskman/msg/TaskStatus.msg
===================================================================
--- pkg/trunk/sandbox/web/taskman/msg/TaskStatus.msg (rev 0)
+++ pkg/trunk/sandbox/web/taskman/msg/TaskStatus.msg 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,5 @@
+Header header
+string taskid
+string username
+string status
+time started
Added: pkg/trunk/sandbox/web/taskman/src/taskman.py
===================================================================
--- pkg/trunk/sandbox/web/taskman/src/taskman.py (rev 0)
+++ pkg/trunk/sandbox/web/taskman/src/taskman.py 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,242 @@
+#!/usr/bin/env python
+# 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 Willow Garage, Inc. 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.
+#
+# Revision $Id$
+
+PKG = 'taskman' # this package name
+NAME = 'taskman'
+
+import roslib; roslib.load_manifest(PKG)
+
+from taskman.srv import *
+from taskman.msg import *
+import rospy
+
+import roslib.names
+import roslib.network
+
+from roslaunch.config import ROSLaunchConfig
+from roslaunch.launch import ROSLaunchRunner
+from roslaunch.pmon import pmon_shutdown as _pmon_shutdown
+from roslaunch.xmlloader import *
+
+import subprocess
+
+def getPackagePath(pkg):
+ pkgpath = subprocess.Popen(["rospack", "find", pkg], stdout=subprocess.PIPE).communicate()[0].strip()
+ return pkgpath
+
+class TaskGroup:
+ def __init__(self, manager):
+ self.task = TaskStatus(None, None, None, None, None)
+ self.app = None
+ self.runner = None
+ self.childGroups = []
+ self.manager = manager
+
+ def __del__(self):
+ if self.manager: self.manager = None
+ if self.childGroups: self.childGroups = None
+
+ def launch(self):
+ config = ROSLaunchConfig()
+ loader = XmlLoader()
+ path = getPackagePath(self.app.package)
+ print "pkgpath", path
+ print "launchfile", self.app.launch_file
+ #os.chdir(pkgpath)
+ fn = os.path.join(path, self.app.launch_file)
+ try:
+ loader.load(fn, config)
+ except:
+ self.task.status = "error"
+ self.manager.pub.publish(self.task)
+ return
+
+ self.runner = ROSLaunchRunner(rospy.get_param("/run_id"), config, is_core=False)
+ self.runner.pm.add_process_listener(self)
+ self.runner.launch()
+
+ def stop(self):
+ if not self.runner: return
+ self.runner.stop()
+ self.runner = None
+
+ def process_died(self, process_name, exit_code):
+ #print "process_died", process_name, exit_code
+ #print self.runner.pm.procs
+ if len(self.runner.pm.procs) == 1:
+ self.runner = None
+ #print "ALL DONE!"
+ self.manager._stopTask(self)
+
+
+ def __repr__(self):
+ return "<TaskGroup %s %s %s>" % (self.app.provides, self.app.taskid, len(self.childGroups))
+
+class App:
+ def __init__(self, taskid):
+ # TODO catch file system exception
+ package, app_file = taskid.split('/', 1)
+ path = getPackagePath(package)
+ doc = yaml.load(open(os.path.join(path, app_file)))
+ try:
+ self.taskid = taskid
+ self.app_file = app_file
+ self.name = doc['name']
+ self.package = doc['package']
+ self.provides = doc['provides']
+ self.launch_file = doc['launch_file']
+ self.depends = doc['depends']
+ except KeyError:
+ print "Invalid YAML file"
+
+
+
+class TaskManager:
+ def __init__(self):
+ self.pub = rospy.Publisher("TaskStatus", TaskStatus, self)
+ self._taskGroups = {}
+ self._apps = {}
+
+ def start_task(self, req):
+ app = App(req.taskid)
+ pgroup = None
+ group = self._taskGroups.get(app.provides, None)
+ if group:
+ if group.task.taskid == req.taskid:
+ print "already running"
+ return StartTaskResponse("already running")
+
+ self._stopTask(group)
+
+ if app.depends and app.depends.strip():
+ print "depends", app.depends
+ pgroup = self._taskGroups.get(app.depends, None)
+ if not pgroup:
+ print "no parent task group %s running." % str(app.depends)
+ return StartTaskResponse("no parent task group %s running." % str(app.depends))
+
+ self._apps[req.taskid] = app
+ group = TaskGroup(self)
+ group.app = app
+ if app.provides:
+ self._taskGroups[app.provides] = group
+
+ if pgroup:
+ pgroup.childGroups.append(group)
+
+ print "startTask [%s, %s, %s]" % (req.taskid, app.name, req.username)
+ group.task.taskid = req.taskid
+ group.task.username = req.username
+ group.task.started = rospy.get_rostime()
+ group.task.status = "starting"
+
+ self.pub.publish(group.task)
+
+ group.launch()
+
+ group.task.status = "running"
+ self.pub.publish(group.task)
+
+ return StartTaskResponse("done")
+
+ def showstate(self):
+ print "_" * 40
+ for provides, group in self._taskGroups.items():
+ print provides, group.childGroups
+
+ def _stopTask(self, group):
+ print "_stopTask", group.app.provides
+
+ group.task.status = "stopping"
+ self.pub.publish(group.task)
+
+ print "childGroups", group, group.childGroups
+ for cgroup in group.childGroups[:]:
+ self._stopTask(cgroup)
+
+ group.stop()
+
+ group.task.status = "stopped"
+ self.pub.publish(group.task)
+
+ if group.app.depends:
+ pgroup = self._taskGroups.get(group.app.depends.strip(), None)
+ if pgroup:
+ pgroup.childGroups.remove(group)
+
+ if group.app.provides:
+ print "removing", group.app.provides
+ del self._taskGroups[group.app.provides]
+
+ def stop_task(self, req):
+ app = self._apps[req.taskid]
+
+ group = self._taskGroups.get(app.provides, None)
+ if not group:
+ msg = "no such group: " + str(app.provides)
+ return StopTaskResponse(msg)
+
+ self._stopTask(group)
+
+ del self._apps[req.taskid]
+
+ return StopTaskResponse("done")
+
+ def status_update(self, req):
+ for provides, group in self._taskGroups.items():
+ self.pub.publish(group.task)
+ return StatusUpdateResponse("done")
+
+
+ def peer_subscribe(self, topic_name, topic_publish, peer_publish):
+ pass
+
+ def peer_unsubscribe(self, topic_name, numPeers):
+ pass
+
+
+def server():
+ rospy.init_node(NAME)
+
+ tm = TaskManager()
+ s1 = rospy.Service('start_task', StartTask, tm.start_task)
+ s2 = rospy.Service('stop_task', StopTask, tm.stop_task)
+ s3 = rospy.Service('status_update', StatusUpdate, tm.status_update)
+
+ # spin() keeps Python from exiting until node is shutdown
+ rospy.spin()
+
+if __name__ == "__main__":
+ server()
Property changes on: pkg/trunk/sandbox/web/taskman/src/taskman.py
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/trunk/sandbox/web/taskman/srv/StartTask.srv
===================================================================
--- pkg/trunk/sandbox/web/taskman/srv/StartTask.srv (rev 0)
+++ pkg/trunk/sandbox/web/taskman/srv/StartTask.srv 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,4 @@
+string taskid
+string username
+---
+string status
Added: pkg/trunk/sandbox/web/taskman/srv/StatusUpdate.srv
===================================================================
--- pkg/trunk/sandbox/web/taskman/srv/StatusUpdate.srv (rev 0)
+++ pkg/trunk/sandbox/web/taskman/srv/StatusUpdate.srv 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,2 @@
+---
+string status
\ No newline at end of file
Added: pkg/trunk/sandbox/web/taskman/srv/StopTask.srv
===================================================================
--- pkg/trunk/sandbox/web/taskman/srv/StopTask.srv (rev 0)
+++ pkg/trunk/sandbox/web/taskman/srv/StopTask.srv 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,4 @@
+string taskid
+string username
+---
+string status
\ No newline at end of file
Added: pkg/trunk/sandbox/web/taskman/test/joystick.app
===================================================================
--- pkg/trunk/sandbox/web/taskman/test/joystick.app (rev 0)
+++ pkg/trunk/sandbox/web/taskman/test/joystick.app 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,7 @@
+name: Joystick
+package: pr2_core
+launch_file: teleop_joystick_tuck.launch
+description: Move the base with the joystick
+icon:
+provides:
+depends: pr2_core
Added: pkg/trunk/sandbox/web/taskman/test/pr2_core.app
===================================================================
--- pkg/trunk/sandbox/web/taskman/test/pr2_core.app (rev 0)
+++ pkg/trunk/sandbox/web/taskman/test/pr2_core.app 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,7 @@
+name: PR2 Core
+package: pr2_core
+launch_file: pr2_core.launch
+description: Bring up most of the PR2
+icon:
+provides: pr2_core
+depends: pr2_core
Added: pkg/trunk/sandbox/web/taskman/test/startTask.py
===================================================================
--- pkg/trunk/sandbox/web/taskman/test/startTask.py (rev 0)
+++ pkg/trunk/sandbox/web/taskman/test/startTask.py 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# 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 Willow Garage, Inc. 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.
+#
+# Revision $Id$
+
+## Simple demo of a rospy service client that calls a service to add
+## two integers.
+
+PKG = 'taskman' # this package name
+
+import roslib; roslib.load_manifest(PKG)
+
+import sys
+import os
+import string
+
+import rospy
+
+# imports the AddTwoInts service
+from taskman.srv import *
+
+def startTask(task):
+ rospy.wait_for_service('start_task')
+
+ try:
+ # create a handle to the add_two_ints service
+ start_task = rospy.ServiceProxy('start_task', StartTask)
+ resp1 = start_task(task, "hassan")
+
+ return resp1.status
+ except rospy.ServiceException, e:
+ print "Service call failed: %s"%e
+
+if __name__ == "__main__":
+ startTask(sys.argv[1])
Property changes on: pkg/trunk/sandbox/web/taskman/test/startTask.py
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/trunk/sandbox/web/taskman/test/stopTask.py
===================================================================
--- pkg/trunk/sandbox/web/taskman/test/stopTask.py (rev 0)
+++ pkg/trunk/sandbox/web/taskman/test/stopTask.py 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+# 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 Willow Garage, Inc. 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.
+#
+# Revision $Id$
+
+## Simple demo of a rospy service client that calls a service to add
+## two integers.
+
+PKG = 'taskman' # this package name
+
+import roslib; roslib.load_manifest(PKG)
+
+import sys
+import os
+import string
+
+import rospy
+
+from taskman.srv import *
+
+def stopTask(task):
+ rospy.wait_for_service('stop_task')
+
+ try:
+ stop_task = rospy.ServiceProxy('stop_task', StopTask)
+ resp1 = stop_task(task, "hassan")
+
+ return resp1.status
+ except rospy.ServiceException, e:
+ print "Service call failed: %s"%e
+
+if __name__ == "__main__":
+ stopTask(sys.argv[1])
Property changes on: pkg/trunk/sandbox/web/taskman/test/stopTask.py
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/trunk/sandbox/web/taskman/test/talker.app
===================================================================
--- pkg/trunk/sandbox/web/taskman/test/talker.app (rev 0)
+++ pkg/trunk/sandbox/web/taskman/test/talker.app 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,7 @@
+name: Talker/Listener
+package: rospy_tutorials
+launch_file: 001_talker_listener/talker_listener.launch
+description: ROS's hello world equivilant
+icon:
+provides: talkers
+depends:
Added: pkg/trunk/sandbox/web/taskman/test/talker1.app
===================================================================
--- pkg/trunk/sandbox/web/taskman/test/talker1.app (rev 0)
+++ pkg/trunk/sandbox/web/taskman/test/talker1.app 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,7 @@
+name: Talker/Listener
+package: rospy_tutorials
+launch_file: 001_talker_listener/talker_listener.launch
+description: ROS's hello world equivilant
+icon:
+provides: talk
+depends: talkers
Added: pkg/trunk/sandbox/web/taskman/test/talker2.app
===================================================================
--- pkg/trunk/sandbox/web/taskman/test/talker2.app (rev 0)
+++ pkg/trunk/sandbox/web/taskman/test/talker2.app 2009-08-19 02:00:32 UTC (rev 22210)
@@ -0,0 +1,7 @@
+name: Talker/Listener
+package: rospy_tutorials
+launch_file: 001_talker_listener/talker_listener.launch
+description: ROS's hello world equivilant
+icon:
+provides: talk
+depends: talkers
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|