| """ |
| A Franka Panda reaches for 10 randomly places targets. |
| This script contains examples of: |
| - Linear (IK) paths. |
| - Scene manipulation (creating an object and moving it). |
| """ |
| from os.path import dirname, join, abspath |
| from pyrep import PyRep |
| from pyrep.robots.arms.panda import Panda |
| from pyrep.objects.shape import Shape |
| from pyrep.const import PrimitiveShape |
| from pyrep.errors import ConfigurationPathError |
| import numpy as np |
| import math |
|
|
| LOOPS = 10 |
| SCENE_FILE = join(dirname(abspath(__file__)), 'scene_panda_reach_target.ttt') |
| pr = PyRep() |
| pr.launch(SCENE_FILE, headless=False) |
| pr.start() |
| agent = Panda() |
|
|
| |
| target = Shape.create(type=PrimitiveShape.SPHERE, |
| size=[0.05, 0.05, 0.05], |
| color=[1.0, 0.1, 0.1], |
| static=True, respondable=False) |
|
|
| position_min, position_max = [0.8, -0.2, 1.0], [1.0, 0.2, 1.4] |
|
|
| starting_joint_positions = agent.get_joint_positions() |
|
|
| for i in range(LOOPS): |
|
|
| |
| agent.set_joint_positions(starting_joint_positions) |
|
|
| |
| pos = list(np.random.uniform(position_min, position_max)) |
| target.set_position(pos) |
|
|
| |
| try: |
| path = agent.get_path( |
| position=pos, euler=[0, math.radians(180), 0]) |
| except ConfigurationPathError as e: |
| print('Could not find path') |
| continue |
|
|
| |
| done = False |
| while not done: |
| done = path.step() |
| pr.step() |
|
|
| print('Reached target %d!' % i) |
|
|
| pr.stop() |
| pr.shutdown() |
|
|