How Do I Load scenes using vrep-api-python ?

Typically: "How do I... ", "How can I... " questions
psychemedia
Posts: 3
Joined: 09 Sep 2017, 01:10

How Do I Load scenes using vrep-api-python ?

Postby psychemedia » 09 Sep 2017, 18:17

I'm new to V-REP, just trying to get to grips with it, and looking to use it from Python (to which end, I put together a VM containing VREP + Jupyter notebooks here: https://github.com/psychemedia/ou-robotics-vrep/tree/master/robotVM).

One thing I can't see to do offhand is open a scene into V-REP. Here's script I guessed at:

Code: Select all

from pyrep import VRep
from pyrep.vrep.vrep import simxLoadScene
from pyrep.vrep import vrep as v
from pyrep.common import ReturnCommandError

class sceneloader:

    def __init__(self, api: VRep):
        self._api = api
        self._def_op_mode = v.simx_opmode_oneshot_wait
        self.id = api._id

    def loadScene(self,path):
        clientID=self.id
        res = simxLoadScene(clientID, path, 0xFF, self._def_op_mode)
        print(res)

        if res != v.simx_return_ok:
            raise ReturnCommandError(res)

scene='/vagrant/scenes/Pioneer.ttt'
with VRep.connect("127.0.0.1", 19997) as api:
    r=sceneloader(api)
    r.loadScene(scene)


Repost of question on SO: https://stackoverflow.com/questions/461 ... api-python

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

Re: How Do I Load scenes using vrep-api-python ?

Postby coppelia » 10 Sep 2017, 16:44

Hello,

what is the returned res? Also, did you try to specify the absolute path the the file. From what I remember, the path can be absolute, but also relative to the V-REP's installation folder.

Cheers

psychemedia
Posts: 3
Joined: 09 Sep 2017, 01:10

Re: How Do I Load scenes using vrep-api-python ?

Postby psychemedia » 11 Sep 2017, 15:31

Hi

I get response: 8

I am trying to load a file in using an absolute path.

If I try using a relative path to the simulator homedir (os.environ["VREP"]), I get error 32 (client side error).

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

Re: How Do I Load scenes using vrep-api-python ?

Postby coppelia » 12 Sep 2017, 14:59

The first error code means there was an error on the server side (i.e. V-REP), the second error code means there was an error on the client side (i.e. remote API client).

Cheers

psychemedia
Posts: 3
Joined: 09 Sep 2017, 01:10

Re: How Do I Load scenes using vrep-api-python ?

Postby psychemedia » 25 Sep 2017, 13:26

Re: error codes: yes, I get that; but I'm not sure what I'm doing wrong / how to chase the error down?

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

Re: How Do I Load scenes using vrep-api-python ?

Postby coppelia » 26 Sep 2017, 13:04

Did you try to load the scene if it is located directly in the same folder as your remote API client or V-REP installation folder.
I have just tested (on windows) and following works:

Code: Select all

import vrep

print 'Program started'
vrep.simxFinish(-1) # just in case, close all opened connections
clientID=vrep.simxStart('127.0.0.1',19997,True,True,5000,5)
if clientID!=-1:
    print 'Connected to remote API server'
    # relative to remote API client location, relative path:
    vrep.simxLoadScene(clientID,'test/testScene.ttt',0xFF,vrep.simx_opmode_blocking)
    # relative to V-REP executable location, relative path:
    vrep.simxLoadScene(clientID,'scenes/collisionDetectionDemo.ttt',0x00,vrep.simx_opmode_blocking)
    # relative to remote API client location, absolute path:
    vrep.simxLoadScene(clientID,'c:/python27/test/testScene.ttt',0xFF,vrep.simx_opmode_blocking)
    # relative to V-REP executable location, absolute path:
    vrep.simxLoadScene(clientID,'d:/v_rep/qrelease/release/scenes/collisionDetectionDemo.ttt',0x00,vrep.simx_opmode_blocking)
    vrep.simxFinish(clientID)
else:
    print 'Failed connecting to remote API server'
print 'Program ended'


Cheers


Return to “General questions”

Who is online

Users browsing this forum: No registered users and 24 guests