Skip to content

Commit 44c96b1

Browse files
committed
fix(ik): ik optional bug and fr3 example
- Fixed bug where the ik value optional was wrongly interpreted - adapted fr3 example to the new ik version
1 parent 93523a0 commit 44c96b1

3 files changed

Lines changed: 27 additions & 20 deletions

File tree

python/examples/fr3.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import sys
3+
from time import sleep
34

45
import numpy as np
56
import rcsss
@@ -11,9 +12,12 @@
1112
from rcsss.control.fr3_desk import FCI, Desk, DummyResourceManager
1213
from rcsss.control.utils import load_creds_fr3_desk
1314
from rcsss.envs.base import RobotInstance
15+
from rcsss.envs.factories import get_urdf_path
1416

1517
ROBOT_IP = "192.168.101.1"
1618
ROBOT_INSTANCE = RobotInstance.SIMULATION
19+
# replace this with a path to a robot urdf file if you dont have the utn models
20+
URDF_PATH = None
1721

1822
logger = logging.getLogger(__name__)
1923
logger.setLevel(logging.DEBUG)
@@ -46,10 +50,11 @@ def main():
4650
with resource_manger:
4751
if ROBOT_INSTANCE == RobotInstance.SIMULATION:
4852
simulation = sim.Sim(rcsss.scenes["fr3_empty_world"])
49-
robot = rcsss.sim.FR3(simulation, "0", str(rcsss.scenes["lab"].parent / "fr3.urdf"))
53+
urdf_path = get_urdf_path(URDF_PATH, allow_none_if_not_found=False)
54+
ik = rcsss.common.IK(urdf_path)
55+
robot = rcsss.sim.FR3(simulation, "0", ik)
5056
cfg = sim.FR3Config()
5157
cfg.tcp_offset = rcsss.common.Pose(rcsss.common.FrankaHandTCPOffset())
52-
cfg.ik_duration_in_milliseconds = 300
5358
cfg.realtime = False
5459
robot.set_parameters(cfg)
5560

python/rcsss/envs/factories.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ def default_realsense(name2id: dict[str, str]):
5656
return RealSenseCameraSet(cam_cfg)
5757

5858

59+
def get_urdf_path(urdf_path: str | None, allow_none_if_not_found: bool = False) -> str | None:
60+
if urdf_path is None and "lab" in rcsss.scenes:
61+
urdf_path = str(rcsss.scenes["lab"].parent / "fr3.urdf")
62+
assert os.path.exists(urdf_path), "Automatic deduced urdf path does not exist. Corrupted models directory."
63+
logger.info("Using automatic found urdf.")
64+
elif urdf_path is None and not allow_none_if_not_found:
65+
msg = "This pip package was not built with the UTN lab models, please pass the urdf and mjcf path."
66+
raise ValueError(msg)
67+
elif urdf_path is not None:
68+
logger.warning("No urdf path was found. Proceeding, but set_cartesian methods will result in errors.")
69+
return urdf_path
70+
71+
5972
def fr3_hw_env(
6073
ip: str,
6174
control_mode: ControlMode,
@@ -66,12 +79,7 @@ def fr3_hw_env(
6679
max_relative_movement: float | None = None,
6780
urdf_path: str | None = None,
6881
) -> gym.Env:
69-
if urdf_path is None and "lab" in rcsss.scenes:
70-
urdf_path = str(rcsss.scenes["lab"].parent / "fr3.urdf")
71-
assert os.path.exists(urdf_path), "Automatic deduced urdf path does not exist. Corrupted models directory."
72-
logger.info("Using automatic found urdf.")
73-
elif urdf_path is None:
74-
logger.warning("No urdf path was found. Proceeding, but set_cartesian methods will result in errors.")
82+
urdf_path = get_urdf_path(urdf_path, allow_none_if_not_found=True)
7583

7684
ik = rcsss.common.IK(urdf_path) if urdf_path is not None else None
7785
robot = rcsss.hw.FR3(ip, ik)
@@ -121,6 +129,7 @@ def default_mujoco_cameraset_cfg():
121129
cameras = {
122130
"wrist": SimCameraConfig(identifier="eye-in-hand_0", type=int(CameraType.fixed)),
123131
"default_free": SimCameraConfig(identifier="", type=int(CameraType.default_free)),
132+
# "bird_eye": SimCameraConfig(identifier="bird-eye-cam", type=int(CameraType.fixed)),
124133
}
125134
return SimCameraSetConfig(cameras=cameras, resolution_width=1280, resolution_height=720, frame_rate=10)
126135

@@ -134,20 +143,13 @@ def fr3_sim_env(
134143
urdf_path: str | None = None,
135144
mjcf: str | PathLike = "fr3_empty_world",
136145
) -> gym.Env[ObsArmsGrCam, LimitedJointsRelDictType]:
137-
138-
if urdf_path is None and "lab" in rcsss.scenes:
139-
urdf_path = str(rcsss.scenes["lab"].parent / "fr3.urdf")
140-
assert os.path.exists(urdf_path), "Automatic deduced urdf path does not exist. Corrupted models directory."
141-
logger.info("Using automatic found urdf.")
142-
elif urdf_path is None:
143-
msg = "This pip package was not built with the UTN lab models, please pass the urdf and mjcf path."
144-
raise ValueError(msg)
146+
urdf_path = get_urdf_path(urdf_path, allow_none_if_not_found=False)
145147

146148
if mjcf not in rcsss.scenes:
147149
logger.warning("mjcf not found as key in scenes, interpreting mjcf as path the mujoco scene xml")
148150

149151
simulation = sim.Sim(rcsss.scenes.get(mjcf, mjcf)) # type: ignore
150-
ik = rcsss.common.IK(urdf_path)
152+
ik = rcsss.common.IK(urdf_path) # type: ignore
151153
robot = rcsss.sim.FR3(simulation, "0", ik)
152154
robot.set_parameters(robot_cfg)
153155
env: gym.Env = FR3Env(robot, control_mode)

src/sim/FR3.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ std::optional<std::shared_ptr<common::IK>> FR3::get_ik() { return this->m_ik; }
154154

155155
void FR3::set_cartesian_position(const common::Pose& pose) {
156156
// pose is assumed to be in the robots coordinate frame
157-
auto joints =
157+
auto joint_vals =
158158
this->m_ik->ik(pose, this->get_joint_position(), this->cfg.tcp_offset);
159-
if (!joints.has_value()) {
159+
if (joint_vals.has_value()) {
160160
this->state.ik_success = true;
161-
this->set_joint_position(joints.value());
161+
this->set_joint_position(joint_vals.value());
162162
} else {
163163
this->state.ik_success = false;
164164
}

0 commit comments

Comments
 (0)