记录vrep中使用视觉传感器(Kinect、Vision sensor)时的一些操作。
1.Kinect篇 memo①放入blobDetectionCamera和Kinect,选中这两个shape中的这三项,然后把这三项放在一起形成一个新的shape
如下:
(笔者改名为Vision_RGBD_UR5),这样做实际上就是利用了blobcamera的外观,本质上这个新的shape还是kinect传感器,这样做有一个好处就是:由于kinect传感器的外形,有些时候在对sensor进行rotation或者translatin时kinect不太方便观察,这个blob传感器不一样,反正就一个镜头,比较容易观察。(可能没有讲清楚,笔者也不造该如何讲,只可意会)
完成上述步骤点击仿真按钮不会出现任何图像,我们还需要写一个Lua script。选中该sensor,ADD->Associated Child Script->Non threaded
function sysCall_init() depthCam=sim.getObjectHandle('kinect_depth') depthView=sim.floatingViewAdd(0.9,0.9,0.2,0.2,0) sim.adjustView(depthView,depthCam,64) colorCam=sim.getObjectHandle('kinect_rgb') colorView=sim.floatingViewAdd(0.9,0.69,0.2,0.2,0) sim.adjustView(colorView,colorCam,64) end function sysCall_cleanup() end将上述demo添加到lua script中,简单的解释一下其中的函数意义。 sim.getObjectHandle笔者的理解是就是要对给定参数的vision sensor进行处理,相当于启动这个sensor,sim.floatingViewAdd(0.9,0.9,0.2,0.2,0)这句话的意思是在env中添加floatview,(后面也会提到如何添加floatview) 这是官方给出的parameters的解释: https://www.coppeliarobotics.com/helpFiles/en/regularApi/simFloatingViewAdd.htm
simFloatingViewAdd / sim.floatingViewAddDescription Adds a floating view to current page. See also the sim.floatingViewRemove, sim.adjustView and sim.cameraFitToView functions. C synopsis simInt simFloatingViewAdd(simFloat posX,simFloat posY,simFloat sizeX,simFloat sizeY,simInt options) C parameters
posX & posY:relative position of the center of the floating view. Accepted values are between 0 and 1.
sizeX & sizeY:relative size of the floating view. Accepted values are between 0 and 1. options: bit-coded: bit0 set (1)=double click allows swapping the floating view with the main view bit1 set (2)=the floating view doesn’t he a close button bit2 set (4)=the floating view cannot be shifted bit3 set (8)=the floating view cannot be resized C return value Handle of the floating view, or -1 in case of an error. Lua synopsis number floatingViewHandle=sim.floatingViewAdd(number posX,number posY,number sizeX,number sizeY,number options) Lua parameters Same as C-function Lua return values Same as C-function
前两个参数其实就是要添加的floatview的中心点坐标,接下来两个采参数表示窗口的相对大小(笔者尝试改了几个参数发现没什么变化,筒子们可以尝试以下,欢迎留言)最后一个参数,如果是1则表示可以和主窗口相互切换,是2表示窗口右上角没有关闭选项,4表示无法shifted;8表示无法resize 。设置为其他参数无影响.
添加过上述代码之后点击运行就可以弹出这样的floatview
如果你的rgb窗口一片黑,可能有下面几种情况。首先查看vrep中最下方的info提示有没有说script有错误,如果没有错误还有一个可能的原因就是你的camera在world坐标系中的z轴的距离太远了。这是因为这个blobcamera有一定的视野距离, 如下图,这是camera在z轴为0.85m左右的时候的采集到的图像,是正常的
倘若再抬高一些,到0.99m左右的时候发现视野就全黑了。
所以如果view中全是黑色一片,可以考虑调一下sensor高度。
另外就是要注意可以根据自己project的实际需要调节一下sensor的scene object properties
可以修改剪切平面(Near/Far Clipping Plane)、视场角(FOV)、分辨率(Resolution )的值,kinect的视场角一般是57,这个可不调,可以适当调节Far Clipping Plane这个参数值,通过调节这一参数值可以适当的改变kinect所获取的视野大小。
这部分可以参考下面几篇blog,理论和操作讲解的都比较全 https://blog.csdn.net/weixin_34319817/article/details/94562081 https://www.cnblogs.com/21207-iHome/p/7120497.html https://zhuanlan.zhihu.com/p/106059246 http://www.mamicode.com/info-detail-1887732.html
memo①在env中如何添加Floatview,可查看这篇blog(笔者小白菜竟然因为这一个小小的issue困了半个小时,无语) https://blog.csdn.net/qq_33374294/article/details/98877817
其他blog: https://blog.csdn.net/qq_29945727/article/details/98469621
目前只用了这么多,暂时写到这里,后续如果有进一步的学习会持续更新。