The Coppelia Robotics V-REP simulator is a fully featured three dimensional simulator for a wide range of robot models.
As well as providing an integrated development environment that supports scripting of robot programs, the simulator offers an API A(aapplication programming interface) that allows the simulated robots to be controlled from a remote script, such as a script executed via a Jupyter notebook.
The robots that appear in the simulator all have real world counterparts. In this course, you will have an opportunity to work with several simulated robots, including:
To start programming the robots, you need to ensure that two applications are running on your computer:
To simplify things, we have created some IPython magic (really! That's what it's called...) that allows you to connect to the V-REP simulator from a notebook code cell. A robot inside a simulator scene can then be controlled directly from Python code run in the code cell.
To connect to the simulator, first ensure that the simulator application is running.
In the notebook, load in and run the generic initialisation scripts in a code cell:
%run 'Set-up.ipynb'
%run 'Loading scenes.ipynb'
Load in an run an appropriate robot class definition file:
%run 'vrep_models/ROBOT_MODEL.ipynb'
The following have been defined:
Robot Class | Robot definition file |
---|---|
lineTracer |
vrep_models/lineTracer.ipynb |
PioneerP3DX |
vrep_models/PioneerP3DX.ipynb |
You can then open a scene in the simulator and connect to it using cell magic of the form:
%%vrepsim 'PATH/TO/SCENE.ttt' RobotClass
The magic cell magic then works as follows:
robot
that instantiates a class corresponding to RobotClass
; an object corresponding to that robot class should exist inside the sceneThe following scenes and robot classes have been defined:
Notebook | Scene | Robot Class |
---|---|---|
Demo - linetracer.ipynb |
OU_grey lines.ttt |
lineTracer |
Demo - square 1.ipynb |
OU_Pioneer.ttt |
PioneerP3DX |
For example, the following cell loads in the initialisation scripts:
In [1]:
%run 'Set-up.ipynb'
%run 'Loading scenes.ipynb'
Load in a robot definition file appropriate to the scene you intend to load - when it loads it will give you a preview of the robot classes that have been loaded in and the methods defined on them.
In [2]:
%run 'vrep_models/PioneerP3DX.ipynb'
The following cell connects to the simulator, loads the OU_Pioneer.ttt
scene, and connects to the PioneerP3DX
object that is preloaded inside the scene. The robot
object is created automatically and can be called by the code running in the cell.
Run the cell and watch what happens to robot in the simulator.
In [5]:
%%vrepsim '../scenes/OU_Pioneer.ttt' PioneerP3DX
import time
robot.rotate_right()
time.sleep(5)
You can also run the magic without specifying a scene name. In this case, the code in the cell will run against the currently loaded, in focus scene. TO DO - CHECK THIS For example:
%%vrepsim PioneerP3DX
Note that you will need to ensure that a robot of the correct class is available inside the scene.
Valid models can be found in the ../models
directory:
In [6]:
!ls ../models
The simulator and the notebook can each take up quite a lot of your computer screen. We suggest a screen layout something like the following:
You can find a range of help files describing how to work with the actual simulator, such as changing camera views and moving the robot, in the ../howtos
directory.
In [8]:
!ls ../howtos
Hopefully, you won't have any problems starting the simulator and connecting to it. If you do, here are some things to check.
Check environment variable settings - these can be set via the Set-up.ipynb
notebook.
You may need to check the connection settings. You can set these from a notebook used to control a robot by setting the following variables:
vrep_ip
: by default, this is set to '127.0.0.1'
vrep_port
: by default, this is set to 19997