Skip to content

Commit e34a4b9

Browse files
Merge branch 'main' into luca/parameter_service
Signed-off-by: Luca Della Vedova <[email protected]>
2 parents 095a00f + 9082816 commit e34a4b9

File tree

35 files changed

+476
-148
lines changed

35 files changed

+476
-148
lines changed

.github/workflows/rust.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ jobs:
3737
container:
3838
image: ${{ matrix.docker_image }}
3939
steps:
40-
- uses: actions/checkout@v2
40+
- uses: actions/checkout@v4
4141

4242
- name: Search packages in this repository
4343
id: list_packages
4444
run: |
4545
echo ::set-output name=package_list::$(colcon list --names-only)
4646
4747
- name: Setup ROS environment
48-
uses: ros-tooling/setup-ros@v0.6
48+
uses: ros-tooling/setup-ros@v0.7
4949
with:
5050
required-ros-distributions: ${{ matrix.ros_distribution }}
5151
use-ros2-testing: ${{ matrix.ros_distribution == 'rolling' }}
5252

5353
- name: Setup Rust
54-
uses: dtolnay/rust-toolchain@1.71.0
54+
uses: dtolnay/rust-toolchain@1.74.0
5555
with:
5656
components: clippy, rustfmt
5757

@@ -87,7 +87,12 @@ jobs:
8787
for path in $(colcon list | awk '$3 == "(ament_cargo)" { print $2 }'); do
8888
cd $path
8989
echo "Running clippy in $path"
90-
cargo clippy --all-targets --all-features -- -D warnings
90+
# Run clippy for all features except generate_docs (needed for docs.rs)
91+
if [ "$(basename $path)" = "rclrs" ]; then
92+
cargo clippy --all-targets -F default,dyn_msg -- -D warnings
93+
else
94+
cargo clippy --all-targets --all-features -- -D warnings
95+
fi
9196
cd -
9297
done
9398
@@ -98,7 +103,14 @@ jobs:
98103
for path in $(colcon list | awk '$3 == "(ament_cargo)" && $1 != "examples_rclrs_minimal_pub_sub" && $1 != "examples_rclrs_minimal_client_service" { print $2 }'); do
99104
cd $path
100105
echo "Running cargo test in $path"
101-
cargo test --all-features
106+
# Run cargo test for all features except generate_docs (needed for docs.rs)
107+
if [ "$(basename $path)" = "rclrs" ]; then
108+
cargo test -F default,dyn_msg
109+
elif [ "$(basename $path)" = "rosidl_runtime_rs" ]; then
110+
cargo test -F default
111+
else
112+
cargo test --all-features
113+
fi
102114
cd -
103115
done
104116

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN apt-get update && apt-get install -y \
1212
&& rm -rf /var/lib/apt/lists/*
1313

1414
# Install Rust and the cargo-ament-build plugin
15-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.71.0 -y
15+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.74.0 -y
1616
ENV PATH=/root/.cargo/bin:$PATH
1717
RUN cargo install cargo-ament-build
1818

docs/writing-your-first-rclrs-node.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use std::sync::Arc;
4747
use std_msgs::msg::String as StringMsg;
4848

4949
struct RepublisherNode {
50-
node: rclrs::Node,
50+
node: Arc<rclrs::Node>,
5151
_subscription: Arc<rclrs::Subscription<StringMsg>>,
5252
data: Option<StringMsg>,
5353
}
@@ -114,7 +114,7 @@ use std::sync::{Arc, Mutex}; // (1)
114114
use std_msgs::msg::String as StringMsg;
115115

116116
struct RepublisherNode {
117-
node: rclrs::Node,
117+
node: Arc<rclrs::Node>,
118118
_subscription: Arc<rclrs::Subscription<StringMsg>>,
119119
data: Arc<Mutex<Option<StringMsg>>>, // (2)
120120
}

examples/message_demo/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "examples_rclrs_message_demo"
3-
version = "0.3.1"
3+
version = "0.4.1"
44
authors = ["Nikolai Morin <[email protected]>"]
55
edition = "2021"
66

@@ -12,13 +12,13 @@ path = "src/message_demo.rs"
1212
anyhow = {version = "1", features = ["backtrace"]}
1313

1414
[dependencies.rclrs]
15-
version = "0.3"
15+
version = "0.4"
1616

1717
[dependencies.rosidl_runtime_rs]
18-
version = "0.3"
18+
version = "0.4"
1919

2020
[dependencies.rclrs_example_msgs]
21-
version = "0.3"
21+
version = "0.4"
2222
features = ["serde"]
2323

2424
[dependencies.serde_json]

examples/message_demo/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
schematypens="http://www.w3.org/2001/XMLSchema"?>
55
<package format="3">
66
<name>examples_rclrs_message_demo</name>
7-
<version>0.3.1</version>
7+
<version>0.4.1</version>
88
<description>Package containing an example of message-related functionality in rclrs.</description>
99
<maintainer email="[email protected]">Nikolai Morin</maintainer>
1010
<license>Apache License 2.0</license>

examples/minimal_client_service/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "examples_rclrs_minimal_client_service"
3-
version = "0.3.1"
3+
version = "0.4.1"
44
authors = ["Esteve Fernandez <[email protected]>"]
55
edition = "2021"
66

@@ -21,10 +21,10 @@ anyhow = {version = "1", features = ["backtrace"]}
2121
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread", "time"] }
2222

2323
[dependencies.rclrs]
24-
version = "0.3"
24+
version = "0.4"
2525

2626
[dependencies.rosidl_runtime_rs]
27-
version = "0.3"
27+
version = "0.4"
2828

2929
[dependencies.example_interfaces]
3030
version = "*"

examples/minimal_client_service/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
schematypens="http://www.w3.org/2001/XMLSchema"?>
55
<package format="3">
66
<name>examples_rclrs_minimal_client_service</name>
7-
<version>0.3.1</version>
7+
<version>0.4.1</version>
88
<description>Package containing an example of the client-service mechanism in rclrs.</description>
99
<maintainer email="[email protected]">Esteve Fernandez</maintainer>
1010
<license>Apache License 2.0</license>

examples/minimal_pub_sub/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "examples_rclrs_minimal_pub_sub"
3-
version = "0.3.1"
3+
version = "0.4.1"
44
# This project is not military-sponsored, Jacob's employment contract just requires him to use this email address
55
authors = ["Esteve Fernandez <[email protected]>", "Nikolai Morin <[email protected]>", "Jacob Hassold <[email protected]>"]
66
edition = "2021"
@@ -29,10 +29,10 @@ path = "src/zero_copy_publisher.rs"
2929
anyhow = {version = "1", features = ["backtrace"]}
3030

3131
[dependencies.rclrs]
32-
version = "0.3"
32+
version = "0.4"
3333

3434
[dependencies.rosidl_runtime_rs]
35-
version = "0.3"
35+
version = "0.4"
3636

3737
[dependencies.std_msgs]
3838
version = "*"

examples/minimal_pub_sub/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
schematypens="http://www.w3.org/2001/XMLSchema"?>
55
<package format="3">
66
<name>examples_rclrs_minimal_pub_sub</name>
7-
<version>0.3.1</version>
7+
<version>0.4.1</version>
88
<description>Package containing an example of the publish-subscribe mechanism in rclrs.</description>
99
<maintainer email="[email protected]">Esteve Fernandez</maintainer>
1010
<maintainer email="[email protected]">Nikolai Morin</maintainer>

rclrs/Cargo.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rclrs"
3-
version = "0.3.1"
3+
version = "0.4.1"
44
# This project is not military-sponsored, Jacob's employment contract just requires him to use this email address
55
authors = ["Esteve Fernandez <[email protected]>", "Nikolai Morin <[email protected]>", "Jacob Hassold <[email protected]>"]
66
edition = "2021"
@@ -16,14 +16,15 @@ path = "src/lib.rs"
1616
[dependencies]
1717
# Needed for dynamically finding type support libraries
1818
ament_rs = { version = "0.2", optional = true }
19+
# Needed for uploading documentation to docs.rs
20+
cfg-if = "1.0.0"
21+
1922
# Needed for clients
2023
futures = "0.3"
2124
# Needed for dynamic messages
2225
libloading = { version = "0.8", optional = true }
23-
# Needed for /clock topic subscription when using simulation time
24-
rosgraph_msgs = "*"
2526
# Needed for the Message trait, among others
26-
rosidl_runtime_rs = "0.3"
27+
rosidl_runtime_rs = "0.4"
2728

2829
[dev-dependencies]
2930
# Needed for e.g. writing yaml files in tests
@@ -32,6 +33,15 @@ tempfile = "3.3.0"
3233
[build-dependencies]
3334
# Needed for FFI
3435
bindgen = "0.66.1"
36+
# Needed for uploading documentation to docs.rs
37+
cfg-if = "1.0.0"
3538

3639
[features]
40+
default = []
3741
dyn_msg = ["ament_rs", "libloading"]
42+
# This feature is solely for the purpose of being able to generate documetation without a ROS installation
43+
# The only intended usage of this feature is for docs.rs builders to work, and is not intended to be used by end users
44+
generate_docs = ["rosidl_runtime_rs/generate_docs"]
45+
46+
[package.metadata.docs.rs]
47+
features = ["generate_docs"]

rclrs/build.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,21 @@ fn get_env_var_or_abort(env_var: &'static str) -> String {
1818
}
1919

2020
fn main() {
21-
let ros_distro = get_env_var_or_abort(ROS_DISTRO);
21+
let ros_distro = if let Ok(value) = env::var(ROS_DISTRO) {
22+
value
23+
} else {
24+
let error_msg =
25+
"ROS_DISTRO environment variable not set - please source ROS 2 installation first.";
26+
cfg_if::cfg_if! {
27+
if #[cfg(feature="generate_docs")] {
28+
println!("{}", error_msg);
29+
return;
30+
} else {
31+
panic!("{}", error_msg);
32+
}
33+
}
34+
};
35+
2236
println!("cargo:rustc-cfg=ros_distro=\"{ros_distro}\"");
2337

2438
let mut builder = bindgen::Builder::default()

rclrs/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
schematypens="http://www.w3.org/2001/XMLSchema"?>
55
<package format="3">
66
<name>rclrs</name>
7-
<version>0.3.1</version>
7+
<version>0.4.1</version>
88
<description>Package containing the Rust client library.</description>
99
<maintainer email="[email protected]">Esteve Fernandez</maintainer>
1010
<maintainer email="[email protected]">Nikolai Morin</maintainer>

rclrs/src/arguments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ mod tests {
149149
.map(|x| x.to_string());
150150

151151
let non_ros_args: Vec<String> = extract_non_ros_args(input_args).unwrap();
152-
let expected = vec!["non-ros1", "non-ros2", "non-ros3"];
152+
let expected = ["non-ros1", "non-ros2", "non-ros3"];
153153

154154
if non_ros_args.len() != expected.len() {
155155
return Err(format!(

rclrs/src/clock.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ impl From<ClockType> for rcl_clock_type_t {
2828
/// Struct that implements a Clock and wraps `rcl_clock_t`.
2929
#[derive(Clone, Debug)]
3030
pub struct Clock {
31-
_type: ClockType,
32-
_rcl_clock: Arc<Mutex<rcl_clock_t>>,
31+
kind: ClockType,
32+
rcl_clock: Arc<Mutex<rcl_clock_t>>,
3333
// TODO(luca) Implement jump callbacks
3434
}
3535

3636
/// A clock source that can be used to drive the contained clock. Created when a clock of type
3737
/// `ClockType::RosTime` is constructed
3838
pub struct ClockSource {
39-
_rcl_clock: Arc<Mutex<rcl_clock_t>>,
39+
rcl_clock: Arc<Mutex<rcl_clock_t>>,
4040
}
4141

4242
impl Clock {
@@ -54,52 +54,52 @@ impl Clock {
5454
/// to update it
5555
pub fn with_source() -> (Self, ClockSource) {
5656
let clock = Self::make(ClockType::RosTime);
57-
let clock_source = ClockSource::new(clock._rcl_clock.clone());
57+
let clock_source = ClockSource::new(clock.rcl_clock.clone());
5858
(clock, clock_source)
5959
}
6060

6161
/// Creates a new clock of the given `ClockType`.
62-
pub fn new(type_: ClockType) -> (Self, Option<ClockSource>) {
63-
let clock = Self::make(type_);
62+
pub fn new(kind: ClockType) -> (Self, Option<ClockSource>) {
63+
let clock = Self::make(kind);
6464
let clock_source =
65-
matches!(type_, ClockType::RosTime).then(|| ClockSource::new(clock._rcl_clock.clone()));
65+
matches!(kind, ClockType::RosTime).then(|| ClockSource::new(clock.rcl_clock.clone()));
6666
(clock, clock_source)
6767
}
6868

69-
fn make(type_: ClockType) -> Self {
69+
fn make(kind: ClockType) -> Self {
7070
let mut rcl_clock;
7171
unsafe {
7272
// SAFETY: Getting a default value is always safe.
7373
rcl_clock = Self::init_generic_clock();
7474
let mut allocator = rcutils_get_default_allocator();
7575
// Function will return Err(_) only if there isn't enough memory to allocate a clock
7676
// object.
77-
rcl_clock_init(type_.into(), &mut rcl_clock, &mut allocator)
77+
rcl_clock_init(kind.into(), &mut rcl_clock, &mut allocator)
7878
.ok()
7979
.unwrap();
8080
}
8181
Self {
82-
_type: type_,
83-
_rcl_clock: Arc::new(Mutex::new(rcl_clock)),
82+
kind,
83+
rcl_clock: Arc::new(Mutex::new(rcl_clock)),
8484
}
8585
}
8686

8787
/// Returns the clock's `ClockType`.
8888
pub fn clock_type(&self) -> ClockType {
89-
self._type
89+
self.kind
9090
}
9191

9292
/// Returns the current clock's timestamp.
9393
pub fn now(&self) -> Time {
94-
let mut clock = self._rcl_clock.lock().unwrap();
94+
let mut clock = self.rcl_clock.lock().unwrap();
9595
let mut time_point: i64 = 0;
9696
unsafe {
9797
// SAFETY: No preconditions for this function
9898
rcl_clock_get_now(&mut *clock, &mut time_point);
9999
}
100100
Time {
101101
nsec: time_point,
102-
clock: Arc::downgrade(&self._rcl_clock),
102+
clock: Arc::downgrade(&self.rcl_clock),
103103
}
104104
}
105105

@@ -128,14 +128,14 @@ impl Drop for ClockSource {
128128

129129
impl PartialEq for ClockSource {
130130
fn eq(&self, other: &Self) -> bool {
131-
Arc::ptr_eq(&self._rcl_clock, &other._rcl_clock)
131+
Arc::ptr_eq(&self.rcl_clock, &other.rcl_clock)
132132
}
133133
}
134134

135135
impl ClockSource {
136136
/// Sets the value of the current ROS time.
137137
pub fn set_ros_time_override(&self, nanoseconds: i64) {
138-
let mut clock = self._rcl_clock.lock().unwrap();
138+
let mut clock = self.rcl_clock.lock().unwrap();
139139
// SAFETY: Safe if clock jump callbacks are not edited, which is guaranteed
140140
// by the mutex
141141
unsafe {
@@ -147,16 +147,16 @@ impl ClockSource {
147147
}
148148
}
149149

150-
fn new(clock: Arc<Mutex<rcl_clock_t>>) -> Self {
151-
let source = Self { _rcl_clock: clock };
150+
fn new(rcl_clock: Arc<Mutex<rcl_clock_t>>) -> Self {
151+
let source = Self { rcl_clock };
152152
source.set_ros_time_enable(true);
153153
source
154154
}
155155

156156
/// Sets the clock to use ROS Time, if enabled the clock will report the last value set through
157157
/// `Clock::set_ros_time_override(nanoseconds: i64)`.
158158
fn set_ros_time_enable(&self, enable: bool) {
159-
let mut clock = self._rcl_clock.lock().unwrap();
159+
let mut clock = self.rcl_clock.lock().unwrap();
160160
if enable {
161161
// SAFETY: Safe if clock jump callbacks are not edited, which is guaranteed
162162
// by the mutex

rclrs/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,13 @@ pub fn create_node(context: &Context, node_name: &str) -> Result<Arc<Node>, Rclr
8989
Node::new(context, node_name)
9090
}
9191

92-
/// Creates a [`NodeBuilder`][1].
92+
/// Creates a [`NodeBuilder`].
9393
///
94-
/// Convenience function equivalent to [`NodeBuilder::new()`][2] and [`Node::builder()`][3].
94+
/// Convenience function equivalent to [`NodeBuilder::new()`][1] and [`Node::builder()`][2].
9595
/// Please see that function's documentation.
9696
///
97-
/// [1]: crate::NodeBuilder
98-
/// [2]: crate::NodeBuilder::new
99-
/// [3]: crate::Node::builder
97+
/// [1]: crate::NodeBuilder::new
98+
/// [2]: crate::Node::builder
10099
///
101100
/// # Example
102101
/// ```

0 commit comments

Comments
 (0)