Skip to content

Commit 28346de

Browse files
committed
python extension
1 parent bbec544 commit 28346de

File tree

10 files changed

+179
-48
lines changed

10 files changed

+179
-48
lines changed

docs/installation/index.md

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,90 @@ has_children: true
99

1010
The crate is written in Rust and is communicating difectly wit the **EtherCAT IgH** Master. It uses the rust wrapper crate `ethercat-rs` and builds on top of it to provide a more user friendly interface to the user.
1111

12-
## Downoload the code
12+
### Pre-requisites
1313

14-
You can obtain the code by cloning the repository.
14+
Before you can build and run the code you need to have the following installed on your system:
1515

16-
- Clone the repo
17-
```shell
18-
git clone [email protected]:pollen-robotics/poulpe_ethercat_controller.git
19-
```
16+
- Rust - [installation guide](https://www.rust-lang.org/tools/install)
17+
- EtherCAT IgH Master (for the EtherCAT communication) - [installation guide](installation_ethercat)
18+
19+
### Code version
2020

21-
Check out the branches that you need, depending on the poulpe firmware version that you are using.
21+
This crate is designed to work with the poulpe firmware version, so make sure to check the version of the firmware that you are using and check out the corresponding branch of the code.
2222

2323
`firmware_poulpe` version | `poulpe_etehract_controller` version
2424
--- | ---
2525
v0.9.x | 0.9.x
2626
v1.0.x | 1.0.x or higher
2727
v1.5.x | 1.5.x
2828

29-
For example if you are using the v1.5.x firmware version you should check out the 1.5.x branch:
29+
30+
### Poulpe board EtherCAT configuration
31+
32+
Once when you have everything installed you and before you can run the code you need to configure the poulpe boards on the network if they are not already configured. The configuration is done with the EtherCAT network configuration files. The configuration files are located in the `config` directory.
33+
34+
Here is the [guide to configure the poulpe boards](configure_poulpe) on the network.
35+
36+
## Importing the crate
37+
38+
The crate is designed to be used as a library in your project. You can include it in your `Cargo.toml` file as a dependency:
39+
40+
```toml
41+
....
42+
[dependencies]
43+
...
44+
poulpe_ethercat_controller = { git = "https://github.com/pollen-robotics/poulpe_ethercat_controller.git", branch = "1.5.x" }
45+
```
46+
47+
You can also include only sub-crates that you need. For example, if you only need the GRPC client
48+
49+
```toml
50+
....
51+
[dependencies]
52+
...
53+
poulpe_ethercat_grpc = { git = "https://github.com/pollen-robotics/poulpe_ethercat_controller.git", branch = "1.5.x" }
54+
```
55+
56+
## Python-only installation
57+
58+
If you are using the python-only version of the code you can install the code directly from the repository.
59+
Make sure to use the tag corresponding to the version of the firmware that you are using. For example, if we use the 1.5.4 tag: (see the [tags](https://github.com/pollen-robotics/poulpe_ethercat_controller/tags))
60+
3061
```shell
31-
git checkout 1.5.x
62+
pip install git+https://github.com/pollen-robotics/poulpe_ethercat_controller.git@1.5.4#subdirectory=python_client
3263
```
3364

65+
NOTE:
66+
This install procedure is available from the version 1.5.4 of the `poulpe_ethercat_controller`.
3467

68+
Once this is installed you can use the python client to communicate with the poulpe board.
3569

36-
## Building the code
70+
```python
71+
import python_client
72+
```
3773

38-
The crate is written in Rust and uses the `cargo` build system. All the dependencies are managed by the `cargo` build system, except for the EtherCAT IgH Master.
74+
## Installing from source
3975

40-
So the main dependencies are:
41-
- Rust - [installation guide](https://www.rust-lang.org/tools/install)
42-
- EtherCAT IgH Master (for the EtherCAT communication) - [installation guide](installation_ethercat)
76+
You can obtain the code by cloning the repository.
4377

44-
Once you have all the dependencies installed you can build the code with:
78+
- Clone the repo
79+
```shell
80+
git clone [email protected]:pollen-robotics/poulpe_ethercat_controller.git
81+
```
82+
83+
- Check out the branches that you need, depending on the poulpe firmware version that you are using. For example if you are using the v1.5.x firmware version you should check out the 1.5.x branch:
84+
```shell
85+
git checkout 1.5.x
86+
```
87+
88+
- Once you have all the dependencies installed you can build the code with:
4589
```shell
4690
cargo build --release
4791
```
4892

49-
## Configuration
93+
See how to [install the python bindings](python_client) from the source code.
5094

51-
Once when you have everything installed you and before you can run the code you need to configure the poulpe boards on the network if they are not already configured. The configuration is done with the EtherCAT network configuration files. The configuration files are located in the `config` directory.
5295

53-
Here is the [guide to configure the poulpe boards](configure_poulpe) on the network.
5496

5597

5698
## Running the code

docs/installation/python_client.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@ parent: Installation and configuration
88

99
The `poulpe_ethercat_controller` crate provides a GRPC server and client interface that can be accessed by multiple clients at the same time, either in Rust or Python. The GRPC server is implemented in Rust and the client bindings are generated for both Rust and Python. The python bindings are implemented in `python_client` crate.
1010

11-
## Installation
11+
The simplest way of obtaining the python client is to pip install the code directly from the git the repository, using the tag corresponding to the version of the firmware that you are using. For example, if we use the 1.5.4 tag: (see the [tags](https://github.com/pollen-robotics/poulpe_ethercat_controller/tags))
1212

13+
```shell
14+
pip install git+https://github.com/pollen-robotics/[email protected]#subdirectory=python_client
15+
```
16+
17+
NOTE:
18+
This install procedure is available from the version 1.5.4 of the `poulpe_ethercat_controller`.
19+
20+
21+
## Installation from source
22+
23+
Provided that you already have the `poulpe_ethercat_controller` crate cloned and built, you can install the python client bindings from the source code. You can find more information on how to build the code in the <a href="../">installation and configuration</a> section.
1324

14-
To use this client run the following command:
25+
26+
First place yourself in the `python_client` directory, and then you can build the python client bindings you can use the `maturin` tool.
1527

1628
```bash
1729
maturin develop --release
@@ -23,6 +35,7 @@ INFO:
2335
```bash
2436
conda create -n poulpe_ethercat python=3.10
2537
conda activate poulpe_ethercat
38+
pip install maturin
2639
```
2740

2841
Once you have the virtual environment activated you can run the following command:
@@ -32,30 +45,48 @@ maturin develop --release
3245
```
3346

3447
This will install the python client in the current environment.
35-
And then you can open the notebooks in the `notebooks` folder and scripts in the `scripts` folder to see how to use the client.
48+
And then you can open the notebooks in the `notebooks` folder and scripts in the `scripts` folder to see how to use the client. See the [notebooks](https://github.com/pollen-robotics/poulpe_ethercat_controller/tree/develop/python_client/notebooks) for more information.
3649

3750
The client is a wrapper around the GRPC client generated from the `poulpe_ethercat_grpc/src/client.rs` folder.
3851

39-
## Run the GRPC server
40-
Make sure to run the GRPC server before running the client.
41-
This can be done using the following command:
52+
## Simple example
4253

43-
```bash
44-
cargo run --release ../config/file/here.yaml
54+
Create a simple config file `file_config.yaml` with the following content:
55+
```yaml
56+
ethercat:
57+
master_id: 0
58+
cycle_time_us: 1000 # us - cycle time of the ethercat 1/frequency
59+
command_drop_time_us: 5000 # us (5ms default)
60+
watchdog_timeout_ms: 500 # ms (500ms default)
61+
mailbox_wait_time_ms: 10000 #ms (1s default)
4562
```
4663
47-
## Simple example
64+
And then you can run the following python script:
4865
4966
```python
50-
from python_client import PyPoulpeRemoteClient
67+
from python_client import PyPoulpeRemoteClient, launch_server, get_all_slaves_in_network
5168
import time
5269

70+
# launch the server first
71+
address = launch_server("file_config.yaml")
72+
73+
# wait for the server to start
74+
time.sleep(1.0)
75+
76+
# print all slaves in the network
77+
devices = get_all_slaves_in_network(address)
78+
print("Devices connected in the network: ")
79+
for i,name in zip(devices[0],devices[1]):
80+
print("Slave {}: {}".format(i,name))
81+
82+
83+
# connect to the server
5384
slave_id = 0
5485
no_axis = 3
5586

5687
print('Connecting on slave: {}'.format(slave_id))
5788
# Create an instance of the client
58-
client = PyPoulpeRemoteClient("http://127.0.0.1:50098", [slave_id], 0.001)
89+
client = PyPoulpeRemoteClient(address, [slave_id], 0.001)
5990

6091
time.sleep(1.0)
6192

@@ -69,10 +100,11 @@ print("Slave {} current position: {}".format(slave_id, client.get_position_actua
69100
```
70101
which might output something like:
71102
```shell
72-
Connecting on slave: 0
103+
POULPE controller ready!
73104
Devices connected in the network:
74105
Slave 1: RightWristOrbita3d
75106
Slave 0: RightShoulderOrbita2d
107+
Connecting on slave: 0
76108
Slave 0 compliancy is: True
77109
Slave 0 current position: [-0.0011222249595448375, 3.743586057680659e-05, 6.8065196501265746e-06]
78110
```

ethercat_controller/examples/poulpe_sinus.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use core::net;
21
use ethercat_controller::EtherCatController;
32
use log;
43
use std::env;

ethercat_controller/examples/scan_network.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use std::time::Duration;
55
fn main() {
66
env_logger::init();
77

8-
let id: u16 = 0;
9-
108
log::info!("Creating the EtherCAT master");
119
let ec = EtherCatController::open(0, Duration::from_millis(2), 1000, 500, 1000).unwrap();
1210

mkdocs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ theme:
1616
- python
1717
- terminal
1818
- console
19+
- toml
1920
hljs_style: github
2021
custom_dir: docs/custom_theme/
2122
logo: img/favicon.ico

python_client/notebooks/orbita2d_test_assembly.ipynb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,33 @@
2121
},
2222
{
2323
"cell_type": "code",
24-
"execution_count": 2,
24+
"execution_count": 1,
2525
"id": "a4c135e1-94e8-4bd6-a40a-81f1827cd8ba",
2626
"metadata": {},
2727
"outputs": [
2828
{
2929
"name": "stdout",
3030
"output_type": "stream",
3131
"text": [
32-
"POULPE controller ready!\n"
32+
"POULPE controller ready!\n",
33+
"Devices connected in the network: \n",
34+
"Slave 0: RightShoulderOrbita2d\n"
3335
]
3436
}
3537
],
3638
"source": [
3739
"import python_client\n",
38-
"python_client.launch_server(\"../../config/ethercat.yaml\")"
40+
"import time\n",
41+
"\n",
42+
"# launch the server\n",
43+
"address = python_client.launch_server(\"../../config/ethercat.yaml\")\n",
44+
"time.sleep(1)\n",
45+
"\n",
46+
"# print all slaves in the network\n",
47+
"devices = python_client.get_all_slaves_in_network(address)\n",
48+
"print(\"Devices connected in the network: \")\n",
49+
"for i,name in zip(devices[0],devices[1]):\n",
50+
" print(\"Slave {}: {}\".format(i,name))"
3951
]
4052
},
4153
{
@@ -67,7 +79,7 @@
6779
"n_axis = 2 # 2 or 3\n",
6880
"\n",
6981
"# Create an instance of the client\n",
70-
"client = PyPoulpeRemoteClient(\"http://127.0.0.1:50098\", [slave_id], 0.001)\n",
82+
"client = PyPoulpeRemoteClient(address, [slave_id], 0.001)\n",
7183
"\n",
7284
"print(client.get_connected_devices())\n",
7385
"\n",

python_client/notebooks/orbita3d_test_assembly.ipynb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@
3535
],
3636
"source": [
3737
"import python_client\n",
38-
"python_client.launch_server(\"../../config/ethercat.yaml\")"
38+
"import time\n",
39+
"\n",
40+
"# launch the server\n",
41+
"address = python_client.launch_server(\"../../config/ethercat.yaml\")\n",
42+
"time.sleep(1)\n",
43+
"\n",
44+
"# print all slaves in the network\n",
45+
"devices = python_client.get_all_slaves_in_network(address)\n",
46+
"print(\"Devices connected in the network: \")\n",
47+
"for i,name in zip(devices[0],devices[1]):\n",
48+
" print(\"Slave {}: {}\".format(i,name))"
3949
]
4050
},
4151
{
@@ -67,7 +77,7 @@
6777
"n_axis = 3# 2 or 3\n",
6878
"\n",
6979
"# Create an instance of the client\n",
70-
"client = PyPoulpeRemoteClient(\"http://127.0.0.1:50098\", [slave_id], 0.001)\n",
80+
"client = PyPoulpeRemoteClient(address, [slave_id], 0.001)\n",
7181
"\n",
7282
"print(client.get_connected_devices())\n",
7383
"\n",

python_client/notebooks/poulpe_test.ipynb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,33 @@
1818
},
1919
{
2020
"cell_type": "code",
21-
"execution_count": 3,
21+
"execution_count": 1,
2222
"id": "45a55cd9-9ed1-43c7-9f18-63b4499ece82",
2323
"metadata": {},
2424
"outputs": [
2525
{
2626
"name": "stdout",
2727
"output_type": "stream",
2828
"text": [
29-
"POULPE controller ready!\n"
29+
"POULPE controller ready!\n",
30+
"Devices connected in the network: \n",
31+
"Slave 0: RightShoulderOrbita2d\n"
3032
]
3133
}
3234
],
3335
"source": [
3436
"import python_client\n",
35-
"python_client.launch_server(\"../../config/ethercat.yaml\")"
37+
"import time\n",
38+
"\n",
39+
"# launch the server\n",
40+
"address = python_client.launch_server(\"../../config/ethercat.yaml\")\n",
41+
"time.sleep(1)\n",
42+
"\n",
43+
"# print all slaves in the network\n",
44+
"devices = python_client.get_all_slaves_in_network(address)\n",
45+
"print(\"Devices connected in the network: \")\n",
46+
"for i,name in zip(devices[0],devices[1]):\n",
47+
" print(\"Slave {}: {}\".format(i,name))"
3648
]
3749
},
3850
{
@@ -67,7 +79,7 @@
6779
"\n",
6880
"print(\"Connecting to slave {}\".format(slave_id))\n",
6981
"# Create an instance of the client\n",
70-
"client = PyPoulpeRemoteClient(\"http://127.0.0.1:50098\", [slave_id], 0.001)\n",
82+
"client = PyPoulpeRemoteClient(address, [slave_id], 0.001)\n",
7183
"# print the connected clients\n",
7284
"devs = client.get_connected_devices()\n",
7385
"print(\"Connected to slaves | ids: {} , names: {}\".format(devs[0],devs[1]) )\n",
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import python_client
2+
import time
23

34
print("Launching the EhterCAT server")
45

5-
# launch the server and allow ctrl-c to stop the server
6-
python_client.launch_server("../../config/ethercat.yaml")
6+
# launch the server
7+
address = python_client.launch_server("../../config/ethercat.yaml")
8+
time.sleep(1)
79

10+
# print all slaves in the network
11+
devices = python_client.get_all_slaves_in_network(address)
12+
print("Devices connected in the network: ")
13+
for i,name in zip(devices[0],devices[1]):
14+
print("Slave {}: {}".format(i,name))
15+
16+
817
while True:
918
pass

0 commit comments

Comments
 (0)