0

我需要在编码为的 v-rep 接近传感器上以米为单位获取距离java

我只能知道它是否检测到障碍物,而不是距离

任何想法?

4

1 回答 1

0

我发现这样做的方法是在接近传感器上创建一个子脚本。在 V-Rep 中,选择接近传感器后,转到Add --> associated child script --> Non-Threaded 然后使sysCall_actuation()外观类似于:

function sysCall_actuation()
    local name = sim.getObjectName(sim.getObjectAssociatedWithScript(sim.handle_self))
    result,distance,detectedPoint,detectedObjectHandle = sim.handleProximitySensor(sim.handle_self)
    if distance then
        sim.setFloatSignal("mydistance", distance);
    end
end

这会读取距离传感器的距离并将其推送到信号(如跨平台变量类型的东西)。然后在java端有这样的东西:

    FloatW val = new FloatW(-1);
    vrep.simxGetFloatSignal(clientID, "mydistance", val, remoteApi.simx_opmode_buffer);//call this with simx_opmode_streaming once before this to start vrep streaming the distances

这将获取从 vrep 发送的值,并以 FloatW 的形式为您提供距离。

于 2018-05-14T23:06:51.857 回答