mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-21 11:39:50 +00:00
fix: precise_sleep is never called with negative value (#2757)
This commit is contained in:
@@ -196,7 +196,7 @@ def teleop_loop(teleop: Teleoperator, env: gym.Env, fps: int):
|
|||||||
obs, info = env.reset()
|
obs, info = env.reset()
|
||||||
|
|
||||||
dt_s = time.perf_counter() - loop_start
|
dt_s = time.perf_counter() - loop_start
|
||||||
precise_sleep(1 / fps - dt_s)
|
precise_sleep(max(1 / fps - dt_s, 0.0))
|
||||||
loop_s = time.perf_counter() - loop_start
|
loop_s = time.perf_counter() - loop_start
|
||||||
print(f"\ntime: {loop_s * 1e3:.2f}ms ({1 / loop_s:.0f} Hz)")
|
print(f"\ntime: {loop_s * 1e3:.2f}ms ({1 / loop_s:.0f} Hz)")
|
||||||
|
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ for idx in range(dataset.num_frames):
|
|||||||
}
|
}
|
||||||
robot.send_action(action)
|
robot.send_action(action)
|
||||||
|
|
||||||
precise_sleep(1.0 / dataset.fps - (time.perf_counter() - t0))
|
precise_sleep(max(1.0 / dataset.fps - (time.perf_counter() - t0), 0.0))
|
||||||
|
|
||||||
robot.disconnect()
|
robot.disconnect()
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ def replay(cfg: ReplayConfig):
|
|||||||
robot.send_action(action)
|
robot.send_action(action)
|
||||||
|
|
||||||
dt_s = time.perf_counter() - start_episode_t
|
dt_s = time.perf_counter() - start_episode_t
|
||||||
precise_sleep(1 / dataset.fps - dt_s)
|
precise_sleep(max(1 / dataset.fps - dt_s, 0.0))
|
||||||
|
|
||||||
robot.disconnect()
|
robot.disconnect()
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ def main():
|
|||||||
# Send action to robot
|
# Send action to robot
|
||||||
_ = robot.send_action(joint_action)
|
_ = robot.send_action(joint_action)
|
||||||
|
|
||||||
precise_sleep(1.0 / dataset.fps - (time.perf_counter() - t0))
|
precise_sleep(max(1.0 / dataset.fps - (time.perf_counter() - t0), 0.0))
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
robot.disconnect()
|
robot.disconnect()
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ def main():
|
|||||||
# Send action to robot
|
# Send action to robot
|
||||||
_ = robot.send_action(joint_action)
|
_ = robot.send_action(joint_action)
|
||||||
|
|
||||||
precise_sleep(1.0 / dataset.fps - (time.perf_counter() - t0))
|
precise_sleep(max(1.0 / dataset.fps - (time.perf_counter() - t0), 0.0))
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
robot.disconnect()
|
robot.disconnect()
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ def act_with_policy(
|
|||||||
|
|
||||||
if cfg.env.fps is not None:
|
if cfg.env.fps is not None:
|
||||||
dt_time = time.perf_counter() - start_time
|
dt_time = time.perf_counter() - start_time
|
||||||
precise_sleep(1 / cfg.env.fps - dt_time)
|
precise_sleep(max(1 / cfg.env.fps - dt_time, 0.0))
|
||||||
|
|
||||||
|
|
||||||
# Communication Functions - Group all gRPC/messaging functions
|
# Communication Functions - Group all gRPC/messaging functions
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ class RobotEnv(gym.Env):
|
|||||||
reset_follower_position(self.robot, np.array(self.reset_pose))
|
reset_follower_position(self.robot, np.array(self.reset_pose))
|
||||||
log_say("Reset the environment done.", play_sounds=True)
|
log_say("Reset the environment done.", play_sounds=True)
|
||||||
|
|
||||||
precise_sleep(self.reset_time_s - (time.perf_counter() - start_time))
|
precise_sleep(max(self.reset_time_s - (time.perf_counter() - start_time), 0.0))
|
||||||
|
|
||||||
super().reset(seed=seed, options=options)
|
super().reset(seed=seed, options=options)
|
||||||
|
|
||||||
@@ -713,7 +713,7 @@ def control_loop(
|
|||||||
transition = env_processor(transition)
|
transition = env_processor(transition)
|
||||||
|
|
||||||
# Maintain fps timing
|
# Maintain fps timing
|
||||||
precise_sleep(dt - (time.perf_counter() - step_start_time))
|
precise_sleep(max(dt - (time.perf_counter() - step_start_time), 0.0))
|
||||||
|
|
||||||
if dataset is not None and cfg.dataset.push_to_hub:
|
if dataset is not None and cfg.dataset.push_to_hub:
|
||||||
logging.info("Pushing dataset to hub")
|
logging.info("Pushing dataset to hub")
|
||||||
@@ -745,7 +745,7 @@ def replay_trajectory(
|
|||||||
)
|
)
|
||||||
transition = action_processor(transition)
|
transition = action_processor(transition)
|
||||||
env.step(transition[TransitionKey.ACTION])
|
env.step(transition[TransitionKey.ACTION])
|
||||||
precise_sleep(1 / cfg.env.fps - (time.perf_counter() - start_time))
|
precise_sleep(max(1 / cfg.env.fps - (time.perf_counter() - start_time), 0.0))
|
||||||
|
|
||||||
|
|
||||||
@parser.wrap()
|
@parser.wrap()
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ def record_loop(
|
|||||||
log_rerun_data(observation=obs_processed, action=action_values)
|
log_rerun_data(observation=obs_processed, action=action_values)
|
||||||
|
|
||||||
dt_s = time.perf_counter() - start_loop_t
|
dt_s = time.perf_counter() - start_loop_t
|
||||||
precise_sleep(1 / fps - dt_s)
|
precise_sleep(max(1 / fps - dt_s, 0.0))
|
||||||
|
|
||||||
timestamp = time.perf_counter() - start_episode_t
|
timestamp = time.perf_counter() - start_episode_t
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ def replay(cfg: ReplayConfig):
|
|||||||
_ = robot.send_action(processed_action)
|
_ = robot.send_action(processed_action)
|
||||||
|
|
||||||
dt_s = time.perf_counter() - start_episode_t
|
dt_s = time.perf_counter() - start_episode_t
|
||||||
precise_sleep(1 / dataset.fps - dt_s)
|
precise_sleep(max(1 / dataset.fps - dt_s, 0.0))
|
||||||
|
|
||||||
robot.disconnect()
|
robot.disconnect()
|
||||||
|
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ def teleop_loop(
|
|||||||
move_cursor_up(len(robot_action_to_send) + 3)
|
move_cursor_up(len(robot_action_to_send) + 3)
|
||||||
|
|
||||||
dt_s = time.perf_counter() - loop_start
|
dt_s = time.perf_counter() - loop_start
|
||||||
precise_sleep(1 / fps - dt_s)
|
precise_sleep(max(1 / fps - dt_s, 0.0))
|
||||||
loop_s = time.perf_counter() - loop_start
|
loop_s = time.perf_counter() - loop_start
|
||||||
print(f"Teleop loop time: {loop_s * 1e3:.2f}ms ({1 / loop_s:.0f} Hz)")
|
print(f"Teleop loop time: {loop_s * 1e3:.2f}ms ({1 / loop_s:.0f} Hz)")
|
||||||
move_cursor_up(1)
|
move_cursor_up(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user