grasping_ros.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # Copyright (C) 2009 Rosen Diankov
00004 # 
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #     http://www.apache.org/licenses/LICENSE-2.0
00009 # 
00010 # Unless required by applicable law or agreed to in writing, software
00011 # distributed under the License is distributed on an "AS IS" BASIS,
00012 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 # See the License for the specific language governing permissions and
00014 # limitations under the License. 
00015 """
00016 To execute on 8 cores of the current localhost, first store roscore and then run:
00017 
00018 .. code-block:: bash
00019 
00020   roscd openrave_database; rosrun parallel_util workmanagerlauncher.py --module=grasping_ros --launchservice='8*localhost'
00021 
00022 For more options run:
00023 
00024 .. code-block:: bash
00025 
00026   rosrun parallel_util workmanagerlauncher.py --help
00027 
00028 """
00029 
00030 from __future__ import with_statement # for python 2.5
00031 
00032 PKG = 'openrave_database' # ROS package name for dependencies
00033 import roslib; roslib.load_manifest(PKG)
00034 
00035 from numpy import *
00036 import numpy
00037 import sys, time
00038 from optparse import OptionParser
00039 from openravepy import *
00040 from openravepy.databases import grasping
00041 
00042 model = producer = consumer = gatherer = produceriter = None
00043 producercount = 0
00044 def start(args=None):
00045     global model, producer, consumer, gatherer
00046     try:
00047         options,model = grasping.GraspingModel.InitializeFromParser(args=args)
00048         producer, consumer, gatherer, num = model.generatepcg(*model.autogenerateparams(options))
00049     except Exception, e:
00050         print e
00051         print 'faile with args: ',args
00052     print 'total jobs: ',num
00053     
00054 def service_start(args):
00055     start(args)
00056     
00057 def service_processrequest(*args):
00058     global consumer
00059     return consumer(*args)
00060 
00061 def server_processresponse(*args):
00062     global gatherer
00063     if len(args) > 0:
00064         gatherer(*args)
00065 
00066 def server_requestwork():
00067     global producer, produceriter,producercount
00068     try:
00069         print 'grasping ',producercount
00070         producercount += 1
00071         if produceriter is None:
00072             produceriter=producer()
00073         return produceriter.next()
00074     except:
00075         return None
00076 
00077 def server_start(args):
00078     global producercount
00079     start(args)
00080     producercount = 0
00081 
00082 def server_end():
00083     global model, gatherer
00084     gatherer()
00085     model.save()
00086 
00087 def launcher_start(args):
00088     start(args)
00089     return ''
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


openrave_database
Author(s): Rosen Diankov (rosen.diankov@gmail.com)
autogenerated on Sun Mar 24 2013 01:48:43