simplegrasping Module
Shows how to use the grasping.GraspingModel to compute valid grasps for manipulation.
Running the Example:
openrave.py --example simplegrasping
Description
This type of example is suited for object geometries that are dynamically created from sensor data.
Command-line
Usage: openrave.py [options]
Shows how to use the grasping.GraspingModel to compute valid grasps for
manipulation.
Options:
-h, --help show this help message and exit
--scene=SCENE Scene file to load (default=data/wamtest1.env.xml)
--manipname=MANIPNAME
Choose the manipulator to perform the grasping for
OpenRAVE Environment Options:
--loadplugin=_LOADPLUGINS
List all plugins and the interfaces they provide.
--collision=_COLLISION
Default collision checker to use
--physics=_PHYSICS physics engine to use (default=none)
--viewer=_VIEWER viewer to use (default=qtcoin)
--server=_SERVER server to use (default=None).
--serverport=_SERVERPORT
port to load server on (default=4765).
--module=_MODULES module to load, can specify multiple modules. Two
arguments are required: "name" "args".
-l _LEVEL, --level=_LEVEL, --log_level=_LEVEL
Debug level, one of
(fatal,error,warn,info,debug,verbose,verifyplans)
--testmode if set, will run the program in a finite amount of
time and spend computation time validating results.
Used for testing
Main Python Code
def main(env,options):
"Main example code."
env.Load(options.scene)
robot = env.GetRobots()[0]
if options.manipname is not None:
robot.SetActiveManipulator(options.manipname)
bodies = [b for b in env.GetBodies() if not b.IsRobot() and linalg.norm(b.ComputeAABB().extents()) < 0.2]
target = bodies[random.randint(len(bodies))]
print 'choosing target %s'%target
ikmodel = databases.inversekinematics.InverseKinematicsModel(robot=robot,iktype=IkParameterization.Type.Transform6D)
if not ikmodel.load():
ikmodel.autogenerate()
gmodel = databases.grasping.GraspingModel(robot,target)
if not gmodel.load():
print 'generating grasping model (one time computation)'
gmodel.init(friction=0.4,avoidlinks=[])
gmodel.generate(approachrays=gmodel.computeBoxApproachRays(delta=0.04,normalanglerange=0))
gmodel.save()
returnnum = 5
print 'computing first %d valid grasps'%returnnum
validgrasps,validindices = gmodel.computeValidGrasps(returnnum=returnnum)
for validgrasp in validgrasps:
gmodel.showgrasp(validgrasp)
print 'choosing a random grasp and move to its preshape'
basemanip = openravepy.interfaces.BaseManipulation(robot)
with env:
initialvalues = robot.GetDOFValues(gmodel.manip.GetArmIndices())
for validgrasp in random.permutation(validgrasps):
try:
gmodel.moveToPreshape(validgrasp)
print 'move robot arm to grasp'
Tgrasp = gmodel.getGlobalGraspTransform(validgrasp,collisionfree=True)
basemanip.MoveToHandPosition(matrices=[Tgrasp])
break
except planning_error,e:
print 'try again: ',e
robot.WaitForController(10)
taskmanip = openravepy.interfaces.TaskManipulation(robot)
taskmanip.CloseFingers()
robot.WaitForController(10)
with env:
robot.Grab(target)
raw_input('press any key to release')
taskmanip.ReleaseFingers(target=target)
robot.WaitForController(10)
print 'initial values'
basemanip.MoveManipulator(initialvalues)
robot.WaitForController(10)
print 'using the grasp iterator'
with env:
for validgrasp,validindex in gmodel.validGraspIterator():
gmodel.showgrasp(validgrasp,useik=True,collisionfree=True,delay=0.4)
Class Definitions
-
openravepy.examples.simplegrasping.main(env, options)[ソース]
Main example code.
-
openravepy.examples.simplegrasping.run(*args, **kwargs)[ソース]
Command-line execution of the example.
パラメタ: | args – arguments for script to parse, if not specified will use sys.argv |