紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
-
小车在RViz里面就可以动,在gazebo里面就不能动,不知道为啥,还请大佬多多指教!!!
<launch> <!-- 设置launch文件的参数 --> <arg name="world_name" value="$(find mrobot_gazebo)/worlds/playground.world"/> <arg name="paused" default="false"/> <arg name="use_sim_time" default="true"/> <arg name="gui" default="true"/> <arg name="headless" default="false"/> <arg name="debug" default="false"/> <!-- 运行gazebo仿真环境 --> <include file="$(find gazebo_ros)/launch/empty_world.launch"> <arg name="world_name" value="$(arg world_name)" /> <arg name="debug" value="$(arg debug)" /> <arg name="gui" value="$(arg gui)" /> <arg name="paused" value="$(arg paused)"/> <arg name="use_sim_time" value="$(arg use_sim_time)"/> <arg name="headless" value="$(arg headless)"/> </include> <!-- 加载机器人模型描述参数/urdf/xacro/gazebo/mbot_base_gazebo.xacro --> <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mbot_description)/urdf/xacro/gazebo/mbot_base_gazebo.xacro'" /> <!-- 设置GUI参数,显示关节控制插件 --> <param name="use_gui" value="$(arg gui)"/> <node name="arbotix" pkg="arbotix_python" type="arbotix_driver" output="screen"> <rosparam file="$(find mbot_description)/config/fake_mbot_arbotix.yaml" command="load" /> <param name="sim" value="true"/> </node> <!-- 运行joint_state_publisher节点,发布机器人的关节状态 --> <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node> <!-- 运行robot_state_publisher节点,发布tf --> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" output="screen" > <param name="publish_frequency" type="double" value="50.0" /> </node> <!-- 在gazebo中加载机器人模型--> <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-urdf -model mrobot -param robot_description"/> <!-- 运行rviz可视化界面 --> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_arbotix.rviz" required="true" /> </launch>
第二段:urdf/xacro/gazebo/mbot_base_gazebo.xacro
<?xml version="1.0"?> <robot name="mbot" xmlns:xacro="http://www.ros.org/wiki/xacro"> <!-- PROPERTY LIST --> <xacro:property name="M_PI" value="3.1415926"/> <xacro:property name="base_mass" value="20" /> <xacro:property name="base_radius" value="0.20"/> <xacro:property name="base_length" value="0.16"/> <xacro:property name="wheel_mass" value="2"/> <xacro:property name="wheel_radius" value="0.06"/> <xacro:property name="wheel_length" value="0.025"/> <xacro:property name="wheel_joint_y" value="0.19"/> <xacro:property name="wheel_joint_z" value="0.05"/> <xacro:property name="caster_mass" value="0.5"/> <xacro:property name="caster_radius" value="0.015"/> <!-- wheel_radius - ( base_length/2 - wheel_joint_z) --> <xacro:property name="caster_joint_x" value="0.18"/> <!-- Defining the colors used in this robot --> <material name="yellow"> <color rgba="1 0.4 0 1"/> </material> <material name="black"> <color rgba="0 0 0 0.95"/> </material> <material name="gray"> <color rgba="0.75 0.75 0.75 1"/> </material> <!-- Macro for inertia matrix --> <xacro:macro name="sphere_inertial_matrix" params="m r"> <inertial> <mass value="${m}" /> <inertia ixx="${2*m*r*r/5}" ixy="0" ixz="0" iyy="${2*m*r*r/5}" iyz="0" izz="${2*m*r*r/5}" /> </inertial> </xacro:macro> <xacro:macro name="cylinder_inertial_matrix" params="m r h"> <inertial> <mass value="${m}" /> <inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0" iyy="${m*(3*r*r+h*h)/12}" iyz = "0" izz="${m*r*r/2}" /> </inertial> </xacro:macro> <!-- Macro for robot wheel --> <xacro:macro name="wheel" params="prefix reflect"> <joint name="base_${prefix}_wheel_joint" type="continuous"> <origin xyz="0 ${reflect*wheel_joint_y} ${-wheel_joint_z}" rpy="0 0 0"/> <parent link="base_link"/> <child link="${prefix}_wheel_link"/> <axis xyz="0 1 0"/> </joint> <link name="${prefix}_wheel_link"> <visual> <origin xyz=" 0 0 0 " rpy="${M_PI/2} 0 0" /> <geometry> <cylinder radius="${wheel_radius}" length = "${wheel_length}"/> </geometry> <material name="gray" /> </visual> <collision> <origin xyz="0 0 0" rpy="${M_PI/2} 0 0 " /> <geometry> <cylinder radius="${wheel_radius}" length="${wheel_length}" /> </geometry> </collision> <cylinder_inertial_matrix m="${wheel_mass}" r="${wheel_radius}" h="${wheel_length}" /> </link> <gazebo reference="${prefix}_wheel_link"> <material>Gazebo/Gray</material> </gazebo> <!-- Transmission is important to link the joints and the controller --> <transmission name="${prefix}_wheel_joint_trans"> <type>transmission_interface/SimpleTransmission</type> <joint name="${prefix}_wheel_joint" > <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> </joint> <actuator name="${prefix}_wheel_joint_motor"> <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface> <mechanicalReduction>1</mechanicalReduction> </actuator> </transmission> </xacro:macro> <!-- Macro for robot caster --> <xacro:macro name="caster" params="prefix reflect"> <joint name="${prefix}_caster_joint" type="continuous"> <origin xyz="${reflect*caster_joint_x} 0 ${-(base_length/2 + caster_radius)}" rpy="0 0 0" /> <parent link="base_link"/> <child link="${prefix}_caster_link" /> <axis xyz="0 1 0"/> </joint> <link name="${prefix}_caster_link"> <visual> <origin xyz=" 0 0 0 " rpy="0 0 0" /> <geometry> <sphere radius="${caster_radius}" /> </geometry> <material name="black" /> </visual> <collision> <origin xyz="0 0 0" rpy="0 0 0 " /> <geometry> <sphere radius="${caster_radius}" /> </geometry> </collision> <sphere_inertial_matrix m="${caster_mass}" r="${caster_radius}" /> </link> <gazebo reference="${prefix}_caster_link"> <material>Gazebo/Black</material> </gazebo> </xacro:macro> <xacro:macro name="mbot_base_gazebo"> <link name="base_footprint"> <visual> <origin xyz=" 0 0 0 " rpy="0 0 0" /> <geometry> <box size="0.001 0.001 0.001" /> </geometry> </visual> </link> <gazebo reference="base_footprint"> <turnGravityOff>false</turnGravityOff> </gazebo> <joint name="base_footprint_joint" type="fixed"> <origin xyz="0 0 ${base_length/2 + caster_radius*2}" rpy="0 0 0" /> <parent link="base_footprint"/> <child link="base_link" /> </joint> <link name="base_link"> <visual> <origin xyz=" 0 0 0 " rpy="0 0 0" /> <geometry> <cylinder length="${base_length}" radius="${base_radius}" /> </geometry> <material name="yellow" /> </visual> <collision> <origin xyz="0 0 0" rpy="0 0 0 " /> <geometry> <cylinder length="${base_length}" radius="${base_radius}" /> </geometry> </collision> <cylinder_inertial_matrix m="${base_mass}" r="${base_radius}" h="${base_length}" /> </link> <gazebo reference="base_link"> <material>Gazebo/Blue</material> </gazebo> <wheel prefix="l" reflect="-1"/> <wheel prefix="r" reflect="1"/> <caster prefix="front" reflect="-1"/> <caster prefix="back" reflect="1"/> <!-- controller --> <gazebo> <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so"> <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>${wheel_joint_y*2}</wheelSeparation> <wheelDiameter>${2*wheel_radius}</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> </xacro:macro> <xacro:mbot_base_gazebo/> </robot>
-
朋友,不知道你和我是不是同样的问题,或许可以试试看
sudo apt install ros-melodic-gazebo-ros-pkgs ros-melodic-gazebo-msgs ros-melodic-gazebo-plugins ros-melodic-gazebo-ros-control
参考
https://www.freesion.com/article/8223995772/
-
@1687028512 谢谢你呀,我跑了一下例程,例程没问题。应该是我这个代码了问题!!谢谢你
-
@821234877 客气了~多多交流呀
-
-
-