Skip to content

Commit baee473

Browse files
committed
fix(gripper): joint value calculation
- so101 min/max joint values in radians - fixed width calculation in normalized gripper - added header files in include to linting and formatting
1 parent c3fa76c commit baee473

4 files changed

Lines changed: 73 additions & 8 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ COMPILE_MODE = Release
55
# CPP
66
cppcheckformat:
77
clang-format --dry-run -Werror -i $(shell find ${CPPSRC} -name '*.cpp' -o -name '*.cc' -o -name '*.h')
8+
clang-format --dry-run -Werror -i $(shell find include -name '*.cpp' -o -name '*.cc' -o -name '*.h')
89
clang-format --dry-run -Werror -i $(shell find extensions/rcs_fr3/src -name '*.cpp' -o -name '*.cc' -o -name '*.h')
910

1011
cppformat:
1112
clang-format -Werror -i $(shell find ${CPPSRC} -name '*.cpp' -o -name '*.cc' -o -name '*.h')
13+
clang-format -Werror -i $(shell find include -name '*.cpp' -o -name '*.cc' -o -name '*.h')
1214
clang-format -Werror -i $(shell find extensions/rcs_fr3/src -name '*.cpp' -o -name '*.cc' -o -name '*.h')
1315

1416
cpplint:
1517
clang-tidy -p=build --warnings-as-errors='*' $(shell find ${CPPSRC} -name '*.cpp' -o -name '*.cc' -name '*.h')
18+
clang-tidy -p=build --warnings-as-errors='*' $(shell find include -name '*.cpp' -o -name '*.cc' -name '*.h')
1619

1720
# import errors
1821
# clang-tidy -p=build --warnings-as-errors='*' $(shell find extensions/rcs_fr3/src -name '*.cpp' -o -name '*.cc' -name '*.h')
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import logging
2+
3+
import numpy as np
4+
from rcs.envs.base import ControlMode, RelativeTo
5+
from rcs.envs.creators import SimEnvCreator
6+
7+
import rcs
8+
from rcs import sim
9+
10+
logger = logging.getLogger(__name__)
11+
logger.setLevel(logging.INFO)
12+
13+
14+
def main():
15+
16+
robot_cfg = sim.SimRobotConfig()
17+
robot_cfg.actuators = ["1", "2", "3", "4", "5"]
18+
robot_cfg.joints = [
19+
"1",
20+
"2",
21+
"3",
22+
"4",
23+
"5",
24+
]
25+
robot_cfg.base = "base"
26+
robot_cfg.robot_type = rcs.common.RobotType.UR5e
27+
robot_cfg.attachment_site = "gripper"
28+
robot_cfg.arm_collision_geoms = []
29+
gripper_cfg = sim.SimGripperConfig
30+
gripper_cfg.min_actuator_width = -0.17453292519943295
31+
gripper_cfg.max_actuator_width = 1.7453292519943295
32+
gripper_cfg.min_joint_width = -0.17453292519943295
33+
gripper_cfg.max_joint_width = 1.7453292519943295
34+
env_rel = SimEnvCreator()(
35+
control_mode=ControlMode.JOINTS,
36+
collision_guard=False,
37+
robot_cfg=robot_cfg,
38+
gripper_cfg=gripper_cfg,
39+
# cameras=default_mujoco_cameraset_cfg(),
40+
max_relative_movement=np.deg2rad(5),
41+
relative_to=RelativeTo.LAST_STEP,
42+
mjcf=rcs.scenes["so101_empty_world"]["mjb"],
43+
urdf_path=rcs.scenes["so101_empty_world"]["urdf"],
44+
)
45+
env_rel.get_wrapper_attr("sim").open_gui()
46+
47+
for _ in range(10):
48+
obs, info = env_rel.reset()
49+
for _ in range(10):
50+
# sample random relative action and execute it
51+
act = env_rel.action_space.sample()
52+
obs, reward, terminated, truncated, info = env_rel.step(act)
53+
if truncated or terminated:
54+
logger.info("Truncated or terminated!")
55+
return
56+
57+
58+
if __name__ == "__main__":
59+
main()

include/rcs/Robot.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,21 @@ static const std::unordered_map<RobotType, RobotMetaConfig> robots_meta_config =
6262
// TODO: update this to angle values
6363
RobotMetaConfig{
6464
// q_home (5‐vector):
65-
(VectorXd(5) << -9.40612320177057, -99.66130397967824,
66-
99.9124726477024, 69.96996996996998, -9.095744680851055)
65+
(VectorXd(5) << -0.1805846, -1.91335968, 1.56934507, 1.16014604,
66+
-0.25400112)
6767
.finished(),
6868
// dof:
6969
5,
7070
// joint_limits (2×5):
7171
(Eigen::Matrix<double, 2, Eigen::Dynamic, Eigen::ColMajor>(2, 5) <<
7272
// low 5‐tuple
73-
-100.0,
74-
-100.0, -100.0, -100.0, -100.0,
73+
-1.9198621771937616,
74+
-1.9198621771937634, -1.7453292519943295, -1.6580627969561903,
75+
-2.7925268969992407,
76+
7577
// high 5‐tuple
76-
100.0, 100.0, 100.0, 100.0, 100.0)
78+
1.9198621771937616, 1.9198621771937634, 1.5707963267948966,
79+
1.6580627969561903, 2.7925268969992407)
7780
.finished()}}}};
7881

7982
struct RobotConfig {

src/sim/SimGripper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ double SimGripper::get_normalized_width() {
9494
// TODO: maybe we should use the mujoco sensors? Not sure what the difference
9595
// is between reading out from qpos and reading from the sensors.
9696
double width =
97-
(this->sim->d->qpos[this->joint_id] - this->cfg.min_actuator_width) /
98-
(this->cfg.max_joint_width - this->cfg.min_actuator_width);
97+
(this->sim->d->qpos[this->joint_id] + this->cfg.min_joint_width) /
98+
(this->cfg.max_joint_width + this->cfg.min_joint_width);
9999
// sometimes the joint is slightly outside of the bounds
100100
if (width < 0) {
101101
width = 0;
@@ -159,7 +159,7 @@ void SimGripper::m_reset() {
159159
this->state = SimGripperState();
160160
// reset state hard
161161
this->sim->d->qpos[this->joint_id] = this->cfg.max_joint_width;
162-
this->sim->d->ctrl[this->actuator_id] = this->cfg.max_joint_width;
162+
this->sim->d->ctrl[this->actuator_id] = this->cfg.max_actuator_width;
163163
}
164164

165165
void SimGripper::reset() { this->m_reset(); }

0 commit comments

Comments
 (0)