当前位置: 首页 > news >正文

宠物网站建设策划书眉山住房和城乡建设局网站

宠物网站建设策划书,眉山住房和城乡建设局网站,百度搜索优化建议,青海网站建设与维护一个完整的简单的launch文件配置过程1.编写launch文件2.配置package.xml3.配置setup.py#xff08;python包#xff09;4.配置CMakeList(C包)5.编译运行# 在 ROS 2 的 Python 启动文件中#xff0c;这些导入语句用于引入各类启动模块#xff0c;以构建和配置节点启动流程 f…一个完整的简单的launch文件配置过程1.编写launch文件2.配置package.xml3.配置setup.pypython包4.配置CMakeList(C包)5.编译运行 # 在 ROS 2 的 Python 启动文件中这些导入语句用于引入各类启动模块以构建和配置节点启动流程 from launch import LaunchDescription from launch_ros.actions import Nodedef generate_launch_description():return LaunchDescription([Node(packageturtlesim,namespaceturtlesim1,executableturtlesim_node,namesim),Node(packageturtlesim,namespaceturtlesim2,executableturtlesim_node,namesim),Node(packageturtlesim,executablemimic,namemimic,remappings[(/input/pose, /turtlesim1/turtle1/pose),(/output/cmd_vel, /turtlesim2/turtle1/cmd_vel),])])package.xml加入以下内容  exec_dependros2launch/exec_dependCMakeList:  to the end of the file (but before ament_package()). # Install launch files. install(DIRECTORYlaunchDESTINATION share/${PROJECT_NAME}/ )package.list: import os from glob import glob # Other imports ...package_name py_launch_examplesetup(# Other parameters ...data_files[# ... Other data files# Include all launch files.(os.path.join(share, package_name, launch), glob(launch/*))] ) 替换表达式 from launch import LaunchDescription from launch.actions import IncludeLaunchDescription from launch.substitutions import PathJoinSubstitution from launch_ros.substitutions import FindPackageSharedef generate_launch_description():colors {background_r: 200}return LaunchDescription([# 使用PathJoinSubstitution和FindPackageShare动态构建启动文件路径IncludeLaunchDescription(PathJoinSubstitution([FindPackageShare(launch_tutorial),launch,example_substitutions.launch.py]),# 传递给被包含启动文件的参数launch_arguments{turtlesim_ns: turtlesim2,use_provided_red: True,new_background_r: colors[background_r],}.items())]) 在 Python 中.items() 是字典dict对象的一个方法用于将字典转换为可迭代的键值对元组列表。又如 from launch import LaunchDescription from launch.actions import DeclareLaunchArgument, ExecuteProcess, TimerAction from launch.conditions import IfCondition from launch.substitutions import LaunchConfiguration, PythonExpression from launch_ros.actions import Nodedef generate_launch_description():# turtlesim_ns LaunchConfiguration(turtlesim_ns)use_provided_red LaunchConfiguration(use_provided_red)new_background_r LaunchConfiguration(new_background_r)return LaunchDescription([DeclareLaunchArgument(turtlesim_ns,default_valueturtlesim1),DeclareLaunchArgument(use_provided_red,default_valueFalse),DeclareLaunchArgument(new_background_r,default_value200),Node(packageturtlesim,namespaceturtlesim_ns,executableturtlesim_node,namesim),ExecuteProcess(cmd[[ros2 service call ,turtlesim_ns,/spawn ,turtlesim/srv/Spawn ,{x: 2, y: 2, theta: 0.2}]],shellTrue),ExecuteProcess(cmd[[ros2 param set ,turtlesim_ns,/sim background_r ,120]],shellTrue),TimerAction(period2.0,actions[ExecuteProcess(conditionIfCondition(PythonExpression([new_background_r, 200, and ,use_provided_red])),cmd[[ros2 param set ,turtlesim_ns,/sim background_r ,new_background_r]],shellTrue),],)])为什么需要 LaunchConfiguration简单说LaunchConfiguration就像一个 “参数占位符”。当你在 Launch 文件中声明了一个启动参数比如DeclareLaunchArgument(turtlesim_ns)LaunchConfiguration可以引用这个参数的值让你在后续的节点、动作配置中动态使用它而不用写死具体数值。比如你声明了一个参数background_r默认值为 200但用户启动时可能会通过命令行修改为 255。LaunchConfiguration(background_r)就能自动获取用户输入的最新值无需修改 Launch 文件代码。命令行进程调用 ExecuteProcess(cmd[[ros2 param set ,turtlesim_ns,/sim background_r ,120]],shellTrue),条件执行 TimerAction(period2.0,actions[ExecuteProcess(conditionIfCondition(PythonExpression([new_background_r, 200, and ,use_provided_red])),cmd[[ros2 param set ,turtlesim_ns,/sim background_r ,new_background_r]],shellTrue),],)格式  TimerAction(period .... # 多少时间后actions [ExecuteProcess(condition IfCondition(...... # 具体条件),cmd [ [........... # 命令行指令]],shell True),],)这段代码的作用是在启动后 2 秒检查特定条件是否满足如果满足则执行一条 ROS 2 命令修改 turtlesim 模拟器的背景红色值。ROS 2 中的事件处理器Event Handlers使用示例 from launch import LaunchDescription from launch.actions import (DeclareLaunchArgument,EmitEvent,ExecuteProcess,LogInfo,RegisterEventHandler,TimerAction ) from launch.conditions import IfCondition from launch.event_handlers import (OnExecutionComplete,OnProcessExit,OnProcessIO,OnProcessStart,OnShutdown ) from launch.events import Shutdown from launch.substitutions import (EnvironmentVariable,FindExecutable,LaunchConfiguration,LocalSubstitution,PythonExpression ) from launch_ros.actions import Nodedef generate_launch_description():turtlesim_ns LaunchConfiguration(turtlesim_ns)use_provided_red LaunchConfiguration(use_provided_red)new_background_r LaunchConfiguration(new_background_r)turtlesim_ns_launch_arg DeclareLaunchArgument(turtlesim_ns,default_valueturtlesim1)use_provided_red_launch_arg DeclareLaunchArgument(use_provided_red,default_valueFalse)new_background_r_launch_arg DeclareLaunchArgument(new_background_r,default_value200)turtlesim_node Node(packageturtlesim,namespaceturtlesim_ns,executableturtlesim_node,namesim)spawn_turtle ExecuteProcess(cmd[[FindExecutable(nameros2), service call ,turtlesim_ns,/spawn ,turtlesim/srv/Spawn ,{x: 2, y: 2, theta: 0.2}]],shellTrue)change_background_r ExecuteProcess(cmd[[FindExecutable(nameros2), param set ,turtlesim_ns,/sim background_r ,120]],shellTrue)change_background_r_conditioned ExecuteProcess(conditionIfCondition(PythonExpression([new_background_r, 200, and ,use_provided_red])),cmd[[FindExecutable(nameros2), param set ,turtlesim_ns,/sim background_r ,new_background_r]],shellTrue)return LaunchDescription([turtlesim_ns_launch_arg,use_provided_red_launch_arg,new_background_r_launch_arg,turtlesim_node,RegisterEventHandler(OnProcessStart(target_actionturtlesim_node,on_start[LogInfo(msgTurtlesim started, spawning turtle),spawn_turtle])),RegisterEventHandler(OnProcessIO(target_actionspawn_turtle,on_stdoutlambda event: LogInfo(msgSpawn request says {}.format(event.text.decode().strip())))),RegisterEventHandler(OnExecutionComplete(target_actionspawn_turtle,on_completion[LogInfo(msgSpawn finished),change_background_r,TimerAction(period2.0,actions[change_background_r_conditioned],)])),RegisterEventHandler(OnProcessExit(target_actionturtlesim_node,on_exit[LogInfo(msg(EnvironmentVariable(nameUSER), closed the turtlesim window)),EmitEvent(eventShutdown(reasonWindow closed))])),RegisterEventHandler(OnShutdown(on_shutdown[LogInfo(msg[Launch was asked to shutdown: , LocalSubstitution(event.reason)])])),]) 详解这个启动文件创建了一个 turtlesim 模拟器并实现了以下功能启动 turtlesim 节点后自动生成一只新乌龟捕获生成乌龟的服务响应并打印日志乌龟生成完成后修改模拟器背景颜色2 秒后根据参数条件再次修改背景颜色当 turtlesim 窗口关闭时自动终止整个启动过程捕获系统关闭事件并打印关闭原因1.节点与命令定义 turtlesim_node Node(packageturtlesim,namespaceturtlesim_ns,executableturtlesim_node,namesim ) spawn_turtle ExecuteProcess(...) # 生成乌龟的服务调用 change_background_r ExecuteProcess(...) # 修改背景颜色的命令 change_background_r_conditioned ExecuteProcess(...) # 条件性修改背景颜色 这些组件定义了要执行的基本操作但它们的执行时机由事件处理器控制。2.事件处理器注册 RegisterEventHandler(OnProcessStart(target_actionturtlesim_node,on_start[LogInfo(...), spawn_turtle]) ) OnProcessStart当turtlesim_node启动时触发生成乌龟的命令。 RegisterEventHandler(OnProcessIO(target_actionspawn_turtle,on_stdoutlambda event: LogInfo(...)) ) OnProcessIO捕获spawn_turtle命令的标准输出提取服务响应信息。当执行spawn_turtle命令即调用turtlesim/srv/Spawn服务时服务响应会通过标准输出返回。例如 ros2 service call /turtlesim1/spawn turtlesim/srv/Spawn {x: 2, y: 2, theta: 0.2} 服务成功响应后控制台会打印 [INFO] [launch]: Spawn request says Created turtle [turtle2] 这表明新乌龟已成功生成并且名称为turtle2。 RegisterEventHandler(OnExecutionComplete(target_actionspawn_turtle,on_completion[LogInfo(...), change_background_r, TimerAction(...)]) ) OnExecutionComplete当spawn_turtle命令完成后修改背景颜色并设置一个 2 秒后的延迟动作。 RegisterEventHandler(OnProcessExit(target_actionturtlesim_node,on_exit[LogInfo(...), EmitEvent(eventShutdown(...))]) ) OnProcessExit当turtlesim_node退出时触发系统关闭事件。 RegisterEventHandler(OnShutdown(on_shutdown[LogInfo(...)]) ) OnShutdown捕获系统关闭事件打印关闭原因。3.编译执行  ros2 launch launch_tutorial example_event_handlers.launch.py turtlesim_ns:turtlesim3 use_provided_red:True new_background_r:200管理大型工程顶层管理 from launch import LaunchDescription from launch.actions import IncludeLaunchDescription from launch.substitutions import PathJoinSubstitution from launch_ros.substitutions import FindPackageSharedef generate_launch_description():launch_dir PathJoinSubstitution([FindPackageShare(launch_tutorial), launch])return LaunchDescription([IncludeLaunchDescription(PathJoinSubstitution([launch_dir, turtlesim_world_1.launch.py])),IncludeLaunchDescription(PathJoinSubstitution([launch_dir, turtlesim_world_2.launch.py])),IncludeLaunchDescription(PathJoinSubstitution([launch_dir, broadcaster_listener.launch.py]),launch_arguments{target_frame: carrot1}.items()),IncludeLaunchDescription(PathJoinSubstitution([launch_dir, mimic.launch.py])),IncludeLaunchDescription(PathJoinSubstitution([launch_dir, fixed_broadcaster.launch.py])),IncludeLaunchDescription(PathJoinSubstitution([launch_dir, turtlesim_rviz.launch.py])),])在launch文件设置参数 from launch import LaunchDescription from launch.actions import DeclareLaunchArgument from launch.substitutions import LaunchConfiguration from launch_ros.actions import Nodedef generate_launch_description():return LaunchDescription([DeclareLaunchArgument(background_r, default_value0),DeclareLaunchArgument(background_g, default_value84),DeclareLaunchArgument(background_b, default_value122),Node(packageturtlesim,executableturtlesim_node,namesim,parameters[{background_r: LaunchConfiguration(background_r),background_g: LaunchConfiguration(background_g),background_b: LaunchConfiguration(background_b),}]),])通过YAML文件设置参数 from launch import LaunchDescription from launch.substitutions import PathJoinSubstitution from launch_ros.actions import Node from launch_ros.substitutions import FindPackageSharedef generate_launch_description():return LaunchDescription([Node(packageturtlesim,executableturtlesim_node,namespaceturtlesim2,namesim,parameters[PathJoinSubstitution([FindPackageShare(launch_tutorial), config, turtlesim.yaml])],),])/turtlesim2/sim:ros__parameters:background_b: 255background_g: 86background_r: 150整个/turtlesim2/sim代表的是 “位于turtlesim2命名空间下、名为sim的turtlesim节点”其后的ros__parameters则是该节点的具体参数配置如背景色的 RGB 值命名空间 当启动文件需要包含大量节点时手动为每个节点单独设置命名空间会变得繁琐且易出错。PushRosNamespace 提供了一种更优雅的解决方案让你可以为一组节点批量设置命名空间。首先remove the namespaceturtlesim2 line from the turtlesim_world_2.launch.py 。然后按照以下修改 from launch.actions import GroupAction from launch_ros.actions import PushRosNamespace...GroupAction(actions[PushROSNamespace(turtlesim2),IncludeLaunchDescription(PathJoinSubstitution([launch_dir, turtlesim_world_2.launch.py])),]),那么在turtlesim_world_2.launch.py中的每一个节点都有一个turtlesim2前缀的命令空间。节点复用 from launch import LaunchDescription from launch.actions import DeclareLaunchArgument from launch.substitutions import LaunchConfigurationfrom launch_ros.actions import Nodedef generate_launch_description():return LaunchDescription([DeclareLaunchArgument(target_frame, default_valueturtle1,descriptionTarget frame name.,),Node(packageturtle_tf2_py,executableturtle_tf2_broadcaster,namebroadcaster1,parameters[{turtlename: turtle1}],),Node(packageturtle_tf2_py,executableturtle_tf2_broadcaster,namebroadcaster2,parameters[{turtlename: turtle2}],),Node(packageturtle_tf2_py,executableturtle_tf2_listener,namelistener,parameters[{target_frame: LaunchConfiguration(target_frame)}],),]) 话题重映射 from launch import LaunchDescription from launch_ros.actions import Nodedef generate_launch_description():return LaunchDescription([Node(packageturtlesim,executablemimic,namemimic,remappings[(/input/pose, /turtle2/pose),(/output/cmd_vel, /turtlesim2/turtle1/cmd_vel),])]) 启动rviz并按照文件配置 from launch import LaunchDescription from launch.substitutions import PathJoinSubstitution from launch_ros.actions import Node from launch_ros.substitutions import FindPackageSharedef generate_launch_description():return LaunchDescription([Node(packagerviz2,executablerviz2,namerviz2,arguments[-d, PathJoinSubstitution([FindPackageShare(turtle_tf2_py), rviz, turtle_rviz.rviz])],),])动态配置节点名 from launch import LaunchDescription from launch.actions import DeclareLaunchArgument from launch.substitutions import EnvironmentVariable, LaunchConfiguration from launch_ros.actions import Nodedef generate_launch_description():return LaunchDescription([DeclareLaunchArgument(node_prefix,default_value[EnvironmentVariable(USER), _],descriptionprefix for node name),Node(packageturtle_tf2_py,executablefixed_frame_tf2_broadcaster,name[LaunchConfiguration(node_prefix), fixed_broadcaster],),])声明一个启动参数node_prefix默认值为当前系统用户的用户名加上下划线例如doubao_启动一个节点节点名称由node_prefix和固定后缀fixed_broadcaster组成例如doubao_fixed_broadcaster更新setup.py: import os from glob import glob from setuptools import setup ...data_files[...(os.path.join(share, package_name, launch),glob(launch/*)),(os.path.join(share, package_name, config),glob(config/*.yaml)),(os.path.join(share, package_name, rviz),glob(config/*.rviz)),],
http://www.pierceye.com/news/192251/

相关文章:

  • 家乡ppt模板免费下载网站合肥百姓网网站建设
  • 免费整套ppt模板下载网站东莞建设教育网站
  • 漯河网站建设漯河ps制作个人网站首页
  • 电商网站公司软件开发和软件研发
  • 网站建设浙江公司网站开发运营新人要注意什么
  • 外贸网站模板哪里下载家里电脑可以做网站服务器吗
  • 长沙门户网站北京设计网站的公司
  • 站长统计平面设计找工作难吗
  • seo建站公司推荐电商平台活动策划方案
  • 建设淘宝客网站.lc和ev手机对比平台
  • vue 做企业网站特产网站开发背景
  • 奉新网站制作dede视频网站源码
  • 做动画网站去哪采集建设网站需要的资金清单
  • 网站后台发邮件注册公司需要什么证件和手续
  • 炫酷特效网站万网虚拟主机免费空间
  • 公司网站模板最新怀远网站建设哪家好
  • 交互式网站定义如何网上找加工订单
  • 一个域名可以做几个网站吗南城网站建设公司
  • 宝安商城网站建设flash新手入门简单动画制作
  • 设置网站建设WordPress adsen
  • 网站与微信内容建设与运维总结建筑网络图
  • 网站模板文件不存在网站建设礻金手指下拉十二
  • 东莞浩智建设网站公司做百度推广员赚钱吗
  • qq网站推广代码昆明哪里做网站
  • 章丘营销型网站设计公司青岛网络优化排名
  • 制作网站模板的发展空间wordpress 阿里云 cdn
  • 交互式网站备案万网域名网站建设
  • 备案 个人网站名称月坛网站建设公司
  • 网站建设要解决哪些方面的事项临海外发加工网
  • 甜品店网站开发背景江宁区住房建设局网站