Skip to content

Commit

Permalink
Merge pull request #2 from mojin-robotics/action_bridge
Browse files Browse the repository at this point in the history
Action bridge
  • Loading branch information
fmessmer authored Sep 20, 2022
2 parents 0ba6fda + f31c7d0 commit ec11ae5
Show file tree
Hide file tree
Showing 14 changed files with 1,516 additions and 32 deletions.
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rmw_implementation_cmake REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rclcpp_action REQUIRED)

# find ROS 1 packages
set(cmake_extras_files cmake/find_ros1_package.cmake cmake/find_ros1_interface_packages.cmake)
Expand Down Expand Up @@ -43,6 +44,7 @@ if(NOT ros1_roscpp_FOUND)
endif()

find_ros1_package(std_msgs REQUIRED)
find_ros1_package(actionlib REQUIRED)

# Dependency that we should only look for if ROS 1 is installed (it's not present on a ROS 2
# system; see https://github.com/ros2/ros1_bridge/pull/331#issuecomment-1188111510)
Expand Down Expand Up @@ -110,7 +112,7 @@ foreach(package_name ${ros2_interface_packages})
file(TO_CMAKE_PATH "${interface_file}" interface_name)
get_filename_component(interface_basename "${interface_name}" NAME_WE)
# skipping actions and request and response messages of services
if(NOT "${interface_name}" MATCHES "^(msg|srv)/" OR "${interface_basename}" MATCHES "_(Request|Response)$")
if(NOT "${interface_name}" MATCHES "^(msg|srv|action)/" OR "${interface_basename}" MATCHES "_(Request|Response)$")
continue()
endif()
string(REPLACE "/" "__" interface_name "${interface_name}")
Expand Down Expand Up @@ -189,7 +191,7 @@ add_library(${PROJECT_NAME} SHARED
ament_target_dependencies(${PROJECT_NAME}
${prefixed_ros1_message_packages}
${ros2_interface_packages}
"rclcpp"
"rclcpp" "rclcpp_action"
"ros1_roscpp"
"ros1_std_msgs")

Expand All @@ -205,6 +207,13 @@ custom_executable(static_bridge
target_link_libraries(static_bridge
${PROJECT_NAME})

custom_executable(action_bridge
"src/action_bridge.cpp"
ROS1_DEPENDENCIES
TARGET_DEPENDENCIES ${ros2_interface_packages})
target_link_libraries(action_bridge
${PROJECT_NAME})

custom_executable(parameter_bridge
"src/parameter_bridge.cpp"
ROS1_DEPENDENCIES
Expand Down
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ ros2 run demo_nodes_cpp add_two_ints_client
This example expands on example 3 by selecting a subset of topics and services to be bridged.
This is handy when, for example, you have a system that runs most of it's stuff in either ROS 1 or ROS 2 but needs a few nodes from the 'opposite' version of ROS.
Where the `dynamic_bridge` bridges all topics and service, the `parameter_bridge` uses the ROS 1 parameter server to choose which topics and services are bridged.
**Note**: The service bridge is **monodirectional**. You must use either `services_2_to_1` and/or `services_1_or_2` to bridge ROS 2 -> ROS 1 or ROS 1 -> ROS 2 services accordingly.
**Note**: The service bridge is **monodirectional**. You must use either `services_2_to_1` and/or `services_1_to_2` to bridge ROS 2 -> ROS 1 or ROS 1 -> ROS 2 services accordingly.
For example, to bridge only the `/chatter` topic bidirectionally, and the `/add_two_ints service` from ROS 2 to ROS 1 only, create this configuration file, `bridge.yaml`:

```yaml
Expand Down Expand Up @@ -502,3 +502,51 @@ topics:
```
Note that the `qos` section can be omitted entirely and options not set are left default.

# Action bridge

This bridge extends the `ros1_bridge` to action interface. The bridge works in both directions, meaning an action goal can be sent from ROS1 client to ROS2 server, or from ROS2 client to ROS1 server.

The arguments for `action_bridge` node are:
`direction`: from client (`ros1` or `ros2`)
e.g.:
- `ROS1` client to `ROS2` server --> `direction` = `ros1`
- `ROS2` client to `ROS1` server --> `direction` = `ros2`

`package`: package of the `ROS1` server node
`type`: action interface type of `ROS1`
`name`: action name

For sending goals from ROS2 action client to ROS1 action server
```
# Terminal 1 -- action bridge
# Make sure roscore is already running
source <ros1_bridge-install-dir>/setup.bash
ros2 run ros1_bridge action_bridge ros1 actionlib_tutorials Fibonacci fibonacci

# Terminal 2 -- ROS1 action server
source <ros1-install-dir>/setup.bash
rosrun actionlib_tutorials fibonacci_server

# Terminal 3 -- ROS2 action client
source <ros2-install-dir>/setup.bash
ros2 run action_tutorials_cpp fibonacci_action_client 20
```
For sending goals from ROS1 action client to ROS2 action server
```
# Terminal 1 -- action bridge
# Make sure roscore is already running
source <ros1_bridge-install-dir>/setup.bash
ros2 run ros1_bridge action_bridge ros2 action_tutorials_interfaces action/Fibonacci fibonacci

# Terminal 2 -- ROS2 action server
source <ros2-install-dir>/setup.bash
ros2 run action_tutorials_cpp fibonacci_action_server

# Terminal 3 -- ROS1 action client
source <ros1-install-dir>/setup.bash
rosrun actionlib_tutorials fibonacci_client 20
```
`dynamic_bridge` has been extended to handle actions as well.
Loading

0 comments on commit ec11ae5

Please sign in to comment.