feat: add all code
This commit is contained in:
70
chapt10/chapt10_ws/.vscode/settings.json
vendored
Normal file
70
chapt10/chapt10_ws/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"bitset": "cpp",
|
||||
"chrono": "cpp",
|
||||
"compare": "cpp",
|
||||
"complex": "cpp",
|
||||
"concepts": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"semaphore": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeindex": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
}
|
||||
}
|
||||
2729
chapt10/chapt10_ws/pub5_sub5_2M.txt
Normal file
2729
chapt10/chapt10_ws/pub5_sub5_2M.txt
Normal file
File diff suppressed because it is too large
Load Diff
24
chapt10/chapt10_ws/shm.xml
Normal file
24
chapt10/chapt10_ws/shm.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
|
||||
|
||||
<data_writer profile_name="default publisher profile" is_default_profile="true">
|
||||
<qos>
|
||||
<publishMode>
|
||||
<kind>SYNCHRONOUS</kind>
|
||||
</publishMode>
|
||||
<data_sharing>
|
||||
<kind>AUTOMATIC</kind>
|
||||
</data_sharing>
|
||||
</qos>
|
||||
<historyMemoryPolicy>DYNAMIC</historyMemoryPolicy>
|
||||
</data_writer>
|
||||
|
||||
<data_reader profile_name="default subscription profile" is_default_profile="true">
|
||||
<qos>
|
||||
<data_sharing>
|
||||
<kind>AUTOMATIC</kind>
|
||||
</data_sharing>
|
||||
</qos>
|
||||
<historyMemoryPolicy>DYNAMIC</historyMemoryPolicy>
|
||||
</data_reader>
|
||||
</profiles>
|
||||
56
chapt10/chapt10_ws/src/learn_compose/CMakeLists.txt
Normal file
56
chapt10/chapt10_ws/src/learn_compose/CMakeLists.txt
Normal file
@@ -0,0 +1,56 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(learn_compose)
|
||||
|
||||
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)
|
||||
# uncomment the following section in order to fill in
|
||||
# further dependencies manually.
|
||||
# find_package(<dependency> REQUIRED)
|
||||
|
||||
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()
|
||||
|
||||
find_package(rclcpp REQUIRED)
|
||||
find_package(std_msgs REQUIRED)
|
||||
find_package(rclcpp_components REQUIRED)
|
||||
include_directories(include)
|
||||
add_executable(intra_process_pubsub
|
||||
src/intra_process_pubsub.cpp
|
||||
src/talker.cpp
|
||||
src/listener.cpp
|
||||
)
|
||||
ament_target_dependencies(intra_process_pubsub std_msgs rclcpp rclcpp_components)
|
||||
|
||||
install(TARGETS intra_process_pubsub
|
||||
DESTINATION lib/${PROJECT_NAME})
|
||||
|
||||
|
||||
find_package(rclcpp_components REQUIRED)
|
||||
add_library(talker_component SHARED src/talker.cpp)
|
||||
ament_target_dependencies(talker_component "std_msgs" "rclcpp" "rclcpp_components")
|
||||
rclcpp_components_register_nodes(talker_component "learn_compose::Talker")
|
||||
|
||||
add_library(listener_component SHARED src/listener.cpp)
|
||||
ament_target_dependencies(listener_component "std_msgs" "rclcpp" "rclcpp_components")
|
||||
rclcpp_components_register_nodes(listener_component "learn_compose::Listener")
|
||||
|
||||
install(TARGETS talker_component listener_component
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
|
||||
ament_package()
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef LEARN_COMPOSE__LISTENER_COMPONENT_HPP_
|
||||
#define LEARN_COMPOSE__LISTENER_COMPONENT_HPP_
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "std_msgs/msg/int32.hpp"
|
||||
|
||||
namespace learn_compose {
|
||||
|
||||
class Listener : public rclcpp::Node {
|
||||
public:
|
||||
explicit Listener(const rclcpp::NodeOptions &options);
|
||||
|
||||
private:
|
||||
rclcpp::Subscription<std_msgs::msg::Int32>::SharedPtr sub_;
|
||||
};
|
||||
|
||||
} // namespace learn_compose
|
||||
|
||||
#endif // LEARN_COMPOSE__LISTENER_COMPONENT_HPP_
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef LEARN_COMPOSE__TALKER_COMPONENT_HPP_
|
||||
#define LEARN_COMPOSE__TALKER_COMPONENT_HPP_
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "std_msgs/msg/int32.hpp"
|
||||
|
||||
namespace learn_compose {
|
||||
|
||||
class Talker : public rclcpp::Node {
|
||||
public:
|
||||
explicit Talker(const rclcpp::NodeOptions &options);
|
||||
|
||||
private:
|
||||
int32_t count_;
|
||||
rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr pub_;
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
};
|
||||
|
||||
} // namespace learn_compose
|
||||
|
||||
#endif // LEARN_COMPOSE__TALKER_COMPONENT_HPP_
|
||||
18
chapt10/chapt10_ws/src/learn_compose/package.xml
Normal file
18
chapt10/chapt10_ws/src/learn_compose/package.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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>learn_compose</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "learn_compose/listener.hpp"
|
||||
#include "learn_compose/talker.hpp"
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
rclcpp::init(argc, argv);
|
||||
rclcpp::executors::SingleThreadedExecutor executor;
|
||||
|
||||
rclcpp::NodeOptions options; // 创建节点选项
|
||||
options.use_intra_process_comms(true); // 使用进程内通信
|
||||
auto talker = std::make_shared<learn_compose::Talker>(options);
|
||||
auto listener = std::make_shared<learn_compose::Listener>(options);
|
||||
|
||||
executor.add_node(talker);
|
||||
executor.add_node(listener);
|
||||
executor.spin();
|
||||
|
||||
rclcpp::shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
20
chapt10/chapt10_ws/src/learn_compose/src/listener.cpp
Normal file
20
chapt10/chapt10_ws/src/learn_compose/src/listener.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "learn_compose/listener.hpp"
|
||||
#include <chrono>
|
||||
|
||||
namespace learn_compose {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
Listener::Listener(const rclcpp::NodeOptions &options)
|
||||
: Node("listener", options) {
|
||||
sub_ = this->create_subscription<std_msgs::msg::Int32>(
|
||||
"count", 10, [&](const std_msgs::msg::Int32::UniquePtr msg) {
|
||||
RCLCPP_INFO(this->get_logger(), "收到数据:%d(0x%lX)", msg->data,
|
||||
reinterpret_cast<std::uintptr_t>(msg.get()));
|
||||
});
|
||||
}
|
||||
} // namespace learn_compose
|
||||
|
||||
|
||||
#include "rclcpp_components/register_node_macro.hpp"
|
||||
RCLCPP_COMPONENTS_REGISTER_NODE(learn_compose::Listener)
|
||||
24
chapt10/chapt10_ws/src/learn_compose/src/talker.cpp
Normal file
24
chapt10/chapt10_ws/src/learn_compose/src/talker.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <chrono>
|
||||
#include "learn_compose/talker.hpp"
|
||||
|
||||
namespace learn_compose {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
Talker::Talker(const rclcpp::NodeOptions &options) : Node("talker", options) {
|
||||
pub_ = this->create_publisher<std_msgs::msg::Int32>("count", 10);
|
||||
auto callback = [&]() -> void {
|
||||
std_msgs::msg::Int32::UniquePtr msg(new std_msgs::msg::Int32());
|
||||
msg->data = count_++;
|
||||
RCLCPP_INFO(this->get_logger(), "发布数据:%d(0x%lX)", msg->data,
|
||||
reinterpret_cast<std::uintptr_t>(msg.get()));
|
||||
pub_->publish(std::move(msg));
|
||||
};
|
||||
timer_ = this->create_wall_timer(1s, callback);
|
||||
}
|
||||
} // namespace learn_compose
|
||||
|
||||
|
||||
|
||||
#include "rclcpp_components/register_node_macro.hpp"
|
||||
RCLCPP_COMPONENTS_REGISTER_NODE(learn_compose::Talker)
|
||||
36
chapt10/chapt10_ws/src/learn_dds_cpp/CMakeLists.txt
Normal file
36
chapt10/chapt10_ws/src/learn_dds_cpp/CMakeLists.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(learn_dds_cpp)
|
||||
|
||||
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(rclcpp REQUIRED)
|
||||
find_package(std_msgs REQUIRED)
|
||||
|
||||
|
||||
add_executable(shm_pub src/shm_pub.cpp)
|
||||
ament_target_dependencies(shm_pub
|
||||
rclcpp std_msgs
|
||||
)
|
||||
|
||||
install(TARGETS shm_pub
|
||||
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)
|
||||
ament_lint_auto_find_test_dependencies()
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
ament_package()
|
||||
21
chapt10/chapt10_ws/src/learn_dds_cpp/package.xml
Normal file
21
chapt10/chapt10_ws/src/learn_dds_cpp/package.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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>learn_dds_cpp</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<depend>rclcpp</depend>
|
||||
<depend>std_msgs</depend>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
30
chapt10/chapt10_ws/src/learn_dds_cpp/src/shm_pub.cpp
Normal file
30
chapt10/chapt10_ws/src/learn_dds_cpp/src/shm_pub.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "rclcpp/loaned_message.hpp"
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "std_msgs/msg/int32.hpp"
|
||||
|
||||
class LoanedMessagePublisher : public rclcpp::Node {
|
||||
public:
|
||||
LoanedMessagePublisher() : Node("loaned_message_publisher") {
|
||||
publisher_ =
|
||||
this->create_publisher<std_msgs::msg::Int32>("loaned_int_topic", 10);
|
||||
timer_ = this->create_wall_timer(std::chrono::seconds(1), [&]() {
|
||||
auto message = publisher_->borrow_loaned_message(); // 1.租借消息
|
||||
message.get().data = count_++; // 2.放入数据
|
||||
RCLCPP_INFO(this->get_logger(), "发布数据:%d", message.get().data);
|
||||
publisher_->publish(std::move(message)); // 3.发布数据
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr publisher_;
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
int32_t count_{0};
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
rclcpp::init(argc, argv);
|
||||
auto node = std::make_shared<LoanedMessagePublisher>();
|
||||
rclcpp::spin(node);
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
36
chapt10/chapt10_ws/src/learn_executor_cpp/CMakeLists.txt
Normal file
36
chapt10/chapt10_ws/src/learn_executor_cpp/CMakeLists.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(learn_executor_cpp)
|
||||
|
||||
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)
|
||||
# uncomment the following section in order to fill in
|
||||
# further dependencies manually.
|
||||
# find_package(<dependency> REQUIRED)
|
||||
|
||||
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()
|
||||
|
||||
find_package(rclcpp REQUIRED)
|
||||
find_package(example_interfaces REQUIRED)
|
||||
find_package(std_msgs REQUIRED)
|
||||
|
||||
add_executable(learn_executor src/learn_executor.cpp)
|
||||
ament_target_dependencies(learn_executor rclcpp example_interfaces std_msgs)
|
||||
|
||||
install(TARGETS learn_executor
|
||||
DESTINATION lib/${PROJECT_NAME})
|
||||
|
||||
ament_package()
|
||||
18
chapt10/chapt10_ws/src/learn_executor_cpp/package.xml
Normal file
18
chapt10/chapt10_ws/src/learn_executor_cpp/package.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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>learn_executor_cpp</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "example_interfaces/srv/add_two_ints.hpp"
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "std_msgs/msg/string.hpp"
|
||||
#include <sstream>
|
||||
|
||||
class LearnExecutorNode : public rclcpp::Node {
|
||||
public:
|
||||
LearnExecutorNode() : Node("learn_executor") {
|
||||
publisher_ =
|
||||
this->create_publisher<std_msgs::msg::String>("string_topic", 10);
|
||||
timer_ = this->create_wall_timer(
|
||||
std::chrono::seconds(1),
|
||||
std::bind(&LearnExecutorNode::timer_callback, this));
|
||||
service_callback_group_ = this->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive); // 互斥回调组
|
||||
service_ = this->create_service<example_interfaces::srv::AddTwoInts>(
|
||||
"add_two_ints",
|
||||
std::bind(&LearnExecutorNode::add_two_ints_callback, this,
|
||||
std::placeholders::_1, std::placeholders::_2),
|
||||
rmw_qos_profile_services_default, service_callback_group_);
|
||||
}
|
||||
|
||||
private:
|
||||
void timer_callback() {
|
||||
auto msg = std_msgs::msg::String();
|
||||
msg.data = "话题发布:" + thread_info();
|
||||
RCLCPP_INFO(this->get_logger(), msg.data.c_str());
|
||||
publisher_->publish(msg);
|
||||
}
|
||||
|
||||
std::string thread_info() {
|
||||
std::ostringstream thread_str;
|
||||
thread_str << "线程ID:" << std::this_thread::get_id();
|
||||
return thread_str.str();
|
||||
}
|
||||
|
||||
void add_two_ints_callback(
|
||||
const std::shared_ptr<example_interfaces::srv::AddTwoInts::Request>
|
||||
request,
|
||||
std::shared_ptr<example_interfaces::srv::AddTwoInts::Response> response) {
|
||||
RCLCPP_INFO(this->get_logger(), "服务开始处理:%s", thread_info().c_str());
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
response->sum = request->a + request->b;
|
||||
RCLCPP_INFO(this->get_logger(), "服务处理完成:%s", thread_info().c_str());
|
||||
}
|
||||
|
||||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
rclcpp::Service<example_interfaces::srv::AddTwoInts>::SharedPtr service_;
|
||||
rclcpp::CallbackGroup::SharedPtr service_callback_group_;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
rclcpp::init(argc, argv);
|
||||
auto node = std::make_shared<LearnExecutorNode>();
|
||||
// auto executor = rclcpp::executors::SingleThreadedExecutor();
|
||||
auto executor = rclcpp::executors::MultiThreadedExecutor();
|
||||
executor.add_node(node);
|
||||
executor.spin();
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
from rclpy.executors import MultiThreadedExecutor, SingleThreadedExecutor
|
||||
from rclpy.callback_groups import MutuallyExclusiveCallbackGroup, ReentrantCallbackGroup
|
||||
from std_msgs.msg import String
|
||||
from example_interfaces.srv import AddTwoInts
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
||||
class LearnExecutorNode(Node):
|
||||
def __init__(self):
|
||||
super().__init__('learn_executor')
|
||||
self.publisher = self.create_publisher(String, 'string_topic', 10)
|
||||
self.timer = self.create_timer(1.0, self.timer_callback)
|
||||
my_callback_group = ReentrantCallbackGroup()
|
||||
self.service = self.create_service(
|
||||
AddTwoInts, 'add_two_ints', self.add_two_ints_callback,
|
||||
callback_group=my_callback_group)
|
||||
# self.service = self.create_service(
|
||||
# AddTwoInts, 'add_two_ints', self.add_two_ints_callback)
|
||||
|
||||
def timer_callback(self):
|
||||
msg = String()
|
||||
msg.data = f'话题发布,线程ID:{threading.get_ident()} 线程总数:{threading.active_count()}'
|
||||
self.get_logger().info(msg.data)
|
||||
self.publisher.publish(msg)
|
||||
|
||||
def add_two_ints_callback(self, request: AddTwoInts.Request, response: AddTwoInts.Response):
|
||||
self.get_logger().info(f'处理服务,线程ID:{threading.get_ident()}')
|
||||
time.sleep(10) # 模拟处理延时
|
||||
response.sum = request.a + request.b
|
||||
self.get_logger().info(f'处理完成,线程ID:{threading.get_ident()}')
|
||||
return response
|
||||
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
node = LearnExecutorNode()
|
||||
# executor = SingleThreadedExecutor()
|
||||
executor = MultiThreadedExecutor()
|
||||
executor.add_node(node)
|
||||
executor.spin()
|
||||
rclpy.shutdown()
|
||||
18
chapt10/chapt10_ws/src/learn_executor_py/package.xml
Normal file
18
chapt10/chapt10_ws/src/learn_executor_py/package.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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>learn_executor_py</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<test_depend>ament_copyright</test_depend>
|
||||
<test_depend>ament_flake8</test_depend>
|
||||
<test_depend>ament_pep257</test_depend>
|
||||
<test_depend>python3-pytest</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_python</build_type>
|
||||
</export>
|
||||
</package>
|
||||
4
chapt10/chapt10_ws/src/learn_executor_py/setup.cfg
Normal file
4
chapt10/chapt10_ws/src/learn_executor_py/setup.cfg
Normal file
@@ -0,0 +1,4 @@
|
||||
[develop]
|
||||
script_dir=$base/lib/learn_executor_py
|
||||
[install]
|
||||
install_scripts=$base/lib/learn_executor_py
|
||||
26
chapt10/chapt10_ws/src/learn_executor_py/setup.py
Normal file
26
chapt10/chapt10_ws/src/learn_executor_py/setup.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
package_name = 'learn_executor_py'
|
||||
|
||||
setup(
|
||||
name=package_name,
|
||||
version='0.0.0',
|
||||
packages=find_packages(exclude=['test']),
|
||||
data_files=[
|
||||
('share/ament_index/resource_index/packages',
|
||||
['resource/' + package_name]),
|
||||
('share/' + package_name, ['package.xml']),
|
||||
],
|
||||
install_requires=['setuptools'],
|
||||
zip_safe=True,
|
||||
maintainer='fishros',
|
||||
maintainer_email='87068644+fishros@users.noreply.github.com',
|
||||
description='TODO: Package description',
|
||||
license='TODO: License declaration',
|
||||
tests_require=['pytest'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'learn_executor=learn_executor_py.learn_executor:main'
|
||||
],
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
from ament_copyright.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
# Remove the `skip` decorator once the source file(s) have a copyright header
|
||||
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
|
||||
@pytest.mark.copyright
|
||||
@pytest.mark.linter
|
||||
def test_copyright():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found errors'
|
||||
25
chapt10/chapt10_ws/src/learn_executor_py/test/test_flake8.py
Normal file
25
chapt10/chapt10_ws/src/learn_executor_py/test/test_flake8.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Copyright 2017 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.
|
||||
|
||||
from ament_flake8.main import main_with_errors
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.flake8
|
||||
@pytest.mark.linter
|
||||
def test_flake8():
|
||||
rc, errors = main_with_errors(argv=[])
|
||||
assert rc == 0, \
|
||||
'Found %d code style errors / warnings:\n' % len(errors) + \
|
||||
'\n'.join(errors)
|
||||
23
chapt10/chapt10_ws/src/learn_executor_py/test/test_pep257.py
Normal file
23
chapt10/chapt10_ws/src/learn_executor_py/test/test_pep257.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
from ament_pep257.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.linter
|
||||
@pytest.mark.pep257
|
||||
def test_pep257():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found code style errors / warnings'
|
||||
@@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(learn_lifecyclenode_cpp)
|
||||
|
||||
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(rclcpp REQUIRED)
|
||||
find_package(rclcpp_lifecycle REQUIRED)
|
||||
|
||||
add_executable(learn_lifecyclenode src/learn_lifecyclenode.cpp)
|
||||
ament_target_dependencies(learn_lifecyclenode
|
||||
rclcpp rclcpp_lifecycle
|
||||
)
|
||||
|
||||
install(TARGETS learn_lifecyclenode
|
||||
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)
|
||||
ament_lint_auto_find_test_dependencies()
|
||||
endif()
|
||||
|
||||
ament_package()
|
||||
21
chapt10/chapt10_ws/src/learn_lifecyclenode_cpp/package.xml
Normal file
21
chapt10/chapt10_ws/src/learn_lifecyclenode_cpp/package.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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>learn_lifecyclenode_cpp</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<depend>rclcpp</depend>
|
||||
<depend>rclcpp_lifecycle</depend>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "rclcpp_lifecycle/lifecycle_node.hpp"
|
||||
|
||||
using CallbackReturn =
|
||||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
|
||||
|
||||
class LearnLifeCycleNode : public rclcpp_lifecycle::LifecycleNode {
|
||||
public:
|
||||
LearnLifeCycleNode()
|
||||
: rclcpp_lifecycle::LifecycleNode("lifecyclenode") {
|
||||
timer_period_ = 1.0;
|
||||
timer_ = nullptr;
|
||||
RCLCPP_INFO(get_logger(), "%s: 已创建", get_name());
|
||||
}
|
||||
|
||||
CallbackReturn on_configure(const rclcpp_lifecycle::State &state) override {
|
||||
(void)state;
|
||||
timer_period_ = 1.0;
|
||||
RCLCPP_INFO(get_logger(), "on_configure():配置周期 timer_period");
|
||||
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::
|
||||
CallbackReturn::SUCCESS;
|
||||
}
|
||||
|
||||
CallbackReturn on_activate(const rclcpp_lifecycle::State &state) override {
|
||||
(void)state;
|
||||
timer_ = create_wall_timer(
|
||||
std::chrono::seconds(static_cast<int>(timer_period_)),
|
||||
[this]() { RCLCPP_INFO(get_logger(), "定时器打印进行中..."); });
|
||||
RCLCPP_INFO(get_logger(), "on_activate():处理激活指令,创建定时器");
|
||||
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::
|
||||
CallbackReturn::SUCCESS;
|
||||
}
|
||||
|
||||
CallbackReturn on_deactivate(const rclcpp_lifecycle::State &state) override {
|
||||
(void)state;
|
||||
timer_.reset();
|
||||
RCLCPP_INFO(get_logger(), "on_deactivate():处理失活指令,停止定时器");
|
||||
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::
|
||||
CallbackReturn::SUCCESS;
|
||||
}
|
||||
|
||||
CallbackReturn on_shutdown(const rclcpp_lifecycle::State &state) override {
|
||||
(void)state;
|
||||
timer_.reset();
|
||||
RCLCPP_INFO(get_logger(), "on_shutdown():处理关闭指令");
|
||||
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::
|
||||
CallbackReturn::SUCCESS;
|
||||
}
|
||||
|
||||
private:
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
double timer_period_;
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
rclcpp::init(argc, argv);
|
||||
auto node = std::make_shared<LearnLifeCycleNode>();
|
||||
rclcpp::spin(node->get_node_base_interface());
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import rclpy
|
||||
from rclpy.lifecycle import LifecycleNode, TransitionCallbackReturn
|
||||
|
||||
class LearnLifeCycleNode(LifecycleNode):
|
||||
def __init__(self):
|
||||
super().__init__('lifecyclenode')
|
||||
self.timer_period = 0
|
||||
self.timer_ = None
|
||||
self.get_logger().info(f'{self.get_name()}:已创建')
|
||||
|
||||
def timer_callback(self):
|
||||
self.get_logger().info('定时器打印进行中...')
|
||||
|
||||
def on_configure(self, state):
|
||||
self.timer_period = 1.0 # 设置定时器周期
|
||||
self.get_logger().info('on_configure():配置周期 timer_period')
|
||||
return TransitionCallbackReturn.SUCCESS
|
||||
|
||||
def on_activate(self, state):
|
||||
self.timer_ = self.create_timer(self.timer_period, self.timer_callback)
|
||||
self.get_logger().info('on_activate():处理激活指令,创建定时器')
|
||||
return TransitionCallbackReturn.SUCCESS
|
||||
|
||||
def on_deactivate(self, state):
|
||||
self.destroy_timer(self.timer_) # 销毁定时器
|
||||
self.get_logger().info('on_deactivate():处理失活指令停止定时器')
|
||||
return TransitionCallbackReturn.SUCCESS
|
||||
|
||||
def on_cleanup(self, state):
|
||||
self.timer_ = None
|
||||
self.timer_period = 0
|
||||
self.get_logger().info('on_cleanup():处理清理指令')
|
||||
return TransitionCallbackReturn.SUCCESS
|
||||
|
||||
def on_shutdown(self, state):
|
||||
# 定时器未销毁则销毁
|
||||
if self.timer_: self.destroy_timer(self.timer_)
|
||||
self.get_logger().info('on_shutdown():处理关闭指令')
|
||||
return TransitionCallbackReturn.SUCCESS
|
||||
|
||||
def on_error(self, state):
|
||||
# 直接调用父类处理
|
||||
return super().on_error(state)
|
||||
|
||||
def main():
|
||||
rclpy.init()
|
||||
node = LearnLifeCycleNode()
|
||||
rclpy.spin(node)
|
||||
rclpy.shutdown()
|
||||
18
chapt10/chapt10_ws/src/learn_lifecyclenode_py/package.xml
Normal file
18
chapt10/chapt10_ws/src/learn_lifecyclenode_py/package.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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>learn_lifecyclenode_py</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<test_depend>ament_copyright</test_depend>
|
||||
<test_depend>ament_flake8</test_depend>
|
||||
<test_depend>ament_pep257</test_depend>
|
||||
<test_depend>python3-pytest</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_python</build_type>
|
||||
</export>
|
||||
</package>
|
||||
4
chapt10/chapt10_ws/src/learn_lifecyclenode_py/setup.cfg
Normal file
4
chapt10/chapt10_ws/src/learn_lifecyclenode_py/setup.cfg
Normal file
@@ -0,0 +1,4 @@
|
||||
[develop]
|
||||
script_dir=$base/lib/learn_lifecyclenode_py
|
||||
[install]
|
||||
install_scripts=$base/lib/learn_lifecyclenode_py
|
||||
26
chapt10/chapt10_ws/src/learn_lifecyclenode_py/setup.py
Normal file
26
chapt10/chapt10_ws/src/learn_lifecyclenode_py/setup.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
package_name = 'learn_lifecyclenode_py'
|
||||
|
||||
setup(
|
||||
name=package_name,
|
||||
version='0.0.0',
|
||||
packages=find_packages(exclude=['test']),
|
||||
data_files=[
|
||||
('share/ament_index/resource_index/packages',
|
||||
['resource/' + package_name]),
|
||||
('share/' + package_name, ['package.xml']),
|
||||
],
|
||||
install_requires=['setuptools'],
|
||||
zip_safe=True,
|
||||
maintainer='fishros',
|
||||
maintainer_email='87068644+fishros@users.noreply.github.com',
|
||||
description='TODO: Package description',
|
||||
license='TODO: License declaration',
|
||||
tests_require=['pytest'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'learn_lifecyclenode=learn_lifecyclenode_py.learn_lifecyclenode:main'
|
||||
],
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
from ament_copyright.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
# Remove the `skip` decorator once the source file(s) have a copyright header
|
||||
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
|
||||
@pytest.mark.copyright
|
||||
@pytest.mark.linter
|
||||
def test_copyright():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found errors'
|
||||
@@ -0,0 +1,25 @@
|
||||
# Copyright 2017 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.
|
||||
|
||||
from ament_flake8.main import main_with_errors
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.flake8
|
||||
@pytest.mark.linter
|
||||
def test_flake8():
|
||||
rc, errors = main_with_errors(argv=[])
|
||||
assert rc == 0, \
|
||||
'Found %d code style errors / warnings:\n' % len(errors) + \
|
||||
'\n'.join(errors)
|
||||
@@ -0,0 +1,23 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
from ament_pep257.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.linter
|
||||
@pytest.mark.pep257
|
||||
def test_pep257():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found code style errors / warnings'
|
||||
@@ -0,0 +1,35 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(learn_message_filter_cpp)
|
||||
|
||||
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(rclcpp REQUIRED)
|
||||
find_package(message_filters REQUIRED)
|
||||
find_package(nav_msgs REQUIRED)
|
||||
find_package(sensor_msgs REQUIRED)
|
||||
|
||||
add_executable(timesync_test src/timesync_test.cpp)
|
||||
ament_target_dependencies(timesync_test
|
||||
rclcpp message_filters nav_msgs sensor_msgs
|
||||
)
|
||||
|
||||
install(TARGETS timesync_test
|
||||
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)
|
||||
ament_lint_auto_find_test_dependencies()
|
||||
endif()
|
||||
|
||||
ament_package()
|
||||
23
chapt10/chapt10_ws/src/learn_message_filter_cpp/package.xml
Normal file
23
chapt10/chapt10_ws/src/learn_message_filter_cpp/package.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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>learn_message_filter_cpp</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<depend>rclcpp</depend>
|
||||
<depend>message_filters</depend>
|
||||
<depend>nav_msgs</depend>
|
||||
<depend>sensor_msgs</depend>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "message_filters/subscriber.h"
|
||||
#include "message_filters/sync_policies/approximate_time.h"
|
||||
#include "message_filters/sync_policies/exact_time.h"
|
||||
#include "message_filters/sync_policies/latest_time.h"
|
||||
#include "message_filters/time_synchronizer.h"
|
||||
#include "nav_msgs/msg/odometry.hpp"
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "sensor_msgs/msg/imu.hpp"
|
||||
|
||||
using Imu = sensor_msgs::msg::Imu;
|
||||
using Odometry = nav_msgs::msg::Odometry;
|
||||
using namespace message_filters;
|
||||
|
||||
// 同步策略:严格时间对齐策略
|
||||
// using MySyncPolicy = sync_policies::ExactTime<Imu, Odometry>;
|
||||
// 同步策略:大约时间对齐策略
|
||||
// using MySyncPolicy = sync_policies::ApproximateTime<Imu, Odometry>;
|
||||
// 同步策略:最新时间对齐策略
|
||||
using MySyncPolicy = sync_policies::LatestTime<Imu, Odometry>;
|
||||
|
||||
|
||||
class TimeSyncTestNode : public rclcpp::Node {
|
||||
public:
|
||||
TimeSyncTestNode() : Node("sync_node") {
|
||||
// 1.订阅 imu 话题并注册回调并打印时间戳
|
||||
imu_sub_ = std::make_shared<Subscriber<Imu>>(this, "imu");
|
||||
imu_sub_->registerCallback<Imu::SharedPtr>(
|
||||
[&](const Imu::SharedPtr &imu_msg) {
|
||||
RCLCPP_INFO(get_logger(), "imu(%u,%u)", imu_msg->header.stamp.sec,
|
||||
imu_msg->header.stamp.nanosec);
|
||||
});
|
||||
// 2.订阅 odom 话题并注册回调函数打印时间戳
|
||||
odom_sub_ = std::make_shared<Subscriber<Odometry>>(this, "odom");
|
||||
odom_sub_->registerCallback<Odometry::SharedPtr>(
|
||||
[&](const Odometry::SharedPtr &odom_msg) {
|
||||
RCLCPP_INFO(get_logger(), "odom(%u,%u)", odom_msg->header.stamp.sec,
|
||||
odom_msg->header.stamp.nanosec);
|
||||
});
|
||||
// 3.创建对应策略的同步器同步两个话题,并注册回调函数打印数据
|
||||
// synchronizer_ = std::make_shared<Synchronizer<MySyncPolicy>>(
|
||||
// MySyncPolicy(10), *imu_sub_, *odom_sub_);
|
||||
|
||||
// 3.创建对应策略的同步器同步两个话题,并注册回调函数打印数据
|
||||
synchronizer_ = std::make_shared<Synchronizer<MySyncPolicy>>(
|
||||
MySyncPolicy(), *imu_sub_, *odom_sub_);
|
||||
synchronizer_->registerCallback(
|
||||
std::bind(&TimeSyncTestNode::result_callback, this,
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
private:
|
||||
void result_callback(const Imu::ConstSharedPtr imu_msg,
|
||||
const Odometry::ConstSharedPtr odom_msg) {
|
||||
RCLCPP_INFO(get_logger(), "imu(%u,%u),odom(%u,%u))",
|
||||
imu_msg->header.stamp.sec, imu_msg->header.stamp.nanosec,
|
||||
odom_msg->header.stamp.sec, odom_msg->header.stamp.nanosec);
|
||||
}
|
||||
|
||||
std::shared_ptr<Subscriber<Imu>> imu_sub_;
|
||||
std::shared_ptr<Subscriber<Odometry>> odom_sub_;
|
||||
std::shared_ptr<Synchronizer<MySyncPolicy>> synchronizer_;
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
rclcpp::init(argc, argv);
|
||||
auto node = std::make_shared<TimeSyncTestNode>();
|
||||
rclcpp::spin(node);
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
from sensor_msgs.msg import Imu
|
||||
from nav_msgs.msg import Odometry
|
||||
from message_filters import Subscriber, ApproximateTimeSynchronizer
|
||||
|
||||
class TimeSyncTestNode(Node):
|
||||
def __init__(self):
|
||||
super().__init__('sync_node')
|
||||
# 1. 订阅 imu 话题并注册回调并打印时间戳
|
||||
self.imu_sub = Subscriber(self, Imu, 'imu')
|
||||
self.imu_sub.registerCallback(self.imu_callback)
|
||||
# 2. 订阅 odom 话题并注册回调函数打印时间戳
|
||||
self.odom_sub = Subscriber(self, Odometry, 'odom')
|
||||
self.odom_sub.registerCallback(self.odom_callback)
|
||||
# 3. 创建对应策略的同步器同步两个话题,并注册回调函数打印数据
|
||||
self.synchronizer = ApproximateTimeSynchronizer(
|
||||
[self.imu_sub, self.odom_sub], 10,
|
||||
slop=0.01, # slop 表示时间窗口单位为秒
|
||||
)
|
||||
self.synchronizer.registerCallback(self.result_callback)
|
||||
|
||||
def imu_callback(self, imu_msg):
|
||||
self.get_logger().info(
|
||||
f'imu({imu_msg.header.stamp.sec},{imu_msg.header.stamp.nanosec})')
|
||||
|
||||
def odom_callback(self, odom_msg):
|
||||
self.get_logger().info(
|
||||
f'odom({odom_msg.header.stamp.sec},{odom_msg.header.stamp.nanosec})')
|
||||
|
||||
def result_callback(self, imu_msg, odom_msg):
|
||||
self.get_logger().info(
|
||||
f'imu({imu_msg.header.stamp.sec},{imu_msg.header.stamp.nanosec}),odom({odom_msg.header.stamp.sec},{odom_msg.header.stamp.nanosec})')
|
||||
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
node = TimeSyncTestNode()
|
||||
rclpy.spin(node)
|
||||
rclpy.shutdown()
|
||||
18
chapt10/chapt10_ws/src/learn_message_filter_py/package.xml
Normal file
18
chapt10/chapt10_ws/src/learn_message_filter_py/package.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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>learn_message_filter_py</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<test_depend>ament_copyright</test_depend>
|
||||
<test_depend>ament_flake8</test_depend>
|
||||
<test_depend>ament_pep257</test_depend>
|
||||
<test_depend>python3-pytest</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_python</build_type>
|
||||
</export>
|
||||
</package>
|
||||
4
chapt10/chapt10_ws/src/learn_message_filter_py/setup.cfg
Normal file
4
chapt10/chapt10_ws/src/learn_message_filter_py/setup.cfg
Normal file
@@ -0,0 +1,4 @@
|
||||
[develop]
|
||||
script_dir=$base/lib/learn_message_filter_py
|
||||
[install]
|
||||
install_scripts=$base/lib/learn_message_filter_py
|
||||
26
chapt10/chapt10_ws/src/learn_message_filter_py/setup.py
Normal file
26
chapt10/chapt10_ws/src/learn_message_filter_py/setup.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
package_name = 'learn_message_filter_py'
|
||||
|
||||
setup(
|
||||
name=package_name,
|
||||
version='0.0.0',
|
||||
packages=find_packages(exclude=['test']),
|
||||
data_files=[
|
||||
('share/ament_index/resource_index/packages',
|
||||
['resource/' + package_name]),
|
||||
('share/' + package_name, ['package.xml']),
|
||||
],
|
||||
install_requires=['setuptools'],
|
||||
zip_safe=True,
|
||||
maintainer='fishros',
|
||||
maintainer_email='87068644+fishros@users.noreply.github.com',
|
||||
description='TODO: Package description',
|
||||
license='TODO: License declaration',
|
||||
tests_require=['pytest'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'timesync_test=learn_message_filter_py.timesync_test:main'
|
||||
],
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
from ament_copyright.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
# Remove the `skip` decorator once the source file(s) have a copyright header
|
||||
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
|
||||
@pytest.mark.copyright
|
||||
@pytest.mark.linter
|
||||
def test_copyright():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found errors'
|
||||
@@ -0,0 +1,25 @@
|
||||
# Copyright 2017 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.
|
||||
|
||||
from ament_flake8.main import main_with_errors
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.flake8
|
||||
@pytest.mark.linter
|
||||
def test_flake8():
|
||||
rc, errors = main_with_errors(argv=[])
|
||||
assert rc == 0, \
|
||||
'Found %d code style errors / warnings:\n' % len(errors) + \
|
||||
'\n'.join(errors)
|
||||
@@ -0,0 +1,23 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
from ament_pep257.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.linter
|
||||
@pytest.mark.pep257
|
||||
def test_pep257():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found code style errors / warnings'
|
||||
37
chapt10/chapt10_ws/src/learn_qos_cpp/CMakeLists.txt
Normal file
37
chapt10/chapt10_ws/src/learn_qos_cpp/CMakeLists.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(learn_qos_cpp)
|
||||
|
||||
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)
|
||||
# uncomment the following section in order to fill in
|
||||
# further dependencies manually.
|
||||
# find_package(<dependency> REQUIRED)
|
||||
|
||||
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()
|
||||
|
||||
find_package(rclcpp REQUIRED)
|
||||
find_package(nav_msgs REQUIRED)
|
||||
|
||||
add_executable(reliability_test src/reliability_test.cpp)
|
||||
ament_target_dependencies(reliability_test
|
||||
rclcpp nav_msgs
|
||||
)
|
||||
|
||||
install(TARGETS reliability_test
|
||||
DESTINATION lib/${PROJECT_NAME})
|
||||
|
||||
ament_package()
|
||||
18
chapt10/chapt10_ws/src/learn_qos_cpp/package.xml
Normal file
18
chapt10/chapt10_ws/src/learn_qos_cpp/package.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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>learn_qos_cpp</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
@@ -0,0 +1,56 @@
|
||||
#include <nav_msgs/msg/odometry.hpp>
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
|
||||
class OdomPublisherSubscriber : public rclcpp::Node
|
||||
{
|
||||
public:
|
||||
OdomPublisherSubscriber() : Node("odom_publisher_subscriber")
|
||||
{
|
||||
rclcpp::QoS qos_profile(10); // 队列深度为10
|
||||
qos_profile.reliability(RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT); // 可靠性策略
|
||||
qos_profile.durability(RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL); // 持久性策略
|
||||
qos_profile.history(RMW_QOS_POLICY_HISTORY_KEEP_LAST); // 历史记录策略
|
||||
qos_profile.deadline(rclcpp::Duration(1, 0)); // 截止时间为1秒
|
||||
|
||||
odom_publisher_ = this->create_publisher<nav_msgs::msg::Odometry>(
|
||||
"odom", qos_profile);
|
||||
|
||||
// // 创建发布者并设置QoS为sensor
|
||||
// odom_publisher_ = this->create_publisher<nav_msgs::msg::Odometry>(
|
||||
// "odom", rclcpp::SensorDataQoS());
|
||||
|
||||
// 创建订阅者(默认QoS配置)队列深度设置为 5
|
||||
// odom_subscription_ = this->create_subscription<nav_msgs::msg::Odometry>(
|
||||
// "odom", 5,
|
||||
// [this](const nav_msgs::msg::Odometry::SharedPtr msg) {
|
||||
// (void)msg;
|
||||
// RCLCPP_INFO(this->get_logger(), "收到里程计消息");
|
||||
// });
|
||||
|
||||
odom_subscription_ = this->create_subscription<nav_msgs::msg::Odometry>(
|
||||
"odom", rclcpp::SensorDataQoS(),
|
||||
[this](const nav_msgs::msg::Odometry::SharedPtr msg)
|
||||
{
|
||||
(void)msg;
|
||||
RCLCPP_INFO(this->get_logger(), "收到里程计消息");
|
||||
});
|
||||
|
||||
// 创建一个1秒的定时器,并指定回调函数
|
||||
timer_ = this->create_wall_timer(std::chrono::seconds(1), [this]()
|
||||
{ odom_publisher_->publish(nav_msgs::msg::Odometry()); });
|
||||
}
|
||||
|
||||
private:
|
||||
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr odom_publisher_;
|
||||
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr odom_subscription_;
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
rclcpp::init(argc, argv);
|
||||
auto odom_node = std::make_shared<OdomPublisherSubscriber>();
|
||||
rclcpp::spin(odom_node);
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
from nav_msgs.msg import Odometry
|
||||
from rclpy import qos
|
||||
from rclpy.duration import Duration
|
||||
|
||||
|
||||
|
||||
class OdomPublisherSubscriber(Node):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__('odom_publisher_subscriber')
|
||||
# 创建发布者并设置QoS为sensor
|
||||
qos_profile = qos.QoSProfile(
|
||||
depth=10, # 队列深度
|
||||
reliability=qos.ReliabilityPolicy.BEST_EFFORT, # 可靠性
|
||||
durability=qos.DurabilityPolicy.TRANSIENT_LOCAL, # 持久性
|
||||
history=qos.HistoryPolicy.KEEP_LAST, # 历史记录策略
|
||||
deadline=Duration(seconds=1.0, nanoseconds=0),
|
||||
)
|
||||
# 在订阅和发布中使用
|
||||
self.odom_publisher = self.create_publisher(Odometry, 'odom', qos_profile)
|
||||
# 创建订阅者(默认QoS配置)队列深度设置为 5
|
||||
self.odom_subscriber = self.create_subscription(
|
||||
Odometry, 'odom', self.odom_callback,qos.qos_profile_sensor_data)
|
||||
# 创建一个1秒的定时器,并指定回调函数
|
||||
self.timer = self.create_timer(1.0, self.timer_callback)
|
||||
|
||||
def odom_callback(self, msg):
|
||||
self.get_logger().info('收到里程计消息')
|
||||
|
||||
def timer_callback(self):
|
||||
odom_msg = Odometry() # 创建一个Odometry消息
|
||||
self.odom_publisher.publish(odom_msg) # 发布消息
|
||||
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
odom_node = OdomPublisherSubscriber()
|
||||
rclpy.spin(odom_node)
|
||||
rclpy.shutdown()
|
||||
18
chapt10/chapt10_ws/src/learn_qos_py/package.xml
Normal file
18
chapt10/chapt10_ws/src/learn_qos_py/package.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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>learn_qos_py</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="87068644+fishros@users.noreply.github.com">fishros</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<test_depend>ament_copyright</test_depend>
|
||||
<test_depend>ament_flake8</test_depend>
|
||||
<test_depend>ament_pep257</test_depend>
|
||||
<test_depend>python3-pytest</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_python</build_type>
|
||||
</export>
|
||||
</package>
|
||||
4
chapt10/chapt10_ws/src/learn_qos_py/setup.cfg
Normal file
4
chapt10/chapt10_ws/src/learn_qos_py/setup.cfg
Normal file
@@ -0,0 +1,4 @@
|
||||
[develop]
|
||||
script_dir=$base/lib/learn_qos_py
|
||||
[install]
|
||||
install_scripts=$base/lib/learn_qos_py
|
||||
26
chapt10/chapt10_ws/src/learn_qos_py/setup.py
Normal file
26
chapt10/chapt10_ws/src/learn_qos_py/setup.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
package_name = 'learn_qos_py'
|
||||
|
||||
setup(
|
||||
name=package_name,
|
||||
version='0.0.0',
|
||||
packages=find_packages(exclude=['test']),
|
||||
data_files=[
|
||||
('share/ament_index/resource_index/packages',
|
||||
['resource/' + package_name]),
|
||||
('share/' + package_name, ['package.xml']),
|
||||
],
|
||||
install_requires=['setuptools'],
|
||||
zip_safe=True,
|
||||
maintainer='fishros',
|
||||
maintainer_email='87068644+fishros@users.noreply.github.com',
|
||||
description='TODO: Package description',
|
||||
license='TODO: License declaration',
|
||||
tests_require=['pytest'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'reliability_test=learn_qos_py.reliability_test:main'
|
||||
],
|
||||
},
|
||||
)
|
||||
25
chapt10/chapt10_ws/src/learn_qos_py/test/test_copyright.py
Normal file
25
chapt10/chapt10_ws/src/learn_qos_py/test/test_copyright.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
from ament_copyright.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
# Remove the `skip` decorator once the source file(s) have a copyright header
|
||||
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
|
||||
@pytest.mark.copyright
|
||||
@pytest.mark.linter
|
||||
def test_copyright():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found errors'
|
||||
25
chapt10/chapt10_ws/src/learn_qos_py/test/test_flake8.py
Normal file
25
chapt10/chapt10_ws/src/learn_qos_py/test/test_flake8.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Copyright 2017 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.
|
||||
|
||||
from ament_flake8.main import main_with_errors
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.flake8
|
||||
@pytest.mark.linter
|
||||
def test_flake8():
|
||||
rc, errors = main_with_errors(argv=[])
|
||||
assert rc == 0, \
|
||||
'Found %d code style errors / warnings:\n' % len(errors) + \
|
||||
'\n'.join(errors)
|
||||
23
chapt10/chapt10_ws/src/learn_qos_py/test/test_pep257.py
Normal file
23
chapt10/chapt10_ws/src/learn_qos_py/test/test_pep257.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
from ament_pep257.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.linter
|
||||
@pytest.mark.pep257
|
||||
def test_pep257():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found code style errors / warnings'
|
||||
23
chapt10/chapt10_ws/topic_sub_limit.xml
Normal file
23
chapt10/chapt10_ws/topic_sub_limit.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
|
||||
|
||||
<!-- 默认发布者配置 -->
|
||||
<publisher profile_name="default_publisher" is_default_profile="true">
|
||||
<historyMemoryPolicy>DYNAMIC</historyMemoryPolicy>
|
||||
</publisher>
|
||||
|
||||
<!-- 默认订阅者配置 -->
|
||||
<subscriber profile_name="default_subscriber" is_default_profile="true">
|
||||
<historyMemoryPolicy>DYNAMIC</historyMemoryPolicy>
|
||||
</subscriber>
|
||||
|
||||
<!-- 话题 chatter 的发布者配置 -->
|
||||
<publisher profile_name="/chatter">
|
||||
<historyMemoryPolicy>DYNAMIC</historyMemoryPolicy>
|
||||
<matchedSubscribersAllocation>
|
||||
<initial>0</initial>
|
||||
<maximum>1</maximum>
|
||||
<increment>1</increment>
|
||||
</matchedSubscribersAllocation>
|
||||
</publisher>
|
||||
</profiles>
|
||||
32
chapt10/rosbag2_message_filter/metadata.yaml
Normal file
32
chapt10/rosbag2_message_filter/metadata.yaml
Normal file
@@ -0,0 +1,32 @@
|
||||
rosbag2_bagfile_information:
|
||||
version: 5
|
||||
storage_identifier: sqlite3
|
||||
duration:
|
||||
nanoseconds: 221085265896
|
||||
starting_time:
|
||||
nanoseconds_since_epoch: 1697985428618130944
|
||||
message_count: 33156
|
||||
topics_with_message_count:
|
||||
- topic_metadata:
|
||||
name: /imu
|
||||
type: sensor_msgs/msg/Imu
|
||||
serialization_format: cdr
|
||||
offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 2\n deadline:\n sec: 9223372036\n nsec: 854775807\n lifespan:\n sec: 9223372036\n nsec: 854775807\n liveliness: 1\n liveliness_lease_duration:\n sec: 9223372036\n nsec: 854775807\n avoid_ros_namespace_conventions: false"
|
||||
message_count: 22104
|
||||
- topic_metadata:
|
||||
name: /odom
|
||||
type: nav_msgs/msg/Odometry
|
||||
serialization_format: cdr
|
||||
offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 1\n deadline:\n sec: 9223372036\n nsec: 854775807\n lifespan:\n sec: 9223372036\n nsec: 854775807\n liveliness: 1\n liveliness_lease_duration:\n sec: 9223372036\n nsec: 854775807\n avoid_ros_namespace_conventions: false"
|
||||
message_count: 11052
|
||||
compression_format: ""
|
||||
compression_mode: ""
|
||||
relative_file_paths:
|
||||
- rosbag2_message_filter.db3
|
||||
files:
|
||||
- path: rosbag2_message_filter.db3
|
||||
starting_time:
|
||||
nanoseconds_since_epoch: 1697985428618130944
|
||||
duration:
|
||||
nanoseconds: 221085265896
|
||||
message_count: 33156
|
||||
BIN
chapt10/rosbag2_message_filter/rosbag2_message_filter.db3
Normal file
BIN
chapt10/rosbag2_message_filter/rosbag2_message_filter.db3
Normal file
Binary file not shown.
Reference in New Issue
Block a user