forked from stepjam/PyRep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for suction cups. Added Dobot.
- Loading branch information
Showing
12 changed files
with
162 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from pyrep.robots.arms.arm import Arm | ||
|
||
|
||
class Dobot(Arm): | ||
|
||
def __init__(self, count: int = 0): | ||
super().__init__(count, 'Dobot', 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from pyrep.robots.end_effectors.suction_cup import SuctionCup | ||
|
||
|
||
class BaxterSuctionCup(SuctionCup): | ||
|
||
def __init__(self, count: int = 0): | ||
super().__init__(count, 'BaxterSuctionCup') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from pyrep.robots.end_effectors.suction_cup import SuctionCup | ||
|
||
|
||
class DobotSuctionCup(SuctionCup): | ||
|
||
def __init__(self, count: int = 0): | ||
super().__init__(count, 'Dobot_suctionCup') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from typing import List | ||
from pyrep.objects.object import Object | ||
from pyrep.objects.shape import Shape | ||
from pyrep.objects.proximity_sensor import ProximitySensor | ||
from pyrep.objects.force_sensor import ForceSensor | ||
|
||
|
||
class SuctionCup(Shape): | ||
"""Represents all suction cups. | ||
""" | ||
|
||
def __init__(self, count: int, name: str, base_name: str = None): | ||
suffix = '' if count == 0 else '#%d' % (count - 1) | ||
super().__init__(name + suffix if base_name is None else base_name + suffix) | ||
self._proximity_sensor = ProximitySensor('%s_sensor%s' % (name, suffix)) | ||
self._attach_point = ForceSensor('%s_connection%s' % (name, suffix)) | ||
self._old_parents = [] | ||
self._grasped_objects = [] | ||
|
||
def grasp(self, obj: Object) -> bool: | ||
"""Attach the object to the suction cup if it is detected. | ||
Note: The does not move the object up to the suction cup. Therefore, the | ||
proximity sensor should have a short range in order for the suction | ||
grasp to look realistic. | ||
:param obj: The object to grasp if detected. | ||
:return: True if the object was detected/grasped. | ||
""" | ||
detected = self._proximity_sensor.is_detected(obj) | ||
# Check if detected and that we are not already grasping it. | ||
if detected and obj not in self._grasped_objects: | ||
self._grasped_objects.append(obj) | ||
self._old_parents.append(obj.get_parent()) | ||
obj.set_parent(self._attach_point, keep_in_place=True) | ||
return detected | ||
|
||
def release(self) -> None: | ||
"""Release any objects that have been sucked. | ||
Note: The does not actuate the gripper, but instead simply detaches any | ||
grasped objects. | ||
""" | ||
for grasped_obj, old_parent in zip( | ||
self._grasped_objects, self._old_parents): | ||
# Check if the object still exists | ||
if grasped_obj.still_exists(): | ||
grasped_obj.set_parent(old_parent, keep_in_place=True) | ||
self._grasped_objects = [] | ||
self._old_parents = [] | ||
|
||
def get_grasped_objects(self) -> List[Object]: | ||
"""Gets the objects that are currently in the suction cup. | ||
:return: A list of grasped objects. | ||
""" | ||
return self._grasped_objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import unittest | ||
from tests.core import TestCore | ||
from pyrep import PyRep | ||
from pyrep.objects.shape import Shape | ||
from os import path | ||
|
||
from pyrep.robots.end_effectors.dobot_suction_cup import DobotSuctionCup | ||
from pyrep.robots.end_effectors.baxter_suction_cup import BaxterSuctionCup | ||
|
||
ASSET_DIR = path.join(path.dirname(path.abspath(__file__)), 'assets') | ||
|
||
SUCTION_CUPS = [ | ||
('DobotSuctionCup', DobotSuctionCup), | ||
('BaxterSuctionCup', BaxterSuctionCup), | ||
] | ||
|
||
|
||
class TestSuctionCups(TestCore): | ||
|
||
def setUp(self): | ||
self.pyrep = PyRep() | ||
self.pyrep.launch(path.join( | ||
ASSET_DIR, 'test_scene_robots.ttt'), headless=True) | ||
self.pyrep.step() | ||
self.pyrep.start() | ||
|
||
def test_get_suction_cup(self): | ||
for cup_name, cup_type in SUCTION_CUPS: | ||
with self.subTest(suction_cup=cup_name): | ||
cup = cup_type() | ||
self.assertIsInstance(cup, cup_type) | ||
|
||
def test_grasp_and_release_with_suction(self): | ||
for cup_name, cup_type in SUCTION_CUPS: | ||
with self.subTest(suction_cup=cup_name): | ||
suction_cube = Shape('%s_cube' % cup_name) | ||
cube = Shape('cube') | ||
cup = cup_type() | ||
self.pyrep.step() | ||
grasped = cup.grasp(cube) | ||
self.assertFalse(grasped) | ||
self.assertEqual(len(cup.get_grasped_objects()), 0) | ||
grasped = cup.grasp(suction_cube) | ||
self.assertTrue(grasped) | ||
self.assertListEqual(cup.get_grasped_objects(), [suction_cube]) | ||
cup.release() | ||
self.assertEqual(len(cup.get_grasped_objects()), 0) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |