-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ROS2: Add base class for Node in gazebo plugins #771
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8058f6a
Move gazebo_ros files for porting
cd236f7
Create base Node class for gazebo plugins with ROS2
112aec3
Enable linters and make them happy
chapulina dcf67e2
Add simple test for gazebo_ros::Node
d2790f3
Remove Node::Create using sdf until it is implemented
8a64d97
Remove internal logic to check init, add more tests
chapulina 4f5d13d
Call init from node in case it hasn't been called yet
chapulina d5e448b
Fix bug in test_plugins not ensuring all topics were received
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(gazebo_ros) | ||
|
||
|
||
# Default to C++14 | ||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 14) | ||
endif() | ||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
# we dont use add_compile_options with pedantic in message packages | ||
# because the Python C extensions dont comply with it | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") | ||
endif() | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(gazebo_dev REQUIRED) | ||
|
||
include_directories(include) | ||
|
||
add_library(gazebo_ros_node SHARED src/node.cpp src/executor.cpp) | ||
ament_target_dependencies(gazebo_ros_node "rclcpp" "gazebo_dev") | ||
|
||
ament_export_include_directories(include) | ||
ament_export_libraries(gazebo_ros_node) | ||
ament_export_dependencies(rclcpp) | ||
ament_export_dependencies(gazebo_dev) | ||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
ament_lint_auto_find_test_dependencies() | ||
find_package(ament_cmake_gtest REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
add_library(gazebo_ros_plugin_example SHARED test/gazebo_ros_plugin_example.cpp) | ||
target_link_libraries(gazebo_ros_plugin_example gazebo_ros_node) | ||
ament_target_dependencies(gazebo_ros_plugin_example "rclcpp" "gazebo_dev" "std_msgs") | ||
ament_add_gtest(test_gazebo_ros_plugin_example test/test_gazebo_ros_plugin_example.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
ament_target_dependencies(test_gazebo_ros_plugin_example "rclcpp" "std_msgs") | ||
endif() | ||
|
||
ament_package() | ||
|
||
install(DIRECTORY include/ | ||
DESTINATION include) | ||
|
||
install(TARGETS gazebo_ros_node | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib | ||
RUNTIME DESTINATION bin) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2018 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef GAZEBO_ROS__EXECUTOR_HPP_ | ||
#define GAZEBO_ROS__EXECUTOR_HPP_ | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
#include <gazebo/common/common.hh> | ||
|
||
namespace gazebo_ros | ||
{ | ||
|
||
/// Executor run in a separate thread to handle events from all #gazebo_ros::Node instances | ||
/** | ||
* \class Executor executor.hpp <gazebo_ros/executor.hpp> | ||
*/ | ||
class Executor : public rclcpp::executors::MultiThreadedExecutor | ||
{ | ||
public: | ||
/// Create an instance and start the internal thread | ||
Executor(); | ||
|
||
/// Stops the internal executor and joins with the internal thread | ||
virtual ~Executor(); | ||
|
||
private: | ||
/// Thread where the executor spins until destruction | ||
std::thread spin_thread_; | ||
|
||
/// Spin executor, called in #spin_thread_ | ||
void run(); | ||
|
||
/// Shutdown ROS, called when gazebo sigint handle arrives so ROS is shutdown cleanly | ||
void shutdown(); | ||
|
||
/// Connection to gazebo sigint event | ||
gazebo::event::ConnectionPtr sigint_handle_; | ||
}; | ||
} // namespace gazebo_ros | ||
#endif // GAZEBO_ROS__EXECUTOR_HPP_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nitpick: members should come after functions, see guide