小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
Gazebo与RViz联合仿真时odom消失
-
irobot.urdf(sw2urdf导出urdf+differ_controller+laser)
odom_gazebo.launch
odom_rviz.launch联合仿真时出现问题:
RViz单独仿真无问题:
-
irobot.urdf
<?xml version="1.0" encoding="utf-8"?> <robot name="irobot"> <link name="base_footprint"> <visual> <geometry> <sphere radius="0.001" /> </geometry> <material name=""> <color rgba="0 0 0 0" /> </material> </visual> </link> <link name="base_link"> <inertial> <origin xyz="0.0353 6.2375E-05 0.0378" rpy="0 0 0" /> <mass value="4.4466" /> <inertia ixx="0.037776" ixy="0" ixz="0" iyy="0.026331" iyz="0" izz="0.060251" /> </inertial> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/base_link.STL" /> </geometry> <material name=""> <color rgba="0 0 0 1" /> </material> </visual> <collision> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/base_link.STL" /> </geometry> </collision> </link> <joint name="base_link2base_footprint" type="fixed"> <parent link="base_footprint" /> <child link="base_link" /> <origin xyz="0 0 0.011" /> <!--irobot_height/2--> </joint> <link name="top_link"> <inertial> <origin xyz="-0.005083 -0.000153 0.000877" rpy="0 0 0" /> <mass value="0.11187" /> <inertia ixx="0.0008137" ixy="0" ixz="0" iyy="0.00071" iyz="0" izz="0.001524" /> </inertial> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/top_link.STL" /> </geometry> <material name=""> <color rgba="0 1 0 1" /> </material> </visual> <collision> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/top_link.STL" /> </geometry> </collision> </link> <joint name="top_joint" type="fixed"> <origin xyz="0 0 0.0699" rpy="0 0 0" /> <parent link="base_link" /> <child link="top_link" /> <axis xyz="0 0 0" /> <limit lower="0" upper="0" effort="0" velocity="0" /> </joint> <link name="laser_link"> <inertial> <origin xyz="-4.0578E-09 2.09E-09 0.00303" rpy="0 0 0" /> <mass value="0.001737" /> <inertia ixx="4.1116E-08" ixy="0" ixz="0" iyy="4.1116E-08" iyz="0" izz="7.8771E-08" /> </inertial> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/laser_link.STL" /> </geometry> <material name=""> <color rgba="1 0 0 1" /> </material> </visual> <collision> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/laser_link.STL" /> </geometry> </collision> </link> <joint name="laser_joint" type="fixed"> <origin xyz="0.155 0 0.07433" rpy="0 0 0" /> <parent link="base_link" /> <child link="laser_link" /> <axis xyz="0 0 0" /> <limit lower="0" upper="0" effort="0" velocity="0" /> </joint> <link name="driven_link"> <inertial> <origin xyz="0 -4.6809E-19 4.3368E-19" rpy="0 0 0" /> <mass value="0.014137" /> <inertia ixx="1.2723E-06" ixy="0" ixz="0" iyy="1.2723E-06" iyz="0" izz="1.2723E-06" /> </inertial> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/driven_link.STL" /> </geometry> <material name=""> <color rgba="1 1 1 1" /> </material> </visual> <collision> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/driven_link.STL" /> </geometry> </collision> </link> <joint name="driven_joint" type="continuous"> <origin xyz="0.13 0 0.00438" rpy="0 0 0" /> <parent link="base_link" /> <child link="driven_link" /> <axis xyz="0 0 1" /> <limit lower="-3.14" upper="3.14" effort="0" velocity="0" /> </joint> <link name="left_wheel_link"> <inertial> <origin xyz="5.9165E-31 -1.3878E-17 3.4694E-18" rpy="0 0 0" /> <mass value="0.066366" /> <inertia ixx="2.2972E-05" ixy="0" ixz="0" iyy="2.2972E-05" iyz="0" izz="4.3005E-05" /> </inertial> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/left_wheel_link.STL" /> </geometry> <material name=""> <color rgba="1 1 1 1" /> </material> </visual> <collision> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/left_wheel_link.STL" /> </geometry> </collision> </link> <joint name="left_wheel_joint" type="continuous"> <origin xyz="0 -0.10045 0.02538" rpy="0 0 0" /> <parent link="base_link" /> <child link="left_wheel_link" /> <axis xyz="0 -1 0" /> <limit lower="-3.14" upper="3.14" effort="0" velocity="0" /> </joint> <link name="right_wheel_link"> <inertial> <origin xyz="-1.5766E-18 1.3878E-17 3.4694E-18" rpy="0 0 0" /> <mass value="0.066366" /> <inertia ixx="2.2972E-05" ixy="0" ixz="0" iyy="2.2972E-05" iyz="0" izz="4.3005E-05" /> </inertial> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/right_wheel_link.STL" /> </geometry> <material name=""> <color rgba="1 1 1 1" /> </material> </visual> <collision> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://irobot/meshes/right_wheel_link.STL" /> </geometry> </collision> </link> <joint name="right_wheel_joint" type="continuous"> <origin xyz="0 0.10045 0.02538" rpy="0 0 0" /> <parent link="base_link" /> <child link="right_wheel_link" /> <axis xyz="0 -1 0" /> <limit lower="-3.14" upper="3.14" effort="0" velocity="0" /> </joint> <!--color--> <gazebo reference="base_link"> <material>Gazebo/Black</material> </gazebo> <gazebo reference="top_link"> <material>Gazebo/Green</material> </gazebo> <gazebo reference="laser_link"> <material>Gazebo/Red</material> </gazebo> <gazebo reference="camera_link"> <material>Gazebo/Red</material> </gazebo> <gazebo reference="driven_link"> <material>Gazebo/White</material> </gazebo> <gazebo reference="left_wheel_link"> <material>Gazebo/White</material> </gazebo> <gazebo reference="right_wheel_link"> <material>Gazebo/White</material> </gazebo> <!-- controller --> <transmission name="left_wheel_joint_trans"> <type>transmission_interface/SimpleTransmission</type> <joint name="left_wheel_joint"> <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> </joint> <actuator name="left_wheel_joint_motor"> <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> <mechanicalReduction>1</mechanicalReduction> </actuator> </transmission> <transmission name="right_wheel_joint_trans"> <type>transmission_interface/SimpleTransmission</type> <joint name="right_wheel_joint"> <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> </joint> <actuator name="right_wheel_joint_motor"> <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> <mechanicalReduction>1</mechanicalReduction> </actuator> </transmission> <gazebo> <plugin filename="libgazebo_ros_diff_drive.so" name="differential_drive_controller"> <rosDebugLevel>Debug</rosDebugLevel> <publishWheelTF>true</publishWheelTF> <robotNamespace>/</robotNamespace> <publishTf>1</publishTf> <publishWheelJointState>true</publishWheelJointState> <alwaysOn>true</alwaysOn> <updateRate>100.0</updateRate> <legacyMode>true</legacyMode> <leftJoint>left_wheel_joint</leftJoint> <rightJoint>right_wheel_joint</rightJoint> <wheelSeparation>0.277</wheelSeparation> <wheelDiameter>0.073</wheelDiameter> <broadcastTF>1</broadcastTF> <wheelTorque>30</wheelTorque> <wheelAcceleration>1.8</wheelAcceleration> <commandTopic>cmd_vel</commandTopic> <odometryFrame>odom</odometryFrame> <odometryTopic>odom</odometryTopic> <robotBaseFrame>base_footprint</robotBaseFrame> </plugin> </gazebo> <!--laser--> <gazebo reference="laser_link"> <sensor name="rplidar" type="ray"> <pose>0 0 0 0 0 0</pose> <visualize>true</visualize> <update_rate>5.5</update_rate> <ray> <scan> <horizontal> <samples>360</samples> <resolution>1</resolution> <min_angle>-3</min_angle> <max_angle>3</max_angle> </horizontal> </scan> <range> <min>0.10</min> <max>30.0</max> <resolution>0.01</resolution> </range> <noise> <type>gaussian</type> <mean>0.0</mean> <stddev>0.01</stddev> </noise> </ray> <plugin filename="libgazebo_ros_laser.so" name="gazebo_rplidar"> <topicName>/scan</topicName> <frameName>laser_link</frameName> </plugin> </sensor> </gazebo> </robot>
odom_gazebo.launch
<launch> <param name="robot_description" textfile="$(find irobot)/urdf/irobot.urdf" /> <include file="$(find gazebo_ros)/launch/empty_world.launch"/> <node name="tf_footprint_base" pkg="tf" type="static_transform_publisher" args="0 0 0 0 0 0 base_link base_footprint 40" /> <node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model irobot -param robot_description" /> <node name="fake_joint_calibration" pkg="rostopic" type="rostopic" args="pub /calibrated std_msgs/Bool true" /> </launch>
odom_rviz.launch
<launch> <param name="robot_description" textfile="$(find irobot)/urdf/irobot.urdf" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find irobot)/config/irobot.rviz" /> <node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /> <node name="arbotix" pkg="arbotix_python" type="arbotix_driver" output="screen"> <rosparam file="$(find irobot)/config/diff_controller.yaml" command="load" /> <param name="sim" value="true" /> </node> </launch>
-
初步估计是TF问题,晚点我看一下,代码可以改成用代码块包裹一下,太长了,不好看。
-
此回复已被删除! -
@924453613 每个帖子都可以再次编辑和删除的,不用再发一个哈哈,菜单在右下角。
-
@924453613
需要补充一些内容- 补充一下rqt_tf_tree的截图
- 补充一下gazebo版本系统版本和ros版本
- 补充
config/diff_controller.yaml
文件内容
同时做如下的尝试:
- 从
odom_rviz.launch
删除arbotix节点后运行
-
@小鱼
rqt_tf_tree
ubuntu18.04-melodic-gazebo11
config/diff_controller.yaml
# 该文件是控制器配置,一个机器人模型可能有多个控制器,比如: 底盘、机械臂、夹持器(机械手).... # 因此,根 name 是 controller controllers: { # 单控制器设置 base_controller: { #类型: 差速控制器 type: diff_controller, #参考坐标 base_frame_id: base_footprint, #两个轮子之间的间距 base_width: 0.277, #控制频率 ticks_meter: 2000, #PID控制参数,使机器人车轮快速达到预期速度 Kp: 12, Kd: 12, Ki: 0, Ko: 50, #加速限制 accel_limit: 1.0 } }
删除arbotix结果
-
@924453613 看一下rqt_grapher,有几个joint_states的发布者。
-
@小鱼 只有一个
-
@924453613 这个rqt_graph看起来非常不对劲。因为两轮差速这边也会发布机器人的
joint_states
,所以不需要再启动joint_state_publisher
。修改odom_rviz.py
<launch> <param name="robot_description" textfile="$(find irobot)/urdf/irobot.urdf" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find irobot)/config/irobot.rviz" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /> <node name="arbotix" pkg="arbotix_python" type="arbotix_driver" output="screen"> <rosparam file="$(find irobot)/config/diff_controller.yaml" command="load" /> <param name="sim" value="true" /> </node> </launch>
-
@小鱼 有rqt_graph了 RViz中tf还是断开的
-
@924453613 你看这里,一个话题有两个发布者,robot_state_publisher都不知道听谁的,所以导致TF错误,按照我上一条回复把joint_state_publisher干掉试试。
-
@小鱼
干掉之后是这样的 RViz中tf还是断开的
-
@924453613 现在还是有两个发布者在发布joint_states,只需要一个gazebo即可,请按照之前帖子里的提示删掉arbotix控制器程序。
另外需要注意的是,arbotix的功能和urdf中配置的differential_drive_controller功能是相同(从两者的配置可以看出,都有轮子名称,轮子间距等配置),但differential_drive_controller才是用于gazebo仿真使用的。
-
@小鱼 感谢鱼总这么晚还在解答我的问题 我删除arbotix后 我重新查看tf树发现以下问题
1.odom到base_link断开
2.tf树与最初发布帖子时不同
rqt_graph如下
-
@924453613 首先恭喜你,离成功越来越近了,注意两轮差速模型的配置项
robotBaseFrame
,该项为其发布的joint_states参考的frame名称。<plugin filename="libgazebo_ros_diff_drive.so" name="differential_drive_controller"> <robotBaseFrame>base_footprint</robotBaseFrame> </plugin>
尝试进一步修改:
- 将
<robotBaseFrame>
的base_footprint
->base_link
,这样gazebo发布数据时应该会将base_link
->left/right_joint
- 尝试删除静态发布
footprint
->base_link
,因为在我看来,它也是多余的,两者之间的关系在URDF中已经给出。
<node name="tf_footprint_base" pkg="tf" type="static_transform_publisher" args="0 0 0 0 0 0 base_link base_footprint 40" />
- 将
-
@小鱼 感谢鱼总,目前tf树仍有问题,夜已深鱼总早点休息,明早我会继续尝试,非常感谢。
-
@924453613 ok,目前看到对应的tf还是没有链接起来,需要注意的地方就是上文中提到的,可以多次修改尝试,祝早日成功,早点休息。
-
@小鱼 非常感谢鱼总的解答目前已经解决,问题大概率是出现在odom_rviz.launch中重复出现了/arbotix,导致tf树出错了,谢谢
-
@924453613 很高兴能够看到该问题被解决掉,如果方便可以贴一下解决后的代码在本帖子中,方便其他小伙伴在遇到相同问题提供帮助。