从配置文件读取串口名
This commit is contained in:
parent
101bc924aa
commit
c55105c9bf
@ -78,6 +78,13 @@ def generate_launch_description():
|
|||||||
package="rtk",
|
package="rtk",
|
||||||
executable="rtk_node",
|
executable="rtk_node",
|
||||||
name="rtk_node",
|
name="rtk_node",
|
||||||
|
parameters=[
|
||||||
|
os.path.join(
|
||||||
|
get_package_share_directory("rtk"),
|
||||||
|
"config",
|
||||||
|
"rtk_params.yaml"
|
||||||
|
)
|
||||||
|
], # 从YAML文件加载参数
|
||||||
output="screen",
|
output="screen",
|
||||||
respawn=True,
|
respawn=True,
|
||||||
respawn_delay=2
|
respawn_delay=2
|
||||||
|
|||||||
@ -40,6 +40,9 @@ ament_target_dependencies(
|
|||||||
|
|
||||||
install(TARGETS rtk_node DESTINATION lib/${PROJECT_NAME})
|
install(TARGETS rtk_node DESTINATION lib/${PROJECT_NAME})
|
||||||
|
|
||||||
|
# 安装配置文件和启动文件
|
||||||
|
install(DIRECTORY config launch DESTINATION share/${PROJECT_NAME})
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING)
|
||||||
find_package(ament_lint_auto REQUIRED)
|
find_package(ament_lint_auto REQUIRED)
|
||||||
# the following line skips the linter which checks for copyrights
|
# the following line skips the linter which checks for copyrights
|
||||||
|
|||||||
4
src/perception/rtk/config/rtk_params.yaml
Normal file
4
src/perception/rtk/config/rtk_params.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
rtk:
|
||||||
|
ros__parameters:
|
||||||
|
# 串口设备名称
|
||||||
|
serial_port: "/dev/ttyTHS1"
|
||||||
23
src/perception/rtk/launch/rtk.launch.py
Normal file
23
src/perception/rtk/launch/rtk.launch.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from launch import LaunchDescription
|
||||||
|
from launch_ros.actions import Node
|
||||||
|
from ament_index_python.packages import get_package_share_directory
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def generate_launch_description():
|
||||||
|
# 获取配置文件路径
|
||||||
|
config_dir = os.path.join(
|
||||||
|
get_package_share_directory("rtk"), "config", "rtk_params.yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
return LaunchDescription(
|
||||||
|
[
|
||||||
|
Node(
|
||||||
|
package="rtk",
|
||||||
|
executable="rtk_node",
|
||||||
|
name="rtk_node",
|
||||||
|
parameters=[config_dir], # 从YAML文件加载参数
|
||||||
|
output="screen",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
@ -23,7 +23,10 @@ class rtk_node : public rclcpp::Node
|
|||||||
|
|
||||||
// 初始化串口读取
|
// 初始化串口读取
|
||||||
boost_serial = new Boost_serial();
|
boost_serial = new Boost_serial();
|
||||||
boost_serial->init("/dev/ttyTHS1");
|
std::string serial_port;
|
||||||
|
this->declare_parameter("serial_port", "/dev/ttyTHS1");
|
||||||
|
this->get_parameter("serial_port", serial_port);
|
||||||
|
boost_serial->init(serial_port.c_str());
|
||||||
|
|
||||||
// 创建发布者
|
// 创建发布者
|
||||||
command_publisher_ = this->create_publisher<sweeper_interfaces::msg::Rtk>("rtk_message", 10);
|
command_publisher_ = this->create_publisher<sweeper_interfaces::msg::Rtk>("rtk_message", 10);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user