Skip to content

Commit 519b8bc

Browse files
committed
Add TF listener/faker examples and cross-compile support
Add two new examples demonstrating TF (transform) message handling with rosrust. The tf_listener example subscribes to transform messages from a ROS master and prints them to stdout. The tf_faker example publishes synthetic transform data in a circular motion pattern. Add Cross.toml configuration to enable cross-compilation by passing through the ROSRUST_MSG_PATH environment variable, which is required for message code generation during cross-compilation to different architectures like arm64. Update README with documentation for both new examples and simplify cross-compilation instructions to use the cross tool instead of manual environment variable setup. This reduces friction for developers targeting non-native platforms.
1 parent 7ec8730 commit 519b8bc

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed

Cross.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build.env]
2+
passthrough = ["ROSRUST_MSG_PATH"]

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ implementation is inspired by the official chatter python example from the ROS
4343
wiki, which demonstrates a simple communication between two nodes using ROS
4444
messages.
4545

46+
### TF Listener/Faker
47+
48+
Subscribe to TF messages from an external ROS master:
49+
50+
```bash
51+
RUST_LOG=info ROSRUST_MSG_PATH=`realpath messages` cargo run --example tf_listener
52+
```
53+
54+
Publish fake TF transforms:
55+
56+
```bash
57+
RUST_LOG=info ROSRUST_MSG_PATH=`realpath messages` cargo run --example tf_faker
58+
```
59+
60+
Use `ROS_MASTER_URI` to connect to a different master (default: `http://localhost:11311`).
61+
62+
Cross-compile for arm64:
63+
64+
```bash
65+
ROSRUST_MSG_PATH=`realpath messages` cross build --example tf_listener --target aarch64-unknown-linux-gnu --release
66+
```
67+
4668
### Debugging with official ROS docker image
4769

4870
To showcase that this ROS core implementation can be used with official ROS
@@ -74,9 +96,7 @@ contribute code, feel free to submit a pull request.
7496

7597

7698
## Cross-compilation to arm64
99+
77100
```bash
78-
apt install libssl-dev:arm64
79-
export AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu/
80-
export AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR=/usr/include/aarch64-linux-gnu/
81-
cargo build --target aarch64-unknown-linux-gnu --release
101+
cross build --target aarch64-unknown-linux-gnu --release
82102
```

examples/tf_faker.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::env;
2+
3+
fn main() {
4+
env_logger::init();
5+
6+
let master_uri = env::var("ROS_MASTER_URI").unwrap_or_else(|_| "http://localhost:11311".into());
7+
env::set_var("ROS_MASTER_URI", &master_uri);
8+
9+
rosrust::init("tf_faker");
10+
11+
let pub_tf = rosrust::publish("/tf", 10).expect("Failed to create /tf publisher");
12+
let rate = rosrust::rate(10.0);
13+
let mut seq = 0u32;
14+
15+
while rosrust::is_ok() {
16+
let now = rosrust::now();
17+
let t = seq as f64 * 0.1;
18+
19+
let mut msg = rosrust_msg::tf2_msgs::TFMessage::default();
20+
let mut tf = rosrust_msg::geometry_msgs::TransformStamped::default();
21+
22+
tf.header.seq = seq;
23+
tf.header.stamp = now;
24+
tf.header.frame_id = "world".into();
25+
tf.child_frame_id = "base_link".into();
26+
tf.transform.translation.x = t.sin();
27+
tf.transform.translation.y = t.cos();
28+
tf.transform.translation.z = 0.0;
29+
tf.transform.rotation.w = 1.0;
30+
31+
msg.transforms.push(tf);
32+
pub_tf.send(msg).ok();
33+
34+
seq += 1;
35+
rate.sleep();
36+
}
37+
}

examples/tf_listener.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::env;
2+
3+
fn main() {
4+
env_logger::init();
5+
6+
let master_uri = env::var("ROS_MASTER_URI").unwrap_or_else(|_| "http://localhost:11311".into());
7+
env::set_var("ROS_MASTER_URI", &master_uri);
8+
9+
rosrust::init("tf_listener");
10+
11+
let _sub = rosrust::subscribe("/tf", 10, |msg: rosrust_msg::tf2_msgs::TFMessage| {
12+
for tf in &msg.transforms {
13+
println!(
14+
"{} -> {}: t=[{:.3}, {:.3}, {:.3}] r=[{:.3}, {:.3}, {:.3}, {:.3}]",
15+
tf.header.frame_id,
16+
tf.child_frame_id,
17+
tf.transform.translation.x,
18+
tf.transform.translation.y,
19+
tf.transform.translation.z,
20+
tf.transform.rotation.x,
21+
tf.transform.rotation.y,
22+
tf.transform.rotation.z,
23+
tf.transform.rotation.w,
24+
);
25+
}
26+
})
27+
.expect("Failed to subscribe to /tf");
28+
29+
rosrust::spin();
30+
}

0 commit comments

Comments
 (0)