Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
/target
/out
/_work
49 changes: 46 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ dunce = "1.0.2"
tracing = "0.1.36"

port_check = "0.3"
which = "8.0.0"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ available example name (verified :ok_hand:):
- rust-dataflow-url
- rust-dataflow-git
- multiple-daemons(ci run is not implemented yet)
- [customed-ros2-dataflow](./examples/customed-ros2-dataflow/README.md)
- zenoh-dataflow
18 changes: 10 additions & 8 deletions examples/c-dataflow/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dora_tracing::set_up_tracing;
use eyre::{bail, Context};
use eyre::{Context, bail};
use std::{
env::consts::{DLL_PREFIX, DLL_SUFFIX, EXE_SUFFIX},
path::Path,
Expand All @@ -8,7 +8,7 @@ use std::{
#[tokio::main]
async fn main() -> eyre::Result<()> {
set_up_tracing("c-dataflow-runner").wrap_err("failed to set up tracing")?;

let dora = std::path::PathBuf::from(std::env::var("DORA").unwrap());
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
std::env::set_current_dir(root.join(file!()).parent().unwrap())
Expand All @@ -25,7 +25,7 @@ async fn main() -> eyre::Result<()> {
build_dir.join("node_api.h"),
)
.await?;

build_c_node(&dora, "node.c", "c_node").await?;
build_c_node(&dora, "sink.c", "c_sink").await?;
build_c_node(&dora, "counter.c", "c_counter").await?;
Expand All @@ -39,13 +39,14 @@ async fn main() -> eyre::Result<()> {
async fn build_package(package: &str) -> eyre::Result<()> {
let dora = std::env::var("DORA").unwrap();
let cargo = std::env::var("CARGO").unwrap();

let mut cmd = tokio::process::Command::new("bash");
let manifest = std::path::PathBuf::from(dora).join("Cargo.toml");
let manifest = manifest.to_str().unwrap();
cmd.args(["-c",
&format!("cargo build --release --manifest-path {manifest} --package {package}",
)]);
cmd.args([
"-c",
&format!("cargo build --release --manifest-path {manifest} --package {package}",),
]);
if !cmd.status().await?.success() {
bail!("failed to compile {package}");
};
Expand All @@ -57,7 +58,8 @@ async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let dora = std::env::var("DORA").unwrap();
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--manifest-path").arg(std::path::PathBuf::from(dora).join("Cargo.toml"));
cmd.arg("--manifest-path")
.arg(std::path::PathBuf::from(dora).join("Cargo.toml"));
cmd.arg("--package").arg("dora-cli");
cmd.arg("--release");
cmd.arg("--")
Expand Down
2 changes: 1 addition & 1 deletion examples/cmake-dataflow/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dora_tracing::set_up_tracing;
use eyre::{bail, Context};
use eyre::{Context, bail};
use std::path::Path;

#[tokio::main]
Expand Down
57 changes: 57 additions & 0 deletions examples/customed-ros2-dataflow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# ROS2 Integration with Dora

This example demonstrates how to integrate ROS2 nodes with Dora's dataflow framework.

## Prerequisites

- ROS2 installed (tested with ROS2 Jazzy)
- Dora framework installed
- Rust toolchain
- `colcon` build system

## Environment Setup

Set the following environment variables:

```bash
# Point to your Dora repository
export DORA=/path/to/dora

# Point to your ROS2 setup script
export ROS=/opt/ros/jazzy/setup.bash
```

## Examples

### 1. ROS2 Service Integration (Dora as Server)

```bash
cargo run --example customed-ros2-dataflow service
```

Uses `dataflow.yml` and the `add_client` ROS package.

### 2. ROS2 Action Integration (Dora as Client)

```bash
cargo run --example customed-ros2-dataflow action
```

Uses `dataflow_action.yml` and the `fibonacci_action_server` ROS package.

## Usage

```
cargo run --example customed-ros2-dataflow [service|action]
```

- `service`: Dora acts as a server, terminates after ROS client finishes
- `action`: Dora acts as a client, terminates the ROS server after completing its work

## Files

- `main.rs` - Example runner
- `dataflow.yml` - Service example configuration
- `dataflow_action.yml` - Action example configuration
- `dora_nodes/src/dora_server.rs` - ROS2 service server implementation
- `dora_nodes/src/dora_action_client.rs` - ROS2 action client implementation
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rosidl_generate_interfaces(
"msg/Num.msg"
"msg/Sphere.msg"
"srv/AddThreeInts.srv"
"action/Fibonacci.action"
DEPENDENCIES geometry_msgs
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int32 order
---
int32[] sequence
---
int32[] partial_sequence
39 changes: 38 additions & 1 deletion examples/customed-ros2-dataflow/customed_nodes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,57 @@ find_package(ament_cmake REQUIRED)

find_package(customed_interfaces REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(rclcpp_action REQUIRED)

# Three Ints Add Server
add_executable(add_service src/add_service.cpp)
ament_target_dependencies(add_service rclcpp customed_interfaces)
install(TARGETS
add_service
DESTINATION
lib/${PROJECT_NAME})


# Three Ints Add Client
add_executable(add_client src/add_client.cpp)
ament_target_dependencies(add_client rclcpp customed_interfaces)
install(TARGETS
add_client
DESTINATION
lib/${PROJECT_NAME})

# Fibonacci Action Server
add_library(fib_server SHARED src/fib_server.cpp)
target_include_directories(fib_server PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(fib_server
PRIVATE "CUSTOM_ACTION_CPP_BUILDING_DLL")
ament_target_dependencies(fib_server rclcpp customed_interfaces rclcpp_components rclcpp_action)
rclcpp_components_register_node(fib_server PLUGIN "customed_nodes::FibonacciActionServer" EXECUTABLE fibonacci_server)
install(TARGETS
fib_server
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

# Fibonacci Action Client
add_library(fib_client SHARED src/fib_client.cpp)
target_include_directories(fib_client PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(fib_client
PRIVATE "CUSTOM_ACTION_CPP_BUILDING_DLL")
ament_target_dependencies(fib_client rclcpp customed_interfaces rclcpp_components rclcpp_action)
rclcpp_components_register_node(fib_client PLUGIN "customed_nodes::FibonacciActionClient" EXECUTABLE fibonacci_client)
install(TARGETS
fib_client
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef CUSTOM_ACTION_CPP__VISIBILITY_CONTROL_H_
#define CUSTOM_ACTION_CPP__VISIBILITY_CONTROL_H_

#ifdef __cplusplus
extern "C"
{
#endif

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define CUSTOM_ACTION_CPP_EXPORT __attribute__ ((dllexport))
#define CUSTOM_ACTION_CPP_IMPORT __attribute__ ((dllimport))
#else
#define CUSTOM_ACTION_CPP_EXPORT __declspec(dllexport)
#define CUSTOM_ACTION_CPP_IMPORT __declspec(dllimport)
#endif
#ifdef CUSTOM_ACTION_CPP_BUILDING_DLL
#define CUSTOM_ACTION_CPP_PUBLIC CUSTOM_ACTION_CPP_EXPORT
#else
#define CUSTOM_ACTION_CPP_PUBLIC CUSTOM_ACTION_CPP_IMPORT
#endif
#define CUSTOM_ACTION_CPP_PUBLIC_TYPE CUSTOM_ACTION_CPP_PUBLIC
#define CUSTOM_ACTION_CPP_LOCAL
#else
#define CUSTOM_ACTION_CPP_EXPORT __attribute__ ((visibility("default")))
#define CUSTOM_ACTION_CPP_IMPORT
#if __GNUC__ >= 4
#define CUSTOM_ACTION_CPP_PUBLIC __attribute__ ((visibility("default")))
#define CUSTOM_ACTION_CPP_LOCAL __attribute__ ((visibility("hidden")))
#else
#define CUSTOM_ACTION_CPP_PUBLIC
#define CUSTOM_ACTION_CPP_LOCAL
#endif
#define CUSTOM_ACTION_CPP_PUBLIC_TYPE
#endif

#ifdef __cplusplus
}
#endif

#endif // CUSTOM_ACTION_CPP__VISIBILITY_CONTROL_H_
4 changes: 3 additions & 1 deletion examples/customed-ros2-dataflow/customed_nodes/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<buildtool_depend>ament_cmake</buildtool_depend>

<depend>customed_interfaces</depend>

<depend>rclcpp_components</depend>
<depend>rclcpp_action</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

Expand Down
Loading
Loading