<launch>
<set_env name="GZ_SIM_RESOURCE_PATH" value="$(find-pkg-share gazebo_pkg)/etc/"/>
<group>
<let name="robot_description" value="$(command 'xacro $(find-pkg-share gazebo_pkg)/urdf/total.xacro')"/>
<node pkg="rviz2" exec="rviz2" name="rviz2" output="screen" args="-d $(find-pkg-share gazebo_pkg)/etc/empty1.rviz"/>
<!--rviz2 need this node below-->
<node pkg="robot_state_publisher" exec="robot_state_publisher" name="robot_state_publisher">
<param name="robot_description" value="$(var robot_description)"/>
</node>
<node name="joint_state_publisher" exec="joint_state_publisher" pkg="joint_state_publisher"/>
<include file="$(find-pkg-share ros_gz_sim)/launch/gz_sim.launch.py">
<arg name="ign_args" value="default.sdf"/>
</include>
<node pkg="ros_gz_sim" exec="create" args="-world default -topic /robot_description">
</node>
<node pkg="ros_gz_bridge" exec="parameter_bridge" name="bridge1" args="turtle1/cmd_vel@geometry_msgs/msg/Twist@ignition.msgs.Twist">
</node>
<!--
<node pkg="ros_gz_bridge" exec="parameter_bridge" name="bridge2" args="/radar_sensor100@sensor_msgs/msg/LaserScan@ignition.msgs.LaserScan"/>
-->
</group>
</launch>
<robot name="move" xmlns:xacro="http://wiki.ros.org/wiki/xacro">
<xacro:macro name="joint_trans" params="joint_name">
<transmission name="${joint_name}_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="${joint_name}">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
</joint>
<actuator name="${joint_name}_motor">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
<mechanicalReduction>1</mechanicalReduction>
</actuator>
</transmission>
</xacro:macro>
<xacro:joint_trans joint_name="left_wheel2base" />
<xacro:joint_trans joint_name="right_wheel2base" />
<gazebo>
<plugin
filename="libignition-gazebo-diff-drive-system.so"
name="ignition::gazebo::systems::DiffDrive">
<left_joint>left_wheel2base</left_joint>
<right_joint>right_wheel2base</right_joint>
<wheel_separation>${base_radius * 2}</wheel_separation>
<wheel_radius>${wheel_radius}</wheel_radius>
<odom_publish_frequency>1</odom_publish_frequency>
<topic>turtle1/cmd_vel</topic>
</plugin>
</gazebo>
</robot>
/ /// / /// // // //
<launch>
<set_env name="GZ_SIM_RESOURCE_PATH" value="$(find-pkg-share gazebo_pkg)/etc/"/>
<group>
<let name="robot_description" value="$(command 'xacro $(find-pkg-share gazebo_pkg)/urdf/total.xacro')"/>
<node pkg="rviz2" exec="rviz2" name="rviz2" output="screen" args="-d $(find-pkg-share gazebo_pkg)/etc/empty1.rviz"/>
<!--rviz2 need this node below-->
<node pkg="robot_state_publisher" exec="robot_state_publisher" name="robot_state_publisher">
<param name="robot_description" value="$(var robot_description)"/>
</node>
<node name="joint_state_publisher" exec="joint_state_publisher" pkg="joint_state_publisher"/>
<include file="$(find-pkg-share ros_gz_sim)/launch/gz_sim.launch.py">
<arg name="ign_args" value="default.sdf"/>
</include>
<node pkg="ros_gz_sim" exec="create" args="-world default -topic /robot_description">
</node>
<node pkg="ros_gz_bridge" exec="parameter_bridge" name="bridge1" args="/turtle1/cmd_vel@geometry_msgs/msg/Twist@ignition.msgs.Twist">
</node><!--there must not be a '/' in upper line eg:/turtle1/cmd_vel is wrong-->
<!--
<node pkg="ros_gz_bridge" exec="parameter_bridge" name="bridge2" args="radar_sensor100@sensor_msgs/msg/LaserScan@ignition.msgs.LaserScan"/>
-->
</group>
</launch>
<robot name="move" xmlns:xacro="http://wiki.ros.org/wiki/xacro">
<xacro:macro name="joint_trans" params="joint_name">
<transmission name="${joint_name}_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="${joint_name}">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
</joint>
<actuator name="${joint_name}_motor">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
<mechanicalReduction>1</mechanicalReduction>
</actuator>
</transmission>
</xacro:macro>
<xacro:joint_trans joint_name="left_wheel2base" />
<xacro:joint_trans joint_name="right_wheel2base" />
<gazebo>
<plugin
filename="libignition-gazebo-diff-drive-system.so"
name="ignition::gazebo::systems::DiffDrive">
<left_joint>left_wheel2base</left_joint>
<right_joint>right_wheel2base</right_joint>
<wheel_separation>${base_radius * 2}</wheel_separation>
<wheel_radius>${wheel_radius}</wheel_radius>
<odom_publish_frequency>1</odom_publish_frequency>
<topic>/turtle1/cmd_vel</topic>
</plugin>
</gazebo>
</robot>
这2代码都可以正常运行,但是我搞不懂,为什么乌龟控制主题只有一个,接收控制的节点为什么可以是2个?一个是turtle1/cmd_vel
还有一个事/turtle1/cmd_vel呢难道解析的时候从第一个不是符号/的地方开始吗,如果这样//turtle1/cmd_vel也是合法的试试看