diff --git a/.gitignore b/.gitignore index e69de29bb2..daba3febf6 100644 Binary files a/.gitignore and b/.gitignore differ diff --git a/requirements.txt b/requirements.txt index 2d3d95d455..d52f717b66 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ python-markdown-math imageio numpy matplotlib -tensorflow \ No newline at end of file +tensorflow +mujoco>=2.3.0 \ No newline at end of file diff --git a/src/drone_simulation/main.py b/src/drone_simulation/main.py new file mode 100644 index 0000000000..78f334b53d --- /dev/null +++ b/src/drone_simulation/main.py @@ -0,0 +1,112 @@ +# simple_visible_drone.py +import mujoco +import mujoco.viewer +import numpy as np +import time +import os +import glob + +# 定义日志文件路径(可根据实际情况修改) +LOG_FILE_PATHS = [ + "mujoco.log", + "drone_simulation.log", + "./logs/*.log" +] + + +def delete_log_files(): + """删除指定的日志文件(无控制台输出)""" + deleted_count = 0 + for path in LOG_FILE_PATHS: + if "*" in path: + for file in glob.glob(path): + try: + os.remove(file) + deleted_count += 1 + except (FileNotFoundError, PermissionError): + continue + else: + if os.path.exists(path): + try: + os.remove(path) + deleted_count += 1 + except (FileNotFoundError, PermissionError): + continue + + +# 最小化但可见的模型 +MJCF_MODEL = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +""" + + +def main(): + # 删除日志文件(无输出) + delete_log_files() + + # 加载模型和数据 + model = mujoco.MjModel.from_xml_string(MJCF_MODEL) + data = mujoco.MjData(model) + + # 等待3秒(无提示) + time.sleep(3) + + with mujoco.viewer.launch_passive(model, data) as viewer: + # 设置相机视角 + viewer.cam.lookat[:] = [0, 0, 1] + viewer.cam.distance = 8.0 + viewer.cam.azimuth = 45 + viewer.cam.elevation = -30 + + t = 0 + while viewer.is_running() and t < 20: + # 简单的上下浮动 + force_z = 20 * np.sin(t * 2) + 50 + + # 应用力 + data.qfrc_applied[2] = force_z + + # 缓慢旋转 + data.qfrc_applied[5] = 5 * np.sin(t * 0.5) + + mujoco.mj_step(model, data) + viewer.sync() + + t += 0.01 + time.sleep(0.01) + + +if __name__ == "__main__": + main() diff --git a/src/drone_simulation/model.xml b/src/drone_simulation/model.xml new file mode 100644 index 0000000000..717a287e45 --- /dev/null +++ b/src/drone_simulation/model.xml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file