Skip to content

Commit 6fdae07

Browse files
committed
fixed issue with CloseHand in sim
1 parent dc1d384 commit 6fdae07

File tree

1 file changed

+121
-3
lines changed

1 file changed

+121
-3
lines changed

src/prpy/base/micohand.py

Lines changed: 121 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,114 @@ def OpenHand(self, value=0., timeout=None):
123123
else:
124124
return self.MoveHand(f1=value, f2=value, timeout=timeout)
125125

126-
def CloseHand(self, value=0.8, timeout=None):
127-
""" Close the hand.
126+
#!/usr/bin/env python
127+
128+
# Copyright (c) 2014, Carnegie Mellon University
129+
# All rights reserved.
130+
# Authors: Tekin Mericli <tekin@cmu.edu>
131+
#
132+
# Redistribution and use in source and binary forms, with or without
133+
# modification, are permitted provided that the following conditions are met:
134+
#
135+
# - Redistributions of source code must retain the above copyright notice, this
136+
# list of conditions and the following disclaimer.
137+
# - Redistributions in binary form must reproduce the above copyright notice,
138+
# this list of conditions and the following disclaimer in the documentation
139+
# and/or other materials provided with the distribution.
140+
# - Neither the name of Carnegie Mellon University nor the names of its
141+
# contributors may be used to endorse or promote products derived from this
142+
# software without specific prior written permission.
143+
#
144+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
145+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
146+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
147+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
148+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
149+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
150+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
151+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
152+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
153+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
154+
# POSSIBILITY OF SUCH DAMAGE.
155+
156+
import numpy
157+
import openravepy
158+
from .. import util
159+
from ..exceptions import PrPyException
160+
from endeffector import EndEffector
161+
162+
class MicoHand(EndEffector):
163+
def __init__(self, sim, manipulator):
164+
EndEffector.__init__(self, manipulator)
165+
166+
robot = manipulator.GetRobot()
167+
env = robot.GetEnv()
168+
169+
self.simulated = sim
170+
171+
with env:
172+
accel_limits = robot.GetDOFAccelerationLimits()
173+
accel_limits[self.GetIndices()] = 1.
174+
robot.SetDOFAccelerationLimits(accel_limits)
175+
176+
if sim:
177+
robot = manipulator.GetRobot()
178+
self.controller = robot.AttachController(
179+
self.GetName(), '', self.GetIndices(), 0, True)
180+
181+
def CloneBindings(self, parent):
182+
super(MicoHand, self).CloneBindings(parent)
183+
184+
self.simulated = True
185+
186+
def MoveHand(self, f1, f2, timeout=None):
187+
"""
188+
Change the hand preshape. This function blocks until trajectory
189+
execution finishes. This can be changed by changing the timeout
190+
parameter to a maximum number of seconds. Pass zero to return
191+
instantantly.
192+
193+
@param f1 finger 1 angle
194+
@param f2 finger 2 angle
195+
@param timeout blocking execution timeout
196+
"""
197+
198+
from openravepy import PlannerStatus
199+
200+
robot = self.GetParent()
201+
202+
with robot.GetEnv():
203+
sp = openravepy.Robot.SaveParameters
204+
with robot.CreateRobotStateSaver(sp.ActiveDOF):
205+
robot.SetActiveDOFs(self.GetIndices())
206+
cspec = robot.GetActiveConfigurationSpecification('linear')
207+
current_preshape = robot.GetActiveDOFValues()
208+
209+
# Default any None's to the current DOF values.
210+
desired_preshape = current_preshape.copy()
211+
if f1 is not None: desired_preshape[0] = f1
212+
if f2 is not None: desired_preshape[1] = f2
213+
214+
# Create a two waypoint trajectory to the target configuration.
215+
traj = openravepy.RaveCreateTrajectory(robot.GetEnv(), '')
216+
traj.Init(cspec)
217+
traj.Insert(0, current_preshape)
218+
traj.Insert(1, desired_preshape)
219+
220+
# Time the trajectory so we can execute it.
221+
result = openravepy.planningutils.RetimeTrajectory(
222+
traj, False, 1., 1., 'LinearTrajectoryRetimer')
223+
224+
if result not in [ PlannerStatus.HasSolution,
225+
PlannerStatus.InterruptedWithSolution ]:
226+
raise PrPyException('Failed timing finger trajectory.')
227+
228+
# Execute the trajectory.
229+
return robot.ExecuteTrajectory(traj)
230+
231+
def OpenHand(self, value=0., timeout=None):
232+
"""
233+
Open the hand.
128234
@param timeout blocking execution timeout
129235
"""
130236
if self.simulated:
@@ -133,7 +239,7 @@ def CloseHand(self, value=0.8, timeout=None):
133239

134240
with robot.CreateRobotStateSaver(p.ActiveDOF | p.ActiveManipulator):
135241
self.manipulator.SetActive()
136-
robot.task_manipulation.CloseFingers()
242+
robot.task_manipulation.ReleaseFingers()
137243

138244
if timeout:
139245
robot.WaitForController(timeout)
@@ -142,6 +248,18 @@ def CloseHand(self, value=0.8, timeout=None):
142248
else:
143249
return self.MoveHand(f1=value, f2=value, timeout=timeout)
144250

251+
def CloseHand(self, value=0.8, timeout=None):
252+
""" Close the hand.
253+
@param timeout blocking execution timeout
254+
"""
255+
return self.MoveHand(f1=value, f2=value, timeout=timeout)
256+
257+
def CloseHandTight(self, value=1.2, timeout=None):
258+
""" Close the hand tightly.
259+
@param timeout blocking execution timeout
260+
"""
261+
return self.CloseHand(value=value, timeout=timeout)
262+
145263
def CloseHandTight(self, value=1.2, timeout=None):
146264
""" Close the hand tightly.
147265
@param timeout blocking execution timeout

0 commit comments

Comments
 (0)