Georg commited on
Commit ·
05fc5ca
1
Parent(s): e636f34
Update mujoco_server.py and ur5_env.py for improved teleoperation and target positioning
Browse files- Adjusted the velocity range in the UI for cartesian translation, changing the default from 50 mm/s to 5 mm/s and modifying the input range for finer control.
- Implemented a repeat mechanism for teleoperation commands to enhance responsiveness during key presses.
- Updated the target positioning logic in the UR5 environment to consistently raise the target position by 0.3 meters, ensuring better alignment with the end effector's height.
- mujoco_server.py +41 -8
- robots/ur5/ur5_env.py +5 -3
mujoco_server.py
CHANGED
|
@@ -1560,10 +1560,10 @@ def index():
|
|
| 1560 |
<button class="jog-btn" onmousedown="startJog('cartesian_translation', 'z', '+')" onmouseup="stopJog()" ontouchstart="startJog('cartesian_translation', 'z', '+'); event.preventDefault()" ontouchend="stopJog()">+</button>
|
| 1561 |
</div>
|
| 1562 |
</div>
|
| 1563 |
-
|
| 1564 |
-
|
| 1565 |
-
|
| 1566 |
-
|
| 1567 |
</div>
|
| 1568 |
<div class="control-group">
|
| 1569 |
<label>Rotation (RPY)</label>
|
|
@@ -1720,8 +1720,10 @@ def index():
|
|
| 1720 |
'KeyW', 'KeyA', 'KeyS', 'KeyD', 'KeyQ', 'KeyE',
|
| 1721 |
'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'
|
| 1722 |
]);
|
| 1723 |
-
let teleopTranslationStep = 0.
|
| 1724 |
let teleopVerticalStep = 0.01;
|
|
|
|
|
|
|
| 1725 |
let lastTeleopCommand = {dx: 0, dy: 0, dz: 0};
|
| 1726 |
|
| 1727 |
function humanizeScene(scene) {
|
|
@@ -2317,7 +2319,31 @@ def index():
|
|
| 2317 |
return armRobotTypes.has(active.robot) ? armTeleopKeys.has(code) : locomotionKeys.has(code);
|
| 2318 |
}
|
| 2319 |
|
| 2320 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2321 |
let dx = 0, dy = 0, dz = 0;
|
| 2322 |
if (keysPressed.has('KeyW')) dx += teleopTranslationStep;
|
| 2323 |
if (keysPressed.has('KeyS')) dx -= teleopTranslationStep;
|
|
@@ -2331,7 +2357,7 @@ def index():
|
|
| 2331 |
Math.abs(dy - lastTeleopCommand.dy) < 1e-6 &&
|
| 2332 |
Math.abs(dz - lastTeleopCommand.dz) < 1e-6;
|
| 2333 |
|
| 2334 |
-
if (unchanged) {
|
| 2335 |
return;
|
| 2336 |
}
|
| 2337 |
|
|
@@ -2344,8 +2370,15 @@ def index():
|
|
| 2344 |
|
| 2345 |
function handleKeyStateChange() {
|
| 2346 |
if (isArmRobot()) {
|
| 2347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2348 |
} else {
|
|
|
|
| 2349 |
updateCmdFromKeys();
|
| 2350 |
if (teleopStatus) {
|
| 2351 |
teleopStatus.innerText = 'UI teleop idle';
|
|
|
|
| 1560 |
<button class="jog-btn" onmousedown="startJog('cartesian_translation', 'z', '+')" onmouseup="stopJog()" ontouchstart="startJog('cartesian_translation', 'z', '+'); event.preventDefault()" ontouchend="stopJog()">+</button>
|
| 1561 |
</div>
|
| 1562 |
</div>
|
| 1563 |
+
<div style="margin-top: 8px;">
|
| 1564 |
+
<label style="font-size: 0.85em;">Velocity: <span id="trans_vel_val">5</span> mm/s</label>
|
| 1565 |
+
<input type="range" id="trans_velocity" min="1" max="100" step="1" value="5" oninput="updateTransVelocity()" style="width: 100%;">
|
| 1566 |
+
</div>
|
| 1567 |
</div>
|
| 1568 |
<div class="control-group">
|
| 1569 |
<label>Rotation (RPY)</label>
|
|
|
|
| 1720 |
'KeyW', 'KeyA', 'KeyS', 'KeyD', 'KeyQ', 'KeyE',
|
| 1721 |
'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'
|
| 1722 |
]);
|
| 1723 |
+
let teleopTranslationStep = 0.005; // meters per keyboard nudge
|
| 1724 |
let teleopVerticalStep = 0.01;
|
| 1725 |
+
const TELEOP_REPEAT_INTERVAL_MS = 80;
|
| 1726 |
+
let teleopRepeatTimer = null;
|
| 1727 |
let lastTeleopCommand = {dx: 0, dy: 0, dz: 0};
|
| 1728 |
|
| 1729 |
function humanizeScene(scene) {
|
|
|
|
| 2319 |
return armRobotTypes.has(active.robot) ? armTeleopKeys.has(code) : locomotionKeys.has(code);
|
| 2320 |
}
|
| 2321 |
|
| 2322 |
+
function hasActiveTeleopKeys() {
|
| 2323 |
+
for (const key of armTeleopKeys) {
|
| 2324 |
+
if (keysPressed.has(key)) {
|
| 2325 |
+
return true;
|
| 2326 |
+
}
|
| 2327 |
+
}
|
| 2328 |
+
return false;
|
| 2329 |
+
}
|
| 2330 |
+
|
| 2331 |
+
function startTeleopRepeat() {
|
| 2332 |
+
if (teleopRepeatTimer) {
|
| 2333 |
+
return;
|
| 2334 |
+
}
|
| 2335 |
+
teleopRepeatTimer = setInterval(() => updateArmTeleopFromKeys(true), TELEOP_REPEAT_INTERVAL_MS);
|
| 2336 |
+
}
|
| 2337 |
+
|
| 2338 |
+
function stopTeleopRepeat() {
|
| 2339 |
+
if (!teleopRepeatTimer) {
|
| 2340 |
+
return;
|
| 2341 |
+
}
|
| 2342 |
+
clearInterval(teleopRepeatTimer);
|
| 2343 |
+
teleopRepeatTimer = null;
|
| 2344 |
+
}
|
| 2345 |
+
|
| 2346 |
+
function updateArmTeleopFromKeys(force = false) {
|
| 2347 |
let dx = 0, dy = 0, dz = 0;
|
| 2348 |
if (keysPressed.has('KeyW')) dx += teleopTranslationStep;
|
| 2349 |
if (keysPressed.has('KeyS')) dx -= teleopTranslationStep;
|
|
|
|
| 2357 |
Math.abs(dy - lastTeleopCommand.dy) < 1e-6 &&
|
| 2358 |
Math.abs(dz - lastTeleopCommand.dz) < 1e-6;
|
| 2359 |
|
| 2360 |
+
if (unchanged && !force) {
|
| 2361 |
return;
|
| 2362 |
}
|
| 2363 |
|
|
|
|
| 2370 |
|
| 2371 |
function handleKeyStateChange() {
|
| 2372 |
if (isArmRobot()) {
|
| 2373 |
+
const active = hasActiveTeleopKeys();
|
| 2374 |
+
updateArmTeleopFromKeys(active);
|
| 2375 |
+
if (active) {
|
| 2376 |
+
startTeleopRepeat();
|
| 2377 |
+
} else {
|
| 2378 |
+
stopTeleopRepeat();
|
| 2379 |
+
}
|
| 2380 |
} else {
|
| 2381 |
+
stopTeleopRepeat();
|
| 2382 |
updateCmdFromKeys();
|
| 2383 |
if (teleopStatus) {
|
| 2384 |
teleopStatus.innerText = 'UI teleop idle';
|
robots/ur5/ur5_env.py
CHANGED
|
@@ -159,6 +159,7 @@ class UR5Env(gym.Env):
|
|
| 159 |
ee_pos = self.get_end_effector_pos()
|
| 160 |
ee_quat = self.get_end_effector_quat()
|
| 161 |
self._target_pos = ee_pos.astype(np.float32)
|
|
|
|
| 162 |
roll, pitch, yaw = IKController.quat_to_euler(ee_quat)
|
| 163 |
self._target_euler = np.array([roll, pitch, yaw], dtype=np.float32)
|
| 164 |
|
|
@@ -570,10 +571,11 @@ class UR5Env(gym.Env):
|
|
| 570 |
ee_pos = self.get_end_effector_pos()
|
| 571 |
ee_quat = self.get_end_effector_quat()
|
| 572 |
if self.scene_name == "scene_t_push" and self.t_target_body_id != -1:
|
| 573 |
-
target_pos = self.data.xpos[self.t_target_body_id]
|
| 574 |
else:
|
| 575 |
-
target_pos = ee_pos
|
| 576 |
-
|
|
|
|
| 577 |
|
| 578 |
# Convert EE quaternion to euler for target orientation
|
| 579 |
roll, pitch, yaw = IKController.quat_to_euler(ee_quat)
|
|
|
|
| 159 |
ee_pos = self.get_end_effector_pos()
|
| 160 |
ee_quat = self.get_end_effector_quat()
|
| 161 |
self._target_pos = ee_pos.astype(np.float32)
|
| 162 |
+
self._target_pos[2] += 0.3
|
| 163 |
roll, pitch, yaw = IKController.quat_to_euler(ee_quat)
|
| 164 |
self._target_euler = np.array([roll, pitch, yaw], dtype=np.float32)
|
| 165 |
|
|
|
|
| 571 |
ee_pos = self.get_end_effector_pos()
|
| 572 |
ee_quat = self.get_end_effector_quat()
|
| 573 |
if self.scene_name == "scene_t_push" and self.t_target_body_id != -1:
|
| 574 |
+
target_pos = self.data.xpos[self.t_target_body_id].astype(np.float32)
|
| 575 |
else:
|
| 576 |
+
target_pos = ee_pos.astype(np.float32)
|
| 577 |
+
target_pos[2] += 0.3
|
| 578 |
+
self._target_pos = target_pos
|
| 579 |
|
| 580 |
# Convert EE quaternion to euler for target orientation
|
| 581 |
roll, pitch, yaw = IKController.quat_to_euler(ee_quat)
|