Skip to content

Commit 35d74e7

Browse files
Work on doc.
1 parent 9ff76ec commit 35d74e7

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Rustypot: a Rust package to communicate with Dynamixel motors
1+
# Rustypot: a Rust package to communicate with Dynamixel/Feetech motors
22

33
[![Build Status]][actions] [![Latest Version]][crates.io]
44

@@ -10,7 +10,7 @@
1010

1111
## Getting started
1212

13-
Rustypot is yet another communication library for robotis Dynamixel motors. It is currently used in the [Reachy project](https://www.pollen-robotics.com/reachy/).
13+
Rustypot is a communication library for Dynamixel/Feetech motors. It is used in the [Reachy project](https://www.pollen-robotics.com/reachy/). More types of servo can be added in the future.
1414

1515
## Feature Overview
1616

@@ -20,9 +20,19 @@ Rustypot is yet another communication library for robotis Dynamixel motors. It i
2020
* Easy support for new type of motors (register definition through macros). Currently support for dynamixel XL320, XL330, XL430, XM430, MX*, Orbita 2D & 3D.
2121
* Pure Rust
2222

23+
To add new servo, please refer to the [Servo documentation](./servo/README.md).
24+
25+
## APIs
26+
27+
It exposes two APIs:
28+
* `DynamixelProtocolHandler`: low-level API. It handles the serial communication and the Dynamixel protocol parsing. It can be used for fine-grained control of the shared bus with other communication.
29+
* `Controller`: high-level API for the Dynamixel protocol. Simpler and cleaner API but it takes full ownership of the io (it can still be shared if wrapped with a mutex for instance).
30+
31+
See the examples below for usage.
32+
2333
### Examples
2434
```rust
25-
use rustypot::{device::mx, DynamixelSerialIO};
35+
use rustypot::{DynamixelProtocolHandler, servo::dynamixel::mx};
2636
use std::time::Duration;
2737

2838
fn main() {
@@ -31,16 +41,36 @@ fn main() {
3141
.open()
3242
.expect("Failed to open port");
3343

34-
let io = DynamixelSerialIO::v1();
44+
let dph = DynamixelProtocolHandler::v1();
3545

3646
loop {
3747
let pos =
38-
mx::read_present_position(&io, serial_port.as_mut(), 11).expect("Communication error");
48+
mx::read_present_position(&dph, serial_port.as_mut(), 11).expect("Communication error");
3949
println!("Motor 11 present position: {:?}", pos);
4050
}
4151
}
4252
```
4353

54+
```rust
55+
use rustypot::servo::feetech::sts3215::STS3215Controller;
56+
57+
fn main() {
58+
let serial_port = serialport::new("/dev/ttyUSB0", 1_000_000)
59+
.timeout(Duration::from_millis(1000))
60+
.open()
61+
.unwrap();
62+
63+
let mut c = STS3215Controller::new()
64+
.with_protocol_v1()
65+
.with_serial_port(serial_port);
66+
67+
let pos = c.read_present_position(&vec![1, 2]).unwrap();
68+
println!("Motors present position: {:?}", pos);
69+
70+
c.write_goal_position(&vec![1, 2], &vec![1000, 2000]).unwrap();
71+
}
72+
```
73+
4474
## Documentation
4575

4676
See https://docs.rs/rustypot for more information on APIs and examples.

src/lib.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
//! Yet another communication library for robotis Dynamixel motors.
1+
//! A low-level communication library for servo (Dynamixel and Feetech motors).
22
//!
33
//! ## Feature Overview
44
//!
55
//! * Relies on [serialport] for serial communication
6-
//! * Support for dynamixel protocol v1 and v2 (can also use both on the same io)
6+
//! * Support for dynamixel protocol v1 and v2 (both can be used on the same io)
77
//! * Support for sync read and sync write operations
88
//! * Easy support for new type of motors (register definition through macros)
99
//! * Pure Rust
1010
//!
11-
//! *Note: this version use std and Vec extensively.*
11+
//! ## APIs
12+
//!
13+
//! It exposes two APIs:
14+
//! * `DynamixelProtocolHandler`: low-level API. It handles the serial communication and the Dynamixel protocol parsing. It can be used for fine-grained control of the shared bus with other communication.
15+
//! * `Controller`: high-level API for the Dynamixel protocol. Simpler and cleaner API but it takes full ownership of the io (it can still be shared if wrapped with a mutex for instance).
16+
//!
17+
//! See the examples below for usage.
1218
//!
1319
//! ## Examples
20+
//!
21+
//! ### With the low-level API
1422
//! ```no_run
15-
//! use rustypot::{DynamixelProtocolHandler, device::mx};
23+
//! use rustypot::{DynamixelProtocolHandler, servo::dynamixel::mx};
1624
//! use std::time::Duration;
1725
//!
1826
//! let mut serial_port = serialport::new("/dev/ttyACM0", 1_000_000)
@@ -26,6 +34,24 @@
2634
//! mx::read_present_position(&dph, serial_port.as_mut(), 11).expect("Communication error");
2735
//! println!("Motor 11 present position: {:?}", pos);
2836
//! ```
37+
//!
38+
//! ### With the high-level API
39+
//! ```no_run
40+
//! use rustypot::servo::feetech::sts3215::STS3215Controller;
41+
//!
42+
//! let serial_port = serialport::new(serialportname, baudrate)
43+
//! .timeout(Duration::from_millis(1000))
44+
//! .open()?;
45+
//!
46+
//! let mut c = STS3215Controller::new()
47+
//! .with_protocol_v1()
48+
//! .with_serial_port(serial_port);
49+
//!
50+
//! let pos = c.read_present_position(&vec![1, 2])?;
51+
//! println!("Motors present position: {:?}", pos);
52+
//!
53+
//! c.write_goal_position(&vec![1, 2], &vec![1000, 2000])?;
54+
//! ```
2955
3056
pub mod servo;
3157

src/servo/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Adding support for a new servo
2+
3+
> ⚠️ **Warning:** This documentation is only intended for servos that communicate via the Dynamixel Protocol (v1 or v2), such as the Robotis Dynamixel or Feetech servos.
4+
5+
* Create a new file in the service folder (or a subfolder such as feetech or dynamixel), for instance [sts3215.rs](./servo/feetech/sts3215.rs) in the feetech folder. Make sure to add its declaration in the parent module (for instance in [./servo/feetech/mod.rs]) as they must be explicitly declared in Rust. Something like this:
6+
```rust
7+
pub mod sts3215.rs
8+
```
9+
10+
* Add the servo definition in the new file. You can use the [XL430](./servo/dynamixel/xl430.rs) as a template. The macro should defined the `name` of the servo, the `protocol version` used and then a list of all registers with their name, address, access and type.
11+
12+
* Finally, add the servo registration in the servo root module [./servo/mod.rs]. You can specify all variants supported by your servo definition. This registration allows for the scan function to detect your new kind of servo.

0 commit comments

Comments
 (0)