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

ROS 发行版 jazzy 加载urdf 渲染到 RVIZ2

新版启动urdf需要两个包分别为urdf_tutorial、urdf_launch

配置package.xml

<exec_depend>rviz_common</exec_depend>

<exec_depend>rviz_default_plugins</exec_depend>

<exec_depend>rviz2</exec_depend>

<exec_depend>robot_state_publisher</exec_depend>

<exec_depend>joint_state_publisher</exec_depend>

<exec_depend>joint_state_publisher_gui</exec_depend>

<exec_depend>xacro</exec_depend>

<exec_depend>launch_ros</exec_depend>

CMakeLists.txt配置

install(DIRECTORY launch worlds urdf meshes models rviz

DESTINATION share/${PROJECT_NAME})

launch.py 内容

from launch import LaunchDescription

from launch_ros.substitutions import FindPackageShare

from launch.actions import DeclareLaunchArgument,IncludeLaunchDescription

from launch.substitutions import PathJoinSubstitution,LaunchConfiguration,Command

from launch_ros.actions import Node

from launch_ros.parameter_descriptions import ParameterValue

from launch.conditions import IfCondition,UnlessCondition

import os

def generate_launch_description():

ld = LaunchDescription()

## 找到 项目 包

samll_turtle_dir = FindPackageShare("small_turtle")

## URDF Model 路径

urdf_model_path = PathJoinSubstitution([samll_turtle_dir,"urdf","small_turtle.urdf"])

## urdf_model_path = os.path.join(samll_turtle_dir,"urdf","small_turtle.urdf")

## rviz 配置文件路径

rviz_config_path = PathJoinSubstitution([samll_turtle_dir,"rviz","display.rviz"])

## joint_state_publisher_gui 配置

gui_arg = DeclareLaunchArgument(name="gui",default_value="true",choices=["true","false"],

description="Flag to enable joint_state_publisher_gui")

ld.add_action(gui_arg)

## 声明 rviz

rviz_arg = DeclareLaunchArgument(name="rvizconfig",default_value=rviz_config_path,

description="Absolute path to rviz config file")

ld.add_action(rviz_arg)

## 声明 urdf model

ld.add_action(DeclareLaunchArgument(name="model",default_value=urdf_model_path,

description="Path to robot urdf"))

## robot_state_publisher 配置

robot_description_content = ParameterValue(Command(["xacro ",LaunchConfiguration("model")]),value_type=str)

robot_state_publisher_node = Node(

package="robot_state_publisher",

executable="robot_state_publisher",

parameters=[{"robot_description":robot_description_content}]

)

ld.add_action(robot_state_publisher_node)

## joint_state_publisher

joint_state_publisher_node = Node(

package="joint_state_publisher",

executable="joint_state_publisher",

condition=UnlessCondition(LaunchConfiguration("gui"))

)

ld.add_action(joint_state_publisher_node)

## joint_state_publisher_gui

joint_state_publisher_gui_node = Node(

package="joint_state_publisher_gui",

executable="joint_state_publisher_gui",

condition=IfCondition(LaunchConfiguration("gui"))

)

ld.add_action(joint_state_publisher_gui_node)

## rviz

rviz_node = Node(

package="rviz2",

executable="rviz2",

arguments=["-d",LaunchConfiguration("rvizconfig")],

output="screen"

)

ld.add_action(rviz_node)

return ld


http://www.mrgr.cn/news/22128.html

相关文章:

  • 价格适中超微小间距P1.8全彩LED显示屏广泛应用于COB会议一体机
  • 代理IP池功能组件
  • 【redis】redis的特性和主要应用场景
  • Linux编译运行cpp源文件
  • c/c++面试100道
  • 心觉:潜意识是一个免费的“超级工作狂”,你居然不会用
  • IP包头的总长度字段和UDP包头的长度字段之间的关系
  • 数据结构(邓俊辉)学习笔记】排序 6——希尔排序:框架 + 实例
  • 738. 单调递增的数字
  • vue组件间通信
  • 基于SpringBoot框架和Flask的图片差异检测与展示系统
  • js事件冒泡和事件委托
  • C++异常
  • Java高级编程—网络编程(完整详解,包括UDP通信方式、TCP通信方式、TCP三次握手、TCP四次挥手,附有代码+案列)
  • ④JdbcTemplate与声明式事务
  • MATLAB绘图基础6:MATLAB绘图基础
  • 仕考网:2025年公务员国考备考技巧
  • FastAPI数据模型:使用FormData extra参数防止数据污染
  • Python——将原来的gt.txt文件存为gt_原始.txt,修改后的文件作为 gt.txt
  • 基于Java+SpringBoot+Vue+MySQL的西安旅游管理系统网站