This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ROBOTIS-Platform/develop
Added lifecycle and action examples
- Loading branch information
Showing
32 changed files
with
1,195 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Changelog for package examples_lifecycle | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
1.1.0 (2019-10-07) | ||
------------------ | ||
* Added example package for lifecycle | ||
* Contributors: Darby Lim | ||
|
||
1.0.0 (2019-08-05) | ||
------------------ | ||
* None | ||
|
||
0.1.0 (2019-05-15) | ||
------------------ | ||
* None |
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,69 @@ | ||
################################################################################ | ||
# Set minimum required version of cmake, project name and compile options | ||
################################################################################ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(examples_lifecycle) | ||
|
||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 14) | ||
endif() | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
################################################################################ | ||
# Find and load build settings from external packages | ||
################################################################################ | ||
find_package(ament_cmake REQUIRED) | ||
find_package(lifecycle_msgs REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(rclcpp_lifecycle REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
|
||
################################################################################ | ||
# Build | ||
################################################################################ | ||
include_directories( | ||
include | ||
) | ||
|
||
set(LIFECYCLE_NODE_NAME robot) | ||
|
||
set(dependencies | ||
"lifecycle_msgs" | ||
"rclcpp" | ||
"rclcpp_lifecycle" | ||
"std_msgs" | ||
) | ||
|
||
add_executable(${LIFECYCLE_NODE_NAME} src/main.cpp src/robot.cpp) | ||
ament_target_dependencies(${LIFECYCLE_NODE_NAME} ${dependencies}) | ||
|
||
################################################################################ | ||
# Install | ||
################################################################################ | ||
install(TARGETS | ||
${LIFECYCLE_NODE_NAME} | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
install(DIRECTORY launch | ||
DESTINATION share/${PROJECT_NAME} | ||
) | ||
|
||
################################################################################ | ||
# Test | ||
################################################################################ | ||
if(BUILD_TESTING) | ||
find_package(ament_cmake_pytest REQUIRED) | ||
find_package(ament_cmake_gtest REQUIRED) | ||
find_package(ament_lint_auto REQUIRED) | ||
ament_lint_auto_find_test_dependencies() | ||
endif() | ||
|
||
################################################################################ | ||
# Macro for ament package | ||
################################################################################ | ||
ament_export_include_directories(include) | ||
ament_package() |
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 @@ | ||
https://design.ros2.org/articles/node_lifecycle.html |
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,89 @@ | ||
/******************************************************************************* | ||
* Copyright 2019 ROBOTIS CO., LTD. | ||
* | ||
* 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. | ||
*******************************************************************************/ | ||
|
||
/* Authors: Darby Lim */ | ||
|
||
#ifndef EXAMPLES_LIFECYCLE_ROBOT_HPP_ | ||
#define EXAMPLES_LIFECYCLE_ROBOT_HPP_ | ||
|
||
// Load smart pointer | ||
#include <memory> | ||
// Load std::string | ||
#include <string> | ||
// Load move, forward, tuple and etc (https://en.cppreference.com/w/cpp/header/utility) | ||
#include <utility> | ||
// Load change_state service in lifecycle_msgs | ||
#include <lifecycle_msgs/srv/change_state.hpp> | ||
// Load RCLCPP Lifecycle Node Library (https://github.com/ros2/rclcpp/tree/master/rclcpp_lifecycle) | ||
#include <rclcpp_lifecycle/lifecycle_node.hpp> | ||
// Load string message in std_msgs | ||
#include <std_msgs/msg/string.hpp> | ||
|
||
|
||
using LifecycleReturn = | ||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn; | ||
|
||
namespace robotis | ||
{ | ||
class Robot : public rclcpp_lifecycle::LifecycleNode | ||
{ | ||
public: | ||
// 'explicit' makes block data conversion | ||
explicit Robot(const bool & auto_activate); | ||
|
||
// Specify overriding functions | ||
LifecycleReturn on_configure(const rclcpp_lifecycle::State &) override; | ||
LifecycleReturn on_activate(const rclcpp_lifecycle::State &) override; | ||
LifecycleReturn on_deactivate(const rclcpp_lifecycle::State &) override; | ||
LifecycleReturn on_cleanup(const rclcpp_lifecycle::State &) override; | ||
LifecycleReturn on_shutdown(const rclcpp_lifecycle::State &) override; | ||
|
||
private: | ||
// Get all parameters when you set in launch file or yaml | ||
void get_parameters(); | ||
|
||
// Initialization robot | ||
void plugin_robot(); | ||
|
||
// Shutdown robot | ||
void unplug_robot(); | ||
|
||
// Declare status of robot | ||
void run(); | ||
|
||
// Declare status of robot | ||
void stop(); | ||
|
||
// Declare robot name. This variable will be set by parameters | ||
std::string robot_name_; | ||
|
||
// Declare robot state. This variable will be changed by lifecycle state | ||
std::string robot_state_; | ||
|
||
// Declare topic message as unique pointer | ||
std::unique_ptr<std_msgs::msg::String> msg_; | ||
|
||
// Declare publisher as shared pointer | ||
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<std_msgs::msg::String>> pub_; | ||
|
||
// Declare timer to publish data periodically | ||
rclcpp::TimerBase::SharedPtr timer_; | ||
|
||
// Declare client to change state | ||
std::shared_ptr<rclcpp::Client<lifecycle_msgs::srv::ChangeState>> client_change_state_; | ||
}; | ||
} // robotis | ||
#endif // EXAMPLES_LIFECYCLE_ROBOT_HPP_ |
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 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2019 ROBOTIS CO., LTD. | ||
# | ||
# 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. | ||
# | ||
# Authors: Darby Lim | ||
|
||
from launch import LaunchDescription | ||
from launch.actions import DeclareLaunchArgument | ||
from launch.actions import LogInfo | ||
from launch.substitutions import LaunchConfiguration | ||
from launch_ros.actions import Node | ||
|
||
|
||
def generate_launch_description(): | ||
auto_activate = LaunchConfiguration('auto_activate', default='False') | ||
namespace = LaunchConfiguration('ns', default='example') | ||
|
||
return LaunchDescription([ | ||
LogInfo(msg=['Execute lifecycle node!!']), | ||
|
||
DeclareLaunchArgument( | ||
'auto_activate', | ||
default_value=auto_activate, | ||
description='Specifying auto activate node'), | ||
|
||
DeclareLaunchArgument( | ||
'ns', | ||
default_value=namespace, | ||
description='Specifying namespace to node'), | ||
|
||
Node( | ||
node_namespace=namespace, | ||
package='examples_lifecycle', | ||
node_executable='robot', | ||
parameters=[{'robot_name': 'C3PO'}], | ||
arguments=['-a', auto_activate], | ||
output='screen'), | ||
]) |
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,20 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>examples_lifecycle</name> | ||
<version>1.1.0</version> | ||
<description> | ||
Examples of ROS 2 RCLCPP Lifecycle nodes | ||
</description> | ||
<author email="thlim@robotis.com">Darby Lim</author> | ||
<maintainer email="pyo@robotis.com">Pyo</maintainer> | ||
<license>Apache 2.0</license> | ||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<depend>lifecycle_msgs</depend> | ||
<depend>rclcpp</depend> | ||
<depend>rclcpp_lifecycle</depend> | ||
<depend>std_msgs</depend> | ||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
Oops, something went wrong.