Python机器人库Roboticstoolbox报错Application error: a client-side exception has occurred解决方法
项目场景:
做机械臂运动规划,打算使用Python的Roboticstoolbox库进行机械臂仿真,安装roboticstoolbox-python==1.1.0后运行Panda机械臂示例代码,代码如下:
import swift
import roboticstoolbox as rtb
import spatialmath as sm
import numpy as np
env = swift.Swift()
env.launch(realtime=True)
panda = rtb.models.Panda()
panda.q = panda.qr
Tep = panda.fkine(panda.q) * sm.SE3.Trans(0.2, 0.2, 0.45)
arrived = False
env.add(panda)
dt = 0.05
while not arrived:
v, arrived = rtb.p_servo(panda.fkine(panda.q), Tep, 1)
panda.qd = np.linalg.pinv(panda.jacobe(panda.q)) @ v
env.step(dt)
# Uncomment to stop the browser tab from closing
# env.hold()
问题描述
运行代码后没有出现预期的结果,同时chrom浏览器报如下错误:
Application error: a client-side exception has occurred (see the browser console for more information).
按F12进入浏览器控制台,显示资源文件加载失败,但进入报错的路径后都能找到对应的资源文件。
原因分析:
在网上查找原因,发现是swift库自身的问题:Remove leading slash for paths to be retrieved
主要是因为siwft库在生成文件的路径时,会多生成一个斜杆,类似:/C:\Users
,这种情况在Linux系统下不报错,但是windows系统没法识别这样的路径,导致报错。
解决方案:
按照网页里的提示,需要修改swift库里面的SwiftRoute.py,首先找到安装swift库的虚拟环境,之后查找SwiftRoute.py文件,安装的swift-sim库版本是1.1.0,需要修改文件里第390行的代码,将代码里的self.path[9:]
改成self.path[10:]
,修改后的代码如下:
elif self.path == "/?" + str(socket_port):
self.path = "index.html"
elif self.path.startswith("/retrieve/"):
# print(f"Retrieving file: {self.path[10:]}")
self.path = urllib.parse.unquote(self.path[10:])
self.send_file_via_real_path()
return
重新运行示例代码,可以正常显示结果,最终显示效果如下:
作者:C_mony