pycharm连接webots,用python控制机器人
Webots:Controller编写(Python)
运行----编辑配置
总
PATH
D:\webots\lib\controller; D:\webots\msys64\mingw64\bin; D:\Webots\msys64\mingw64\bin\cpp;
分
D:\webots\lib\controller\\;
D:\webots\msys64\mingw64\bin\\;
D:\Webots\msys64\mingw64\bin\cpp;
系统环境变量
%WEBOTS_HOME%\lib\controller
%WEBOTS_HOME%\msys64\mingw64\bin
%WEBOTS_HOME%\msys64\mingw64\bin\cpp
from controller import Robot
robot = Robot()
timestep = int(robot.getBasicTimeStep())
robot_name = robot.getControllerArguments();
motor1 = robot.getMotor('right wheel motor')
motor2 = robot.getMotor('left wheel motor')
motor1.setPosition(float('inf'))
motor2.setPosition(float('inf'))
motor1.setVelocity(2)
motor2.setVelocity(5)
robot.step(timestep)
t=0
while robot.step(timestep) != -1:
t=t+1
报错结论:
以上配置后出现以下错误
D:\Anaconda\envs\yolov5_src\lib\site-packages\numpy\__init__.py:148: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "F:/仿真webots/control_bot.py", line 1, in <module>
from controller import Robot
File "D:\webots\lib\controller\python37\controller.py", line 16, in <module>
import _controller
ImportError: DLL load failed: 找不到指定的模块。
理论上当添加web下的路径到系统的环境变量中后,可直接使用将 D:\webots\lib\controller\python37
文件夹复制到项目中,并在这个文件夹下进行,main文件的使用
例子wbt下载