Skip to content
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 8 commits into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
132 changes: 0 additions & 132 deletions .ros1_unported/gazebo_ros/CMakeLists.txt

This file was deleted.

43 changes: 0 additions & 43 deletions .ros1_unported/gazebo_ros/package.xml

This file was deleted.

File renamed without changes.
50 changes: 50 additions & 0 deletions gazebo_ros/CMakeLists.txt
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)

51 changes: 51 additions & 0 deletions gazebo_ros/include/gazebo_ros/executor.hpp
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_;
Copy link
Contributor

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


/// 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_
Loading