Skip to content

Commit fa8fd90

Browse files
author
Johannes Hechtl
committed
added new ik to ur5e
1 parent 5a871ca commit fa8fd90

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

examples/ur5e/ur5e_env_cartesian_control.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
logger.setLevel(logging.INFO)
1717

1818
ROBOT_IP = "192.168.1.15"
19-
ROBOT_INSTANCE = RobotPlatform.HARDWARE
19+
ROBOT_INSTANCE = RobotPlatform.SIMULATION # Change to RobotPlatform.HARDWARE for real robot
2020

2121

2222
def main():
@@ -46,36 +46,35 @@ def main():
4646
robot_cfg.robot_type = rcs.common.RobotType.UR5e
4747
robot_cfg.attachment_site = "attachment_site"
4848
robot_cfg.arm_collision_geoms = []
49+
robot_cfg.mjcf_scene_path = rcs.scenes["ur5e_empty_world"].mjb
50+
robot_cfg.kinematic_model_path = rcs.scenes["ur5e_empty_world"].mjcf_robot
4951
env_rel = SimEnvCreator()(
50-
control_mode=ControlMode.CARTESIAN_TQuat,
52+
control_mode=ControlMode.CARTESIAN_TRPY,
5153
collision_guard=False,
5254
robot_cfg=robot_cfg,
5355
gripper_cfg=None,
54-
# cameras=default_mujoco_cameraset_cfg(),
5556
max_relative_movement=0.5,
5657
relative_to=RelativeTo.LAST_STEP,
57-
mjcf=rcs.scenes["ur5e_empty_world"].mjb,
58-
urdf_path=rcs.scenes["ur5e_empty_world"].urdf,
5958
)
6059
env_rel.get_wrapper_attr("sim").open_gui()
6160

6261
obs, info = env_rel.reset()
6362

64-
act = {"xyzrpy": [0.0, 0, 0.0, 0, 0, np.deg2rad(45)], "gripper": 0}
65-
obs, reward, terminated, truncated, info = env_rel.step(act)
63+
# act = {"xyzrpy": [0.0, 0, 0.0, 0, 0, np.deg2rad(45)], "gripper": 0}
64+
# obs, reward, terminated, truncated, info = env_rel.step(act)
6665

6766
for _ in range(100):
6867
for _ in range(10):
6968
# move 1cm in x direction (forward) and close gripper
70-
act = {"tquat": [0.01, 0, 0, 0.0087265, 0, 0, 0.9999619], "gripper": 0}
69+
act = {"xyzrpy": [-0.1, 0, 0, 0.0, 0, 0], "gripper": 0}
7170
obs, reward, terminated, truncated, info = env_rel.step(act)
7271
if truncated or terminated:
7372
logger.info("Truncated or terminated!")
7473
return
7574
sleep(0.1)
7675
for _ in range(10):
7776
# move 1cm in negative x direction (backward) and open gripper
78-
act = {"tquat": [-0.01, 0, 0, -0.0087265, 0, 0, 0.9999619], "gripper": 1}
77+
act = {"xyzrpy": [-0.01, 0, 0, -0.0087265, 0, 0, 0.9999619], "gripper": 1}
7978
obs, reward, terminated, truncated, info = env_rel.step(act)
8079
if truncated or terminated:
8180
logger.info("Truncated or terminated!")

examples/ur5e/ur5e_env_joint_control.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from time import sleep
23

34
import numpy as np
45
from rcs._core.common import RobotPlatform
@@ -14,7 +15,8 @@
1415
logger.setLevel(logging.INFO)
1516

1617
ROBOT_IP = "192.168.25.201"
17-
ROBOT_INSTANCE = RobotPlatform.HARDWARE
18+
ROBOT_INSTANCE = RobotPlatform.SIMULATION
19+
# ROBOT_INSTANCE = RobotPlatform.HARDWARE
1820

1921

2022
def main():
@@ -44,18 +46,15 @@ def main():
4446
robot_cfg.robot_type = rcs.common.RobotType.UR5e
4547
robot_cfg.attachment_site = "attachment_site"
4648
robot_cfg.arm_collision_geoms = []
49+
robot_cfg.mjcf_scene_path = rcs.scenes["ur5e_empty_world"].mjb
50+
robot_cfg.kinematic_model_path = rcs.scenes["ur5e_empty_world"].mjcf_robot
4751
env_rel = SimEnvCreator()(
4852
control_mode=ControlMode.JOINTS,
4953
collision_guard=False,
5054
robot_cfg=robot_cfg,
5155
gripper_cfg=None,
52-
# cameras=default_mujoco_cameraset_cfg(),
5356
max_relative_movement=np.deg2rad(5),
5457
relative_to=RelativeTo.LAST_STEP,
55-
# mjcf=rcs.scenes["ur5e_empty_world"]["mjb"],
56-
mjcf="/home/johannes/repos/learning/robot-control-stack/assets/scenes/ur5e_empty_world/scene.xml",
57-
# urdf_path=rcs.scenes["ur5e_empty_world"]["urdf"],
58-
urdf_path="/home/johannes/repos/learning/robot-control-stack/assets/ur5e/urdf/ur5e.urdf",
5958
)
6059
env_rel.get_wrapper_attr("sim").open_gui()
6160

@@ -68,6 +67,7 @@ def main():
6867
if truncated or terminated:
6968
logger.info("Truncated or terminated!")
7069
return
70+
sleep(0.4)
7171

7272

7373
if __name__ == "__main__":

extensions/rcs_ur5e/src/rcs_ur5e/creators.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
import gymnasium as gym
4+
import rcs
45
from rcs.camera.hw import HardwareCameraSet
56
from rcs.envs.base import (
67
CameraSetWrapper,
@@ -27,7 +28,12 @@ def __call__( # type: ignore
2728
max_relative_movement: float | tuple[float, float] | None = None,
2829
relative_to: RelativeTo = RelativeTo.LAST_STEP,
2930
) -> gym.Env:
30-
robot = UR5e(ip)
31+
ik = rcs.common.Pin(
32+
robot_cfg.kinematic_model_path,
33+
robot_cfg.attachment_site,
34+
urdf=robot_cfg.kinematic_model_path.endswith(".urdf"),
35+
)
36+
robot = UR5e(ip, ik)
3137
robot.set_config(robot_cfg)
3238
env: gym.Env = RobotEnv(robot, control_mode, home_on_reset=True)
3339

extensions/rcs_ur5e/src/rcs_ur5e/hw.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import rtde_control
1313
import rtde_receive
1414

15+
import rcs
1516
from rcs_ur5e import robotiq_gripper
1617
from rcs import common
1718

@@ -22,6 +23,10 @@
2223

2324
@dataclass(kw_only=True)
2425
class UR5eConfig(common.RobotConfig):
26+
# Kinematics Setup
27+
kinematic_model_path = rcs.scenes["ur5e_empty_world"].mjcf_robot
28+
attachment_site = "attachment_site_testo"
29+
2530
# Robot movement parameters
2631
max_velocity: float = 1.0
2732
max_acceleration: float = 1.0
@@ -139,7 +144,7 @@ def _control_robot(shm_name: str, ip: str, stop_queue: mp.Queue, config_queue: m
139144
# if np.max(np.abs(diff[0:3])) > robot_config.max_servo_cartesian_step:
140145
# diff = (robot_config.max_servo_cartesian_step / np.max(diff)) * diff
141146
# target_pose = (cartesian_state_view + diff).tolist()
142-
# else:
147+
# else: (j.hechtl)
143148
# target_pose = cartesian_target_view.tolist()
144149
ur_control.servoL(
145150
target_pose,
@@ -166,8 +171,8 @@ def _control_robot(shm_name: str, ip: str, stop_queue: mp.Queue, config_queue: m
166171

167172

168173
class UR5e: # (common.Robot): # should inherit and implement common.Robot, but currently there is a bug that needs to be fixed
169-
def __init__(self, ip: str):
170-
self.ik = common.RL(urdf_path="/home/johannes/repos/rcs/assets/ur5e/urdf/ur5e.urdf")
174+
def __init__(self, ip: str, ik: common.Kinematics):
175+
self.ik = ik
171176
self._config = UR5eConfig()
172177
self._config.robot_type = common.RobotType.UR5e
173178
self._ip = ip
@@ -233,7 +238,7 @@ def get_cartesian_position(self) -> common.Pose:
233238
pose = common.Pose(quaternion=rotvec.as_quaternion_vector(), translation=trans)
234239
return common.Pose(rpy_vector=[0, 0, np.deg2rad(180)], translation=[0, 0, 0]).inverse() * pose
235240

236-
def get_ik(self) -> common.IK | None:
241+
def get_ik(self) -> common.Kinematics | None:
237242
return None
238243

239244
def get_joint_position(self) -> np.ndarray[tuple[typing.Literal[6]], np.dtype[np.float64]]:
@@ -312,8 +317,6 @@ def grasp(self) -> None:
312317
"""
313318
self.set_normalized_width(0.0)
314319

315-
# def is_grasped(self) -> bool: ...
316-
317320
def open(self) -> None:
318321
"""
319322
Open the gripper to its maximum width.

0 commit comments

Comments
 (0)