机械臂仿真构建完成

This commit is contained in:
2026-02-24 22:09:19 +08:00
parent 893a5ae069
commit 9d8fc2ba53
460 changed files with 19966 additions and 522 deletions

View File

@@ -1 +1 @@
/opt/ros/humble
/home/quella/ROS2_WS/simulation_ws/trolley/install/trolley:/opt/ros/humble

View File

@@ -0,0 +1,27 @@
# joint_state_broadcaster发布 joint state
# diff_drive_controller订阅 cmd_vel输出轮子速度命令
controller_manager:
ros__parameters:
update_rate: 50
joint_state_broadcaster:
type: joint_state_broadcaster/JointStateBroadcaster
diff_drive_controller:
type: diff_drive_controller/DiffDriveController
diff_drive_controller:
ros__parameters:
left_wheel_names: ["front_left_wheel_joint", "rear_left_wheel_joint"]
right_wheel_names: ["front_right_wheel_joint", "rear_right_wheel_joint"]
wheel_separation: 0.3
wheel_radius: 0.05
base_frame_id: base_link
odom_frame_id: odom
enable_odom_tf: true
cmd_vel_timeout: 0.5
use_stamped_vel: false

View File

@@ -0,0 +1,27 @@
# joint_state_broadcaster发布 joint state
# diff_drive_controller订阅 cmd_vel输出轮子速度命令
controller_manager:
ros__parameters:
update_rate: 50
joint_state_broadcaster:
type: joint_state_broadcaster/JointStateBroadcaster
diff_drive_controller:
type: diff_drive_controller/DiffDriveController
diff_drive_controller:
ros__parameters:
left_wheel_names: ["front_left_wheel_joint", "rear_left_wheel_joint"]
right_wheel_names: ["front_right_wheel_joint", "rear_right_wheel_joint"]
wheel_separation: 0.3
wheel_radius: 0.05
base_frame_id: base_link
odom_frame_id: odom
enable_odom_tf: true
cmd_vel_timeout: 0.5
use_stamped_vel: false

View File

@@ -29,6 +29,8 @@ def generate_launch_description():
parameters=[]
)
# rviz_config=os.path.join(pkg_trolley, 'rviz', 'miniBox.rviz')
rviz = Node(
package='rviz2',
executable='rviz2',

View File

@@ -0,0 +1,79 @@
import os
import tempfile
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription, TimerAction, SetEnvironmentVariable
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
import xacro
def generate_launch_description():
pkg_trolley = get_package_share_directory("trolley")
xacro_path = os.path.join(pkg_trolley, "urdf", "miniBox.urdf.xacro")
pkg_gazebo = get_package_share_directory("gazebo_ros")
controllers_yaml = os.path.join(pkg_trolley, "config", "ros2_controllers.yaml")
# 解析 xacro传入 controllers_yaml 路径
robot_description = xacro.process_file(
xacro_path,
mappings={"controllers_yaml": controllers_yaml}
).toxml()
# ★ 将 urdf 写入固定路径临时文件(不是随机名),方便调试
urdf_tmp_path = "/tmp/box_bot.urdf"
with open(urdf_tmp_path, 'w') as f:
f.write(robot_description)
gazebo = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_gazebo, "launch", "gazebo.launch.py")
)
)
# ★ robot_state_publisher 使用文件路径,不传字符串参数
rsp = Node(
package="robot_state_publisher",
executable="robot_state_publisher",
output="screen",
parameters=[{
"use_sim_time": True,
"robot_description": robot_description,
}],
# ★ 关键:通过环境变量设置 RCL 参数长度限制
additional_env={"RCUTILS_LOGGING_BUFFERED_STREAM": "1"},
)
spawn = Node(
package="gazebo_ros",
executable="spawn_entity.py",
output="screen",
arguments=[
"-file", urdf_tmp_path,
"-entity", "box_bot",
"-z", "0.05",
],
)
spawn_jsb = Node(
package="controller_manager",
executable="spawner",
output="screen",
arguments=["joint_state_broadcaster", "--controller-manager", "/controller_manager"],
)
spawn_dd = Node(
package="controller_manager",
executable="spawner",
output="screen",
arguments=["diff_drive_controller", "--controller-manager", "/controller_manager"],
)
return LaunchDescription([
gazebo,
rsp,
TimerAction(period=3.0, actions=[spawn]),
TimerAction(period=6.0, actions=[spawn_jsb, spawn_dd]),
])

View File

@@ -1,208 +1,2 @@
<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- | This document was autogenerated by xacro from miniBox.urdf.xacro | -->
<!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED | -->
<!-- =================================================================================== -->
<robot name="box_bot">
<!-- base_link-->
<link name="base_link">
<visual>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.06"/>
<geometry>
<box size="0.4 0.3 0.12"/>
</geometry>
<material name="Gray">
<color rgba="0.5 0.5 0.5 1.0"/>
</material>
</visual>
<collision>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.06"/>
<geometry>
<box size="0.4 0.3 0.12"/>
</geometry>
</collision>
<!-- 简化惯性 -->
<inertial>
<origin rpy="0 0 0" xyz="0 0 0.06"/>
<mass value="5.0"/>
<!-- 盒子惯性Ixx = 1/12 m (y^2 + z^2) 等 -->
<inertia ixx="0.04349999999999999" ixy="0" ixz="0" iyy="0.07266666666666667" iyz="0" izz="0.10416666666666666"/>
</inertial>
</link>
<link name="front_left_wheel_link">
<visual>
<origin rpy="1.5708 0.0 0.0" xyz="0.0 0.0 0.0"/>
<geometry>
<cylinder length="0.03" radius="0.05"/>
</geometry>
<material name="Black">
<color rgba="0.1 0.1 0.1 1.0"/>
</material>
</visual>
<collision>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
<geometry>
<cylinder length="0.03" radius="0.05"/>
</geometry>
</collision>
<inertial>
<origin rpy="0 0 0" xyz="0 0 0"/>
<mass value="0.3"/>
<!-- 圆柱体惯性Ixx = Iyy = (1/12) m (3r^2 + h^2) 等 -->
<inertia ixx="0.001" ixy="0" ixz="0" iyy="0.001" iyz="0" izz="0.001"/>
</inertial>
</link>
<joint name="front_left_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="front_left_wheel_link"/>
<origin rpy="0.0 0.0 0.0" xyz="0.15000000000000002 0.15 0.05"/>
<!-- 轮子绕y轴旋转 -->
<axis xyz="0.0 1.0 0.0"/>
</joint>
<link name="front_right_wheel_link">
<visual>
<origin rpy="1.5708 0.0 0.0" xyz="0.0 0.0 0.0"/>
<geometry>
<cylinder length="0.03" radius="0.05"/>
</geometry>
<material name="Black">
<color rgba="0.1 0.1 0.1 1.0"/>
</material>
</visual>
<collision>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
<geometry>
<cylinder length="0.03" radius="0.05"/>
</geometry>
</collision>
<inertial>
<origin rpy="0 0 0" xyz="0 0 0"/>
<mass value="0.3"/>
<!-- 圆柱体惯性Ixx = Iyy = (1/12) m (3r^2 + h^2) 等 -->
<inertia ixx="0.001" ixy="0" ixz="0" iyy="0.001" iyz="0" izz="0.001"/>
</inertial>
</link>
<joint name="front_right_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="front_right_wheel_link"/>
<origin rpy="0.0 0.0 0.0" xyz="0.15000000000000002 -0.15 0.05"/>
<!-- 轮子绕y轴旋转 -->
<axis xyz="0.0 1.0 0.0"/>
</joint>
<link name="rear_left_wheel_link">
<visual>
<origin rpy="1.5708 0.0 0.0" xyz="0.0 0.0 0.0"/>
<geometry>
<cylinder length="0.03" radius="0.05"/>
</geometry>
<material name="Black">
<color rgba="0.1 0.1 0.1 1.0"/>
</material>
</visual>
<collision>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
<geometry>
<cylinder length="0.03" radius="0.05"/>
</geometry>
</collision>
<inertial>
<origin rpy="0 0 0" xyz="0 0 0"/>
<mass value="0.3"/>
<!-- 圆柱体惯性Ixx = Iyy = (1/12) m (3r^2 + h^2) 等 -->
<inertia ixx="0.001" ixy="0" ixz="0" iyy="0.001" iyz="0" izz="0.001"/>
</inertial>
</link>
<joint name="rear_left_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="rear_left_wheel_link"/>
<origin rpy="0.0 0.0 0.0" xyz="-0.25 0.15 0.05"/>
<!-- 轮子绕y轴旋转 -->
<axis xyz="0.0 1.0 0.0"/>
</joint>
<link name="rear_right_wheel_link">
<visual>
<origin rpy="1.5708 0.0 0.0" xyz="0.0 0.0 0.0"/>
<geometry>
<cylinder length="0.03" radius="0.05"/>
</geometry>
<material name="Black">
<color rgba="0.1 0.1 0.1 1.0"/>
</material>
</visual>
<collision>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
<geometry>
<cylinder length="0.03" radius="0.05"/>
</geometry>
</collision>
<inertial>
<origin rpy="0 0 0" xyz="0 0 0"/>
<mass value="0.3"/>
<!-- 圆柱体惯性Ixx = Iyy = (1/12) m (3r^2 + h^2) 等 -->
<inertia ixx="0.001" ixy="0" ixz="0" iyy="0.001" iyz="0" izz="0.001"/>
</inertial>
</link>
<joint name="rear_right_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="rear_right_wheel_link"/>
<origin rpy="0.0 0.0 0.0" xyz="-0.25 -0.15 0.05"/>
<!-- 轮子绕y轴旋转 -->
<axis xyz="0.0 1.0 0.0"/>
</joint>
<!-- 雷达支架 -->
<!-- 通常放到轮心高度 -->
<link name="lidar_mount_link">
<visual>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.16999999999999998"/>
<geometry>
<box size="0.05 0.05 0.10"/>
</geometry>
<material name="Blue">
<color rgba="0.2 0.2 0.8 1.0"/>
</material>
</visual>
<collision>
<origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.16999999999999998"/>
<geometry>
<box size="0.05 0.05 0.10"/>
</geometry>
</collision>
<!-- 简化惯性 -->
<inertial>
<origin rpy="0 0 0" xyz="0 0 0.16999999999999998"/>
<mass value="0.2"/>
<inertia ixx="0.0001" ixy="0" ixz="0" iyy="0.0001" iyz="0" izz="0.0001"/>
</inertial>
</link>
<joint name="lidar_mount_joint" type="fixed">
<parent link="base_link"/>
<child link="lidar_mount_link"/>
<!-- 前方: x正方向 -->
<origin rpy="0.0 0.0 0.0" xyz="0.15000000000000002 0 0"/>
</joint>
<!-- 四轮驱动插件(skid steer) -->
<gazebo>
<plugin filename="libgazebo_ros_skid_steer_drive.so" name="skid_steer_drive">
<ros>
<namespace>/</namespace>
</ros>
<!-- cmd_vel 输入 -->
<commandTopic>cmd_vel</commandTopic>
<!-- 里程计 -->
<odometryTopic>odom</odometryTopic>
<odometryFrame>odom</odometryFrame>
<robotBaseFrame>base_link</robotBaseFrame>
<!-- 四个轮子关节命名 -->
<leftFrontWheelJoint>front_left_wheel_joint</leftFrontWheelJoint>
<rightFrontWheelJoint>front_right_wheel_joint</rightFrontWheelJoint>
<leftRearWheelJoint>rear_left_wheel_joint</leftRearWheelJoint>
<rightRearWheelJoint>rear_right_wheel_joint</rightRearWheelJoint>
<!-- 几何参数 -->
<wheelSeparation>0.3</wheelSeparation>
<wheelDiameter>0.1</wheelDiameter>
<!-- 可调 -->
<wheelTorque>5.0</wheelTorque>
<updateRate>50</updateRate>
</plugin>
</gazebo>
</robot>
data: <?xml version="1.0" ?><!-- =================================================================================== --><!-- | This...
---