I was trying to reproduce this youtube tutorial in V-rep and I came across some problems concerning blob detection. There are some complaints on this matter under the video. I don't believe that blob detection stopped working in recent v-rep versions, but I was unable to make it work (as a new v-rep user myself). Has anyone any idea how to properly implement it?
More specifically, I have a vision sensor named cam
and I want it to follow a red ball. The vision sensor will detect the position of the ball and I will use it to control the joints that steer the sensor (yaw
and pitch
). My script follows
threadFunction=function()
yaw=simGetObjectHandle("yaw")
pitch=simGetObjectHandle("pitch")
cam=simGetObjectHandle("cam")
while simGetSimulationState()~=sim_simulation_advancing_abouttostop do
result,pack1,pack2=simReadVisionSensor(cam)
if result>0 then
xtarget=pack2[5]
ytarget=pack2[6]
simAuxiliaryConsolePrint(out,string.format("\n x: %0.2f, y: %0.2f",xtarget,ytarget))
simSetJointTargetVelocity(yaw,1*(0.5-xtarget))
simSetJointTargetVelocity(pitch,1*(0.5-ytarget))
end
end
end
simSetThreadSwitchTiming(2)
out = simAuxiliaryConsoleOpen("Debug",8,1)
res,err=xpcall(threadFunction,function(err) return debug.traceback(err) end)
if not res then
simAddStatusbarMessage('Lua runtime error: '..err)
end
When I run the simulation I can see that the sensor sees the red ball at some point but result
is always 0 meaning that no detection takes place.
Here is my scene
simReadVisionSensor
function, but there is a statement on that site that reads, "Reads the state of a vision sensor. This function doesn't perform detection, it merely reads the result from a previous call to simHandleVisionSensor. $\endgroup$result > 0
. You never check if there is an error -result < 0
. Double check that you are initializing the detection correctly (callsimHandleVisionSensor
), and then check if you are truly getting no results (result == 0
) or if you are getting an error (result < 0
). $\endgroup$