Skip to content

Commit 6a75e6d

Browse files
committed
update doc
1 parent ef4a879 commit 6a75e6d

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,21 @@ fn main() {
6565
.with_protocol_v1()
6666
.with_serial_port(serial_port);
6767

68-
let pos = c.read_present_position(&vec![1, 2]).unwrap();
68+
let pos = c.sync_read_present_position(&vec![1, 2]).unwrap();
6969
println!("Motors present position: {:?}", pos);
7070

71-
c.write_goal_position(&vec![1, 2], &vec![1000, 2000]).unwrap();
71+
c.sync_write_goal_position(&vec![1, 2], &vec![1000, 2000]).unwrap();
7272
}
7373
```
7474

75+
## Tools
76+
77+
Simple bus scanning tool:
78+
79+
```bash
80+
cargo run --bin=scan -- --serialport=/dev/ttyUSB0 --baudrate=1000000 --protocol=v1
81+
```
82+
7583
## Documentation
7684

7785
See https://docs.rs/rustypot for more information on APIs and examples.
@@ -88,7 +96,7 @@ To build them locally, you can use [maturin](https://www.maturin.rs).
8896
maturin build --release --features python
8997
```
9098

91-
or, if you want to install them in your local python environment:
99+
or, if you want to install them in your local python environment:
92100

93101
```bash
94102
maturin develop --release --features python
@@ -108,4 +116,4 @@ This library is licensed under the [Apache License 2.0](./LICENSE).
108116
## Support
109117

110118
Rustypot is developed and maintained by [Pollen-Robotics](https://pollen-robotics.com). They developed open-source hardware and tools for robotics.
111-
Visit https://pollen-robotics.com to learn more or join the [Discord community](https://discord.com/invite/Kg3mZHTKgs) if you have any questions or want to share your projects.
119+
Visit https://pollen-robotics.com to learn more or join the [Discord community](https://discord.com/invite/Kg3mZHTKgs) if you have any questions or want to share your projects.

python/README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ maturin develop --release --features python
1818

1919
## Usage
2020

21-
The Python bindings exposes the same API as the Controller API in the rust crate.
21+
The Python bindings exposes the same API as the Controller API in the rust crate.
2222

2323
You first need to create a Controller object. For instance, to communicate with a serial port to Feetech STS3215 motors, you can do the following:
2424

@@ -28,17 +28,34 @@ from rustypot.servo import Sts3215SyncController
2828
c = Sts3215SyncController(serial_port='/dev/ttyUSB0', baudrate=100000, timeout=0.1)
2929
```
3030

31-
Then, you can directly read/write any register of the motor. For instance, to read the present position of the motors with id 1 and 2, you can do:
31+
32+
Then, you can directly read/write any register of the motor. For instance, to read the present position of the motor with id 1, you can do:
33+
34+
```python
35+
36+
pos = c.read_present_position(1)
37+
print(pos)
38+
```
39+
40+
You can also write to the motors. For instance, to set the goal position of the motors with id 1 to 90° you can do:
3241

3342
```python
43+
import numpy as np
44+
c.write_goal_position(1, np.deg2rad(90.0))
45+
```
46+
47+
48+
Then, you can also sync_read any registers on multiple motors in a single operations. For instance, to read the present position of the motors with id 1 and 2, you can do:
3449

35-
pos = c.read_present_position([1, 2])
50+
```python
51+
52+
pos = c.sync_read_present_position([1, 2])
3653
print(pos)
3754
```
3855

39-
You can also write to the motors. For instance, to set the goal position of the motors with id 1 and 2 to 0.0 and 90° respectively, you can do:
56+
Same with sync_write. For instance, to set the goal position of the motors with id 1 and 2 to 0.0 and 90° respectively, you can do:
4057

4158
```python
4259
import numpy as np
43-
c.write_goal_position([1, 2], [0.0, np.deg2rad(90.0)])
44-
```
60+
c.sync_write_goal_position([1, 2], [0.0, np.deg2rad(90.0)])
61+
```

src/bin/scan.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ fn main() -> Result<(), Box<dyn Error>> {
4747
let model = dph.read(serial_port.as_mut(), id, 0, 2).unwrap();
4848
let model = u16::from_le_bytes([model[0], model[1]]);
4949
let model = ServoKind::try_from(model);
50-
51-
println!("Found motor with id {id} and model {model:?}");
50+
match model {
51+
Ok(m) => println!("Found motor with id {id} and model: {m:?}"),
52+
Err(e) => println!("Found motor with id {id} with {e:?}"),
53+
}
5254
}
5355
}
5456
Err(e) => eprintln!("Error: {e}"),

src/servo/servo_macro.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,8 @@ macro_rules! register_servo {
845845
pub enum ServoKind {
846846
$(
847847
$(
848-
[<$group:camel $name:camel>],
848+
#[allow(non_camel_case_types)]
849+
[<$group _ $name>],
849850
)+
850851
)+
851852
}
@@ -854,7 +855,7 @@ macro_rules! register_servo {
854855
match model_number {
855856
$(
856857
$(
857-
$model_number => Ok(Self::[<$group:camel $name:camel>]),
858+
$model_number => Ok(Self::[<$group _ $name>]),
858859
)+
859860
)+
860861
_ => Err(format!("Unknown model number: {}", model_number)),

0 commit comments

Comments
 (0)