-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove internal logic to check init, add more tests
- Loading branch information
Showing
11 changed files
with
339 additions
and
223 deletions.
There are no files selected for viewing
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
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
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
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
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,41 @@ | ||
find_package(ament_cmake_gtest REQUIRED) | ||
find_package(ament_lint_auto REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
|
||
# Linters | ||
ament_lint_auto_find_test_dependencies() | ||
|
||
# Plugins | ||
set(plugins | ||
create_before_init | ||
multiple_nodes | ||
proper_init | ||
) | ||
|
||
foreach(plugin ${plugins}) | ||
add_library(${plugin} SHARED plugins/${plugin}.cpp) | ||
target_link_libraries(${plugin} gazebo_ros_node) | ||
ament_target_dependencies(${plugin} | ||
"rclcpp" | ||
"gazebo_dev" | ||
"std_msgs" | ||
) | ||
endforeach() | ||
|
||
# Tests | ||
set(tests | ||
test_plugins | ||
) | ||
|
||
foreach(test ${tests}) | ||
ament_add_gtest(${test} | ||
${test}.cpp | ||
WORKING_DIRECTORY | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
ament_target_dependencies(${test} | ||
"rclcpp" | ||
"std_msgs" | ||
) | ||
endforeach() | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,68 @@ | ||
// 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. | ||
|
||
#include <gazebo/common/Plugin.hh> | ||
|
||
#include <std_msgs/msg/string.hpp> | ||
#include <gazebo_ros/node.hpp> | ||
|
||
#include <memory> | ||
|
||
/// Simple example of a gazebo system plugin which uses a ROS2 node with gazebo_ros::Node. | ||
class CreateBeforeInit : public gazebo::SystemPlugin | ||
{ | ||
public: | ||
/// Called by gazebo to load plugin. Creates #node, #timer_, and #pub | ||
/// \param[in] argc Argument count. | ||
/// \param[in] argv Argument values. | ||
void Load(int argc, char ** argv); | ||
|
||
private: | ||
/// Timer called to publish a message every second | ||
std::shared_ptr<rclcpp::TimerBase> timer_; | ||
}; | ||
|
||
void CreateBeforeInit::Load(int argc, char ** argv) | ||
{ | ||
// Try creating before initializing | ||
auto node = gazebo_ros::Node::Create("create_before_init"); | ||
assert(nullptr == node); | ||
|
||
// Initialize ROS with arguments | ||
rclcpp::init(argc, argv); | ||
|
||
// Now it should be created | ||
node = gazebo_ros::Node::Create("create_before_init"); | ||
assert(nullptr != node); | ||
|
||
// Create a publisher | ||
auto pub = node->create_publisher<std_msgs::msg::String>("test"); | ||
|
||
// Run lambda every 1 second | ||
using namespace std::chrono_literals; | ||
timer_ = node->create_wall_timer(1s, | ||
[node, pub]() { | ||
// Create string message | ||
auto msg = std_msgs::msg::String(); | ||
msg.data = "Hello world"; | ||
|
||
// Warn with this node's name (to test logging) | ||
RCLCPP_WARN(node->get_logger(), "Publishing"); | ||
|
||
// Publish message | ||
pub->publish(msg); | ||
}); | ||
} | ||
|
||
GZ_REGISTER_SYSTEM_PLUGIN(CreateBeforeInit) |
Oops, something went wrong.