-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP for setting robot cell and cell state
- Loading branch information
Showing
8 changed files
with
364 additions
and
20 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
docs/examples/05_backends_pybullet/files/01_set_robot_cell.py
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,21 @@ | ||
from compas.datastructures import Mesh | ||
|
||
import compas_fab | ||
from compas_fab.backends import PyBulletClient | ||
from compas_fab.backends import PyBulletPlanner | ||
from compas_fab.robots import RobotCell | ||
from compas_fab.robots import RigidBody | ||
|
||
with PyBulletClient() as client: | ||
urdf_filepath = compas_fab.get("robot_library/ur5_robot/urdf/robot_description.urdf") | ||
robot = client.load_robot(urdf_filepath) | ||
|
||
robot_cell = RobotCell(robot) | ||
floor_mesh = Mesh.from_stl(compas_fab.get("planning_scene/floor.stl")) | ||
robot_cell.rigid_body_models["floor"] = RigidBody(floor_mesh) | ||
|
||
planner = PyBulletPlanner(client) | ||
planner.set_robot_cell(robot_cell) | ||
# The floor should appear in the PyBullet's GUI | ||
|
||
input("Press Enter to continue...") |
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
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
59 changes: 59 additions & 0 deletions
59
src/compas_fab/backends/pybullet/backend_features/pybullet_set_robot_cell.py
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,59 @@ | ||
from compas_fab.backends.interfaces import SetRobotCell | ||
|
||
import compas | ||
|
||
if not compas.IPY: | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Optional # noqa: F401 | ||
from typing import Dict # noqa: F401 | ||
from typing import List # noqa: F401 | ||
from typing import Tuple # noqa: F401 | ||
|
||
from compas_fab.robots import Robot # noqa: F401 | ||
from compas_robots import Configuration # noqa: F401 | ||
from compas.geometry import Frame # noqa: F401 | ||
from compas_fab.backends.interfaces import ClientInterface # noqa: F401 | ||
from compas_fab.robots import RobotCell # noqa: F401 | ||
from compas_fab.robots import RobotCellState # noqa: F401 | ||
from compas_fab.backends import PyBulletClient # noqa: F401 | ||
|
||
from compas_fab.backends.pybullet.const import STATIC_MASS | ||
|
||
|
||
class PyBulletSetRobotCell(SetRobotCell): | ||
|
||
def set_robot_cell(self, robot_cell, robot_cell_state=None, options=None): | ||
# type: (RobotCell, Optional[RobotCellState], Optional[Dict]) -> None | ||
"""Pass the models in the robot cell to the Pybullet client. | ||
The client keeps the robot cell models in memory and uses them for planning. | ||
Calling this method will override the previous robot cell in the client. | ||
It should be called only if the robot cell models have changed. | ||
""" | ||
client = self.client # type: PyBulletClient | ||
|
||
# TODO: Check for new, modified and removed objects compared to the | ||
# TODO: previous robot cell state and update the PyBullet world accordingly | ||
|
||
# At the moment, all previous object in the PyBullet world are removed | ||
# and the new robot cell is added to the PyBullet world | ||
|
||
# Remove all objects from the PyBullet world | ||
client.remove_all_tools() | ||
client.remove_all_rigid_bodies() | ||
|
||
# Add the robot cell to the PyBullet world | ||
for name, tool in robot_cell.tool_models.items(): | ||
client.add_tool(name, tool.mesh, tool.mass) | ||
for name, rigid_body in robot_cell.rigid_body_models.items(): | ||
client.add_rigid_body(name, rigid_body.mesh, rigid_body.mass) | ||
|
||
# Update the robot cell in the client | ||
self._robot_cell = robot_cell | ||
|
||
# If a robot cell state is provided, update the client's robot cell state | ||
if robot_cell_state: | ||
self.set_robot_cell_state(robot_cell_state, options) |
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
Oops, something went wrong.