Skip to content

Commit

Permalink
Merge pull request #1 from pal-robotics-forks/action_bridge
Browse files Browse the repository at this point in the history
Action bridge
  • Loading branch information
hsd-dev authored Nov 17, 2020
2 parents c4be41c + 6b945fb commit 469b025
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
9 changes: 6 additions & 3 deletions include/ros1_bridge/action_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ class ActionFactory_1_2 : public ActionFactoryInterface
return;
}

// goal_response_callback signature changed after foxy, this implementation
// works with both
std::shared_future<ROS2GoalHandle> gh2_future;
//Changes as per Dashing
auto send_goal_ops = ROS2SendGoalOptions();
send_goal_ops.goal_response_callback =
[this](auto gh2_future) mutable {
auto goal_handle = gh2_future.get();
[this, &gh2_future](auto gh2) mutable {
auto goal_handle = gh2_future.get();
if (!goal_handle)
{
gh1_.setRejected(); // goal was not accepted by remote server
Expand Down Expand Up @@ -168,7 +171,7 @@ class ActionFactory_1_2 : public ActionFactoryInterface
};

// send goal to ROS2 server, set-up feedback
auto gh2_future = client_->async_send_goal(goal2, send_goal_ops);
gh2_future = client_->async_send_goal(goal2, send_goal_ops);

auto future_result = client_->async_get_result(gh2_future.get());
auto res2 = future_result.get();
Expand Down
10 changes: 6 additions & 4 deletions ros1_bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def generate_cpp(output_path, template_dir):
'interface': interface,
'mapped_msgs': [],
'mapped_services': [],
'mapped_actions': [],
}
if interface_type == 'msg':
data_idl_cpp['mapped_msgs'] += [
Expand All @@ -164,12 +165,13 @@ def generate_cpp(output_path, template_dir):
data_idl_cpp['mapped_services'] += [
s for s in data['services']
if s['ros2_package'] == ros2_package_name and
s['ros2_name'] == interface.message_name],
'mapped_actions': [
s['ros2_name'] == interface.message_name]
if interface_type == 'action':
data_idl_cpp['mapped_actions'] += [
s for s in data['actions']
if s['ros2_package'] == ros2_package_name and
s['ros2_name'] == interface.message_name],
}
s['ros2_name'] == interface.message_name]

template_file = os.path.join(
template_dir, 'interface_factories.cpp.em')
output_file = os.path.join(
Expand Down
9 changes: 5 additions & 4 deletions src/action_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@

int main(int argc, char *argv[])
{
// ROS 1 node
ros::init(argc, argv, "ros_bridge");
ros::NodeHandle ros1_node;

// ROS 2 node
// must be before ROS1, because ros::init consumes args like __name and we cannot remap the node
rclcpp::init(argc, argv);
auto ros2_node = rclcpp::Node::make_shared("ros_bridge");

// ROS 1 node
ros::init(argc, argv, "ros_bridge");
ros::NodeHandle ros1_node;

std::string dir = argv[1];
std::string package = argv[2];
std::string type = argv[3];
Expand Down

0 comments on commit 469b025

Please sign in to comment.