ROS四轮小车仿真

ROS 四轮小车仿真

一 、建立模型文件

模型文件代码解释

1

<?xml version="1.0" ?>

<robot name="differential_wheeled_robot" 
  xmlns:xacro="http://www.ros.org/wiki/xacro">

解析xacro文件所需的所有xacro文件的命名空间并添加xacro文件的名称

2

<material name="Black">
    <color rgba="0.0 0.0 0.0 1.0"/>
  </material>
  <material name="Red">
    <color rgba="0.8 0.0 0.0 1.0"/>
  </material>
  <material name="White">
    <color rgba="1.0 1.0 1.0 1.0"/>
  </material>
  <material name="Blue">
    <color rgba="0.0 0.0 0.8 1.0"/>
  </material>
<material name="gray">
    <color rgba="0.0 0.0 0.6 1.0"/>

定义小车所需要的颜色材料信息
3

  <link name="base_link">
    <inertial>
      <mass value="5"/>
      <origin xyz="0 0 0"/>
      <!--The 3x3 rotational inertia matrix. -->
      <inertia ixx="0.0282916666667" ixy="0" ixz="0" iyy="0.0282916666667" iyz="0" izz="0.05625"/>
    </inertial>
    <visual>
      <origin rpy="0 0 0" xyz="0 0 0"/>
      <geometry>
        <box size="0.2 0.2 0.05"/>
      </geometry>
      <material name="White"/>
    </visual>
    <collision>
      <origin rpy="0 0 0 " xyz="0 0 0"/>
      <geometry>
        <box size="0.28 0.17 0.05"/>
      </geometry>
    </collision>
  </link>
  <gazebo reference="base_link">
    <material>Gazebo/Blue</material>
    <turnGravityOff>false</turnGravityOff>
  </gazebo>

定义小车的主体的物理属性 几何形状 材质 以及原点

4

<link name="front_left_wheel">
    <visual>
      <origin rpy="1.57079632679 0  0 " xyz="0 0 0"/>
      <geometry>
        <cylinder length="0.03" radius="0.032"/>
      </geometry>
      <material name="gray"/>
    </visual>
    <collision>
      <origin rpy="1.57079632679 0 0 " xyz="0 0 0"/>
      <geometry>
        <cylinder length="0.03" radius="0.032"/>
      </geometry>
    </collision>
    <inertial>
      <mass value="2.5"/>
      <origin xyz="0 0 0"/>
      <inertia ixx="0.00108333333333" ixy="0" ixz="0" iyy="0.00108333333333" iyz="0" izz="0.002"/>
    </inertial>
  </link>
  <gazebo reference="front_left_wheel">
    <mu1 value="1.0"/>
    <mu2 value="1.0"/>
    <kp value="10000000.0"/>
    <kd value="1.0"/>
    <fdir1 value="1 0 0"/>
    <material>Gazebo/Black</material>
    <turnGravityOff>false</turnGravityOff>
  </gazebo>

定义轮子的物理信息(每个轮子的位置坐标是不同的)
用gazebo reference标签说明摩擦系数,和刚度系数

5

<joint name="front_right_wheel_joint" type="continuous">
    <parent link="base_link"/>
    <child link="front_right_wheel"/>
    <origin rpy="0 0 0" xyz="0.10 -0.10 0.0"/>
    <axis rpy="0  0" xyz="0 1 0"/>
    <limit effort="100" velocity="100"/>
    <joint_properties damping="0.0" friction="0.0"/>
  </joint>

定义小车的关节 两个连杆之间会形成一个关节,第一个是父连杆第二个是子连杆;这里给定了转动的limit。
6

<transmission name="front_right_wheel_joint_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="front_right_wheel_joint"/>
    <actuator name="front_right_wheel_joint_motor">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>

为了使ROS控制机器来驱动机器人,需要定义传动标签来连接执行机构和关节。

7

gazebo>
    <plugin name="object_controller" filename="libgazebo_ros_planar_move.so">
      <commandTopic>cmd_vel</commandTopic>
      <odometryRate>20.0</odometryRate> 
      <broadcastTF>true</broadcastTF>
      <publishOdomTF>true</publishOdomTF>
      <robotBaseFrame>base_link</robotBaseFrame>
      <odometryTopic>odom</odometryTopic>
      <odometryFrame>odom</odometryFrame>
    </plugin>
  </gazebo>

添加gazebo_ros_control插件

<commandTopic>cmd_vel</commandTopic>

该参数是插件的速度指令话题,是ros中的一个twist类型的消息。我们可以将twist消息发布到/cmd_vel话题中,小车就开始移动。

二 、launch文件

<launch>
    <param name="robot_description" command="cat '$(find small_car_model)/urdf/small_car.urdf'"/>

    <!-- send fake joint values -->
    <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
        <param name="use_gui" value="False"/>
    </node>

    <!-- Combine joint values -->
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"/>

    <include file="$(find gazebo_ros)/launch/empty_world.launch">
        <!--<arg name="world_name" value="$(find small_car_model)/worlds/ramp.world"/>-->
        <arg name="paused" value="false"/>
        <arg name="use_sim_time" value="true"/>
        <arg name="gui" value="true"/>
        <arg name="headless" value="false"/>
        <arg name="debug" value="false"/>
        <remap from="tf" to="gazebo_tf"/>
    </include>

    <node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="-urdf -model my_robot -x 0.0 -y 0.0 -z 0 -R 0 -P 0 -Y 0 -param robot_description" />
  
</launch>

在机器人状态发布者代码段
需要把 type="state_publisher"
写成type=robot_state_publisher"

三 键盘控制

在终端中运行下面命令安装键盘功能包

$ sudo apt-get install ros-noetic-teleop-twist-keyboard
$ rosstack profile
$ rospack profile

然后运行节点

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

可以使用u i o
j k l
<>
进行控制

总结

1.在建立模型时候,需要为每个节点添加传动标签
,并且添加控制器
2 tf_tree的正确性
在这里插入图片描述

  • 0
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值