python remote api problem with simxSetJointTargetVelocity

Report crashes, strange behaviour, or apparent bugs
Post Reply
markfink
Posts: 2
Joined: 14 May 2016, 07:29

python remote api problem with simxSetJointTargetVelocity

Post by markfink »

I am using: V-REP version 3.03.00 (rev 1) (V-REP PRO EDU license)
on Ubuntu 16.04

This is not exactly a new problem but I still do not get it and this makes me feel uneasy to use vrep. I would appreciate if you could please explain how to properly deal with this issue. I suspect this problem is in the API wrapper so I would be fine applying a patch.

simxSetJointTargetVelocity always gives me an error (and I can not find out what it means) and it does not set the motor speed unless I call simxGetLastErrors. simxGetLastErrors comes back empty but the crazy thing is that it then works (code below).

I want to use VREP with Tensorflow. Is there something more robust than the python remote api?

Code: Select all

import vrep


# controlling the robot inside v-rep
vrep.simxFinish(-1) # just in case, close all opened connections
clientID = vrep.simxStart('127.0.0.1', 9999, True, True, 5000, 5) # Connect to V-REP

if clientID!=-1:
    print 'Connected to remote API server'
    vrep.simxAddStatusbarMessage(clientID, 'Moin from Python', vrep.simx_opmode_oneshot)

    # Now send some data to V-REP:
    err, left = vrep.simxGetObjectHandle(clientID, 'Pioneer_p3dx_leftMotor', vrep.simx_opmode_oneshot_wait)
    #err, right = vrep.simxGetObjectHandle(clientID, 'Pioneer_p3dx_rightMotor', vrep.simx_opmode_blocking)

    # this always gives an error and I can not figure out what it is
    err = vrep.simxSetJointTargetVelocity(clientID, left, 10.0, vrep.simx_opmode_streaming)
    #err = vrep.simxSetJointTargetVelocity(clientID, right, 0, vrep.simx_opmode_oneshot)
    if err != vrep.simx_return_ok:
        print "SetJointTargetVelocity got error code: %s" % err

    # this line determines if this is successful or not
    # so commenting it out breaks this    
    error = vrep.simxGetLastErrors(clientID, vrep.simx_opmode_blocking)
    
    vrep.simxFinish(clientID)

else:
    print 'Failed connecting to remote API server'
print 'Program ended'

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: python remote api problem with simxSetJointTargetVelocit

Post by coppelia »

Hello Mark,

it seems you are using the remote API in a wrong manner, at least the streaming mode. Have a look here how to correctly use the streaming mode. Basically, when you call the function with simx_opmode_streaming, the function call returns immediately (is not blocking). But behind the scenes the client will send a request to V-REP to start continuously sending a specific value / executing a specific command. So after a few ms (you need to let the "start streaming"-command reach V-REP, and let V-REP send the first streaming value. Only then will you be able to read the return value with simx_opmode_buffer.

Why your code works with simxGetLastErrors is because you execute that command in a blocking fashion: you wait until V-REP has received the command, executed it, and sent back a reply. This procedure will also leave enough time for the "start streaming"-command to reach V-REP, and the first streamed value to be sent back.

The return codes of remote API commands are bit coded, and this can give you a good clue of what is going wrong.

I just noticed that you are not retrieving a value but setting a value (i.e. not simxGetJointTargetVelocity but simxSetJointTargetVelocity). In that case you do not need streaming. In pseudo code you would have for simxSetJointTargetVelocity:

Code: Select all

simxSetJointTargetVelocity(...,simx_opmode_oneshot) // non-blocking operation: send the command and forget about it
and for simxGetJointTargetVelocity:

Code: Select all

simxGetJointTargetVelocity(...,simx_opmode_streaming) // enable streaming of the joint target velocity. Non-blocking operation
while (simxGetJointTargetVelocity(...,simx_opmode_buffer)!=simx_return_ok)
    wait // wait until the first streamed value has arrived.
// from now on, you should be able to always read the last joint target velocity with the operation mode simx_opmode_buffer
Have also a look at the example python code in programming/remoteApiBindings/python/python/simpleTest.py: it illustrates an example for a blocking function call, streaming data, and non-blocking function call.

Cheers

Post Reply