0
$\begingroup$

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. image taken during simulation

Here is my scene

$\endgroup$
9
  • $\begingroup$ "and I came across some problems..." What problems? Your question is extremely vague. $\endgroup$
    – Chuck
    Aug 17, 2015 at 12:57
  • $\begingroup$ Welcome to robotics Controller, but I'm afraid that it is not clear what you are asking. We prefer practical, answerable questions based on actual problems that you face, so it is a good idea to include details of what what you would like to achieve, what you have tried, what you expected to see and what you actually saw. Take a look at How to Ask and tour for more information on how stack exchange works. $\endgroup$
    – Mark Booth
    Aug 17, 2015 at 15:10
  • $\begingroup$ @MarkBooth I have modified my question. If it needs any more details please tell me. Thanks for helping me out. $\endgroup$
    – Controller
    Aug 18, 2015 at 9:46
  • $\begingroup$ I'll move this answer from the comments to an actual answer after this question gets reopened, but until then - I don't know that this is the correct documentation for your 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$
    – Chuck
    Aug 18, 2015 at 12:32
  • $\begingroup$ It also states later on that it returns, "result: detection state (0 or 1), or -1 in case of an error, or if simHandleVisionSensor was never called, or if simResetVisionSensor was previously called." In your code you only ever check if result > 0. You never check if there is an error - result < 0. Double check that you are initializing the detection correctly (call simHandleVisionSensor), and then check if you are truly getting no results (result == 0) or if you are getting an error (result < 0). $\endgroup$
    – Chuck
    Aug 18, 2015 at 12:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.