-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
schunk_wsg_buttons.py
47 lines (39 loc) · 1.71 KB
/
schunk_wsg_buttons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from pydrake.systems.framework import LeafSystem
class SchunkWsgButtons(LeafSystem):
"""
Adds buttons to open/close the Schunk WSG gripper.
.. pydrake_system::
name: SchunkWsgButtons
output_ports:
- position
- max_force
"""
_BUTTON_NAME = "Open/Close Gripper"
"""The name of the button added to the meshcat UI."""
def __init__(self, meshcat, open_position=0.107, closed_position=0.002,
force_limit=40):
""""
Args:
open_position: Target position for the gripper when open.
closed_position: Target position for the gripper when closed.
**Warning**: closing to 0mm can smash the fingers
together and keep applying force even when no
object is grasped.
force_limit: Force limit to send to Schunk WSG controller.
"""
super().__init__()
self.meshcat = meshcat
self.DeclareVectorOutputPort("position", 1, self.CalcPositionOutput)
self.DeclareVectorOutputPort("force_limit", 1,
self.CalcForceLimitOutput)
self._open_button = meshcat.AddButton(self._BUTTON_NAME)
self._open_position = open_position
self._closed_position = closed_position
self._force_limit = force_limit
def CalcPositionOutput(self, context, output):
if self.meshcat.GetButtonClicks(name=self._BUTTON_NAME) % 2 == 0:
output.SetAtIndex(0, self._open_position)
else:
output.SetAtIndex(0, self._closed_position)
def CalcForceLimitOutput(self, context, output):
output.SetAtIndex(0, self._force_limit)