Code Monkey home page Code Monkey logo

vrep-api-python's Introduction

v-rep python

Simple python binding for Coppelia Robotics V-REP simulator (remote API) of version 3.5.0 rev4

Getting started

  1. Requirements: CPython version >= 3.5.2, pip
  2. Install library from PyPI by entering this command:
[sudo] pip install 'git+https://github.com/Troxid/vrep-api-python'

V-Rep specific

Package needs platform-specific native library (remoteApi). It uses two enviroment variables VREP and VREP_LIBRARY. If VREP is unspecified package will use default /usr/share/vrep for it. If VREP_LIBRARY is also unspecified, then it will concatenate VREP with programming/remoteApiBindings/lib/lib/64Bit/. This setup was test tested under LINUX ONLY. We are open for debug under Windows. * For windows users: NOT TESTED

To use package you will need the socket port number, which can be located in V-REP/remoteApiConnections.txt.

Currently implemented things

In the current version is not implemented features such as remote management GUI, additional configuration properties of objects and shapes, etc. Basically implemented those components that are required to control the robot:

  • Joint
  • Proximity sensor
  • Vision sensor
  • Force sensor
  • Position sensor (used for that dummy or shape object)
  • Remote function calls

Example

Designed to be used with examples/Pioneer.ttt.

from pyrep import VRep
import time

class PioneerP3DX:

    def __init__(self, api: VRep):
        self._api = api
        self._left_motor = api.joint.with_velocity_control("Pioneer_p3dx_leftMotor")
        self._right_motor = api.joint.with_velocity_control("Pioneer_p3dx_rightMotor")
        self._left_sensor = api.sensor.proximity("Pioneer_p3dx_ultrasonicSensor3")
        self._right_sensor = api.sensor.proximity("Pioneer_p3dx_ultrasonicSensor6")

    def rotate_right(self, speed=2.0):
        self._set_two_motor(speed, -speed)

    def rotate_left(self, speed=2.0):
        self._set_two_motor(-speed, speed)

    def move_forward(self, speed=2.0):
        self._set_two_motor(speed, speed)

    def move_backward(self, speed=2.0):
        self._set_two_motor(-speed, -speed)

    def _set_two_motor(self, left: float, right: float):
        self._left_motor.set_target_velocity(left)
        self._right_motor.set_target_velocity(right)

    def right_length(self):
        return self._right_sensor.read()[1].distance()

    def left_length(self):
        return self._left_sensor.read()[1].distance()

with VRep.connect("127.0.0.1", 19997) as api:
    r = PioneerP3DX(api)
    while True:
        rl = r.right_length()
        ll = r.left_length()
        if rl > 0.01 and rl < 10:
            r.rotate_left()
        elif ll > 0.01 and ll < 10:
            r.rotate_right()
        else:
            r.move_forward()
        time.sleep(0.1)

License

Copyright (C) 2016-2017 Stanislav Eprikov, Pavel Pletenev

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

vrep-api-python's People

Contributors

asmfreak avatar caio96 avatar troxid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vrep-api-python's Issues

Resetting the connection

(Thanks for posting this example...)

I can get the Pioneer example running by executing the example code in a code cell in a Jupyter notebook, and stopping the cell execution stops the simulator. But if I then try to re-run the code cell, to rerun the demo, I get an error:

---------------------------------------------------------------------------
ReturnCommandError                        Traceback (most recent call last)
<ipython-input-2-10d78785080c> in <module>()
     38         return self._left_sensor.read()[1].distance()
     39 
---> 40 with VRep.connect("127.0.0.1", 19997) as api:
     41     r = PioneerP3DX(api)
     42     while True:

/usr/local/lib/python3.6/site-packages/pyrep/api.py in connect(ip, port)
     26             return VRepApi(res)
     27         else:
---> 28             raise ReturnCommandError(res)
     29 
     30     def __enter__(self):

ReturnCommandError: Undefined return code: -1

The only way I can reconnect from the notebook is to restart the notebook kernel and then re-run the cell?

[RFC] VREP Virtualbox VM With Jupyter notebook

I've started exploring how we might be able to make use of V-REP to support a distance education course in which students would need to run V-REP on their own computers, outside of the control of the institution running the course.

One strategy we have started to explore around distributing software to distance education students is to bundle the software in a virtual machine.

To this end, I had a look at packaging a VirtualBox virtual machine containing:

  1. a Linux desktop;
  2. V-REP;
  3. a Jupyter notebook server;
  4. vrep-api-python package pre-installed in the Python kernel used by the Jupyter notebook.

The idea is that students can access the Jupyter notebook server running in the VM through their own browser running on the host, and then use scripts within the notebook to control the simulator running in the VM. (The simulator port can also be exposed to host.)

My first attempt can be found here: https://github.com/psychemedia/ou-robotics-vrep

I'll share notebooks via that repo, as well as scenes, as and when I get a chance to sketch them out.

The VM is built using vagrant (in use, we would distribute just the user Vagrantfile and a pre-built box).

Loading scenes

Trying to load scenes via the API, I keep getting errors, irrespective of whether I try to use relative or absolute paths on client or server side, from either server or client side depending on setting. The scene files are at the paths specified!

Code I'm using:

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_blocking #v.simx_opmode_oneshot_wait
        self.id = api._id

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

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

scene="/Applications/V-REP_PRO_EDU_V3_4_0_Mac/scenes/khepera3.ttt"
#scene='./Pioneer.ttt'
with VRep.connect("127.0.0.1", 19997) as api:
    r=sceneloader(api)
    r.loadScene(scene)
```

Connecting to server

Trying to connect to the server using with VRep.connect(domain, 19997) as api:, the connection works if I use domain="127.0.0.1" but fails if I use an alias such as domain="localhost" or domain="mydomain":

---------------------------------------------------------------------------
ReturnCommandError                        Traceback (most recent call last)
<ipython-input-7-90f793041880> in <module>()
     31 
     32 
---> 33 with VRep.connect("localhost", 19997) as api:
     34     r = lineFollower(api)
     35     r.fwd_right()

/usr/local/lib/python3.5/dist-packages/pyrep/api.py in connect(ip, port)
     26             return VRepApi(res)
     27         else:
---> 28             raise ReturnCommandError(res)
     29 
     30     def close_connection(self):

ReturnCommandError: Undefined return code: -1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.