RPyC (pronounced as are-pie-see), or Remote Python Call, is a transparent python library for symmetrical remote procedure calls, clustering and distributed-computing. RPyC makes use of object-proxying, a technique that employs python’s dynamic nature, to overcome the physical boundaries between processes and computers, so that remote objects can be manipulated as if they were local. Here are simple steps you need to follow in order to install and use RPyC with ev3dev:
Install RPyC both on the EV3 and on your desktop PC. For the EV3, enter the following command at the command prompt (after you connect with SSH):
sudo easy_install3 rpyc
On the desktop PC, it really depends on your operating system. In case it is some flavor of linux, you should be able to do
sudo pip3 install rpyc
In case it is Windows, there is a win32 installer on the project’s sourceforge page. Also, have a look at the Download and Install page on their site.
Create file rpyc_server.sh
with the following contents on the EV3:
#!/bin/bash
python3 `which rpyc_classic.py`
and make the file executable:
chmod +x rpyc_server.sh
Launch the created file either from SSH session (with
./rpyc_server.sh
command), or from brickman. It should output something
like
INFO:SLAVE/18812:server started on [0.0.0.0]:18812
and keep running.
Now you are ready to connect to the RPyC server from your desktop PC. The
following python script should make a large motor connected to output port
A
spin for a second.
import rpyc
conn = rpyc.classic.connect('ev3dev') # host name or IP address of the EV3
ev3 = conn.modules['ev3dev.ev3'] # import ev3dev.ev3 remotely
m = ev3.LargeMotor('outA')
m.run_timed(time_sp=1000, speed_sp=600)
You can run scripts like this from any interactive python environment, like ipython shell/notebook, spyder, pycharm, etc.
Some advantages of using RPyC with ev3dev are:
The most obvious disadvantage is latency introduced by network connection. This may be a show stopper for robots where reaction speed is essential.