-
Notifications
You must be signed in to change notification settings - Fork 354
Add pluginlib tutorial code #430
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
base: rolling
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Changelog for package polygon_base | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
| project(polygon_base) | ||
|
|
||
| if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
| add_compile_options(-Wall -Wextra -Wpedantic) | ||
| endif() | ||
|
|
||
| # find dependencies | ||
| find_package(ament_cmake REQUIRED) | ||
| find_package(ament_cmake_ros REQUIRED) | ||
| find_package(pluginlib REQUIRED) | ||
|
|
||
| add_library(polygon_base INTERFACE) | ||
| add_library(polygon_base::polygon_base ALIAS polygon_base) | ||
| target_compile_features(polygon_base INTERFACE c_std_99 cxx_std_17) # Require C99 and C++17 | ||
| target_include_directories(polygon_base INTERFACE | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:include/${PROJECT_NAME}>) | ||
mini-1235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| target_link_libraries( | ||
| polygon_base INTERFACE | ||
| ${pluginlib_TARGETS} | ||
| ) | ||
|
|
||
| install( | ||
| DIRECTORY include/ | ||
| DESTINATION include/${PROJECT_NAME} | ||
| ) | ||
| install( | ||
| TARGETS polygon_base | ||
| EXPORT export_${PROJECT_NAME} | ||
| ARCHIVE DESTINATION lib | ||
| LIBRARY DESTINATION lib | ||
| RUNTIME DESTINATION bin | ||
| ) | ||
|
|
||
| if(BUILD_TESTING) | ||
| find_package(ament_lint_auto REQUIRED) | ||
| # the following line skips the linter which checks for copyrights | ||
| # comment the line when a copyright and license is added to all source files | ||
| set(ament_cmake_copyright_FOUND TRUE) | ||
| # the following line skips cpplint (only works in a git repo) | ||
| # comment the line when this package is in a git repo and when | ||
| # a copyright and license is added to all source files | ||
| set(ament_cmake_cpplint_FOUND TRUE) | ||
|
||
| ament_lint_auto_find_test_dependencies() | ||
| endif() | ||
|
|
||
| ament_export_include_directories( | ||
| "include/${PROJECT_NAME}" | ||
| ) | ||
| ament_export_targets( | ||
| export_${PROJECT_NAME} | ||
| ) | ||
|
|
||
| ament_package() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright 2025 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 POLYGON_BASE__REGULAR_POLYGON_HPP_ | ||
| #define POLYGON_BASE__REGULAR_POLYGON_HPP_ | ||
|
|
||
| namespace polygon_base | ||
| { | ||
| class RegularPolygon | ||
| { | ||
| public: | ||
| virtual void initialize(double side_length) = 0; | ||
| virtual double area() = 0; | ||
| virtual ~RegularPolygon() {} | ||
|
|
||
| protected: | ||
| RegularPolygon() {} | ||
| }; | ||
| } // namespace polygon_base | ||
|
|
||
| #endif // POLYGON_BASE__REGULAR_POLYGON_HPP_ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?xml version="1.0"?> | ||
| <?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
| <package format="2"> | ||
| <name>polygon_base</name> | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I rename the package?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you want to do that? and into what name? and if we do that, probably the tutorial in the documentation should be changed accordingly to keep the consistency?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that other packages are prefixed with example_rclcpp, that's why I am asking if it is required to rename it |
||
| <version>0.21.3</version> | ||
| <description>Examples of polygon base</description> | ||
|
||
|
|
||
| <maintainer email="aditya.pande@openrobotics.org">Aditya Pande</maintainer> | ||
mini-1235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <maintainer email="alejandro@openrobotics.org">Alejandro Hernandez Cordero</maintainer> | ||
|
|
||
| <license>Apache License 2.0</license> | ||
|
|
||
| <author email="jacob@openrobotics.org">Jacob Perron</author> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can add yourself here |
||
| <author>Mikael Arguedas</author> | ||
| <author>Morgan Quigley</author> | ||
| <author email="sloretz@openrobotics.org">Shane Loretz</author> | ||
mini-1235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <buildtool_depend>ament_cmake_ros</buildtool_depend> | ||
|
|
||
| <depend>pluginlib</depend> | ||
|
|
||
| <test_depend>ament_lint_auto</test_depend> | ||
| <test_depend>ament_lint_common</test_depend> | ||
|
|
||
| <export> | ||
| <build_type>ament_cmake</build_type> | ||
| </export> | ||
| </package> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. i think this should be generated by release tool. |
||
| Changelog for package polygon_plugins | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
| project(polygon_plugins) | ||
|
|
||
| if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
| add_compile_options(-Wall -Wextra -Wpedantic) | ||
| endif() | ||
|
|
||
| # find dependencies | ||
| find_package(ament_cmake REQUIRED) | ||
| find_package(polygon_base REQUIRED) | ||
| find_package(pluginlib REQUIRED) | ||
|
|
||
| add_library(polygon_plugins SHARED | ||
| src/polygon_plugins.cpp | ||
| ) | ||
| target_compile_features(polygon_plugins PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 | ||
| target_include_directories(polygon_plugins PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:include>) | ||
mini-1235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| target_link_libraries(polygon_plugins PUBLIC | ||
| ${polygon_base_TARGETS} | ||
| ${pluginlib_TARGETS} | ||
| ) | ||
|
|
||
| add_executable(area_node src/area_node.cpp) | ||
| target_include_directories(area_node PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:include/${PROJECT_NAME}>) | ||
mini-1235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| target_compile_features(area_node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 | ||
| target_link_libraries( | ||
| area_node | ||
| ${polygon_base_TARGETS} | ||
| ${pluginlib_TARGETS} | ||
| ) | ||
|
|
||
| install( | ||
| TARGETS polygon_plugins | ||
| EXPORT export_${PROJECT_NAME} | ||
| ARCHIVE DESTINATION lib | ||
| LIBRARY DESTINATION lib | ||
| RUNTIME DESTINATION bin) | ||
| install(TARGETS area_node | ||
| DESTINATION lib/${PROJECT_NAME}) | ||
|
|
||
| if(BUILD_TESTING) | ||
| find_package(ament_lint_auto REQUIRED) | ||
| # the following line skips the linter which checks for copyrights | ||
| # comment the line when a copyright and license is added to all source files | ||
| set(ament_cmake_copyright_FOUND TRUE) | ||
| # the following line skips cpplint (only works in a git repo) | ||
| # comment the line when this package is in a git repo and when | ||
| # a copyright and license is added to all source files | ||
| set(ament_cmake_cpplint_FOUND TRUE) | ||
mini-1235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ament_lint_auto_find_test_dependencies() | ||
| endif() | ||
|
|
||
| pluginlib_export_plugin_description_file(polygon_base plugins.xml) | ||
| ament_package() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright 2025 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 POLYGON_PLUGINS__POLYGON_PLUGINS_HPP_ | ||
| #define POLYGON_PLUGINS__POLYGON_PLUGINS_HPP_ | ||
|
|
||
| namespace polygon_plugins | ||
| { | ||
|
|
||
| class PolygonPlugins | ||
| { | ||
| public: | ||
| PolygonPlugins(); | ||
|
|
||
| virtual ~PolygonPlugins(); | ||
| }; | ||
|
|
||
| } // namespace polygon_plugins | ||
mini-1235 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #endif // POLYGON_PLUGINS__POLYGON_PLUGINS_HPP_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?xml version="1.0"?> | ||
| <?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
| <package format="2"> | ||
| <name>polygon_plugins</name> | ||
| <version>0.21.3</version> | ||
| <description>Example of polygon plugins</description> | ||
|
||
|
|
||
| <maintainer email="aditya.pande@openrobotics.org">Aditya Pande</maintainer> | ||
| <maintainer email="alejandro@openrobotics.org">Alejandro Hernandez Cordero</maintainer> | ||
mini-1235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <license>Apache License 2.0</license> | ||
|
|
||
| <author email="jacob@openrobotics.org">Jacob Perron</author> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add yourself as the author |
||
| <author>Mikael Arguedas</author> | ||
| <author>Morgan Quigley</author> | ||
| <author email="sloretz@openrobotics.org">Shane Loretz</author> | ||
mini-1235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <buildtool_depend>ament_cmake_ros</buildtool_depend> | ||
|
|
||
| <depend>polygon_base</depend> | ||
| <depend>pluginlib</depend> | ||
|
|
||
| <test_depend>ament_lint_auto</test_depend> | ||
| <test_depend>ament_lint_common</test_depend> | ||
|
|
||
| <export> | ||
| <build_type>ament_cmake</build_type> | ||
| </export> | ||
| </package> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <library path="polygon_plugins"> | ||
| <class type="polygon_plugins::Square" base_class_type="polygon_base::RegularPolygon"> | ||
| <description>This is a square plugin.</description> | ||
| </class> | ||
| <class type="polygon_plugins::Triangle" base_class_type="polygon_base::RegularPolygon" name="awesome_triangle"> | ||
| <description>This is a triangle plugin.</description> | ||
| </class> | ||
| </library> | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright 2025 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 <pluginlib/class_loader.hpp> | ||
| #include <polygon_base/regular_polygon.hpp> | ||
|
|
||
| int main(int argc, char ** argv) | ||
| { | ||
| // To avoid unused parameter warnings | ||
| (void) argc; | ||
| (void) argv; | ||
|
|
||
| pluginlib::ClassLoader<polygon_base::RegularPolygon> poly_loader("polygon_base", | ||
| "polygon_base::RegularPolygon"); | ||
|
|
||
| try { | ||
| std::shared_ptr<polygon_base::RegularPolygon> triangle = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include |
||
| poly_loader.createSharedInstance("awesome_triangle"); | ||
| triangle->initialize(10.0); | ||
|
|
||
| std::shared_ptr<polygon_base::RegularPolygon> square = | ||
| poly_loader.createSharedInstance("polygon_plugins::Square"); | ||
| square->initialize(10.0); | ||
|
|
||
| printf("Triangle area: %.2f\n", triangle->area()); | ||
| printf("Square area: %.2f\n", square->area()); | ||
| } catch(pluginlib::PluginlibException & ex) { | ||
| printf("The plugin failed to load for some reason. Error: %s\n", ex.what()); | ||
mini-1235 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright 2025 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 <cmath> | ||
| #include <polygon_base/regular_polygon.hpp> | ||
|
|
||
| namespace polygon_plugins | ||
| { | ||
| class Square : public polygon_base::RegularPolygon | ||
| { | ||
| public: | ||
| void initialize(double side_length) override | ||
| { | ||
| side_length_ = side_length; | ||
| } | ||
|
|
||
| double area() override | ||
| { | ||
| return side_length_ * side_length_; | ||
| } | ||
|
|
||
| protected: | ||
| double side_length_; | ||
| }; | ||
|
|
||
| class Triangle : public polygon_base::RegularPolygon | ||
| { | ||
| public: | ||
| void initialize(double side_length) override | ||
| { | ||
| side_length_ = side_length; | ||
| } | ||
|
|
||
| double area() override | ||
| { | ||
| return 0.5 * side_length_ * getHeight(); | ||
| } | ||
|
|
||
| double getHeight() | ||
| { | ||
| return sqrt((side_length_ * side_length_) - ((side_length_ / 2) * (side_length_ / 2))); | ||
| } | ||
|
|
||
| protected: | ||
| double side_length_; | ||
| }; | ||
| } // namespace polygon_plugins | ||
|
|
||
| #include <pluginlib/class_list_macros.hpp> | ||
|
|
||
| PLUGINLIB_EXPORT_CLASS(polygon_plugins::Square, polygon_base::RegularPolygon) | ||
| PLUGINLIB_EXPORT_CLASS(polygon_plugins::Triangle, polygon_base::RegularPolygon) |
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.
Is this supposed to be during release process? we are planning to release this package, correct?