Skip to content

Commit

Permalink
remove test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Jan 17, 2025
1 parent adc0b64 commit 6640cab
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 121 deletions.
52 changes: 52 additions & 0 deletions kos_sim/simulator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Wrapper around MuJoCo simulation."""

import argparse
import asyncio
import threading
from pathlib import Path

import mujoco
import mujoco_viewer
import numpy as np
from kscale import K

from kos_sim import logger
from kos_sim.config import SimulatorConfig
Expand Down Expand Up @@ -197,3 +200,52 @@ def close(self) -> None:
@property
def timestep(self) -> float:
return self._model.opt.timestep


async def test_simulation_adhoc(
model_name: str, duration: float = 5.0, speed: float = 1.0, render: bool = True
) -> None:
api = K()
bot_dir = await api.download_and_extract_urdf(model_name)
bot_mjcf = next(bot_dir.glob("*.mjcf"))

simulator = MujocoSimulator(bot_mjcf, render=render)

timestep = simulator.timestep
initial_update = last_update = asyncio.get_event_loop().time()

while True:
current_time = asyncio.get_event_loop().time()
if current_time - initial_update > duration:
break

sim_time = current_time - last_update
last_update = current_time
while sim_time > 0:
simulator.step()
sim_time -= timestep

simulator.render()

simulator.close()


async def main() -> None:
parser = argparse.ArgumentParser(description="Test the MuJoCo simulation.")
parser.add_argument("model_name", type=str, help="Name of the model to simulate")
parser.add_argument("--duration", type=float, default=5.0, help="Duration to run simulation (seconds)")
parser.add_argument("--speed", type=float, default=1.0, help="Simulation speed multiplier")
parser.add_argument("--no-render", action="store_true", help="Disable rendering")

args = parser.parse_args()
await test_simulation_adhoc(
args.model_name,
duration=args.duration,
speed=args.speed,
render=not args.no_render,
)


if __name__ == "__main__":
# python -m kos_sim.simulator
asyncio.run(main())
50 changes: 0 additions & 50 deletions kos_sim/test_simulator.py

This file was deleted.

71 changes: 0 additions & 71 deletions kos_sim/test_viewer.py

This file was deleted.

0 comments on commit 6640cab

Please sign in to comment.