Skip to content

Commit fb6551f

Browse files
committed
feat(fr3): frankik integration for analytical fast franka ik
1 parent 6406459 commit fb6551f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

extensions/rcs_fr3/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ version = "0.5.2"
88
description="RCS libfranka integration"
99
dependencies = [
1010
"rcs>=0.5.0",
11+
"frankik @ git+https://github.com/juelg/frankik",
1112
]
1213
readme = "README.md"
1314
maintainers = [

extensions/rcs_fr3/src/rcs_fr3/creators.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import logging
2+
import typing
23
from os import PathLike
34

45
import gymnasium as gym
56
import numpy as np
67
import rcs.hand.tilburg_hand
8+
from rcs._core.common import Kinematics, Pose
79
from rcs.camera.hw import HardwareCameraSet
810
from rcs.envs.base import (
911
CameraSetWrapper,
@@ -22,11 +24,36 @@
2224
from rcs_fr3.utils import default_fr3_hw_gripper_cfg, default_fr3_hw_robot_cfg
2325

2426
import rcs
27+
from frankik import FrankaKinematics
2528

2629
logger = logging.getLogger(__name__)
2730
logger.setLevel(logging.INFO)
2831

2932

33+
class FrankIK(Kinematics):
34+
def __init__(self, allow_elbow_flips: bool = False):
35+
Kinematics.__init__(self)
36+
self.allow_elbow_flips = allow_elbow_flips
37+
self.kin = FrankaKinematics(robot_type="fr3")
38+
39+
def forward(self, q0: np.ndarray[tuple[typing.Literal[7]], np.dtype[np.float64]], tcp_offset: Pose) -> Pose:
40+
print("forward called")
41+
return Pose(pose_matrix=self.kin.forward(q0, tcp_offset.pose_matrix()))
42+
43+
def inverse(
44+
self, pose: Pose, q0: np.ndarray[tuple[typing.Literal[7]], np.dtype[np.float64]], tcp_offset: Pose
45+
) -> np.ndarray[tuple[typing.Literal[7]], np.dtype[np.float64]] | None:
46+
tcp_offset = self.kin.FrankaHandTCPOffset
47+
return self.kin.inverse(
48+
pose.pose_matrix(), q0, tcp_offset.pose_matrix(), allow_elbow_flips=self.allow_elbow_flips
49+
)
50+
51+
52+
# FYI: this needs to be in global namespace to avoid auto garbage collection issues
53+
# pybind11 3.x would avoid this but with smart_holder but we cannot update due to the subfiles issue yet
54+
FastIK = FrankIK()
55+
56+
3057
class RCSFR3EnvCreator(RCSHardwareEnvCreator):
3158
def __call__( # type: ignore
3259
self,
@@ -62,6 +89,7 @@ def __call__( # type: ignore
6289
robot_cfg.attachment_site,
6390
urdf=robot_cfg.kinematic_model_path.endswith(".urdf"),
6491
)
92+
# ik = FastIK
6593
# ik = rcs_robotics_library._core.rl.RoboticsLibraryIK(robot_cfg.kinematic_model_path)
6694
robot = hw.Franka(ip, ik)
6795
robot.set_config(robot_cfg)

0 commit comments

Comments
 (0)