vrep Package

class pypot.vrep.vrep_time(vrep_io)[source]
get_time(trial=0)[source]
sleep(t)[source]
pypot.vrep.from_vrep(config, vrep_host='127.0.0.1', vrep_port=19997, scene=None, tracked_objects=[], tracked_collisions=[], id=None, shared_vrep_io=None)[source]

Create a robot from a V-REP instance.

Parameters:
  • config (str or dict) – robot configuration (either the path to the json or directly the dictionary)
  • vrep_host (str) – host of the V-REP server
  • vrep_port (int) – port of the V-REP server
  • scene (str) – path to the V-REP scene to load and start
  • tracked_objects (list) – list of V-REP dummy object to track
  • tracked_collisions (list) – list of V-REP collision to track
  • id (int) – robot id in simulator (useful when using a scene with multiple robots)
  • vrep_io (VrepIO) – use an already connected VrepIO (useful when using a scene with multiple robots)

This function tries to connect to a V-REP instance and expects to find motors with names corresponding as the ones found in the config.

Note

The Robot returned will also provide a convenience reset_simulation method which resets the simulation and the robot position to its intial stance.

Note

Using the same configuration, you should be able to switch from a real to a simulated robot just by switching from from_config() to from_vrep(). For instance:

import json

with open('my_config.json') as f:
    config = json.load(f)

from pypot.robot import from_config
from pypot.vrep import from_vrep

real_robot = from_config(config)
simulated_robot = from_vrep(config, '127.0.0.1', 19997, 'poppy.ttt')

io Module

class pypot.vrep.io.VrepIO(vrep_host='127.0.0.1', vrep_port=19997, scene=None, start=False)[source]

Bases: pypot.robot.io.AbstractIO

This class is used to get/set values from/to a V-REP scene.

It is based on V-REP remote API (http://www.coppeliarobotics.com/helpFiles/en/remoteApiOverview.htm).

Starts the connection with the V-REP remote API server.

Parameters:
  • vrep_host (str) – V-REP remote API server host
  • vrep_port (int) – V-REP remote API server port
  • scene (str) – path to a V-REP scene file
  • start (bool) – whether to start the scene after loading it

Warning

Only one connection can be established with the V-REP remote server API. So before trying to connect make sure that all previously started connections have been closed (see close_all_connections())

MAX_ITER = 5
TIMEOUT = 0.4
open_io()[source]
close()[source]

Closes the current connection.

load_scene(scene_path, start=False)[source]

Loads a scene on the V-REP server.

Parameters:
  • scene_path (str) – path to a V-REP scene file
  • start (bool) – whether to directly start the simulation after loading the scene

Note

It is assumed that the scene file is always available on the server side.

start_simulation()[source]

Starts the simulation.

Note

Do nothing if the simulation is already started.

Warning

if you start the simulation just after stopping it, the simulation will likely not be started. Use restart_simulation() instead.

restart_simulation()[source]

Re-starts the simulation.

stop_simulation()[source]

Stops the simulation.

pause_simulation()[source]

Pauses the simulation.

resume_simulation()[source]

Resumes the simulation.

get_motor_position(motor_name)[source]

Gets the motor current position.

set_motor_position(motor_name, position)[source]

Sets the motor target position.

get_motor_force(motor_name)[source]

Retrieves the force or torque applied to a joint along/about its active axis.

set_motor_force(motor_name, force)[source]

Sets the maximum force or torque that a joint can exert.

get_object_position(object_name, relative_to_object=None)[source]

Gets the object position.

set_object_position(object_name, position=[0, 0, 0])[source]

Sets the object position.

get_object_orientation(object_name, relative_to_object=None)[source]

Gets the object orientation.

get_object_handle(obj)[source]

Gets the vrep object handle.

get_collision_state(collision_name)[source]

Gets the collision state.

get_collision_handle(collision)[source]

Gets a vrep collisions handle.

get_simulation_current_time(timer='CurrentTime')[source]

Gets the simulation current time.

add_cube(name, position, sizes, mass)[source]

Add Cube

add_sphere(name, position, sizes, mass, precision=[10, 10])[source]

Add Sphere

add_cylinder(name, position, sizes, mass, precision=[10, 10])[source]

Add Cylinder

add_cone(name, position, sizes, mass, precision=[10, 10])[source]

Add Cone

change_object_name(old_name, new_name)[source]

Change object name

call_remote_api(func_name, *args, **kwargs)[source]

Calls any remote API func in a thread_safe way.

Parameters:
  • func_name (str) – name of the remote API func to call
  • args – args to pass to the remote API call
  • kwargs – args to pass to the remote API call

Note

You can add an extra keyword to specify if you want to use the streaming or sending mode. The oneshot_wait mode is used by default (see here for details about possible modes).

Warning

You should not pass the clientId and the operationMode as arguments. They will be automatically added.

As an example you can retrieve all joints name using the following call:

vrep_io.remote_api_call('simxGetObjectGroupData',
                        vrep_io.remote_api.sim_object_joint_type,
                        0,
                        streaming=True)
pypot.vrep.io.close_all_connections()[source]

Closes all opened connection to V-REP remote API server.

exception pypot.vrep.io.VrepIOError(error_code, message)[source]

Bases: exceptions.Exception

Base class for V-REP IO Errors.

exception pypot.vrep.io.VrepIOErrors[source]

Bases: exceptions.Exception

exception pypot.vrep.io.VrepConnectionError[source]

Bases: exceptions.Exception

Base class for V-REP connection Errors.

controller Module

class pypot.vrep.controller.VrepController(vrep_io, scene, motors, sync_freq=50.0, id=None)[source]

Bases: pypot.robot.controller.MotorsController

V-REP motors controller.

Parameters:
  • vrep_io (VrepIO) – vrep io instance
  • scene (str) – path to the V-REP scene file to start
  • motors (list) – list of motors attached to the controller
  • sync_freq (float) – synchronization frequency
  • id (int) – robot id in simulator (useful when using a scene with multiple robots)
setup()[source]

Setups the controller by reading/setting position for all motors.

update()[source]

Synchronization update loop.

At each update all motor position are read from vrep and set to the motors. The motors target position are also send to v-rep.

class pypot.vrep.controller.VrepObjectTracker(io, sensors, sync_freq=50.0)[source]

Bases: pypot.robot.controller.SensorsController

Tracks the 3D position and orientation of a V-REP object.

Parameters:
  • io (AbstractIO) – IO used to communicate with the hardware motors
  • sensors (list) – list of sensors attached to the controller
  • sync_freq (float) – synchronization frequency
setup()[source]

Forces a first update to trigger V-REP streaming.

update()[source]

Updates the position and orientation of the tracked objects.

class pypot.vrep.controller.VrepCollisionDetector(name)[source]

Bases: pypot.robot.sensor.Sensor

colliding
class pypot.vrep.controller.VrepCollisionTracker(io, sensors, sync_freq=50.0)[source]

Bases: pypot.robot.controller.SensorsController

Tracks collision state.

Parameters:
  • io (AbstractIO) – IO used to communicate with the hardware motors
  • sensors (list) – list of sensors attached to the controller
  • sync_freq (float) – synchronization frequency
setup()[source]

Forces a first update to trigger V-REP streaming.

update()[source]

Update the state of the collision detectors.