解决高版本MATLAB robotics toolbox在plot/teach时报错问题

在MATLAB 2019 或者 2020 等高版本里,使用机器人工具箱(robotics toolbox/RTB)对机器人进行可视化时(比如robot.teach,robot.plot)会报错:

Index exceeds the number of array elements (4).

Error in SerialLink/plot>create_robot (line 473)
            d = norm( d(4:6)-d(1:3) ) / 72;

Error in SerialLink/plot (line 256)
        handle = create_robot(robot, opt);

Error in SerialLink/teach (line 102)
        robot.plot(q, args{:});

中文版报错信息为:

索引超出数组元素数目(4)。

出错 SerialLink/plot>create_robot (line 473)
            d = norm( d(4:6)-d(1:3) ) / 72;

出错 SerialLink/plot (line 256)
        handle = create_robot(robot, opt);

出错 SerialLink/teach (line 102)
        robot.plot(q, args{:});

而在MATLAB 2018b及更早版本中不会报错。此时只需在可视化语句之前加上

view(3)

即可解决。
然而每次都要写这个太麻烦了,有一个一劳永逸的办法。首先在命令窗口里键入

edit SerialLink.plot

之后应该弹出

在这里插入图片描述

然后在函数的第一行开始加入

[myModifyForViewErrorA,myModifyForViewErrorB]=view(gca);
if isequal([myModifyForViewErrorA,myModifyForViewErrorB],[0,90])
    view(3)
end

如图:

在这里插入图片描述

之后就不需要每次都写view(3)了,和旧版本的用法一致。

注意以上代码不能简单用view(3)代替,如果只写view(3)的话会在程序运行时不能拖动视角。按照当前解决方案,每次调用SerialLink.plot都会判断一下当前视角,造成执行效率变低一点点点点点,而且当你拖动到正俯视图视角时会自动变成view(3)视角。如果你有更好的解决方案,欢迎留言交流。

评论 63
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值