首页 > 其他分享 >maltab与pybullet联合仿真

maltab与pybullet联合仿真

时间:2023-03-05 14:00:10浏览次数:57  
标签:仿真 maltab windows python pybullet matlab 安装 importlib

matlab和pybullet联合使用

1.matlab 调用python

 1.1.1 matlab与python版本的匹配问题

安装使用的python版本需要与matlab版本对应,参考链接Versions of Python Compatible with MATLAB Products by Release - MATLAB & Simulink (mathworks.com)  及下图

 

 

 

 通过windows终端输入python确定是否安装成功,(注意最好不要用anaconda 安装python,虽然可以使用,但是麻烦)若安装成功后,matlab输入pe=pyenv;

pe.Version,返回为空字符串,matlab却找不到python,可以执行pyversion python.exe。将matlab中python设置好。

接着就可以调用python的库了。

如果安装了numpy库(windows终端输入pip install numpy安装),则可以

clear;

close all;

np = py.importlib.import_module('numpy');

a = np.linspace(0,10,int32(10))

测试numpy库的使用

2.windows下的pybullet安装

windows下安装pybullet比较麻烦,但是ubuntu下使用pybullet和matlab会导致pybullet的GUI窗口打不开matlab崩溃,据说和显卡驱动有问题。没时间探究,遂采用windows平台。

确保windows终端下pip能够使用,接着安装 Microsoft Visual Studio Build Tools, 打开链接,   (搬运于https://deepakjogi.medium.com/how-to-install-pybullet-physics-simulation-in-windows-e1f16baa26f6

选择build tools

 

 

 

选择使用C++的桌面开发

 

 

 

勾选windows10 sdk 和windows 通用C运行时,点击右下角安装

 

 

 

完成安装后打开以管理员身份打开windows终端pip install pybullet 完成安装。

3.matlab测试pybullet

clear;

close all;

np = py.importlib.import_module('numpy');

p = py.importlib.import_module('pybullet');

time = py.importlib.import_module('time');

data =  py.importlib.import_module("pybullet_data");

physicsClient = p.connect(p.GUI);%#or p.DIRECT for non-graphical version

p.setGravity(0,0,-10);

planeId = p.loadURDF("C:\Users\zhou\AppData\Local\Programs\Python\Python38\Lib\site-packages\pybullet_data\plane.urdf");

startPos = [0,0,1];

startOrientation = p.getQuaternionFromEuler([0,0,0]);

boxId = p.loadURDF("C:\Users\zhou\AppData\Local\Programs\Python\Python38\Lib\site-packages\pybullet_data\r2d2.urdf",startPos, startOrientation);

%set the center of mass frame (loadURDF sets base link frame) startPos/Ornp.resetBasePositionAndOrientation(boxId, startPos, startOrientation)

for i=1:1000

    disp(i)

    p.stepSimulation();

    pause(1/240.0);

end

cubePos= p.getBasePositionAndOrientation(boxId);

 

p.disconnect();

测试效果

 

 

 

标签:仿真,maltab,windows,python,pybullet,matlab,安装,importlib
From: https://www.cnblogs.com/Techron/p/17180373.html

相关文章