ROS之Gazebo

<?xml version="1.0"?>
<launch>

  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="true"/>
  <arg name="use_sim_time" default="false"/>
  <arg name="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>

  <!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
   <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="$(find carModel)/worlds/robot.world"/>
    <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>

  <!-- Load the URDF into the ROS Parameter Server -->
  <arg name="model" />
  <param name="robot_description" command="$(find xacro)/xacro.py $(find carModel)/urdf/robot1_base_02.xacro" />

  <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-urdf -model robot1 -param robot_description -z 0.05"/> 

</launch>

首先是把ros自带的gazebo_ros包的启动文件加载进来, 并启动里面的节点

   <include file="$(find gazebo_ros)/launch/empty_world.launch">

然后解码xacro

<param name="robot_description" command="$(find xacro)/xacro.py $(find carModel)/urdf/robot1_base_02.xacro" />

然后启动一个urdf转换节点:

<node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-urdf -model robot1 -param robot_description -z 0.05"/>

再看看这个xacro里面都是啥:

<?xml version="1.0"?>

<robot xmlns:xacro="http://www.ros.org/wiki/xacro"
 	xmlns:sensor="http://playerstage.sourceforge.net/gazebo/xmlschema/#sensor"
    	xmlns:controller="http://playerstage.sourceforge.net/gazebo/xmlschema/#controller"
    	xmlns:interface="http://playerstage.sourceforge.net/gazebo/xmlschema/#interface"
	name="robot1_xacro">

	<xacro:property name="length_wheel" value="0.05" />
	<xacro:property name="radius_wheel" value="0.05" />
	<xacro:macro name="default_inertial" params="mass">
               <inertial>
                       <mass value="${mass}" />
                       <inertia ixx="1.0" ixy="0.0" ixz="0.0"
                                iyy="1.0" iyz="0.0"
                                izz="1.0" />
               </inertial>
	</xacro:macro>
	<xacro:include filename="$(find carModel)/urdf/robot.gazebo" />
	<link name="base_footprint">
   		<visual>
			<geometry>
      				<box size="0.001 0.001 0.001"/>
     			</geometry>
			<origin rpy="0 0 0" xyz="0 0 0"/>
   		</visual>
		<xacro:default_inertial mass="0.0001"/>
 	</link>

	<gazebo reference="base_footprint">
		<material>Gazebo/Green</material>
		<turnGravityOff>false</turnGravityOff>
	</gazebo>

	<joint name="base_footprint_joint" type="fixed">
		<origin xyz="0 0 0" />
		<parent link="base_footprint" />
		<child link="base_link" />
	</joint>

	<link name="base_link">
   		<visual>
			<geometry>
      				<box size="0.2 .3 .1"/>
     			</geometry>
			<origin rpy="0 0 1.54" xyz="0 0 0.05"/>
			<material name="darkblue">
        			<color rgba=".1 .1 .5 1"/>
      			</material>
   		</visual>
		<collision>
			<geometry>
       				<box size="0.2 .3 0.1"/>
			</geometry>
		</collision>
		<xacro:default_inertial mass="10"/>
 	</link>

 	<link name="wheel_1">
   		<visual>
     			<geometry>
       				<cylinder length="${length_wheel}" radius="${radius_wheel}"/>
     			</geometry>
			<!-- <origin rpy="0 1.5 0" xyz="0.1 0.1 0"/> -->
			<origin rpy="0 0 0" xyz="0 0 0"/>
   			<material name="black">
				<color rgba="0 0 0 1"/>
			</material>
		</visual>
		<collision>
			<geometry>
       				<cylinder length="${length_wheel}" radius="${radius_wheel}"/>
			</geometry>
		</collision>
		<xacro:default_inertial mass="1"/>
 	</link>

 	<link name="wheel_2">
   		<visual>
     			<geometry>
       				<cylinder length="${length_wheel}" radius="${radius_wheel}"/>
     			</geometry>
			<!-- <origin rpy="0 1.5 0" xyz="-0.1 0.1 0"/> -->
			<origin rpy="0 0 0" xyz="0 0 0"/>
   			<material name="black"/>
   		</visual>
		<collision>
			<geometry>
       				<cylinder length="${length_wheel}" radius="${radius_wheel}"/>
			</geometry>
		</collision>
		<xacro:default_inertial mass="1"/>

 	</link>

 	<link name="wheel_3">
   		<visual>
     			<geometry>
       				<cylinder length="${length_wheel}" radius="${radius_wheel}"/>
     			</geometry>
			<!-- <origin rpy="0 1.5 0" xyz="0.1 -0.1 0"/> -->

			<origin rpy="0 0 0" xyz="0 0 0"/>
   			<material name="black"/>
   		</visual>
		<collision>
			<geometry>
       				<cylinder length="${length_wheel}" radius="${radius_wheel}"/>
			</geometry>
		</collision>
		<xacro:default_inertial mass="1"/>
 	</link>

 	<link name="wheel_4">
   		<visual>
     			<geometry>
       				<cylinder length="${length_wheel}" radius="${radius_wheel}"/>
     			</geometry>
		<!--	<origin rpy="0 1.5 0" xyz="-0.1 -0.1 0"/> -->
			<origin rpy="0 0 0" xyz="0 0 0" />
   			<material name="black"/>
   		</visual>
		<collision>
			<geometry>
       				<cylinder length="${length_wheel}" radius="${radius_wheel}"/>
			</geometry>
		</collision>
		<xacro:default_inertial mass="1"/>

 	</link>

 <joint name="base_to_wheel1" type="continuous">
   <parent link="base_link"/>
   <child link="wheel_1"/>
   <origin rpy="1.5707 0 0" xyz="0.1 0.15 0"/>
   <axis xyz="0 0 1" />
 </joint>

 <joint name="base_to_wheel2" type="continuous">
   <axis xyz="0 0 1" />
   <anchor xyz="0 0 0" />
   <limit effort="100" velocity="100" />
   <parent link="base_link"/>
   <child link="wheel_2"/>
   <origin rpy="1.5707 0 0" xyz="-0.1 0.15 0"/>
</joint>

 <joint name="base_to_wheel3" type="continuous">
   <parent link="base_link"/>
   <axis xyz="0 0 1" />
   <child link="wheel_3"/>
   <origin rpy="1.5707 0 0" xyz="0.1 -0.15 0"/>
 </joint>

 <joint name="base_to_wheel4" type="continuous">
   <parent link="base_link"/>
   <axis xyz="0 0 1" />
   <child link="wheel_4"/>
   <origin rpy="1.5707 0 0" xyz="-0.1 -0.15 0"/>

 </joint>

分别定义了若干link, 关节.

运行下面的命令:

roslaunch carModel gazebo.launch

为啥有个轮子是绿色的呢?

	<xacro:include filename="$(find carModel)/urdf/robot.gazebo" />

这个gazebo文件里面是轮子的贴图:

<?xml version="1.0"?>
<robot>
  <!-- materials -->
  <gazebo reference="base_link">
    <material>Gazebo/Orange</material>
  </gazebo>

 <gazebo reference="wheel_1">
        <material>Gazebo/Green</material>
 </gazebo>

 <gazebo reference="wheel_2">
        <material>Gazebo/Black</material>
 </gazebo>

 <gazebo reference="wheel_3">
        <material>Gazebo/Black</material>
 </gazebo>

 <gazebo reference="wheel_4">
        <material>Gazebo/Black</material>
 </gazebo>

  <!-- ros_control plugin -->
  <gazebo>
    <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
      <robotNamespace>/robot</robotNamespace>

    </plugin>
  </gazebo>

  <!-- Link1 -->
  <gazebo reference="link1">
    <material>Gazebo/Orange</material>
  </gazebo>

  <!-- Link2 -->
  <gazebo reference="link2">
    <mu1>0.2</mu1>
    <mu2>0.2</mu2>
    <material>Gazebo/Black</material>
  </gazebo>

  <!-- Link3 -->
  <gazebo reference="link3">
    <mu1>0.2</mu1>
    <mu2>0.2</mu2>
    <material>Gazebo/Orange</material>
  </gazebo>

  <!-- camera_link -->
  <gazebo reference="camera_link">
    <mu1>0.2</mu1>
    <mu2>0.2</mu2>
    <material>Gazebo/Red</material>
  </gazebo>

  <!-- hokuyo -->
  <gazebo reference="hokuyo_link">
    <sensor type="ray" name="head_hokuyo_sensor">
      <pose>0 0 0 0 0 0</pose>
      <visualize>false</visualize>
      <update_rate>40</update_rate>
      <ray>
        <scan>
          <horizontal>
            <samples>720</samples>
            <resolution>1</resolution>
            <min_angle>-1.570796</min_angle>
            <max_angle>1.570796</max_angle>
          </horizontal>
        </scan>
        <range>
          <min>0.10</min>
          <max>30.0</max>
          <resolution>0.01</resolution>
        </range>
        <noise>
          <type>gaussian</type>
          <!-- Noise parameters based on published spec for Hokuyo laser
               achieving "+-30mm" accuracy at range < 10m.  A mean of 0.0m and
               stddev of 0.01m will put 99.7% of samples within 0.03m of the true
               reading. -->
          <mean>0.0</mean>
          <stddev>0.01</stddev>
        </noise>
      </ray>
      <plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_laser.so">
        <topicName>/robot/laser/scan</topicName>
        <frameName>hokuyo_link</frameName>
      </plugin>
    </sensor>
  </gazebo>

  <!-- camera -->
  <gazebo reference="camera_link">
    <sensor type="camera" name="camera1">
      <update_rate>30.0</update_rate>
      <camera name="head">
        <horizontal_fov>1.3962634</horizontal_fov>
        <image>
          <width>800</width>
          <height>800</height>
          <format>R8G8B8</format>
        </image>
        <clip>
          <near>0.02</near>
          <far>300</far>
        </clip>
        <noise>
          <type>gaussian</type>
          <!-- Noise is sampled independently per pixel on each frame.
               That pixel‘s noise value is added to each of its color
               channels, which at that point lie in the range [0,1]. -->
          <mean>0.0</mean>
          <stddev>0.007</stddev>
        </noise>
      </camera>
      <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
        <alwaysOn>true</alwaysOn>
        <updateRate>0.0</updateRate>
        <cameraName>robot/camera1</cameraName>
        <imageTopicName>image_raw</imageTopicName>
        <cameraInfoTopicName>camera_info</cameraInfoTopicName>
        <frameName>camera_link</frameName>
        <hackBaseline>0.07</hackBaseline>
        <distortionK1>0.0</distortionK1>
        <distortionK2>0.0</distortionK2>
        <distortionK3>0.0</distortionK3>
        <distortionT1>0.0</distortionT1>
        <distortionT2>0.0</distortionT2>
      </plugin>
    </sensor>
  </gazebo>  

</robot>
时间: 2024-10-12 17:51:47

ROS之Gazebo的相关文章

ROS和Gazebo进行机器人仿真(一)

Gazebo是一种多机器人仿真器,可用于室内外机器人仿真.Gazebo在ROS中有良好的接口,包含ROS和Gazebo的所有控制. 若要实现ROS到Gazebo的通信,我们必须安装ROS-Gazebo接口. 应该安装以下软件包: $ sudo apt install ros-melodic-gazebo-ros-pkgs  ros-melodic-gazebo-msgs  ros-melodic-gazebo-plugins  ros-melodic-gazebo-ros-control *ga

ROS Rviz Gazebo

今天找到了学习RVC的方法,在听video的时候,你看着pdf来跟上节奏,去理解,下课的时候再来matlab编程设计的思想,同时做下note笔记.对于gazebo其是建立在ros系统上的一个调节与控制机器人的控制软件,基于的是ros系统的:Rviz是另外一visualization可视化的工具.可以通过wiki来了解彼此的install以及用法.学习Rviz以及Gazebo的方法是需要不停地在网站上看wiki以及tutorial,同时你需要严格地熟悉ROS的教程,也就是网络上的tutorial,

ROS,Gazebo以及Rviz的启动以及环境设置问题

在基于linux上的ros,其需要注意环境变量,如下是ros gazebo以及rviz的启动方式. rosed baxter_tools enable_robot.py 使用默认的方式打开上述的.py文件,这个打开方式是在桌面的.bashrc里面进行修改,例如可以使用export EDITOR="emacs"这是表示一个新开的窗口,也可以使用"emacs -nw"表示不是新的窗口.此外,修改的bashrc原来的窗口source .bashrc;新开的窗口就是可以的.

ROS和Gazebo进行机器人仿真(二)

一.在Gazebo中使用ROS控制器 在本节中,我们将讨论如何在Gazebo中让机器人的每个关节运动. 为了让关节动起来,我们需要分配一个ROS控制器,尤其是,我们需要为每个关节连上一个与transmission标签内指定的硬件接口兼容的控制器. ROS控制器主要由一套反馈机构组成,可以接受某一设定点,并用执行机构的反馈控制输出. ROS控制器使用硬件接口与硬件交互,硬件接口的主要功能是充当ROS控制器与真实或仿真硬件之间的中介,根据ROS控制器生成的数据来分配 资源控制它. 在本机器人,我们定

ROS机器人程序设计(原书第2版)补充资料 (柒) 第七章 3D建模与仿真 urdf Gazebo V-Rep Webots Morse

ROS机器人程序设计(原书第2版)补充资料 (柒) 第七章 3D建模与仿真 urdf Gazebo V-Rep Webots Morse 书中,大部分出现hydro的地方,直接替换为indigo或jade或kinetic,即可在对应版本中使用. 提供ROS接口的3D软件比较多,本章以最典型的Gazebo介绍为主,从Player/Stage/Gazebo发展而来,现在独立的机器人仿真开发环境,目前2016年最新版本Gazebo7.1配合ROS(kinetic)使用. 补充内容:http://blo

Making my own Autonomous Robot in ROS / Gazebo

Day 1: Setting up ROS: Indigo OS: Ubuntu 14.04 OS: Gazebo 7.0.0 Initialize the workspace To create the basic skeleton of the directory structure, we begin with a workspace {WORKSPACE}_ws, where we set {WORKSPACE}=mybot. cd ~ mkdir -p mybot_ws/src cd

Gazebo機器人仿真學習探索筆記(三)機器人模型

gazebo_models:https://bitbucket.org/osrf/gazebo_models 模型庫下載,可以參考如下命令: ~/Rob_Soft/Gazebo7$ hg clone https://bitbucket.org/osrf/gazebo_models 下載更改目錄下載到指定文件夾中. 模型庫的結構 目錄 配置等可以參考官方文檔,注意model.sdf. 當然也可以將自己制作的模型上傳到庫中,文檔中也有具體說明. code$ hg clone https://[ema

Gazebo与ros_control(1):让模型动起来

不久前,师弟问了我一个问题:"师兄,我要控制一个机器人在仿真环境下运动,需要学什么,或者从哪里入手呢?" 这个问题不是那么好回答,urdf--tf--Gazebo--ros_control--MoveIt,这是我在十多天后才能给出的一个答案.那么之前我是怎么做仿真的呢? 1. 借助Arbotix舵机接口来仿真 之前是在学习<ros by example volume 2 >的时候,接触到一个rbx2_bringup 的package,仿照着里面的https://github

170111-机械臂gazebo基础

前言 依然是基础 参考 Mastering ROS for Robotics Programming.2015 学习记录 概述 需要安装以下包 sudo apt-get install ros-jade-gazebo-ros-pkgs ros-jade-gazeboros ros-jade-gazebo-msgs ros-jade-gazebo-plugins gazebo_ros_msgs: ROS包,为Gazebo提供ros方面的接口 gazebo-msgs: 为ros提供gazebo方面的