kinematicreachability_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=kinematicreachability_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 kinematicreachability
00041 
00042 model = producer = consumer = gatherer = produceriter = None
00043 producercount = 0
00044 def start(args=None):
00045     global model, producer, consumer, gatherer
00046     options,model = kinematicreachability.ReachabilityModel.InitializeFromParser(args=args)
00047     producer, consumer, gatherer, num = model.generatepcg(*model.autogenerateparams(options))
00048     print 'total jobs: ',num
00049 
00050 def service_start(args):
00051     start(args)
00052     
00053 def service_processrequest(*args):
00054     global consumer
00055     return consumer(*args)
00056 
00057 def server_processresponse(*args):
00058     global gatherer
00059     if len(args) > 0:
00060         gatherer(*args)
00061 
00062 def server_requestwork():
00063     global producer, produceriter,producercount
00064     try:
00065         if mod(producercount,1000) == 0:
00066             print 'work ',producercount
00067         producercount += 1
00068         if produceriter is None:
00069             produceriter=producer()
00070         return produceriter.next()
00071     except:
00072         return None
00073 
00074 def server_start(args):
00075     global producercount
00076     start(args)
00077     producercount = 0
00078 
00079 def server_end():
00080     global model, gatherer
00081     gatherer()
00082     model.save()
00083 
00084 def launcher_start(args):
00085     start(args)
00086     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