Page 1 of 1

Python remote api: simxReadProximitySensor

Posted: 29 Sep 2014, 22:01
by rezama
I translated bubbleRobClient.cpp into equivalent python code as a stepping stone for writing my own client in python. When I run bubbleRobClient.py, the variable detectionState returned from simxReadProximitySensor is always evaluating to True. Is there any mistake in how I'm invoking the function?

Here is my implementation of bubbleRobClient.py:

Code: Select all

import vrep
import sys
import time

print 'Program started'

portNb = 0
leftMotorHandle = 0
rightMotorHandle = 0
sensorHandle = 0

if len(sys.argv) >= 5:
    portNb = int(sys.argv[1])
    leftMotorHandle = int(sys.argv[2])
    rightMotorHandle = int(sys.argv[3])
    sensorHandle = int(sys.argv[4])
else:
    print "Indicate following arguments: 'portNumber leftMotorHandle rightMotorHandle sensorHandle'"
    time.sleep(5000.0 / 1000.0)
    sys.exit(0)

vrep.simxFinish(-1) # just in case, close all opened connections
clientID = vrep.simxStart('127.0.0.1', portNb, True, True, 2000, 5)
if clientID != -1:
    print 'Connected to remote API server'
    driveBackStartTime = -99000
    motorSpeeds = [0, 0]

    while vrep.simxGetConnectionId(clientID) != -1:
        (errorCode, detectionState, detectedPoint, detectedObjectHandle, detectedSurfaceNormalVector) = vrep.simxReadProximitySensor(clientID, sensorHandle, vrep.simx_opmode_streaming)
        if errorCode == vrep.simx_return_ok:
            simulationTime = vrep.simxGetLastCmdTime(clientID)
            if simulationTime - driveBackStartTime < 3000:
                motorSpeeds[0] = -3.1415 * 0.5
                motorSpeeds[1] = -3.1415 * 0.25
            else:
                motorSpeeds[0] = 3.1415
                motorSpeeds[1] = 3.1415
                if detectionState:
                    driveBackStartTime = simulationTime

            errorCode = vrep.simxSetJointTargetVelocity(clientID, leftMotorHandle, motorSpeeds[0], vrep.simx_opmode_oneshot)
            vrep.simxSetJointTargetVelocity(clientID, rightMotorHandle, motorSpeeds[1], vrep.simx_opmode_oneshot)
            if errorCode != vrep.simx_return_ok:
                print "SetJointTargetVelocity got error code: %s" % errorCode

        else:
            print "ReadProximitySensor got error code: %s" % errorCode

        time.sleep(5.0 / 1000.0)

    vrep.simxFinish(clientID)
else:
    print 'Failed connecting to remote API server'
print 'Program ended'
Here is how I am launching the python client from the lua script in scene file controlTypeExamples.ttt:

Code: Select all

result = simLaunchExecutable("/usr/bin/python", "bubbleRobClient.py "..portNb.." "..leftMotor.." "..rightMotor.." "..noseSensor, 0)
v-rep version: edu 3.1.2 linux 64

Re: Python remote api: simxReadProximitySensor

Posted: 30 Sep 2014, 11:01
by coppelia
Hello,

yes, you are right, that bug was already corrected in the beta release of version 3.1.3.
Make sure to just replace the file vrep.py, since the official 3.1.3 version should be out in hopefully one day.

Cheers

Re: Python remote api: simxReadProximitySensor

Posted: 30 Sep 2014, 23:30
by rezama
Thanks. I tried downloading the beta and running my code on it. I got the following error message. Thought I would share it, in case this is pointing to another bug that could be fixed before the release.

Code: Select all

Traceback (most recent call last):
  File "bubbleRobClient.py", line 28, in <module>
    import vrep
  File "/home/reza/vrep64/vrep.py", line 44, in <module>
    c_GetJointPosition          = CFUNCTYPE(c_int32,c_int32, c_int32, POINTER(c_float), c_int32)(("simxGetJointPosition", libsimx))
AttributeError: ./remoteApi.so: undefined symbol: simxGetJointPosition
Simulator ended.

Re: Python remote api: simxReadProximitySensor

Posted: 30 Sep 2014, 23:46
by coppelia
I cannot reproduce that error... please wait a few hours, the official release will be out in a few hours. Then try with that one.

Cheers

Re: Python remote api: simxReadProximitySensor

Posted: 01 Oct 2014, 17:52
by rezama
I upgraded to 3.1.3 and I get the same error message. I have copied remoteApi.so to the root folder of v-rep so that libsimx = CDLL("./remoteApi.so") can succeed in the python code. This setup worked in 3.1.2.

Re: Python remote api: simxReadProximitySensor

Posted: 02 Oct 2014, 11:16
by coppelia
are you sure you are using the correct library?
Can you try to recompile it? In programming/remoteApiBindings/lib, simply type make.

Cheers

Re: Python remote api: simxReadProximitySensor

Posted: 02 Oct 2014, 20:23
by rezama
I compiled the library and the generated .so file was identical to the one shipped with v-rep.

I've been working with a clean installation of v-rep 3.1.3.

I've tested this on three different computers (both 32 bit and 64 bit) and I get the same error message. The systems I have used are all based on ubuntu 12.04.

Re: Python remote api: simxReadProximitySensor

Posted: 04 Oct 2014, 12:27
by lonchaneyjr
I seem to have the same error with v-rep 3.1.3 on Ubuntu 14.04 64bit. I also tried recompiling the library, unfortunately with no success. Version 3.1.1 (the last one I used) worked fine.

Re: Python remote api: simxReadProximitySensor

Posted: 04 Oct 2014, 14:36
by coppelia
you are both right!

This problem is only affecting the Linux (32 and 64) releases. The problem is that in the make file we somehow switched to g++, but gcc is needed. So you could recompile it by replacing g++ with gcc, or download the updated release (V3.1.3 rev. 2b) available now.

Cheers

Re: Python remote api: simxReadProximitySensor

Posted: 04 Oct 2014, 15:11
by lonchaneyjr
That was fast, thanks!

Changing g++ to gcc and recompiling remoteApi.so fixed it for me (Ubuntu 14.04, 64-bit).